Wt  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Member Functions | List of all members
Wt::WPopupMenu Class Reference

A menu presented in a popup window. More...

#include <Wt/WPopupMenu>

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

Public Member Functions

 WPopupMenu ()
 Creates a new popup menu.
WPopupMenuItemaddItem (const WString &text)
 Adds an item with given text.
WPopupMenuItemaddItem (const std::string &iconPath, const WString &text)
 Adds an item with given icon and text.
template<class T , class V >
WPopupMenuItemaddItem (const WString &text, T *target, void(V::*method)())
 Adds an item with given text, and specify a slot method to be called when the item is triggered.
template<class T , class V >
WPopupMenuItemaddItem (const std::string &iconPath, const WString &text, T *target, void(V::*method)())
 Adds an item with given text and icon, and specify a slot method to be called when activated.
WPopupMenuItemaddMenu (const WString &text, WPopupMenu *menu)
 Adds a submenu, with given text.
WPopupMenuItemaddMenu (const std::string &iconPath, const WString &text, WPopupMenu *menu)
 Adds a submenu, with given icon and text.
void add (WPopupMenuItem *item)
 Adds a menu item.
void addSeparator ()
 Adds a separator to the menu.
void popup (const WPoint &point)
 Shows the the popup at a position.
void popup (const WMouseEvent &event)
 Shows the the popup at the location of a mouse event.
void popup (WWidget *location, Orientation orientation=Vertical)
 Shows the popup besides a widget.
WPopupMenuItemexec (const WPoint &point)
 Executes the the popup at a position.
WPopupMenuItemexec (const WMouseEvent &event)
 Executes the the popup at the location of a mouse event.
WPopupMenuItemexec (WWidget *location, Orientation orientation=Vertical)
 Executes the popup besides a widget.
WPopupMenuItemresult () const
 Returns the last triggered menu item.
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
 Hides or shows the widget.
virtual void setMaximumSize (const WLength &width, const WLength &height)
 Sets a maximum size.
virtual void setMinimumSize (const WLength &width, const WLength &height)
 Sets a minimum size.
SignalaboutToHide ()
 Signal emitted when the popup is hidden.
Signal< WPopupMenuItem * > & triggered ()
 Signal emitted when an item is activated.
void setAutoHide (bool enabled, int autoHideDelay=0)
 Configure auto-hide when the mouse leaves the menu.
- Public Member Functions inherited from Wt::WCompositeWidget
 WCompositeWidget (WContainerWidget *parent=0)
 Creates a WCompositeWidget.
 WCompositeWidget (WWidget *implementation, WContainerWidget *parent)
 Creates a WCompositeWidget with given implementation.
virtual const std::string id () const
 Returns the (unique) identifier for this object.
virtual void setPositionScheme (PositionScheme scheme)
 Sets the CSS position scheme.
virtual PositionScheme positionScheme () const
 Returns the CSS position scheme.
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=All)
 Sets CSS offsets for a non-statically positioned widget.
virtual WLength offset (Side s) const
 Returns a CSS offset.
virtual void resize (const WLength &width, const WLength &height)
 Resizes the widget.
virtual WLength width () const
 Returns the width.
virtual WLength height () const
 Returns the height.
virtual WLength minimumWidth () const
 Returns the minimum width.
virtual WLength minimumHeight () const
 Returns the minimum height.
virtual WLength maximumWidth () const
 Returns the maximum width.
virtual WLength maximumHeight () const
 Returns the maximum height.
virtual void setLineHeight (const WLength &height)
 Sets the CSS line height for contained text.
virtual WLength lineHeight () const
 Returns the CSS line height for contained text.
virtual void setFloatSide (Side s)
 Specifies a CSS float side.
virtual Side floatSide () const
 Returns the CSS float side.
virtual void setClearSides (WFlags< Side > sides)
 Sets the sides that should be cleared of floats.
virtual WFlags< SideclearSides () const
 Returns the sides that should remain empty.
virtual void setMargin (const WLength &margin, WFlags< Side > sides=All)
 Sets CSS margins around the widget.
virtual WLength margin (Side side) const
 Returns a CSS margin set.
virtual void setHiddenKeepsGeometry (bool enabled)
 Sets whether the widget keeps its geometry when hidden.
virtual bool hiddenKeepsGeometry () const
 Returns whether the widget keeps its geometry when hidden.
