Project

General

Profile

WMenu itemSelected not getting called for first menu item ยป WtMenuStackApp.h

Stas Magill, 07/23/2015 12:04 PM

 

#ifndef WTTEST_WTMENUSTACKAPP_H
#define WTTEST_WTMENUSTACKAPP_H

#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WStackedWidget>
#include <Wt/WMenu>
#include <Wt/WHBoxLayout>
#include <Wt/WVBoxLayout>
#include <Wt/WText>

using namespace Wt;

class WtMenuStackApp : public WApplication
{
public:
WtMenuStackApp(const WEnvironment& in_env) :
WApplication(in_env)
{
setTitle("WtTest");
useStyleSheet("css/wt/wttest.css");

WContainerWidget* divContent= new WContainerWidget();

WStackedWidget* contents= new WStackedWidget();

WMenu* menu= new WMenu(contents, Vertical);
menu->setInternalPathEnabled("/");
menu->itemSelected().connect(this, &WtMenuStackApp::menuChanged);

/////// menuChanged gets called for first item if I add it here

WHBoxLayout* hLayout= new WHBoxLayout();
hLayout->setContentsMargins(0, 0, 0, 0);
hLayout->addWidget(menu, 0);
hLayout->addWidget(contents, 1);
divContent->setLayout(hLayout);

WVBoxLayout* vLayout = new WVBoxLayout(root());
vLayout->setContentsMargins(0, 0, 0, 0);
vLayout->addWidget(divContent);

/////// menuChanged does not get called for first item if I add it here

WContainerWidget* c1= new WContainerWidget(contents);
for (int i= 0; i < 10; i++)
{
new WText("Some text for item 1", c1);
new WBreak(c1);
}
menu->addItem("Item 1", c1, WMenuItem::PreLoading);

WContainerWidget* c2= new WContainerWidget(contents);
for (int i= 0; i < 10; i++)
{
new WText("Some text for item 2", c2);
new WBreak(c2);
}
menu->addItem("Item 2", c2, WMenuItem::PreLoading);
}


private:
void menuChanged(WMenuItem* menu)
{
std::cout<<"MENU CHANGED "<<menu->text()<<"\n";
}
};

#endif
    (1-1/1)