Wt: Wt::WSubMenuItem Class Reference

Wt 3.2.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions
Wt::WSubMenuItem Class Reference

A menu item that contains a nested sub menu. More...

Inheritance diagram for Wt::WSubMenuItem:
[legend]

List of all members.

## Public Member Functions
| WSubMenuItem (const WString &text, WWidget *contents, LoadPolicy policy=LazyLoading)
| Creates a new item.
void | setSubMenu (WMenu *subMenu)
| Sets a sub menu.
WMenu * | subMenu ()
| Returns the sub menu.
virtual std::string | pathComponent () const
| Returns the path component for this item.
## Protected Member Functions
virtual WWidget * | createItemWidget ()
| Creates the widget that represents the item.
virtual void | updateItemWidget (WWidget *itemWidget)
| Updates the widget that represents the item.
virtual void | renderSelected (bool selected)
| Renders the item as selected or unselected.
virtual SignalBase & | activateSignal ()
| Returns the signal used to activate the item.

## Detailed Description

A menu item that contains a nested sub menu.

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);

See also:
  WMenuItem, WMenu

## Constructor & Destructor Documentation

Wt::WSubMenuItem::WSubMenuItem | ( | const WString & | text,
|  | WWidget * | contents,
|  | LoadPolicy | policy = `LazyLoading`
| ) |  |

Creates a new item.

See also:
  WMenuItem::WMenuItem(const WString&, WWidget *, LoadPolicy)

## Member Function Documentation

SignalBase & Wt::WSubMenuItem::activateSignal | ( |  | ) | `[protected, virtual]`

Returns the signal used to activate the item.

The default implementation will tries to cast the itemWidget() or its first child if item is closeable to a WInteractWidget and returns the clicked signal.

Reimplemented from Wt::WMenuItem.

WWidget * Wt::WSubMenuItem::createItemWidget | ( |  | ) | `[protected, virtual]`

Creates the widget that represents the item.

The default implementation will return:

- a WAnchor if item is not closeable and enabled;
- a WText if item is not closeable and disabled;
- a WContainerWidget with WAnchor or WText (the label of enabled or disabled item accordingly) and WText (the close icon) inside if item is closeable.

A call to createItemWidget() is immediately followed by updateItemWidget().

If you reimplement this method, you should probably also reimplement updateItemWidget().

Reimplemented from Wt::WMenuItem.

std::string Wt::WSubMenuItem::pathComponent | ( |  | ) | const`[virtual]`

Returns the path component for this item.

You may want to reimplement this to customize the path component set by the item in the application internal path.

See also:
  setPathComponent()

Note:
  the `path` component is UTF8 encoded (we may fix the API to use WString in the future).

Reimplemented from Wt::WMenuItem.

void Wt::WSubMenuItem::renderSelected | ( | bool | selected | ) | `[protected, virtual]`

Renders the item as selected or unselected.

The default implementation sets the styleclass for itemWidget() to 'item' for an unselected not closeable, 'itemselected' for selected not closeable, 'citem' for an unselected closeable and 'citemselected' for selected closeable item.

Note that this method is called from within a stateless slot implementation, and thus should be stateless as well.

Reimplemented from Wt::WMenuItem.

void Wt::WSubMenuItem::setSubMenu | ( | WMenu * | subMenu | ) |

Sets 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.

Note:
  A sub menu can only be set before the item is added to a menu.

WMenu* Wt::WSubMenuItem::subMenu | ( |  | ) |

Returns the sub menu.

See also:
  setSubMenu()

void Wt::WSubMenuItem::updateItemWidget | ( | WWidget * | itemWidget | ) | `[protected, virtual]`

Updates 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().

See also:
  createItemWidget()

Reimplemented from Wt::WMenuItem.

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator