Wt
3.2.1
|
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 &text, WWidget *contents, LoadPolicy policy=LazyLoading) | |
Creates a new item. | |
void | setText (const WString &text) |
Sets the text for this item. | |
const WString & | text () const |
Returns the text for this item. | |
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. | |
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. | |
void | setHidden (bool hidden) |
Sets whether the item widget is hidden. | |
bool | isHidden () const |
Returns whether the item widget is hidden. | |
void | hide () |
Hides the item widget. | |
void | show () |
Shows the item widget. | |
void | setDisabled (bool disabled) |
Enables or disables an item. | |
bool | isDisabled () const |
Returns whether an item is enabled. | |
void | enable () |
Enables the item. | |
void | disable () |
Disables the item. | |
void | setToolTip (const WString &tip) |
Sets a tooltip. | |
const WString & | toolTip () const |
Returns the tooltip. | |
WMenu * | menu () const |
Returns the menu. | |
WWidget * | contents () const |
Returns the contents widget for this item. | |
WWidget * | itemWidget () |
Returns the widget that represents the item. | |
void | select () |
Selects 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. | |
virtual SignalBase & | closeSignal () |
Returns the signal used to close the item. | |
virtual void | enableAjax () |
Progresses to an Ajax-enabled widget. |
A single item in a menu.
The item determines the look and behaviour of a single item in a WMenu.
By default, for enabled menu items a WMenuItem uses a WAnchor widget. For disabled menu items it uses a WText widget. If item is closeable, WMenuItem puts these widgets and extra WText widget (for a close icon) in a WContainerWidget. When the menu participates in application internal paths (see WMenu::setInternalPathEnabled()), the anchor references the bookmark URL corresponding to the pathComponent() for the item (see WApplication::bookmarkUrl()).
To provide another look for the menu items (such as perhaps adding an icon), you can specialize this class, and reimplement the virtual methods:
To provide another look for the close icon you can override Wt-closeicon
CSS class (see WMenu for more details).
Wt::WMenuItem::WMenuItem | ( | const WString & | text, |
WWidget * | contents, | ||
LoadPolicy | policy = LazyLoading |
||
) |
Creates a new item.
The text specifies the item text. The contents is the widget that must be shown in the WMenu contents stack when the item is selected.
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.
The pathComponent() is derived from text
, and can be customized using setPathComponent().
contents
may be 0, in which case no contents is associated with the item in the contents stack.
SignalBase & Wt::WMenuItem::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 in Wt::WSubMenuItem.
void Wt::WMenuItem::close | ( | ) |
Closes this item.
Hides the item widget and emits WMenu::itemClosed() signal. Only closeable items can be closed.
SignalBase & Wt::WMenuItem::closeSignal | ( | ) | [protected, virtual] |
Returns the signal used to close the item.
The default implementation will tries to cast the itemWidget() (or its second child if item is closeable) to a WInteractWidget and returns the clicked signal.
WWidget * Wt::WMenuItem::contents | ( | ) | const |
Returns the contents widget for this item.
The contents widget is the widget in the WStackedWidget associated with this item.
WWidget * Wt::WMenuItem::createItemWidget | ( | ) | [protected, virtual] |
Creates the widget that represents the item.
The default implementation will return:
A call to createItemWidget() is immediately followed by updateItemWidget().
If you reimplement this method, you should probably also reimplement updateItemWidget().
Reimplemented in Wt::WSubMenuItem.
void Wt::WMenuItem::disable | ( | ) |
void Wt::WMenuItem::enable | ( | ) |
void Wt::WMenuItem::enableAjax | ( | ) | [protected, 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 menu and the contents event handling to use AJAX instead of full page reloads.
You may want to reimplement this method if you want to make changes to widget when AJAX is enabled.
void Wt::WMenuItem::hide | ( | ) |
bool Wt::WMenuItem::isCloseable | ( | ) | const |
Returns whether the item is closeable.
bool Wt::WMenuItem::isDisabled | ( | ) | const |
Returns whether an item is enabled.
bool Wt::WMenuItem::isHidden | ( | ) | const |
Returns whether the item widget is hidden.
WWidget * Wt::WMenuItem::itemWidget | ( | ) |
Returns the widget that represents the item.
This returns the item widget, creating it using createItemWidget() if necessary.
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). Reimplemented in Wt::WSubMenuItem.
void Wt::WMenuItem::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 in Wt::WSubMenuItem.
void Wt::WMenuItem::select | ( | ) |
void Wt::WMenuItem::setCloseable | ( | bool | closeable | ) |
Make it possible to close this item interactively or by close().
void Wt::WMenuItem::setDisabled | ( | bool | disabled | ) |
void Wt::WMenuItem::setHidden | ( | bool | hidden | ) |
Sets whether the item widget is hidden.
Hides or show the item widget.
void Wt::WMenuItem::setPathComponent | ( | const std::string & | path | ) |
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::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().
void Wt::WMenuItem::setToolTip | ( | const WString & | tip | ) |
Sets a tooltip.
The tooltip is displayed when the cursor hovers over the label of the item, i.e. WAnchor or WText, depending on whether the item is enabled or not (see createItemWidget()).
void Wt::WMenuItem::show | ( | ) |
Shows the item widget.
If the item was previously closed it will be shown.
This calls setHidden(false).
void Wt::WMenuItem::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().
Reimplemented in Wt::WSubMenuItem.