Return to Index

MenuBar

Parent class: Widget

The MenuBar widget provides a hierarchical menu widget. The items can be standard menu items, or check items. Accelerator shortcuts can be assigned to menu items also. Each menu item has a unique string path that identifies it in the hierarchy. For example, "File/New" would identify the New item in the File menu. For deeper menus, simply extend the hierarchy: "Edit/Preferences/General Preferences/Set Color...". The following sample creates a minimal menubar for a text editor.
   MenuBar *mbar = new MenuBar;
   mbar->append("File/New", false, true, 'n', MOD_CTRL);
   mbar->append("File/Open", false, false, 'o', MOD_CTRL);
   mbar->append("File/Save", false, false, 's', MOD_CTRL);
   mbar->append("File/Save As", false, true);
   mbar->append("File/Quit");
   mbar->append("Edit/Cut", false, false, 'x', MOD_CTRL);
   mbar->append("Edit/Copy", false, false, 'c', MOD_CTRL);
   mbar->append("Edit/Paste", false, false, 'v', MOD_CTRL);
   mbar->append("Help/About", false, false, 'a', MOD_ALT);

To handle menu events, simply check the event's string in the MenuBar's Activated event handler.
   void SomeWindow::OnMenuBar1Activated( Event &pEvt ) {
     if (pEvt.getString() == "File/New") {
       // code to create a new file
     } else if (pEvt.getString() == "File/Open") {
       // code to open a file
     }
   }


Object Events:
ActivatedAn event generated when a menu item is activated. The getString() method of the event returns the full path of the menu item that was clicked (i.e. "File/Open")

Method Summary:
MenuBar::MenuBar();
void MenuBar::setItems(const StringArray& pItems);
void MenuBar::append(const String& pMenuPath, bool (=false) pCheckable, bool (=false) pWithSep, char (=0) pAccel, KeyModifier (=MOD_NONE) pMod, enabled (=true) pEnabled);
void MenuBar::remove(const String& pPath);
void MenuBar::check(const String& pPath, bool pState);
bool MenuBar::isChecked(const String& pPath);
void MenuBar::enable(const String& pPath, bool pState);
bool MenuBar::isEnabled(const String& pPath);



MenuBar::MenuBar
MenuBar::MenuBar();

Creates a new menu bar widget.

void MenuBar::setItems
void MenuBar::setItems(const StringArray& pItems);

Adds all the items in the array into the menu. The items default to a standard menu item, with no separators, and no accelerators.
Parameters:
const StringArray& pItemsThe hierarchical menu item paths.

void MenuBar::append
void MenuBar::append(const String& pMenuPath, bool (=false) pCheckable, bool (=false) pWithSep, char (=0) pAccel, KeyModifier (=MOD_NONE) pMod, enabled (=true) pEnabled);

Appends a menu item onto the menu bar.
Parameters:
const String& pMenuPathThe hierarchical menu path identifying the item.
bool (=false) pCheckableWhether the item is a check item or a normal one. Defaults to false (a normal item).
bool (=false) pWithSepWhether the menu item is followed by a separator.
char (=0) pAccelThe character of the shortcut. Defaults to 0, which stands for no shortcut.
KeyModifier (=MOD_NONE) pModThe modifier for the shortcut.
enabled (=true) pEnabledWhether the menu item is enabled. If it is disabled, the item is grayed out.

void MenuBar::remove
void MenuBar::remove(const String& pPath);

Removes the specified menu item.
Parameters:
const String& pPathThe path to the menu item.

void MenuBar::check
void MenuBar::check(const String& pPath, bool pState);

Changes the state of a checkable menu item.
Parameters:
const String& pPathThe path to the check item.
bool pStateThe new state of the check item.

bool MenuBar::isChecked
bool MenuBar::isChecked(const String& pPath);

Returns the state of a check item.
Parameters:
const String& pPathThe path to the check item.

void MenuBar::enable
void MenuBar::enable(const String& pPath, bool pState);

Enables or disables a menu item. Disabled items are grayed out and cannot be selected.
Parameters:
const String& pPathThe path to the menu item.
bool pStateThe enabled state of the menu item.

bool MenuBar::isEnabled
bool MenuBar::isEnabled(const String& pPath);

Returns whether a menu item is enabled or disabled.
Parameters:
const String& pPathThe path to the menu item.


Generated automatically by docgen 0.0.1
© 2003 Aron Dobos