A menu is a popup (or pull down) list of items, one of which may be selected before the menu goes away (clicking elsewhere dismisses the menu). Menus may be used to construct either menu bars or popup menus.
A menu item has an integer ID associated with it which can be used to identify the selection, or to change the menu item in some way.
Derived from
Include files
<wx/menu.h>
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).
See also
wxMenuBar, wxWindow::PopupMenu, Event handling overview
Members
wxMenu::wxMenu
wxMenu::~wxMenu
wxMenu::Append
wxMenu::AppendSeparator
wxMenu::Break
wxMenu::Check
wxMenu::Enable
wxMenu::FindItem
wxMenu::FindItemForId
wxMenu::GetHelpString
wxMenu::GetLabel
wxMenu::GetTitle
wxMenu::IsChecked
wxMenu::IsEnabled
wxMenu::SetHelpString
wxMenu::SetLabel
wxMenu::SetTitle
wxMenu::UpdateUI
wxMenu(const wxString& title = "", const wxFunction func = NULL)
Constructs a wxMenu object.
Parameters
title
func
wxPython note:
The wxPython version of the wxMenu constructor
doesn't accept the callback argument because of reference counting
issues. There is a specialized wxMenu constructor called
wxPyMenu which does and can be used for PopupMenus when callbacks
are needed. You must retain a reference to the menu while useing it
otherwise your callback function will get dereferenced when the menu
does.
~wxMenu()
Destructor, destroying the menu.
Note: under Motif, a popup menu must have a valid parent (the window it was last popped up on) when being destroyed. Therefore, make sure you delete or re-use the popup menu before destroying the parent window. Re-use in this context means popping up the menu on a different window from last time, which causes an implicit destruction and recreation of internal data structures.
void Append(int id, const wxString& item, const wxString& helpString = "", const bool checkable = FALSE)
Adds a string item to the end of the menu.
void Append(int id, const wxString& item, wxMenu *subMenu, const wxString& helpString = "")
Adds a pull-right submenu to the end of the menu.
void Append(wxMenuItem* menuItem)
Adds a menu item object. You can specify various extra properties of a menu item this way, such as bitmaps and fonts.
Parameters
id
item
menu
checkable
helpString
menuItem
Remarks
This command can be used after the menu has been shown, as well as on initial creation of a menu or menubar.
See also
wxMenu::AppendSeparator, wxMenu::SetLabel, wxMenu::GetHelpString, wxMenu::SetHelpString, wxMenuItem
wxPython note:
In place of a single overloaded method name, wxPython
implements the following methods:
Append(id, string, helpStr="", checkable=FALSE) | |
AppendMenu(id, string, aMenu, helpStr="") | |
AppendItem(aMenuItem) |
void AppendSeparator()
Adds a separator to the end of the menu.
See also
void Break()
Inserts a break in a menu, causing the next appended item to appear in a new column.
void Check(int id, const bool check)
Checks or unchecks the menu item.
Parameters
id
check
See also
void Enable(int id, const bool enable)
Enables or disables (greys out) a menu item.
Parameters
id
enable
See also
int FindItem(const wxString& itemString) const
Finds the menu item id for a menu item string.
Parameters
itemString
Return value
Menu item identifier, or -1 if none is found.
Remarks
Any special menu codes are stripped out of source and target strings before matching.
See also
wxMenuItem* FindItemForId(int id) const
Finds the menu item object associated with the given menu item identifier.
Parameters
id
Return value
Returns the menu item object, or NULL if it is not found.
See also
wxString GetHelpString(int id) const
Returns the help string associated with a menu item.
Parameters
id
Return value
The help string, or the empty string if there is no help string or the item was not found.
See also
wxMenu::SetHelpString, wxMenu::Append
wxString GetLabel(int id) const
Returns a menu item label.
Parameters
id
Return value
The item label, or the empty string if the item was not found.
See also
wxString GetTitle() const
Returns the title of the menu.
Remarks
This is relevant only to popup menus.
See also
bool IsChecked(int id) const
Determines whether a menu item is checked.
Parameters
id
Return value
TRUE if the menu item is checked, FALSE otherwise.
See also
bool IsEnabled(int id) const
Determines whether a menu item is enabled.
Parameters
id
Return value
TRUE if the menu item is enabled, FALSE otherwise.
See also
void SetHelpString(int id, const wxString& helpString)
Sets an item's help string.
Parameters
id
helpString
See also
void SetLabel(int id, const wxString& label)
Sets the label of a menu item.
Parameters
id
label
See also
wxMenu::Append, wxMenu::GetLabel
void SetTitle(const wxString& title)
Sets the title of the menu.
Parameters
title
Remarks
This is relevant only to popup menus.
See also
void UpdateUI(wxEvtHandler* source = NULL) const
Sends events to source (or owning window if NULL) to update the menu UI. This is called just before the menu is popped up with wxWindow::PopupMenu, but the application may call it at other times if required.
See also