wxmenua 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. a menu item with a special identifier -1 is a separator item and doesn't have an associated command but just makes a separator line appear in the menu. nb: please note that wxid_about and wxid_exit are predefined by wxwidgets and have a special meaning since entries using these ids will be taken out of the normal menus under macos x and will be inserted into the system menu (following the appropriate macos x interface guideline). on palmos wxid_exit is disabled according to palm os companion guidelines. menu items may be either normal items, check items or 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. wxwidgets automatically toggles the flag value when the item is clicked and its value may be retrieved using either ischecked method of wxmenu or wxmenubar itself or by using wxevent::ischecked when you get the menu notification for the item in question. the radio items are similar to the check items except that all the other items in the same radio group are unchecked when a radio item is checked. the radio group is formed by a contiguous range of radio items, i.e. it starts at the 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. allocation strategy all menus except the popup ones must be created on the 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. 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, wxfilehistory (most recently used files menu)
members
wxmenu::wxmenu
wxmenu::wxmenuwxmenu(const wxstring& title = "", long style = 0) constructs a wxmenu object. parameters title
style
wxmenu(long style) constructs a wxmenu object. parameters style
wxmenu::~wxmenu~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.
wxmenu::appendwxmenuitem* append(int id, const wxstring& item = "", const wxstring& helpstring = "", wxitemkind kind = wxitem_normal) adds a string item to the end of the menu. wxmenuitem* append(int id, const wxstring& item, wxmenu *submenu, const wxstring& helpstring = "") adds a pull-right submenu to the end of the menu. append the submenu to the parent menu after you have added your menu items, or accelerators may not be registered properly. wxmenuitem* append(wxmenuitem* menuitem) adds a menu item object. this is the most generic variant of append() method because it may be used for both items (including separators) and submenus and because you can also specify various extra properties of a menu item this way, such as bitmaps and fonts. parameters id
item
menu
kind
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. the item string for the normal menu items (not submenus or separators) may include the accelerator which can be used to activate the menu item from keyboard. the accelerator string follows the item label and is separated from it by a tab character ('\t'). its general syntax is any combination of "ctrl", "alt" and "shift" strings (case doesn't matter) separated by either '-' or '+' characters and followed by the accelerator itself. the accelerator may be any alphanumeric character, any function key (from f1 to f12) or one of the special characters listed in the table below (again, case doesn't matter):
see also wxmenu::appendseparator, wxmenu::appendcheckitem, wxmenu::appendradioitem, wxmenu::appendsubmenu, wxmenu::insert, wxmenu::setlabel, wxmenu::gethelpstring, wxmenu::sethelpstring, wxmenuitem wxpython note: in place of a single overloaded method name, wxpython implements the following methods:
wxmenu::appendcheckitemwxmenuitem* appendcheckitem(int id, const wxstring& item, const wxstring& helpstring = "") adds a checkable item to the end of the menu. see also wxmenu::append, wxmenu::insertcheckitem
wxmenu::appendradioitemwxmenuitem* appendradioitem(int id, const wxstring& item, const wxstring& helpstring = "") 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. see also wxmenu::append, wxmenu::insertradioitem
wxmenu::appendseparatorwxmenuitem* appendseparator() adds a separator to the end of the menu. see also wxmenu::append, wxmenu::insertseparator
wxmenu::appendsubmenuwxmenuitem * appendsubmenu(wxmenu *submenu, const wxstring& text, const wxstring& help = wxemptystring) adds the given submenu to this menu. text is the text shown in the menu for it and help is the help string shown in the status bar when the submenu item is selected.
wxmenu::breakvoid break() inserts a break in a menu, causing the next appended item to appear in a new column.
wxmenu::checkvoid check(int id, const bool check) checks or unchecks the menu item. parameters id
check
see also
wxmenu::deletevoid delete(int id) void delete(wxmenuitem *item) deletes the menu item from the menu. if the item is a submenu, it will not be deleted. use destroy if you want to delete a submenu. parameters id
item
see also wxmenu::finditem, wxmenu::destroy, wxmenu::remove
wxmenu::destroyvoid destroy(int id) void destroy(wxmenuitem *item) deletes the menu item from the menu. if the item is a submenu, it will be deleted. use remove if you want to keep the submenu (for example, to reuse it later). parameters id
item
see also wxmenu::finditem, wxmenu::deletes, wxmenu::remove
wxmenu::enablevoid enable(int id, const bool enable) enables or disables (greys out) a menu item. parameters id
enable
see also
wxmenu::finditemint finditem(const wxstring& itemstring) const finds the menu item id for a menu item string. wxmenuitem * finditem(int id, wxmenu **menu = null) const finds the menu item object associated with the given menu item identifier and, optionally, the (sub)menu it belongs to. wxperl note: in wxperl this method takes just the id parameter; in scalar context it returns the associated wx::menuitem, in list context it returns a 2-element list ( item, submenu ) parameters itemstring
id
menu
return value first form: menu item identifier, or wxnot_found if none is found. second form: returns the menu item object, or null if it is not found. remarks any special menu codes are stripped out of source and target strings before matching. wxpython note: the name of this method in wxpython is finditembyid and it does not support the second parameter.
wxmenu::finditembypositionwxmenuitem* finditembyposition(size_t position) const returns the wxmenuitem given a position in the menu.
wxmenu::gethelpstringwxstring 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
wxmenu::getlabelwxstring getlabel(int id) const returns a menu item label, including any mnemonics and accelerators. parameters id
return value the item label, or the empty string if the item was not found. see also wxmenu::getlabeltext, wxmenu::setlabel
wxmenu::getlabeltextwxstring getlabeltext(int id) const returns a menu item label, without any of the original mnemonics and accelerators. parameters id
return value the item label, or the empty string if the item was not found. see also wxmenu::getlabel, wxmenu::setlabel
wxmenu::getmenuitemcountsize_t getmenuitemcount() const returns the number of items in the menu.
wxmenu::getmenuitemswxmenuitemlist& getmenuitems() const returns the list of items in the menu. wxmenuitemlist is a pseudo-template list class containing wxmenuitem pointers, see wxlist.
wxmenu::gettitlewxstring gettitle() const returns the title of the menu. remarks this is relevant only to popup menus, use wxmenubar::getmenulabel for the menus in the menubar. see also
wxmenu::insertwxmenuitem* insert(size_t pos, wxmenuitem *item) wxmenuitem* insert(size_t pos, int id, const wxstring& item = "", const wxstring& helpstring = "", wxitemkind kind = wxitem_normal) inserts the given item before the position pos. inserting the item at position getmenuitemcount is the same as appending it. see also wxmenu::append, wxmenu::prepend
wxmenu::insertcheckitemwxmenuitem* insertcheckitem(size_t pos, int id, const wxstring& item, const wxstring& helpstring = "") inserts a checkable item at the given position. see also wxmenu::insert, wxmenu::appendcheckitem
wxmenu::insertradioitemwxmenuitem* insertradioitem(size_t pos, int id, const wxstring& item, const wxstring& helpstring = "") inserts a radio item at the given position. see also wxmenu::insert, wxmenu::appendradioitem
wxmenu::insertseparatorwxmenuitem* insertseparator(size_t pos) inserts a separator at the given position. see also wxmenu::insert, wxmenu::appendseparator
wxmenu::ischeckedbool 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
wxmenu::isenabledbool 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
wxmenu::prependwxmenuitem* prepend(wxmenuitem *item) wxmenuitem* prepend(int id, const wxstring& item = "", const wxstring& helpstring = "", wxitemkind kind = wxitem_normal) inserts the given item at position 0, i.e. before all the other existing items. see also wxmenu::append, wxmenu::insert
wxmenu::prependcheckitemwxmenuitem* prependcheckitem(int id, const wxstring& item, const wxstring& helpstring = "") inserts a checkable item at position 0. see also wxmenu::prepend, wxmenu::appendcheckitem
wxmenu::prependradioitemwxmenuitem* prependradioitem(int id, const wxstring& item, const wxstring& helpstring = "") inserts a radio item at position 0. see also wxmenu::prepend, wxmenu::appendradioitem
wxmenu::prependseparatorwxmenuitem* prependseparator() inserts a separator at position 0. see also wxmenu::prepend, wxmenu::appendseparator
wxmenu::removewxmenuitem * remove(int id) wxmenuitem * remove(wxmenuitem *item) removes the menu item from the menu but doesn't delete the associated c++ object. this allows to reuse the same item later by adding it back to the menu (especially useful with submenus). parameters id
item
return value the item which was detached from the menu.
wxmenu::sethelpstringvoid sethelpstring(int id, const wxstring& helpstring) sets an item's help string. parameters id
helpstring
see also
wxmenu::setlabelvoid setlabel(int id, const wxstring& label) sets the label of a menu item. parameters id
label
see also wxmenu::append, wxmenu::getlabel
wxmenu::settitlevoid settitle(const wxstring& title) sets the title of the menu. parameters title
remarks this is relevant only to popup menus, use wxmenubar::setlabeltop for the menus in the menubar. see also
wxmenu::updateuivoid 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
|