Project

General

Profile

Bug #3018 ยป main.cpp

minimal test program - Will Johnson, 04/28/2014 10:47 AM

 
#include <iostream>

#include <Wt/WText>
#include <Wt/WMenuItem>
#include <Wt/WPopupMenu>
#include <Wt/WPushButton>
#include <Wt/WApplication>
#include <Wt/WContainerWidget>


class MinimalWtApp : public Wt::WApplication
{
public:
MinimalWtApp(const Wt::WEnvironment& env)
: Wt::WApplication(env)
{
setTitle("MinimalWtApp");
Wt::WPushButton *button = new Wt::WPushButton( "Menu", domRoot() );
button->setInline( false );
Wt::WPopupMenu *menu = new Wt::WPopupMenu();
menu->setAutoHide( true, 250 );
button->setMenu( menu );
button->mouseWentOver().connect( boost::bind( &Wt::WPopupMenu::popup, menu, button, Wt::Vertical ) );
//Adding a checkable item to the main menu works fine; the
// c++ WMenuItem::isChecked() reflects the browser
Wt::WMenuItem *item = new Wt::WMenuItem( "Main Menu Item" );
menu->addItem( item );
item->setCheckable( true );
item->triggered().connect( this, &MinimalWtApp::addStatus );
Wt::WPopupMenu *submenu = new Wt::WPopupMenu();
menu->addMenu( "Sub Menu", submenu );
//Adding a checkable item to the submenu doesnt work; the
// c++ WMenuItem::isChecked() does not reflect the browser
item = new Wt::WMenuItem( "Sub Item 1" );
submenu->addItem( item );
item->setCheckable( true );
item->triggered().connect( this, &MinimalWtApp::addStatus );
item = new Wt::WMenuItem( "Sub Item 2" );
submenu->addItem( item );
item->setCheckable( true );
item->triggered().connect( this, &MinimalWtApp::addStatus );
item = new Wt::WMenuItem( "Sub Item 3" );
submenu->addItem( item );
item->setCheckable( true );
item->triggered().connect( this, &MinimalWtApp::addStatus );
}//MinimalWtApp constructor
virtual ~MinimalWtApp()
{
}

protected:
void addStatus( Wt::WMenuItem *item )
{
Wt::WString txt = item->text() + (item->isChecked() ? ": Checked" : ": Not Checked");
if( item->text().narrow().find("Main") != std::string::npos )
txt += " (this should be correct)";
else
txt += " (this should be wrong, give it a check)";
Wt::WText *t = new Wt::WText( txt, domRoot() );
t->setInline( false );
}//void addStatus( Wt::WMenuItem *item )
};//class MinimalWtApp


Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
return new MinimalWtApp(env);
}

int main(int argc, char **argv)
{
std::cout << "WT_VERSION=" << std::hex << WT_VERSION << std::endl;
return WRun(argc, argv, &createApplication);
}

    (1-1/1)