Project

General

Profile

Bug #1647 ยป popup_in_nonmodal_dialog.cpp

Max Quatember, 01/29/2013 10:00 AM

 
#include <Wt/WTableView>
#include <Wt/WStandardItemModel>

namespace
{
class DiaNonModal
: public Wt::WDialog
{
public:
DiaNonModal()
: Wt::WDialog()
{
rejectWhenEscapePressed();
setClosable( true );
setModal( false );

contents()->setAttributeValue( "oncontextmenu", "event.cancelBubble = true; event.returnValue = false; return false;" );
auto table = new Wt::WTableView( contents() );
table->setSelectionBehavior( Wt::SelectRows );
table->setSelectionMode( Wt::SingleSelection );
table->mouseWentUp().connect( SLOT( this, DiaNonModal::OnMouseWentUp ) );

auto model = new Wt::WStandardItemModel( 0, 2 );
model->setHeaderData( 0, boost::any( std::string( "1" ) ) );
model->setHeaderData( 1, boost::any( std::string( "2" ) ) );
model->insertRows( model->rowCount(), 1 );
model->setData( model->rowCount() - 1, 0, boost::any( std::string( "" ) ) );
model->setData( model->rowCount() - 1, 1, boost::any( std::string( "right click" ) ) );
table->setModel( model );
}
void OnMouseWentUp( const Wt::WModelIndex& i, const Wt::WMouseEvent& e )
{
auto popup = new Wt::WPopupMenu;
popup->addItem( "dialog disapeared..." );
popup->popup( e );
}
};
class TestNonModal
: public Wt::WApplication
{
public:
TestNonModal( const Wt::WEnvironment& env )
: Wt::WApplication( env )
{
auto button = new Wt::WPushButton( "click" );
root()->addWidget( button );
button->clicked().connect( [&]( const Wt::WMouseEvent& e )
{
( new DiaNonModal() )->exec();
});
}
};
}
    (1-1/1)