If you are not calling event.Skip() for events that you don't process in
these event handlers, menu shortcuts may cease to work.
-
@library{wxcore}
@category{menus}
@remarks Only use this when the menu bar has been associated with a
frame; otherwise, use the wxMenu equivalent call.
*/
- void Check(int id, const bool check);
+ void Check(int id, bool check);
/**
Enables or disables (greys out) a menu item.
@remarks Only use this when the menu bar has been associated with a
frame; otherwise, use the wxMenu equivalent call.
*/
- void Enable(int id, const bool enable);
+ void Enable(int id, bool enable);
/**
Enables or disables a whole menu.
@remarks Only use this when the menu bar has been associated with a frame.
*/
- void EnableTop(int pos, const bool enable);
+ virtual void EnableTop(size_t pos, bool enable);
/**
Finds the menu item object associated with the given menu item identifier.
@return The found menu item object, or @NULL if one was not found.
*/
- wxMenuItem* FindItem(int id, wxMenu menu = NULL) const;
+ virtual wxMenuItem* FindItem(int id, wxMenu* menu = NULL) const;
/**
Returns the index of the menu with the given @a title or @c wxNOT_FOUND if no
@see SetLabelTop()
*/
- wxString GetLabelTop(int pos) const;
+ wxString GetLabelTop(size_t pos) const;
/**
Returns the menu at @a menuIndex (zero-based).
*/
- wxMenu* GetMenu(int menuIndex) const;
+ wxMenu* GetMenu(size_t menuIndex) const;
/**
Returns the number of menus in this menubar.
@see GetMenuLabelText(), SetMenuLabel()
*/
- wxString GetMenuLabel(int pos) const;
+ virtual wxString GetMenuLabel(size_t pos) const;
/**
Returns the label of a top-level menu. Note that the returned string does not
@see GetMenuLabel(), SetMenuLabel()
*/
- wxString GetMenuLabelText(int pos) const;
+ virtual wxString GetMenuLabelText(size_t pos) const;
/**
Inserts the menu at the given position into the menu bar. Inserting menu at
/**
Redraw the menu bar
*/
- void Refresh();
+ virtual void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
/**
Removes the menu from the menu bar and returns the menu object - the caller
@see GetLabelTop()
*/
- void SetLabelTop(int pos, const wxString& label);
+ void SetLabelTop(size_t pos, const wxString& label);
/**
Sets the label of a top-level menu.
@remarks Use only after the menubar has been associated with a frame.
*/
- void SetMenuLabel(int pos, const wxString& label);
+ virtual void SetMenuLabel(size_t pos, const wxString& label);
};
(following the appropriate MacOS X interface guideline).
On PalmOS @e wxID_EXIT is disabled according to Palm OS Companion guidelines.
- Menu items may be either normal items, check items or radio items.
+ Menu items may be either @e normal items, @e check items or @e radio items.
Normal items don't have any special properties while the check items have a
boolean flag associated to them and they show a checkmark in the menu when
the flag is set.
first item of this kind and ends with the first item of a different kind (or
the end of the menu). Notice that because the radio groups are defined in terms
of the item positions inserting or removing the items in the menu containing
- the radio items risks to not work correctly. Finally note that radio items
- are not supported under Motif.
+ the radio items risks to not work correctly.
@section menu_allocation Allocation strategy
- All menus except the popup ones must be created on the heap.
+ All menus except the popup ones must be created on the @b heap.
All menus attached to a menubar or to another menu will be deleted by their
parent when it is deleted.
+
As the frame menubar is deleted by the frame itself, it means that normally
all menus used are deleted automatically.
@section menu_eventhandling Event handling
If the menu is part of a menubar, then wxMenuBar event processing is used.
- With a popup menu, there is a variety of ways to handle a menu selection event
- (wxEVT_COMMAND_MENU_SELECTED).
- Derive a new class from wxMenu and define event table entries using the EVT_MENU macro.
- Set a new event handler for wxMenu, using an object whose class has EVT_MENU entries.
- Provide EVT_MENU handlers in the window which pops up the menu, or in an
- ancestor of this window.
+ With a popup menu (see wxWindow::PopupMenu), there is a variety of ways to
+ handle a menu selection event (@c wxEVT_COMMAND_MENU_SELECTED):
+ - Provide @c EVT_MENU handlers in the window which pops up the menu, or in an
+ ancestor of that window (the simplest method);
+ - Derive a new class from wxMenu and define event table entries using the @c EVT_MENU macro;
+ - Set a new event handler for wxMenu, through wxEvtHandler::SetNextHandler,
+ specifying an object whose class has @c EVT_MENU entries;
+
+ Note that instead of static @c EVT_MENU macros you can also use dynamic
+ connection; see @ref overview_eventhandling_connect.
@library{wxcore}
@category{menus}
@param style
If set to wxMENU_TEAROFF, the menu will be detachable (wxGTK only).
*/
- wxMenu(const wxString& title = "", long style = 0);
+ wxMenu(const wxString& title, long style = 0);
/**
Destructor, destroying the menu.
@see Append(), InsertCheckItem()
*/
wxMenuItem* AppendCheckItem(int id, const wxString& item,
- const wxString& helpString = "");
+ const wxString& help = wxEmptyString);
/**
Adds a radio item to the end of the menu.
All consequent radio items form a group and when an item in the group is
checked, all the others are automatically unchecked.
+ @note Radio items are not supported under wxMotif.
+
@see Append(), InsertRadioItem()
*/
wxMenuItem* AppendRadioItem(int id, const wxString& item,
- const wxString& helpString = "");
+ const wxString& help = wxEmptyString);
/**
Adds a separator to the end of the menu.
@see IsChecked()
*/
- void Check(int id, const bool check);
+ void Check(int id, bool check);
/**
Deletes the menu item from the menu. If the item is a submenu, it will
@see FindItem(), Destroy(), Remove()
*/
- void Delete(int id);
+ bool Delete(int id);
/**
Deletes the menu item from the menu. If the item is a submenu, it will
@see FindItem(), Destroy(), Remove()
*/
- void Delete(wxMenuItem* item);
+ bool Delete(wxMenuItem* item);
/**
Deletes the menu item from the menu. If the item is a submenu, it will
@see FindItem(), Deletes(), Remove()
*/
- void Destroy(int id);
+ bool Destroy(int id);
/**
Deletes the menu item from the menu. If the item is a submenu, it will
@see FindItem(), Deletes(), Remove()
*/
- void Destroy(wxMenuItem* item);
+ bool Destroy(wxMenuItem* item);
/**
Enables or disables (greys out) a menu item.
@see IsEnabled()
*/
- void Enable(int id, const bool enable);
+ void Enable(int id, bool enable);
/**
Finds the menu id for a menu item string.
@return Menu item object or NULL if none is found.
*/
- const wxMenuItem* FindItem(int id, wxMenu** menu = NULL) const;
+ wxMenuItem* FindItem(int id, wxMenu** menu = NULL) const;
/**
Returns the wxMenuItem given a position in the menu.
*/
size_t GetMenuItemCount() const;
+ //@{
/**
Returns the list of items in the menu.
wxMenuItemList is a pseudo-template list class containing wxMenuItem
pointers, see wxList.
*/
- wxMenuItemList GetMenuItems() const;
+ wxMenuItemList& GetMenuItems() const;
+ const wxMenuItemList& GetMenuItems() const;
+ //@}
/**
Returns the title of the menu.
@see SetTitle()
*/
- wxString GetTitle() const;
+ const wxString& GetTitle() const;
/**
Inserts the given @a item before the position @a pos.
@see Append(), Prepend()
*/
wxMenuItem* Insert(size_t pos, int id,
- const wxString& item = "",
- const wxString& helpString = "",
+ const wxString& item = wxEmptyString,
+ const wxString& helpString = wxEmptyString,
wxItemKind kind = wxITEM_NORMAL);
/**
@see Insert(), AppendCheckItem()
*/
- wxMenuItem* InsertCheckItem(size_t pos, int id,
- const wxString& item,
- const wxString& helpString = "");
+ wxMenuItem* InsertCheckItem(size_t pos, int id, const wxString& item,
+ const wxString& helpString = wxEmptyString);
/**
Inserts a radio item at the given position.
@see Insert(), AppendRadioItem()
*/
- wxMenuItem* InsertRadioItem(size_t pos, int id,
- const wxString& item,
- const wxString& helpString = "");
+ wxMenuItem* InsertRadioItem(size_t pos, int id, const wxString& item,
+ const wxString& helpString = wxEmptyString);
/**
Inserts a separator at the given position.
@see Append(), Insert()
*/
- wxMenuItem* Prepend(int id, const wxString& item = "",
- const wxString& helpString = "",
+ wxMenuItem* Prepend(int id, const wxString& item = wxEmptyString,
+ const wxString& helpString = wxEmptyString,
wxItemKind kind = wxITEM_NORMAL);
/**
@see Prepend(), AppendCheckItem()
*/
wxMenuItem* PrependCheckItem(int id, const wxString& item,
- const wxString& helpString = "");
+ const wxString& helpString = wxEmptyString);
/**
Inserts a radio item at position 0.
@see Prepend(), AppendRadioItem()
*/
wxMenuItem* PrependRadioItem(int id, const wxString& item,
- const wxString& helpString = "");
+ const wxString& helpString = wxEmptyString);
/**
Inserts a separator at position 0.