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 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
Constructs a wxMenu object.
Parameters
Constructs a wxMenu object.
Parameters
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.
Adds a string item to the end of the menu.
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.
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
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):
DEL or DELETE | Delete key |
---|---|
INS or INSERT | Insert key |
ENTER or RETURN | Enter key |
PGUP | PageUp key |
PGDN | PageDown key |
LEFT | Left cursor arrow key |
RIGHT | Right cursor arrow key |
UP | Up cursor arrow key |
DOWN | Down cursor arrow key |
HOME | Home key |
END | End key |
SPACE | Space |
TAB | Tab key |
ESC or ESCAPE | Escape key (Windows only) |
See also
wxMenu::AppendSeparator, wxMenu::AppendCheckItem, wxMenu::AppendRadioItem, wxMenu::Insert, wxMenu::SetLabel, wxMenu::GetHelpString, wxMenu::SetHelpString, wxMenuItem
wxPython での注意点: In place of a single overloaded method name, wxPython implements the following methods:
2cm
Append(id, string, helpStr="", checkable=false) | |
AppendMenu(id, string, aMenu, helpStr="") | |
AppendItem(aMenuItem) |
Adds a checkable item to the end of the menu.
See also
wxMenu::Append, wxMenu::InsertCheckItem
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.
NB: Currently only implemented under Windows and GTK, use #if wxHAS_RADIO_MENU_ITEMS to test for availability of this feature.
See also
wxMenu::Append, wxMenu::InsertRadioItem
Adds a separator to the end of the menu.
See also
wxMenu::Append, wxMenu::InsertSeparator
Inserts a break in a menu, causing the next appended item to appear in a new column.
Checks or unchecks the menu item.
Parameters
See also
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
See also
wxMenu::FindItem, wxMenu::Destroy, wxMenu::Remove
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
See also
wxMenu::FindItem, wxMenu::Deletes, wxMenu::Remove
Enables or disables (greys out) a menu item.
Parameters
See also
int 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 での注意点: 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
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 での注意点: The name of this method in wxPython is FindItemById and it does not support the second parameter.
wxMenuItem* FindItemByPosition(size_t position) const
Returns the wxMenuItem given a position in the menu.
wxString GetHelpString(int id) const
Returns the help string associated with a menu item.
Parameters
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
Return value
The item label, or the empty string if the item was not found.
See also
size_t GetMenuItemCount(void) const
Returns the number of items in the menu.
wxMenuItemList& GetMenuItems(void) const
Returns the list of items in the menu. wxMenuItemList is a pseudo-template list class containing wxMenuItem pointers.
Returns the title of the menu.
Remarks
This is relevant only to popup menus, use wxMenuBar::GetLabelTop for the menus in the menubar.
See also
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
Inserts a checkable item at the given position.
See also
wxMenu::Insert, wxMenu::AppendCheckItem
Inserts a radio item at the given position.
See also
wxMenu::Insert, wxMenu::AppendRadioItem
Inserts a separator at the given position.
See also
wxMenu::Insert, wxMenu::AppendSeparator
Determines whether a menu item is checked.
Parameters
Return value
true if the menu item is checked, false otherwise.
See also
Determines whether a menu item is enabled.
Parameters
Return value
true if the menu item is enabled, false otherwise.
See also
Inserts the given item at position , i.e. before all the other
existing items.
See also
wxMenu::Append, wxMenu::Insert
Inserts a checkable item at position .
See also
wxMenu::Prepend, wxMenu::AppendCheckItem
Inserts a radio item at position .
See also
wxMenu::Prepend, wxMenu::AppendRadioItem
Inserts a separator at position .
See also
wxMenu::Prepend, wxMenu::AppendSeparator
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
Return value
The item which was detached from the menu.
Sets an item's help string.
Parameters
See also
Sets the label of a menu item.
Parameters
See also
wxMenu::Append, wxMenu::GetLabel
Sets the title of the menu.
Parameters
Remarks
This is relevant only to popup menus, use wxMenuBar::SetLabelTop for the menus in the menubar.
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
ymasuda 平成17年11月19日