|
#include <Wt/WApplication>
|
|
#include <Wt/WContainerWidget>
|
|
#include <Wt/WMenu>
|
|
#include <Wt/WSubMenuItem>
|
|
#include <Wt/WStackedWidget>
|
|
#include <Wt/WEnvironment>
|
|
#include <Wt/WText>
|
|
|
|
using namespace Wt;
|
|
|
|
class TestApplication : public WApplication
|
|
{
|
|
public:
|
|
TestApplication(const WEnvironment& env);
|
|
|
|
private:
|
|
void menuSelectionChanged(WMenuItem *);
|
|
void pathChanged(const std::string &path);
|
|
};
|
|
|
|
|
|
|
|
TestApplication::TestApplication(const WEnvironment& env)
|
|
: WApplication(env)
|
|
{
|
|
setTitle("Menu test"); // application title
|
|
|
|
// create the stack where the contents will be located
|
|
Wt::WStackedWidget *contents = new Wt::WStackedWidget();
|
|
|
|
// create a top-level menu
|
|
Wt::WMenu *menu = new Wt::WMenu(contents, Wt::Vertical);
|
|
menu->setRenderAsList(true);
|
|
menu->setStyleClass("mymenu");
|
|
menu->setInternalPathEnabled("/");
|
|
|
|
// add two plain items
|
|
menu->addItem("ItemA", new Wt::WText("<h2>A</h2>ItemA contents"))->setPathComponent("");
|
|
menu->addItem("ItemB", new Wt::WText("<h2>B</h2>ItemB contents"));
|
|
|
|
// add an item with a sub menu
|
|
Wt::WSubMenuItem *itemC = new Wt::WSubMenuItem("ItemC", new Wt::WText("<h2>C</h2>ItemC contents"));
|
|
Wt::WMenu *itemCsub = new Wt::WMenu(contents, Wt::Vertical);
|
|
itemCsub->setRenderAsList(true);
|
|
itemCsub->setInternalPathEnabled("itemc/");
|
|
itemCsub->addItem("ItemC1", new Wt::WText("<h2>C1</h2>ItemC1 contents"));
|
|
itemCsub->addItem("ItemC2", new Wt::WText("<h2>C2</h2>ItemC2 contents"));
|
|
itemCsub->addItem("ItemC3", new Wt::WText("<h2>C3</h2>ItemC3 contents"));
|
|
itemC->setSubMenu(itemCsub);
|
|
menu->addItem(itemC);
|
|
|
|
// add an item with a sub menu
|
|
Wt::WSubMenuItem *itemD = new Wt::WSubMenuItem("ItemD", new Wt::WText("<h2>D</h2>ItemD contents"));
|
|
Wt::WMenu *itemDsub = new Wt::WMenu(contents, Wt::Vertical);
|
|
itemDsub->setRenderAsList(true);
|
|
itemDsub->setInternalPathEnabled("itemd/");
|
|
itemDsub->addItem("ItemD1", new Wt::WText("<h2>D1</h2>ItemD1 contents"));
|
|
itemDsub->addItem("ItemD2", new Wt::WText("<h2>D2</h2>ItemD2 contents"));
|
|
itemD->setSubMenu(itemDsub);
|
|
menu->addItem(itemD);
|
|
|
|
// add plain item
|
|
menu->addItem("ItemE", new Wt::WText("<h2>E</h2>ItemE contents"));
|
|
|
|
// signal connections
|
|
menu->itemSelected().connect(this, &TestApplication::menuSelectionChanged);
|
|
itemCsub->itemSelected().connect(this, &TestApplication::menuSelectionChanged);
|
|
itemDsub->itemSelected().connect(this, &TestApplication::menuSelectionChanged);
|
|
internalPathChanged().connect(this, &TestApplication::pathChanged);
|
|
|
|
// add menu and its contents to root container
|
|
root()->addWidget(menu);
|
|
root()->addWidget(new WText("<hr/>"));
|
|
root()->addWidget(contents);
|
|
|
|
}
|
|
|
|
void TestApplication::menuSelectionChanged(WMenuItem *item)
|
|
{
|
|
Wt::log("test") << item->text();
|
|
}
|
|
|
|
void TestApplication::pathChanged(const std::string &path)
|
|
{
|
|
Wt::log("test") << path;
|
|
}
|
|
|
|
|
|
WApplication *createApplication(const WEnvironment& env)
|
|
{
|
|
return new TestApplication(env);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return WRun(argc, argv, &createApplication);
|
|
}
|
|
|