Wt::WMenu Class Reference

The Menu widget offers a menu of options, which correspond to several tabs in a WStackedWidget. More...

#include <WMenu>

Inherits Wt::WCompositeWidget.

Inheritance diagram for Wt::WMenu:

Inheritance graph
[legend]
List of all members.

Public Types

 Vertical
 Vertical.
 Horizontal
 Horizontal.
enum  Orientation { Vertical, Horizontal }
 Menu orientation. More...

Public Member Functions

 WMenu (WStackedWidget *contentsStack, Orientation orientation, WContainerWidget *parent=0)
 Construct a new WMenu.
 ~WMenu ()
 Destructor.
void enableBrowserHistory (const std::string id)
 Make the menu react to browser history.
WMenuItemaddItem (const WString &name, WWidget *contents, WMenuItem::LoadPolicy policy=WMenuItem::LazyLoading)
 Add a menu item.
WMenuItemaddItem (WMenuItem *item)
 Add a menu item.
void select (WMenuItem *item)
 Select the menu item.
void select (int index)
 Select the menu item with the given index number.
std::string browserHistoryId () const
 Get the browser history key for this menu.
const std::vector< WMenuItem * > & items () const
 The menu items.
WMenuItemcurrentItem () const
 The currently selected item.

Public Attributes

Signal< WMenuItem * > itemSelected
 Signal emitted when a new item is selected.

Detailed Description

The Menu widget offers a menu of options, which correspond to several tabs in a WStackedWidget.

The WMenu widget offers menu navigation in conjunction with a WStackedWidget, where different 'contents' are stacked upon each other. Each choice in the menu (which is implemented as a WMenuItem) corresponds to a tab in the contents stack. The contents stack is dedicated to the menu, and should not contain any other widgets than those that are added to it by the WMenu.

An example for using WMenu is:

   // create the stack where the contents will be located
   WStackedWidget *contents = new WStackedWidget(contentsParent);

   // create a menu
   WMenu *menu = new WMenu(contents, WMenu::Vertical, menuParent);

   // add four items using the default lazy loading policy.
   menu->addItem("Introduction", new WText(tr("intro"));
   menu->addItem("Download", new WText("Not yet available"));
   menu->addItem("Demo", new DemoWidget());
   menu->addItem(new WMenuItem("Demo2", new DemoWidget()));

After contruction, by default, the first entry will be selected. At any time, it is possible to select a particular item using the select() member.

The WMenu implementation offers fine-grained control on how contents should be preloaded. By default, all contents is lazy-loaded, only when needed. To improve response time, an item may also be preloaded (using addItem()). In that case, the item will be loaded in the background, before its first use. Once loaded, the contents will be 'cached', and menu operation is also completely client-side.

The layout of the menu may be Horizontal or Vertical. The look of the items may be defined through style sheets. The default WMenuItem implementation uses two style classes to distinguish between activated and inactivated menu items: "item" and "itemselected". By using CSS nested selectors, a different style may be defined for items in a different menu.

For example, the Wt homepage uses the following CSS rules to style the two menu (which both are assigned the style class .menu):

.menu * .item {
  cursor: pointer; cursor: hand;
  color: blue;
  text-decoration: underline;
}

.menu * .itemselected {
  color: blue;
  text-decoration: underline;
  font-weight: bold;  
}
 

See also:
WMenuItem


Member Enumeration Documentation

enum Wt::WMenu::Orientation

Menu orientation.

Enumerator:
Vertical  Vertical.
Horizontal  Horizontal.


Constructor & Destructor Documentation

Wt::WMenu::WMenu ( WStackedWidget contentsStack,
Orientation  orientation,
WContainerWidget parent = 0 
)

Construct a new WMenu.

Construct a menu to manage the widgets in the given contents stack, and with the given orientation.


Member Function Documentation

WMenuItem * Wt::WMenu::addItem ( WMenuItem item  ) 

Add a menu item.

Adds a menu item. Use this form to add specialized WMenuItem implementations (with a different look than the default text).

WMenuItem * Wt::WMenu::addItem ( const WString name,
WWidget contents,
WMenuItem::LoadPolicy  policy = WMenuItem::LazyLoading 
)

Add a menu item.

Adds a menu text item, associated with the contents.

Returns the corresponding WMenuItem.

See also:
select(WMenuItem *)

addItem(WMenuItem *)

std::string Wt::WMenu::browserHistoryId (  )  const [inline]

Get the browser history key for this menu.

Returns an empty string if browser history was not previously enabled with enableBrowserHistory()

void Wt::WMenu::enableBrowserHistory ( const std::string  id  ) 

Make the menu react to browser history.

The id must be an application-wide unique id that identifies this menu.

void Wt::WMenu::select ( int  index  ) 

Select the menu item with the given index number.

Menu items in a menu with N items are indexed from 0 to N-1.

void Wt::WMenu::select ( WMenuItem item  ) 

Select the menu item.

Select the given menu item.


Member Data Documentation

Signal<WMenuItem *> Wt::WMenu::itemSelected

Signal emitted when a new item is selected.

This signal is emitted when a new menu item is selected, either by the user or through a call to one of the select() methods.


The documentation for this class was generated from the following files:
Generated on Sun Jul 1 19:37:18 2007 for Wt by doxygen 1.4.7