Wt  3.3.0
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 &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 WStringtext () 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.
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 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)
WMenumenu () 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.
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.
WWidgetcontents () const
 Returns the contents widget for this item.
WWidgetitemWidget ()
 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.
virtual void renderSelected (bool selected)
 Renders the item as selected or unselected.
virtual void enableAjax ()
 Progresses to an Ajax-enabled widget.

Protected Member Functions

virtual void render (WFlags< RenderFlag > flags)
 Renders the widget.

Detailed Description

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.

CSS

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.


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 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 can be indicated which 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().


Member Function Documentation

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

void* Wt::WMenuItem::data ( ) const

Returns additional data of the item.

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

See also:
WApplication::enableAjax()

Reimplemented from Wt::WWebWidget.

std::string Wt::WMenuItem::icon ( ) const

Returns the item icon path.

See also:
setIcon()
bool Wt::WMenuItem::isCheckable ( ) const

Returns whether the item is checkable.

See also:
setCheckable()
bool Wt::WMenuItem::isChecked ( ) const

Returns the checked state.

This is only used when isCheckable() == true.

See also:
setChecked(bool), isCheckable()
bool Wt::WMenuItem::isCloseable ( ) const

Returns whether the item is closeable.

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

Returns whether this item is a section header.

See also:
WMenu::addSectionHeader()
bool Wt::WMenuItem::isSelectable ( ) const

Returns whether the menu item can be selected.

See also:
setSelectable()
bool Wt::WMenuItem::isSeparator ( ) const

Returns whether this item is a separator.

See also:
WMenu::addSeparator()
WWidget * Wt::WMenuItem::itemWidget ( )

Returns the widget that represents the item (deprecated).

This returns this.

Deprecated:
This is a pre-Wt 3.3.0 artifact which has lost its value since WMenuItem is now a widget.
WLink Wt::WMenuItem::link ( ) const

Returns the associated link.

See also:
setLink()
AnchorTarget Wt::WMenuItem::linkTarget ( ) const

Returns the link target.

See also:
setLinkTarget()
WMenu* Wt::WMenuItem::menu ( ) const

Returns the submenu.

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

Selects this item.

If the item was previously closed it will be shown.

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

See also:
setChecked(), isChecked()
void Wt::WMenuItem::setChecked ( bool  checked)

Sets the checked state.

This is only used when isCheckable() == true.

See also:
setCheckable(bool), isCheckable()
void Wt::WMenuItem::setCloseable ( bool  closeable)

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

See also:
close(), isCloseable()
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::setIcon ( const std::string &  path)

Sets the item icon path.

The icon should have a width of 16 pixels.

See also:
setText()
void Wt::WMenuItem::setLink ( const WLink link)

Sets the associated link.

See also:
Link()
void Wt::WMenuItem::setLinkTarget ( AnchorTarget  target)

Sets the link target.

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

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

Deprecated:
use setMenu() instead
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

Returns the text for this item.

See also:
setText();
Signal<WMenuItem *>& Wt::WMenuItem::triggered ( )

Signal emitted when an item is activated.

Returns this item as argument.

See also:
WMenu::triggered()
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator

Generated on Mon Apr 8 2013 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1