A single item in a menu. More...

Public Types | |
| enum | LoadPolicy { LazyLoading, PreLoading } |
| Enumeration that determines when contents should be loaded. More... | |
Public Member Functions | |
| WMenuItem (const WString &label, WWidget *contents=0, LoadPolicy policy=LazyLoading) | |
| Creates a new item with given label. | |
| void | setText (const WString &text) |
| Sets the text for this item. | |
| const WString & | text () const |
| Returns the text for this item. | |
| void | setIcon (const std::string &path) |
| Sets the item icon path. | |
| std::string | icon () const |
| Returns the item icon path. | |
| void | setCheckable (bool checkable) |
| Sets if the item is checkable. | |
| bool | isCheckable () const |
| Returns whether the item is checkable. | |
| virtual void | setPathComponent (const std::string &path) |
| Sets the path component for this item. | |
| virtual std::string | pathComponent () const |
| Returns the path component for this item. | |
| virtual void | setInternalPathEnabled (bool enabled) |
| Configures internal path support for the item. | |
| virtual bool | internalPathEnabled () const |
| Returns whether an item participates in internal paths. | |
| void | setLink (const WLink &link) |
| Sets the associated link. | |
| WLink | link () const |
| Returns the associated link. | |
| void | setLinkTarget (AnchorTarget target) |
| Sets the link target. | |
| AnchorTarget | linkTarget () const |
| Returns the link target. | |
| void | setMenu (WMenu *menu) |
| Sets a sub menu. | |
| void | setSubMenu (WMenu *menu) |
| Sets a sub menu (deprecated) | |
| WMenu * | menu () const |
| Returns the submenu. | |
| void | setChecked (bool checked) |
| Sets the checked state. | |
| bool | isChecked () const |
| Returns the checked state. | |
| void | setSelectable (bool selectable) |
| Sets whether the menu item can be selected. | |
| bool | isSelectable () const |
| Returns whether the menu item can be selected. | |
| void | setData (void *data) |
| Sets associated additional data with the item. | |
| void * | data () const |
| Returns additional data of the item. | |
| WCheckBox * | checkBox () const |
| Returns the checkbox for a checkable item. | |
| void | setCloseable (bool closeable) |
| Make it possible to close this item interactively or by close(). | |
| bool | isCloseable () const |
| Returns whether the item is closeable. | |
| void | close () |
| Closes this item. | |
| WMenu * | parentMenu () const |
| Returns the menu that contains this item. | |
| void | setContents (WWidget *contents, LoadPolicy policy=LazyLoading) |
| Sets the contents widget for this item. | |
| WWidget * | contents () const |
| Returns the contents widget for this item. | |
| WWidget * | itemWidget () |
| Returns the widget that represents the item (deprecated). | |
| void | select () |
| Selects this item. | |
| Signal< WMenuItem * > & | triggered () |
| Signal emitted when an item is activated. | |
| bool | isSeparator () const |
| Returns whether this item is a separator. | |
| bool | isSectionHeader () const |
| Returns whether this item is a section header. | |
| WAnchor * | anchor () const |
| Returns the anchor of this menu item. | |
| virtual void | renderSelected (bool selected) |
| Renders the item as selected or unselected. | |
| virtual void | enableAjax () |
| Progresses to an Ajax-enabled widget. | |
| virtual void | setHidden (bool hidden, const WAnimation &animation=WAnimation()) |
| Hides or shows the widget. | |
| virtual void | setDisabled (bool disabled) |
| Sets whether the widget is disabled. | |
Protected Member Functions | |
| virtual void | render (WFlags< RenderFlag > flags) |
| Renders the widget. | |
A single item in a menu.
Since Wt 3.3.0, this item is now a proper widget, which renders a single item in a menu.
An optional contents item can be associated with a menu item, which is inserted and shown in the widget stack of the menu to which this menu item belongs.
A menu item renders as a >li&;lt with additional markup/style classes provided by the theme. Unless you use the bootstrap theme, you will need to provide appropriate CSS.
| Wt::WMenuItem::WMenuItem | ( | const WString & | label, |
| WWidget * | contents = 0, |
||
| LoadPolicy | policy = LazyLoading |
||
| ) |
Creates a new item with given label.
The optional contents is a widget that will be shown in the WMenu contents stack when the item is selected. For this widget, a load policy specifies whether the contents widgets is transmitted only when it the item is activated for the first time (LazyLoading) or transmitted prior to first rendering.
If the menu supports internal path navigation, then a default pathComponent() will be derived from the label, and can be customized using setPathComponent().
| WAnchor * Wt::WMenuItem::anchor | ( | ) | const |
Returns the anchor of this menu item.
Can be used to add widgets to the menu.
| WCheckBox* Wt::WMenuItem::checkBox | ( | ) | const |
Returns the checkbox for a checkable item.
| void Wt::WMenuItem::close | ( | ) |
Closes this item.
Hides the item widget and emits WMenu::itemClosed() signal. Only closeable items can be closed.
| WWidget * Wt::WMenuItem::contents | ( | ) | const |
Returns the contents widget for this item.
| void* Wt::WMenuItem::data | ( | ) | const |
Returns additional data of the item.
| void Wt::WMenuItem::enableAjax | ( | ) | [virtual] |
Progresses to an Ajax-enabled widget.
This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.
You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.
Reimplemented from Wt::WWebWidget.
| std::string Wt::WMenuItem::icon | ( | ) | const |
Returns the item icon path.
| bool Wt::WMenuItem::internalPathEnabled | ( | ) | const [virtual] |
Returns whether an item participates in internal paths.
| bool Wt::WMenuItem::isCheckable | ( | ) | const |
Returns whether the item is checkable.
| bool Wt::WMenuItem::isChecked | ( | ) | const |
Returns the checked state.
This is only used when isCheckable() == true.
| bool Wt::WMenuItem::isCloseable | ( | ) | const |
Returns whether the item is closeable.
| bool Wt::WMenuItem::isSectionHeader | ( | ) | const |
Returns whether this item is a section header.
| bool Wt::WMenuItem::isSelectable | ( | ) | const |
Returns whether the menu item can be selected.
| bool Wt::WMenuItem::isSeparator | ( | ) | const |
Returns whether this item is a separator.
Returns the widget that represents the item (deprecated).
This returns this.
| WLink Wt::WMenuItem::link | ( | ) | const |
Returns the associated link.
| AnchorTarget Wt::WMenuItem::linkTarget | ( | ) | const |
Returns the link target.
| WMenu* Wt::WMenuItem::menu | ( | ) | const |
Returns the submenu.
| std::string Wt::WMenuItem::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.
path component is UTF8 encoded (we may fix the API to use WString in the future). | void Wt::WMenuItem::render | ( | WFlags< RenderFlag > | flags | ) | [protected, virtual] |
Renders the widget.
This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().
The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
Reimplemented from Wt::WWebWidget.
| void Wt::WMenuItem::renderSelected | ( | bool | selected | ) | [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.
| void Wt::WMenuItem::select | ( | ) |
| void Wt::WMenuItem::setCheckable | ( | bool | checkable | ) |
Sets if the item is checkable.
When an item is checkable, a checkbox is displayed to the left of the item text (instead of an icon).
| void Wt::WMenuItem::setChecked | ( | bool | checked | ) |
Sets the checked state.
This is only used when isCheckable() == true.
| void Wt::WMenuItem::setCloseable | ( | bool | closeable | ) |
Make it possible to close this item interactively or by close().
| void Wt::WMenuItem::setContents | ( | WWidget * | contents, |
| LoadPolicy | policy = LazyLoading |
||
| ) |
Sets the contents widget for this item.
The contents is a widget that will be shown in the WMenu contents stack when the item is selected. For this widget, the load policy specifies whether the contents widgets is transmitted only when it the item is activated for the first time (LazyLoading) or transmitted prior to first rendering.
| void Wt::WMenuItem::setData | ( | void * | data | ) |
Sets associated additional data with the item.
You can use this to associate model information with a menu item.
| void Wt::WMenuItem::setDisabled | ( | bool | disabled | ) | [virtual] |
Sets whether the widget is disabled.
Enables or disables the widget (including all its descendant widgets). setDisabled(false) will enable this widget and all descendant widgets that are not disabled. A widget is only enabled if it and all its ancestors in the widget tree are disabled.
Typically, a disabled form widget will not allow changing the value, and disabled widgets will not react to mouse click events.
Reimplemented from Wt::WWebWidget.
| void Wt::WMenuItem::setHidden | ( | bool | hidden, |
| const WAnimation & | animation = WAnimation() |
||
| ) | [virtual] |
Hides or shows the widget.
Hides or show the widget (including all its descendant widgets). When setting hidden = false, this widget and all descendant widgets that are not hidden will be shown. A widget is only visible if it and all its ancestors in the widget tree are visible, which may be checked using isVisible().
Reimplemented from Wt::WWebWidget.
| void Wt::WMenuItem::setIcon | ( | const std::string & | path | ) |
| void Wt::WMenuItem::setInternalPathEnabled | ( | bool | enabled | ) | [virtual] |
Configures internal path support for the item.
This configures whether the item supports internal paths (in a menu which supports internal paths).
The default value is true for all items but section headers and separators.
| void Wt::WMenuItem::setLink | ( | const WLink & | link | ) |
Sets the associated link.
| void Wt::WMenuItem::setLinkTarget | ( | AnchorTarget | target | ) |
Sets the link target.
| void Wt::WMenuItem::setMenu | ( | WMenu * | menu | ) |
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.
| void Wt::WMenuItem::setPathComponent | ( | const std::string & | path | ) | [virtual] |
Sets the path component for this item.
The path component is used by the menu item in the application internal path (see WApplication::setInternalPath()), when internal paths are enabled (see WMenu::setInternalPathEnabled()) for the menu.
You may specify an empty path to let a menu item be the "default" menu option.
For example, if WMenu::internalBasePath() is "/examples/" and pathComponent() for is "charts/", then the internal path for the item will be "/examples/charts/".
By default, the path is automatically derived from text(). If a literal text is used, the path is based on the text itself, otherwise on the key. It is converted to lower case, and replacing white space and special characters with '_'.
path should be UTF8 encoded (we may fix the API to use WString in the future). | void Wt::WMenuItem::setSelectable | ( | bool | selectable | ) | [virtual] |
Sets whether the menu item can be selected.
Only a menu item that can be selected can be the result of a popup menu selection.
The default value is true for a normal menu item, and false for a menu item that has a submenu.
An item that is selectable but is disabled can still not be selected.
Reimplemented from Wt::WWebWidget.
| void Wt::WMenuItem::setSubMenu | ( | WMenu * | menu | ) |
Sets a sub menu (deprecated)
| void Wt::WMenuItem::setText | ( | const WString & | text | ) |
Sets the text for this item.
Unless a custom path component was defined, the pathComponent() is also updated based on the new text.
The item widget is updated using updateItemWidget().
| const WString & Wt::WMenuItem::text | ( | ) | const |
Returns the text for this item.
| Signal<WMenuItem *>& Wt::WMenuItem::triggered | ( | ) |
Signal emitted when an item is activated.
Returns this item as argument.
1.7.6.1