Public Member Functions | |
WSubMenuItem (const WString &text, WWidget *contents, LoadPolicy policy=LazyLoading) | |
Create a new item. | |
void | setSubMenu (WMenu *subMenu) |
Set a sub menu. | |
WMenu * | subMenu () |
Return the sub menu. | |
Protected Member Functions | |
virtual WWidget * | createItemWidget () |
Create the widget that represents the item. | |
virtual void | updateItemWidget (WWidget *itemWidget) |
Update the widget that represents the item. | |
virtual void | renderSelected (bool selected) |
Render the item as selected or unselected. | |
virtual SignalBase & | activateSignal () |
Returns the signal used to activate the item. |
This class specializes menu item to have an optional sub menu.
When the item is shown and hidden when the item is selected respectively deselected.
Usage example:
// 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); // add two plain items menu->addItem("Introduction", new Wt::WText(tr("intro")); menu->addItem("Download", new Wt::WText("Not yet available")); // add an item with a sub menu Wt::WSubMenuItem *examples = new Wt::WSubMenuItem("Examples", new Wt::WText(tr("examples"))); Wt::WMenu *examplesMenu = new Wt::WMenu(contents, Wt::Vertical); examplesMenu->addItem("Hello world", new Wt::WText(tr("example.hello-world"))); examplesMenu->addItem("Shopping cart", new Wt::WText(tr("example.shopping"))); examples->setSubMenu(examplesMenu); menu->addItem(examples); addWidget(menu); addWidget(contents);
Wt::WSubMenuItem::WSubMenuItem | ( | const WString & | text, | |
WWidget * | contents, | |||
LoadPolicy | policy = LazyLoading | |||
) |
void Wt::WSubMenuItem::setSubMenu | ( | WMenu * | subMenu | ) |
Set a sub menu.
Ownership of the subMenu
is transferred to the item. In most cases, the sub menu would use the same contents stack as the parent menu.
The default submenu is 0
, in which case the item behaves as a plain WMenuItem.
WMenu* Wt::WSubMenuItem::subMenu | ( | ) | [inline] |
WWidget * Wt::WSubMenuItem::createItemWidget | ( | ) | [protected, virtual] |
Create the widget that represents the item.
The default implementation will simply return a WAnchor. A call to createItemWidget() is immediately followed by updateItemWidget().
If you reimplement this method, you should probably also reimplement updateItemWidget().
Reimplemented from Wt::WMenuItem.
void Wt::WSubMenuItem::updateItemWidget | ( | WWidget * | itemWidget | ) | [protected, virtual] |
Update the widget that represents the item.
The default implementation will cast the itemWidget
to a WAnchor, and set the anchor's text and destination according to text() and pathComponent().
Reimplemented from Wt::WMenuItem.
void Wt::WSubMenuItem::renderSelected | ( | bool | selected | ) | [protected, virtual] |
Render the item as selected or unselected.
The default implementation sets the styleclass for itemWidget() to 'item' for an unselected, and 'itemselected' for a selected item.
Note that this method is called from within a stateless slot implementation, and thus should be stateless as well.
Reimplemented from Wt::WMenuItem.
SignalBase & Wt::WSubMenuItem::activateSignal | ( | ) | [protected, virtual] |
Returns the signal used to activate the item.
The default implementation will tries to cast the itemWidget() to a WInteractWidget and returns the clicked signal.
Reimplemented from Wt::WMenuItem.