virtual bool isHidden () const
 Returns whether the widget is set hidden.
virtual bool isVisible () const
 Returns whether the widget is visible.
virtual void setDisabled (bool disabled)
 Sets whether the widget is disabled.
virtual bool isDisabled () const
 Returns whether the widget is set disabled.
virtual bool isEnabled () const
 Returns whether the widget is enabled.
virtual void setPopup (bool popup)
 Lets the widget overlay over other sibling widgets.
virtual bool isPopup () const
 Returns whether the widget is overlayed.
virtual void setInline (bool isInline)
 Sets whether the widget is displayed inline or as a block.
virtual bool isInline () const
 Returns whether the widget is displayed inline or as block.
virtual void setDecorationStyle (const WCssDecorationStyle &style)
 Sets a CSS decoration style.
virtual WCssDecorationStyledecorationStyle ()
 Returns the decoration style of this widget.
virtual void setStyleClass (const WString &styleClass)
 Sets (one or more) CSS style classes.
virtual WString styleClass () const
 Returns the CSS style class.
virtual void addStyleClass (const WString &styleClass, bool force=false)
 Adds a CSS style class.
virtual void removeStyleClass (const WString &styleClass, bool force=false)
 Removes a CSS style class.
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength::Auto)
 Sets the vertical alignment.
virtual AlignmentFlag verticalAlignment () const
 Returns the vertical alignment.
virtual WLength verticalAlignmentLength () const
 Returns the fixed vertical alignment that was set.
virtual void setToolTip (const WString &text, TextFormat textFormat=PlainText)
 Sets a tooltip.
virtual WString toolTip () const
 Returns the tooltip.
virtual void refresh ()
 Refresh the widget.
virtual void setAttributeValue (const std::string &name, const WString &value)
 Sets an attribute value.
virtual WString attributeValue (const std::string &name) const
 Returns an attribute value.
virtual void setJavaScriptMember (const std::string &name, const std::string &value)
 Sets a JavaScript member.
virtual std::string javaScriptMember (const std::string &name) const
 Returns the value of a JavaScript member.
virtual void callJavaScriptMember (const std::string &name, const std::string &args)
 Calls a JavaScript member.
virtual void load ()
 Loads content just before the widget is used.
virtual bool loaded () const
 Returns whether this widget has been loaded.
virtual void setTabIndex (int index)
 Sets the tab index.
virtual int tabIndex () const
 Returns the tab index.
virtual void setId (const std::string &id)
 Sets the CSS Id.
virtual WWidgetfind (const std::string &name)
 Finds a descendent widget by name.
virtual void setSelectable (bool selectable)
 Sets as selectable.
virtual void doJavaScript (const std::string &js)
 Executes the given JavaScript statements when the widget is rendered or updated.
virtual void propagateSetEnabled (bool enabled)
 Propagates that a widget was enabled or disabled through children.
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 Destructor.
WWidgetparent () const
 Returns the parent widget.
void setWidth (const WLength &width)
 Sets the width.
void setHeight (const WLength &height)
 Sets the height.
virtual void positionAt (const WWidget *widget, Orientation orientation=Vertical)
 Positions a widget next to another widget.
std::string jsRef () const
 Returns a JavaScript expression to the corresponding DOM node.
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
 Sets a mime type to be accepted for dropping.
virtual void stopAcceptDrops (const std::string &mimeType)
 Indicates that a mime type is no longer accepted for dropping.
virtual void htmlText (std::ostream &out)
 Streams the (X)HTML representation.
bool isRendered () const
 Returns whether the widget is rendered.
void hide ()
 Hides the widget.
void animateHide (const WAnimation &animation)
 Hides the widget using an animation.
void show ()
 Shows the widget.
void animateShow (const WAnimation &animation)
 Shows the widget using an animation.
void enable ()
 Enables the widget.
void disable ()
 Disable thes widget.
bool layoutSizeAware () const
 Returns whether the widget is layout size aware.
- Public Member Functions inherited from Wt::WObject
 WObject (WObject *parent=0)
 Create a WObject with a given parent object.
virtual ~WObject ()
 Destructor.
void setObjectName (const std::string &name)
 Sets an object name.
virtual std::string objectName () const
 Returns the object name.
void resetLearnedSlots ()
 Resets learned stateless slot implementations.
