1
|
#include <Wt/WApplication.h>
|
2
|
#include <Wt/WContainerWidget.h>
|
3
|
#include <Wt/WEnvironment.h>
|
4
|
#include <Wt/WPopupMenu.h>
|
5
|
#include <Wt/WPushButton.h>
|
6
|
|
7
|
class TestPopupSubMenu
|
8
|
: public Wt::WApplication
|
9
|
{
|
10
|
public:
|
11
|
TestPopupSubMenu( const Wt::WEnvironment& env )
|
12
|
: Wt::WApplication( env )
|
13
|
{
|
14
|
root()->addNew< Wt::WPushButton >( "show WPopupMenu - Example from Reference" )
|
15
|
->mouseWentUp().connect( this, &TestPopupSubMenu::ShowPopupMenuReferenceExample );
|
16
|
|
17
|
root()->addNew< Wt::WPushButton >( "show WPopupMenu - Custom example" )
|
18
|
->mouseWentUp().connect( this, &TestPopupSubMenu::ShowPopupMenuCustom );
|
19
|
}
|
20
|
|
21
|
void ShowPopupMenuReferenceExample( const Wt::WMouseEvent& me )
|
22
|
{
|
23
|
Wt::WPopupMenu popup;
|
24
|
popup.addItem("Item 1")->setCheckable(true);
|
25
|
popup.addItem("Item 2");
|
26
|
|
27
|
auto subMenu = std::make_unique<Wt::WPopupMenu>();
|
28
|
subMenu->addItem("Sub Item 1");
|
29
|
subMenu->addItem("Sub Item 2");
|
30
|
popup.addMenu("Item 3", std::move(subMenu))->setSelectable( true );
|
31
|
|
32
|
popup.exec( me );
|
33
|
}
|
34
|
|
35
|
std::unique_ptr< Wt::WMenuItem > MenuItem( std::string text, bool checkable = false )
|
36
|
{
|
37
|
auto w = std::make_unique< Wt::WMenuItem >( text );
|
38
|
w->setCheckable( checkable );
|
39
|
return w;
|
40
|
}
|
41
|
std::unique_ptr< Wt::WMenuItem > MenuItem( std::string text, std::unique_ptr< Wt::WPopupMenu > subMenu )
|
42
|
{
|
43
|
auto w = MenuItem( text, false );
|
44
|
w->setMenu( std::move( subMenu ) );
|
45
|
w->setSelectable( true );
|
46
|
return w;
|
47
|
}
|
48
|
std::unique_ptr< Wt::WPopupMenu > CreateExampleMenu()
|
49
|
{
|
50
|
auto popup = std::make_unique< Wt::WPopupMenu >();
|
51
|
popup->addItem( MenuItem( "Item 1", true ) );
|
52
|
popup->addItem( MenuItem( "Item 2" ) );
|
53
|
|
54
|
auto subMenu1 = std::make_unique< Wt::WPopupMenu >();
|
55
|
subMenu1->addItem( MenuItem( "Sub Item 1" ) );
|
56
|
subMenu1->addItem( MenuItem( "Sub Item 2" ) );
|
57
|
popup->addItem( MenuItem( "Item 3", std::move( subMenu1 ) ) );
|
58
|
|
59
|
return popup;
|
60
|
}
|
61
|
void ShowPopupMenuCustom( const Wt::WMouseEvent& me )
|
62
|
{
|
63
|
auto p = root()->addChild( CreateExampleMenu() );
|
64
|
p->exec( me );
|
65
|
root()->removeChild( p );
|
66
|
}
|
67
|
};
|