wxMenu

wxMenu

wxMenu
Functions for wxMenu class

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. A menu item with a special identifier wxID_SEPARATOR is a separator item and doesn't have an associated command but just makes a separator line appear in the menu.

Note: 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 and will be inserted into the system menu (following the appropriate macOS interface guideline).

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/2 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.

Allocation strategy

All menus must be created on the heap because all menus attached to a menubar or to another menu will be deleted by their parent when it is deleted. The only exception to this rule are the popup menus (i.e. menus used with wxWindow:popupMenu/4) as wxWidgets does not destroy them to allow reusing the same menu more than once. But the exception applies only to the menus themselves and not to any submenus of popup menus which are still destroyed by wxWidgets as usual and so must be heap-allocated.

As the frame menubar is deleted by the frame itself, it means that normally all menus used are deleted automatically.

Event handling

Event handlers for the commands generated by the menu items can be connected directly to the menu object itself using wxEvtHandler::Bind() (not implemented in wx). If this menu is a submenu of another one, the events from its items can also be processed in the parent menu and so on, recursively.

If the menu is part of a menu bar, then events can also be handled in wxMenuBar object.

Finally, menu events can also be handled in the associated window, which is either the wxFrame associated with the menu bar this menu belongs to or the window for which wxWindow:popupMenu/4 was called for the popup menus.

See overview_events_bind for how to bind event handlers to the various objects.

See: wxMenuBar, wxWindow:popupMenu/4, Overview events, wxFileHistory (not implemented in wx)

This class is derived (and can use functions) from: wxEvtHandler

wxWidgets docs: 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.

Types

This = wxMenu()

Adds a menu item object.

This is the most generic variant of append/5 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.

Remark: See the remarks for the other append/5 overloads.

See: appendSeparator/1, appendCheckItem/4, appendRadioItem/4, AppendSubMenu() (not implemented in wx), insert/6, setLabel/3, getHelpString/2, setHelpString/3, wxMenuItem

Types

This = wxMenu()
Option = {help, unicode:chardata()} | {kind, wx:wx_enum()}

Adds a menu item.

Example:

or even better for stock menu items (see wxMenuItem:new/1):

Remark: This command can be used after the menu has been shown, as well as on initial creation of a menu or menubar.

See: appendSeparator/1, appendCheckItem/4, appendRadioItem/4, AppendSubMenu() (not implemented in wx), insert/6, setLabel/3, getHelpString/2, setHelpString/3, wxMenuItem

Types

This = wxMenu()

Inserts a break in a menu, causing the next appended item to appear in a new column.

This function only actually inserts a break in wxMSW and does nothing under the other platforms.

Types

This = wxMenu()
ItemString = unicode:chardata()

Finds the menu id for a menu item string.

Return: Menu item identifier, or wxNOT_FOUND if none is found.

Remark: Any special menu codes are stripped out of source and target strings before matching.

Types

This = wxMenu()

Returns a menu item label.

Return: The item label, or the empty string if the item was not found.

See: GetLabelText() (not implemented in wx), setLabel/3

Types

This = wxMenu()

Returns the number of items in the menu.

Types

This = wxMenu()
Pos = Id = integer()
Submenu = wxMenu()
Option = {help, unicode:chardata()}

Inserts the given submenu before the position pos.

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.

See: AppendSubMenu() (not implemented in wx), prepend/5

Types

This = wxMenu()

Determines whether a menu item is checked.

Return: true if the menu item is checked, false otherwise.

See: check/3

Types

This = wxMenu()

Determines whether a menu item is enabled.

Return: true if the menu item is enabled, false otherwise.

See: enable/3

Types

This = wxMenu()

Removes the menu item from the menu but doesn't delete the associated C++ object.

This allows you to reuse the same item later by adding it back to the menu (especially useful with submenus).

Return: A pointer to the item which was detached from the menu.

Types

This = wxMenu()

Sets the title of the menu.

Remark: Notice that you can only call this method directly for the popup menus, to change the title of a menu that is part of a menu bar you need to use wxMenuBar:setLabelTop/3.

See: getTitle/1