template<class T >
void resetLearnedSlot (void(T::*method)())
 Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)())
 Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 Declares a slot to be stateless and learn client-side behaviour in advance.
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method.
void addChild (WObject *child)
 Adds a child object.
virtual void removeChild (WObject *child)
 Removes a child object.
const std::vector< WObject * > & children () const
 Returns the children.

Additional Inherited Members

- Public Types inherited from Wt::WObject
typedef void(WObject::* Method )()
 Typedef for a WObject method without arguments.
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
 Short hand for WString::tr()
- Protected Member Functions inherited from Wt::WCompositeWidget
virtual void enableAjax ()
 Progresses to an Ajax-enabled widget.
void setImplementation (WWidget *widget)
 Set the implementation widget.
WWidgetimplementation ()
 Get the implementation widget.
virtual int boxPadding (Orientation orientation) const
 Returns the widget's built-in padding.
virtual int boxBorder (Orientation orientation) const
 Returns the widget's built-in border width.
- Static Protected Member Functions inherited from Wt::WObject
static WObjectsender ()
 Returns the sender of the current slot call.

Detailed Description

A menu presented in a popup window.

The menu implements a typical context menu, with support for submenu's. It is not to be confused with WMenu which implements an always-visible navigation menu for a web application.

When initially created, the menu is invisible, until popup() or exec() is called. Then, the menu will remain visible until an item is selected, or the user cancels the menu (by hitting Escape or clicking elsewhere).

The implementation assumes availability of JavaScript to position the menu at the current mouse position and provide feed-back of the currently selected item.

Similar in use as WDialog, there are two ways of using the menu. The simplest way is to use one of the exec() methods, to use a reentrant event loop and wait until the user cancelled the popup menu (by hitting Escape or clicking elsewhere), or selected an item.

Alternatively, you can use one of the popup() methods to show the menu and listen to the aboutToHide signal where you read the result().

You have several options to react to the selection of an item:

Usage example:

// Create a menu with some items
popup.addItem("icons/item1.gif", "Item 1");
popup.addItem("Item 2")->setCheckable(true);
popup.addItem("Item 3");
popup.addSeparator();
popup.addItem("Item 4");
popup.addSeparator();
popup.addItem("Item 5");
popup.addItem("Item 6");
popup.addSeparator();
WPopupMenu *subMenu = new WPopupMenu();
subMenu->addItem("Sub Item 1");
subMenu->addItem("Sub Item 2");
popup.addMenu("Item 7", subMenu);
WPopupMenuItem *item = popup.exec(event);
if (item) {
// ... do associated action.
}

CSS

A WPopupMenu has the Wt-popupmenu style class. The look can be overridden using the following style class selectors:

.Wt-popupmenu .Wt-item, .Wt-popupmenu .Wt-selected : item
.Wt-popupmenu .Wt-selected                         : selected item
.Wt-popupmenu .Wt-separator                        : separator

A snapshot of the WPopupMenu:

WPopupMenu-default-1.png
WPopupMenu example (default)
WPopupMenu-polished-1.png
WPopupMenu example (polished)
See Also
WPopupMenuItem

Constructor & Destructor Documentation

Wt::WPopupMenu::WPopupMenu ( )

Creates a new popup menu.

The menu is hidden, by default, and must be shown using popup() or exec().

Member Function Documentation

Signal& Wt::WPopupMenu::aboutToHide ( )

Signal emitted when the popup is hidden.

This signal is emitted when the popup is hidden, either because an item was selected, or when the menu was cancelled.

You can use result() to get the selected item.

void Wt::WPopupMenu::add ( WPopupMenuItem item)

Adds a menu item.

Adds an item to the popup menu.

WPopupMenuItem * Wt::WPopupMenu::addItem ( const WString text)

Adds an item with given text.

Adds an item to the menu with given text, and returns the corresponding item object.

See Also
add(WPopupMenuItem *)
WPopupMenuItem * Wt::WPopupMenu::addItem ( const std::string &  iconPath,
const WString text 
)

Adds an item with given icon and text.

Adds an item to the menu with given text and icon, and returns the corresponding item object.

Note
The icon should have a width of 16 pixels.
See Also
add(WPopupMenuItem *)
template<class T , class V >
WPopupMenuItem * Wt::WPopupMenu::addItem ( const WString text,
T *  target,
void(V::*)()  method 
)

Adds an item with given text, and specify a slot method to be called when the item is triggered.

