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:
Activated | An 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& | pItems | The 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& | pMenuPath | The hierarchical menu path identifying the item. |
bool (=false) | pCheckable | Whether the item is a check item or a normal one. Defaults to false (a normal item). |
bool (=false) | pWithSep | Whether the menu item is followed by a separator. |
char (=0) | pAccel | The character of the shortcut. Defaults to 0, which stands for no shortcut. |
KeyModifier (=MOD_NONE) | pMod | The modifier for the shortcut. |
enabled (=true) | pEnabled | Whether 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& | pPath | The 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& | pPath | The path to the check item. |
bool | pState | The 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& | pPath | The 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& | pPath | The path to the menu item. |
bool | pState | The 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& | pPath | The path to the menu item. |
|
Generated automatically by docgen 0.0.1
© 2003 Aron Dobos