Public Types | Public Member Functions | Protected Member Functions

Wt::WMenuItem Class Reference

A single item in a menu. More...

Inherits Wt::WObject.

Inherited by Wt::WSubMenuItem.

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.
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 SignalBase & activateSignal ()
 Returns the signal used to activate the item.

Detailed Description

A single item in a menu.

The item determines the look and behaviour of a single item in a WMenu.

By default, a WMenuItem is implemented using a WAnchor widget. 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:

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() to a WInteractWidget and returns the clicked signal.

Reimplemented in Wt::WSubMenuItem.

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 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 in Wt::WSubMenuItem.

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

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, 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 in Wt::WSubMenuItem.

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()
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();
const WString& Wt::WMenuItem::text (  )  const [inline]

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.


Generated on Mon Nov 29 2010 08:03:19 for Wt by doxygen 1.7.1