The target and method are connected to the WPopupMenuItem::triggered signal.

See Also
add(WPopupMenuItem *)
template<class T , class V >
WPopupMenuItem * Wt::WPopupMenu::addItem ( const std::string &  iconPath,
const WString text,
T *  target,
void(V::*)()  method 
)

Adds an item with given text and icon, and specify a slot method to be called when activated.

The target and method are connected to the WPopupMenuItem::triggered signal.

Note
The icon should have a width of 16 pixels.
See Also
add(WPopupMenuItem *)
WPopupMenuItem * Wt::WPopupMenu::addMenu ( const WString text,
WPopupMenu menu 
)

Adds a submenu, with given text.

Adds an item with text text, that leads to a submenu menu.

See Also
add(WPopupMenuItem *)
WPopupMenuItem * Wt::WPopupMenu::addMenu ( const std::string &  iconPath,
const WString text,
WPopupMenu menu 
)

Adds a submenu, with given icon and text.

Adds an item with given text and icon, that leads to a submenu menu.

See Also
add(WPopupMenuItem *)
void Wt::WPopupMenu::addSeparator ( )

Adds a separator to the menu.

Adds a separator the popup menu. The separator is an empty div with style-class "separator".

WPopupMenuItem * Wt::WPopupMenu::exec ( const WPoint point)

Executes the the popup at a position.

Displays the popup at a point with document coordinates p, using popup(), and the waits until a menu item is selected, or the menu is cancelled.

Returns the selected menu (or sub-menu) item, or 0 if the user cancelled the menu.

See Also
popup()
WPopupMenuItem * Wt::WPopupMenu::exec ( const WMouseEvent event)

Executes the the popup at the location of a mouse event.

This is a convenience method for exec(const WPoint& p) that uses the event's document coordinates.

See Also
exec(const WPoint&)
WPopupMenuItem * Wt::WPopupMenu::exec ( WWidget location,
Orientation  orientation = Vertical 
)

Executes the popup besides a widget.

See Also
positionAt(), popup(const WPointF&)
void Wt::WPopupMenu::popup ( const WPoint point)

Shows the the popup at a position.

Displays the popup at a point with document coordinates point. The positions intelligent, and will chose one of the four menu corners to correspond to this point so that the popup menu is completely visible within the window.

See Also
exec()
void Wt::WPopupMenu::popup ( const WMouseEvent event)

Shows the the popup at the location of a mouse event.

This is a convenience method for popup(const WPoint&) that uses the event's document coordinates.

See Also
popup(const WPoint& p), WMouseEvent::document()
void Wt::WPopupMenu::popup ( WWidget location,
Orientation  orientation = Vertical 
)

Shows the popup besides a widget.

See Also
positionAt(), popup(const WPointF&)
WPopupMenuItem* Wt::WPopupMenu::result ( ) const

Returns the last triggered menu item.

The result is 0 when the user cancelled the popup menu.

void Wt::WPopupMenu::setAutoHide ( bool  enabled,
int  autoHideDelay = 0 
)

Configure auto-hide when the mouse leaves the menu.

If enabled, The popup menu will be hidden when the mouse leaves the menu for longer than autoHideDelay (milliseconds). The popup menu result will be 0, as if the user cancelled.

By default, this option is disabled.

void Wt::WPopupMenu::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::WCompositeWidget.

void Wt::WPopupMenu::setMaximumSize ( const WLength width,
const WLength height 
)
virtual

Sets a maximum size.

Specifies a maximum size for this widget.

The default maximum width and height are WLength::Auto, indicating no maximum size.

See Also
resize(), setMinimumSize()

Reimplemented from Wt::WCompositeWidget.

void Wt::WPopupMenu::setMinimumSize ( const WLength width,
const WLength height 
)
virtual

Sets a minimum size.

Specify a minimum size for this widget.

The default minimum width and height is 0. The special value WLength::Auto indicates that the initial width is used as minimum size.

When the widget size is actively managed (using e.g. a layout manager), these sizes are taken into account.

See Also
resize(), minimumWidth(), minimumHeight()

Reimplemented from Wt::WCompositeWidget.

Signal<WPopupMenuItem *>& Wt::WPopupMenu::triggered ( )

Signal emitted when an item is activated.

Passes the activated item as argument. This signal is only emitted for the toplevel menu.

See Also
WPopupMenuItem::triggered()

Generated on Wed Oct 22 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2