Project

General

Profile

Bug #3534 ยป hello.C

Florian Ransmayr, 08/26/2014 01:35 PM

 
1
#include <Wt/WApplication>
2
#include <Wt/WContainerWidget>
3
#include <Wt/WMenu>
4
#include <Wt/WStackedWidget>
5
#include <Wt/WTextArea>
6
#include <Wt/WBootstrapTheme>
7
#include <Wt/WImage>
8

    
9
using namespace Wt;
10

    
11
class HelloApplication : public WApplication
12
{
13
public:
14
    HelloApplication(const WEnvironment& env);
15

    
16
private:
17
    void konfigMenuItem(WMenuItem *menuItem);
18

    
19
    void mouseUp(const Wt::WMouseEvent &e);
20

    
21
private:
22
    WImage *m_dragImage;
23
    WTextArea *m_infoTextArea;
24
};
25

    
26
HelloApplication::HelloApplication(const WEnvironment& env)
27
    : WApplication(env), m_dragImage(0)
28
{
29
    setTitle("WMenu draggable + contextMenu");                               // application title
30

    
31
    WBootstrapTheme *theme = new WBootstrapTheme(this);
32
    theme->setVersion(WBootstrapTheme::Version3);
33
    setTheme(theme);
34

    
35
    // Create a stack where the contents will be located.
36
    Wt::WStackedWidget *contents = new Wt::WStackedWidget();
37

    
38
    Wt::WMenu *menu = new Wt::WMenu(contents, Wt::Vertical, root());
39
    menu->setStyleClass("nav nav-pills nav-stacked");
40
    menu->setWidth(150);
41

    
42
    WMenuItem *item = 0;
43
    // Add menu items using the default lazy loading policy.
44
    item = menu->addItem("Drag Me", new WTextArea("Draggable WMeniItem that should have right click context menu as well."));
45
    konfigMenuItem(item);
46
    item = menu->addItem("Drag Me 2", new WTextArea("Another draggable WMeniItem that should have right click context menu as well."));
47
    konfigMenuItem(item);
48

    
49
    root()->addWidget(contents);
50

    
51
    m_infoTextArea = new WTextArea("Drag the WMenuItems in the WMenu or right click on them." ,root());
52
}
53

    
54
void HelloApplication::konfigMenuItem(WMenuItem *menuItem)
55
{
56
    if( 0 == menuItem )
57
        return;
58

    
59
    if( 0 == m_dragImage )
60
    {
61
        m_dragImage = new Wt::WImage("resources/items-ok.gif", root());
62
        m_dragImage->hide();
63
    }
64

    
65
    //If the following line is remved the mouseWentUp signal is received.
66
    menuItem->setDraggable("test", m_dragImage, true);
67

    
68
    menuItem->setAttributeValue("oncontextmenu",
69
                                "event.cancelBubble = true; event.returnValue = false; return false;");
70
    menuItem->mouseWentUp().connect(this, &HelloApplication::mouseUp);
71
}
72

    
73
void HelloApplication::mouseUp(const Wt::WMouseEvent &e)
74
{
75
    //only react to right button clicks
76
    if( e.button() != WMouseEvent::RightButton )
77
        return;
78

    
79
    if( 0 != m_infoTextArea )
80
        m_infoTextArea->setText("MouseWentUp signal received.");
81

    
82
}
83

    
84
WApplication *createApplication(const WEnvironment& env)
85
{
86
    return new HelloApplication(env);
87
}
88

    
89
int main(int argc, char **argv)
90
{
91
    return WRun(argc, argv, &createApplication);
92
}
93

    
    (1-1/1)