Wt  3.2.2
Public Types | Public Member Functions | Protected Member Functions
Wt::WMenuItem Class Reference

A single item in a menu. More...

Inheritance diagram for Wt::WMenuItem:
Inheritance graph
[legend]

List of all members.

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 WStringtext () 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 WStringtoolTip () const
 Returns the tooltip.
WMenumenu () const
 Returns the menu.
WWidgetcontents () const
 Returns the contents widget for this item.
WWidgetitemWidget ()
 Returns the widget that represents the item.
void select ()
 Selects this item.

Protected Member Functions

virtual WWidgetcreateItemWidget ()
 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 SignalBaseactivateSignal ()
 Returns the signal used to activate the item.
virtual SignalBasecloseSignal ()
 Returns the signal used to close the item.
virtual void enableAjax ()
 Progresses to an Ajax-enabled widget.

Detailed Description

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

See also:
WMenu
WMenu::addItem(WMenuItem *)

Member Enumeration Documentation

Enumeration that determines when contents should be loaded.

Enumerator:
LazyLoading 

Lazy loading: on first use.

PreLoading 

Pre-loading: before first use.


Constructor & Destructor Documentation

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.


Member Function Documentation

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.

See also:
setCloseable(), hide()
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 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 in Wt::WSubMenuItem.

void Wt::WMenuItem::disable ( )

Disables the item.

This calls setDisabled(true).

See also:
enable()
void Wt::WMenuItem::enable ( )

Enables the item.

This calls setDisabled(false).

See also:
disable()
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.

See also:
WMenu::enableAjax()
void Wt::WMenuItem::hide ( )

Hides the item widget.

This calls setHidden(true).

See also:
show()
bool Wt::WMenuItem::isCloseable ( ) const

Returns whether the item is closeable.

See also:
setCloseable()
bool Wt::WMenuItem::isDisabled ( ) const

Returns whether an item is enabled.

See also:
setDisabled()
bool Wt::WMenuItem::isHidden ( ) const

Returns whether the item widget is hidden.

See also:
setHidden()
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.

See also:
setPathComponent()
Note:
the 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 ( )

Selects this item.

If the item was previously closed it will be shown.

See also:
close()
void Wt::WMenuItem::setCloseable ( bool  closeable)

Make it possible to close this item interactively or by close().

See also:
close(), isCloseable()
void Wt::WMenuItem::setDisabled ( bool  disabled)

Enables or disables an item.

A disabled item cannot be activated.

See also:
enable(), disable(), isEnabled()
void Wt::WMenuItem::setHidden ( bool  hidden)

Sets whether the item widget is hidden.

Hides or show the item widget.

See also:
hide(), show(), isHidden()
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 '_'.

See also:
setText(), WMenu::setInternalPathEnabled()
Note:
the 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().

See also:
setPathComponent();
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()).

See also:
toolTip()
void Wt::WMenuItem::show ( )

Shows the item widget.

If the item was previously closed it will be shown.

This calls setHidden(false).

See also:
hide(), select()
const WString& Wt::WMenuItem::text ( ) const

Returns the text for this item.

See also:
setText();
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().

See also:
createItemWidget()

Reimplemented in Wt::WSubMenuItem.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator

Generated on Fri Jul 27 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1