|
#include <Wt/WApplication>
|
|
#include <Wt/WContainerWidget>
|
|
#include <Wt/WMenu>
|
|
#include <Wt/WStackedWidget>
|
|
#include <Wt/WTextArea>
|
|
#include <Wt/WBootstrapTheme>
|
|
#include <Wt/WImage>
|
|
|
|
using namespace Wt;
|
|
|
|
class HelloApplication : public WApplication
|
|
{
|
|
public:
|
|
HelloApplication(const WEnvironment& env);
|
|
|
|
private:
|
|
void konfigMenuItem(WMenuItem *menuItem);
|
|
|
|
void mouseUp(const Wt::WMouseEvent &e);
|
|
|
|
private:
|
|
WImage *m_dragImage;
|
|
WTextArea *m_infoTextArea;
|
|
};
|
|
|
|
HelloApplication::HelloApplication(const WEnvironment& env)
|
|
: WApplication(env), m_dragImage(0)
|
|
{
|
|
setTitle("WMenu draggable + contextMenu"); // application title
|
|
|
|
WBootstrapTheme *theme = new WBootstrapTheme(this);
|
|
theme->setVersion(WBootstrapTheme::Version3);
|
|
setTheme(theme);
|
|
|
|
// Create a stack where the contents will be located.
|
|
Wt::WStackedWidget *contents = new Wt::WStackedWidget();
|
|
|
|
Wt::WMenu *menu = new Wt::WMenu(contents, Wt::Vertical, root());
|
|
menu->setStyleClass("nav nav-pills nav-stacked");
|
|
menu->setWidth(150);
|
|
|
|
WMenuItem *item = 0;
|
|
// Add menu items using the default lazy loading policy.
|
|
item = menu->addItem("Drag Me", new WTextArea("Draggable WMeniItem that should have right click context menu as well."));
|
|
konfigMenuItem(item);
|
|
item = menu->addItem("Drag Me 2", new WTextArea("Another draggable WMeniItem that should have right click context menu as well."));
|
|
konfigMenuItem(item);
|
|
|
|
root()->addWidget(contents);
|
|
|
|
m_infoTextArea = new WTextArea("Drag the WMenuItems in the WMenu or right click on them." ,root());
|
|
}
|
|
|
|
void HelloApplication::konfigMenuItem(WMenuItem *menuItem)
|
|
{
|
|
if( 0 == menuItem )
|
|
return;
|
|
|
|
if( 0 == m_dragImage )
|
|
{
|
|
m_dragImage = new Wt::WImage("resources/items-ok.gif", root());
|
|
m_dragImage->hide();
|
|
}
|
|
|
|
//If the following line is remved the mouseWentUp signal is received.
|
|
menuItem->setDraggable("test", m_dragImage, true);
|
|
|
|
menuItem->setAttributeValue("oncontextmenu",
|
|
"event.cancelBubble = true; event.returnValue = false; return false;");
|
|
menuItem->mouseWentUp().connect(this, &HelloApplication::mouseUp);
|
|
}
|
|
|
|
void HelloApplication::mouseUp(const Wt::WMouseEvent &e)
|
|
{
|
|
//only react to right button clicks
|
|
if( e.button() != WMouseEvent::RightButton )
|
|
return;
|
|
|
|
if( 0 != m_infoTextArea )
|
|
m_infoTextArea->setText("MouseWentUp signal received.");
|
|
|
|
}
|
|
|
|
WApplication *createApplication(const WEnvironment& env)
|
|
{
|
|
return new HelloApplication(env);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return WRun(argc, argv, &createApplication);
|
|
}
|
|
|