Project

General

Profile

Bug #805 ยป Wt_menu_test.cc

WMenu Test Program - Anonymous, 04/29/2011 10:51 AM

 
/**
* Compile: g++ -o wt_menu Wt_menu_test.cc -lwt -lwthttp
* Run : /wt_menu --docroot . --http-address=localhost --http-port=4256
*/

#include <Wt/WApplication>
#include <Wt/WStackedWidget>
#include <Wt/WMenu>
#include <Wt/WText>
#include <Wt/WLogger>

class Wt_menu_test : public Wt::WApplication
{
public:
Wt_menu_test(const Wt::WEnvironment& env) :
Wt::WApplication(env)
{
setup();
}

~Wt_menu_test()
{
}

void setup()
{
// create content stack and menu
Wt::WStackedWidget* content_stack = new Wt::WStackedWidget();
Wt::WMenu* menu = new Wt::WMenu(content_stack, Wt::Vertical);
menu->addItem("items", new Wt::WText("content items"))->setPathComponent("items");
menu->addItem("item1", new Wt::WText("content item 1"))->setPathComponent("items/item1");
menu->addItem("item2", new Wt::WText("content item 2"))->setPathComponent("items2");
menu->addItem("other", new Wt::WText("content other"))->setPathComponent("other");
// make menu internal path aware
menu->setInternalPathEnabled("/");
// connect signal
menu->itemSelected().connect(this, &Wt_menu_test::item_selected);
root()->addWidget(menu);
root()->addWidget(content_stack);
}

private:

void item_selected(Wt::WMenuItem* item)
{
log("notice") << "item selected: " << item->text();
}

};

Wt::WApplication* create_application(const Wt::WEnvironment& env)
{
return new Wt_menu_test(env);
}

int main(int argc, char** argv)
{
return Wt::WRun(argc, argv, &create_application);
}

    (1-1/1)