Class: Wx::MenuItem
Overview
A menu item represents an item in a menu.
Note that you usually don’t have to deal with it directly as Menu methods usually construct an object of this class for you. Also please note that the methods related to fonts and bitmaps are currently only implemented for Windows, Mac and GTK+.
Events emitted by this class
The following event-handler methods redirect the events to member method or handler blocks for MenuEvent events. Event handler methods for events emitted by this class:
-
EvtHandler#evt_menu(id, meth = nil, &block): Process a EVT_MENU command, which is generated by a menu item. This type of event is sent as CommandEvent.
-
EvtHandler#evt_menu_range(id1, id2, meth = nil, &block): Process a EVT_MENU command, which is generated by a range of menu items. This type of event is sent as CommandEvent.
-
EvtHandler#evt_menu_open(meth = nil, &block): A menu is about to be opened. On Windows, this is only sent once for each navigation of the menubar (up until all menus have closed). This type of event is sent as MenuEvent.
-
EvtHandler#evt_menu_close(meth = nil, &block): A menu has been just closed. This type of event is sent as MenuEvent.
-
EvtHandler#evt_menu_highlight(id, meth = nil, &block): The menu item with the specified id has been highlighted. If the id is StandardID::ID_NONE, highlighting has been removed from the previously highlighted menu item and there is no highlighted item any more. This is used by Frame to show help prompts in the status bar. This type of event is sent as MenuEvent.
-
EvtHandler#evt_menu_highlight_all(meth = nil, &block): A menu item has been highlighted, i.e. the currently selected menu item has changed. This type of event is sent as MenuEvent.
Category: Menus
Class Method Summary collapse
-
.get_label_text(text) ⇒ String
Strips all accelerator characters and mnemonics from the given text.
Instance Method Summary collapse
-
#add_extra_accel(accel) ⇒ void
Add an extra accelerator for this menu item.
-
#check(check = true) ⇒ void
Checks or unchecks the menu item.
-
#clear_extra_accels ⇒ void
Clear the extra accelerators list.
-
#enable(enable = true) ⇒ void
Enables or disables the menu item.
-
#get_accel ⇒ Wx::AcceleratorEntry
(also: #accel)
Get our accelerator or NULL (caller must delete the pointer).
-
#get_background_colour ⇒ Wx::Colour
(also: #background_colour)
Returns the background colour associated with the menu item.
-
#get_bitmap ⇒ Wx::Bitmap
(also: #bitmap)
Returns the item bitmap.
-
#get_bitmap_bundle ⇒ Wx::BitmapBundle
(also: #bitmap_bundle)
Returns the bitmap bundle containing the bitmap used for this item.
-
#get_disabled_bitmap ⇒ Wx::Bitmap
(also: #disabled_bitmap)
Returns the bitmap used for disabled items.
-
#get_font ⇒ Wx::Font
(also: #font)
Returns the font associated with the menu item.
-
#get_help ⇒ Wx::String
(also: #help)
Returns the help string associated with the menu item.
-
#get_id ⇒ Integer
(also: #id)
Returns the menu item identifier.
-
#get_item_label ⇒ String
(also: #item_label)
Returns the text associated with the menu item including any accelerator characters that were passed to the constructor or #set_item_label.
-
#get_item_label_text ⇒ String
(also: #item_label_text)
Returns the text associated with the menu item, without any accelerator characters.
-
#get_kind ⇒ Wx::ItemKind
(also: #kind)
Returns the item kind, one of ItemKind::ITEM_SEPARATOR, ItemKind::ITEM_NORMAL, ItemKind::ITEM_CHECK or ItemKind::ITEM_RADIO.
-
#get_margin_width ⇒ Integer
(also: #margin_width)
Gets the width of the menu item checkmark bitmap.
-
#get_menu ⇒ Wx::Menu
(also: #menu)
Returns the menu this menu item is in, or NULL if this menu item is not attached.
-
#get_sub_menu ⇒ Wx::Menu
(also: #sub_menu)
Returns the submenu associated with the menu item, or NULL if there isn’t one.
-
#get_text_colour ⇒ Wx::Colour
(also: #text_colour)
Returns the text colour associated with the menu item.
-
#initialize(parentMenu = nil, id = Wx::StandardID::ID_SEPARATOR, text = (''), helpString = (''), kind = Wx::ItemKind::ITEM_NORMAL, subMenu = nil) ⇒ Wx::MenuItem
constructor
Constructs a MenuItem object.
-
#is_check ⇒ Boolean
(also: #check?)
Returns true if the item is a check item.
-
#is_checkable ⇒ Boolean
(also: #checkable?)
Returns true if the item is checkable.
-
#is_checked ⇒ Boolean
(also: #checked?)
Returns true if the item is checked.
-
#is_enabled ⇒ Boolean
(also: #enabled?)
Returns true if the item is enabled.
-
#is_radio ⇒ Boolean
(also: #radio?)
Returns true if the item is a radio button.
-
#is_separator ⇒ Boolean
(also: #separator?)
Returns true if the item is a separator.
-
#is_sub_menu ⇒ Boolean
(also: #sub_menu?)
Returns true if the item is a submenu.
-
#set_accel(accel) ⇒ void
(also: #accel=)
Set the accel for this item - this may also be done indirectly with set_text.
-
#set_background_colour(colour) ⇒ void
Sets the background colour associated with the menu item.
- #set_bitmap(*args) ⇒ Object (also: #bitmap=)
-
#set_bitmaps(checked, unchecked = Wx::NULL_BITMAP) ⇒ void
Sets the checked/unchecked bitmaps for the menu item.
-
#set_disabled_bitmap(disabled) ⇒ void
Sets the to be used for disabled menu items.
-
#set_font(font) ⇒ void
Sets the font associated with the menu item.
-
#set_help(helpString) ⇒ void
(also: #help=)
Sets the help string.
-
#set_item_label(label) ⇒ void
(also: #item_label=)
Sets the label associated with the menu item.
-
#set_margin_width(width) ⇒ void
Sets the width of the menu item checkmark bitmap.
-
#set_menu(menu) ⇒ void
(also: #menu=)
Sets the parent menu which will contain this menu item.
-
#set_sub_menu(menu) ⇒ void
(also: #sub_menu=)
Sets the submenu of this menu item.
-
#set_text_colour(colour) ⇒ void
Sets the text colour associated with the menu item.
Methods inherited from Object
#clone, #dup, #is_same_as, #un_share
Constructor Details
#initialize(parentMenu = nil, id = Wx::StandardID::ID_SEPARATOR, text = (''), helpString = (''), kind = Wx::ItemKind::ITEM_NORMAL, subMenu = nil) ⇒ Wx::MenuItem
Constructs a Wx::MenuItem object.
Menu items can be standard, or “stock menu items”, or custom. For the standard menu items (such as commands to open a file, exit the program and so on, see Stock Items for the full list) it is enough to specify just the stock ID and leave text and helpString empty. Some platforms (currently WXGTK only, and see the remark in #set_bitmap documentation) will also show standard bitmaps for stock menu items. Leaving at least text empty for the stock menu items is actually strongly recommended as they will have appearance and keyboard interface (including standard accelerators) familiar to the user. For the custom (non-stock) menu items, text must be specified and while helpString may be left empty, it’s recommended to pass the item description (which is automatically shown by the library in the status bar when the menu item is selected) in this parameter. Finally note that you can e.g. use a stock menu label without using its stock help string:
# use all stock properties:
helpMenu.append(wxID_ABOUT)
# use the stock label and the stock accelerator but not the stock help string:
helpMenu.append(Wx::ID_ABOUT, "", "My custom help string")
# use all stock properties except for the bitmap:
= Wx::MenuItem.new(helpMenu, Wx::ID_ABOUT)
.set_bitmap(Wx::ArtProvider.get_bitmap(Wx::ART_WARNING))
helpMenu.append()
that is, stock properties are set independently one from the other.
430 |
# File 'lib/wx/doc/gen/menu_item.rb', line 430 def initialize(parentMenu=nil, id=Wx::StandardID::ID_SEPARATOR, text=(''), helpString=(''), kind=Wx::ItemKind::ITEM_NORMAL, subMenu=nil) end |
Class Method Details
Instance Method Details
#add_extra_accel(accel) ⇒ void
This method returns an undefined value.
Add an extra accelerator for this menu item.
Additional accelerators are not shown in the item’s label, but still will trigger the menu command when pressed. They can be useful to let multiple keys be used as accelerators for the same command, e.g. KeyCode::K_ADD and KeyCode::K_NUMPAD_ADD. Availability: only available for the WXMSW, WXGTK ports.
394 |
# File 'lib/wx/doc/gen/menu_item.rb', line 394 def add_extra_accel(accel) end |
#check(check = true) ⇒ void
This method returns an undefined value.
Checks or unchecks the menu item.
Note that this only works when the item is already appended to a menu.
437 |
# File 'lib/wx/doc/gen/menu_item.rb', line 437 def check(check=true) end |
#clear_extra_accels ⇒ void
This method returns an undefined value.
Clear the extra accelerators list.
This doesn’t affect the main item accelerator (if any).
400 |
# File 'lib/wx/doc/gen/menu_item.rb', line 400 def clear_extra_accels; end |
#enable(enable = true) ⇒ void
This method returns an undefined value.
Enables or disables the menu item.
442 |
# File 'lib/wx/doc/gen/menu_item.rb', line 442 def enable(enable=true) end |
#get_accel ⇒ Wx::AcceleratorEntry Also known as: accel
Get our accelerator or NULL (caller must delete the pointer)
139 |
# File 'lib/wx/doc/gen/menu_item.rb', line 139 def get_accel; end |
#get_background_colour ⇒ Wx::Colour Also known as: background_colour
Returns the background colour associated with the menu item.
Availability: only available for the WXMSW port.
43 |
# File 'lib/wx/doc/gen/menu_item.rb', line 43 def get_background_colour; end |
#get_bitmap ⇒ Wx::Bitmap Also known as: bitmap
Returns the item bitmap.
This method exists only for compatibility, please use #get_bitmap_bundle in the new code.
50 |
# File 'lib/wx/doc/gen/menu_item.rb', line 50 def get_bitmap; end |
#get_bitmap_bundle ⇒ Wx::BitmapBundle Also known as: bitmap_bundle
Returns the bitmap bundle containing the bitmap used for this item.
The returned bundle is invalid, i.e. empty, if no bitmap is associated with the item.
58 |
# File 'lib/wx/doc/gen/menu_item.rb', line 58 def get_bitmap_bundle; end |
#get_disabled_bitmap ⇒ Wx::Bitmap Also known as: disabled_bitmap
Returns the bitmap used for disabled items.
Availability: only available for the WXMSW port.
66 |
# File 'lib/wx/doc/gen/menu_item.rb', line 66 def get_disabled_bitmap; end |
#get_font ⇒ Wx::Font Also known as: font
Returns the font associated with the menu item.
Availability: only available for the WXMSW port.
74 |
# File 'lib/wx/doc/gen/menu_item.rb', line 74 def get_font; end |
#get_help ⇒ Wx::String Also known as: help
Returns the help string associated with the menu item.
79 |
# File 'lib/wx/doc/gen/menu_item.rb', line 79 def get_help; end |
#get_id ⇒ Integer Also known as: id
Returns the menu item identifier.
84 |
# File 'lib/wx/doc/gen/menu_item.rb', line 84 def get_id; end |
#get_item_label ⇒ String Also known as: item_label
Returns the text associated with the menu item including any accelerator characters that were passed to the constructor or #set_item_label.
93 |
# File 'lib/wx/doc/gen/menu_item.rb', line 93 def get_item_label; end |
#get_item_label_text ⇒ String Also known as: item_label_text
Returns the text associated with the menu item, without any accelerator characters.
102 |
# File 'lib/wx/doc/gen/menu_item.rb', line 102 def get_item_label_text; end |
#get_kind ⇒ Wx::ItemKind Also known as: kind
Returns the item kind, one of ItemKind::ITEM_SEPARATOR, ItemKind::ITEM_NORMAL, ItemKind::ITEM_CHECK or ItemKind::ITEM_RADIO.
107 |
# File 'lib/wx/doc/gen/menu_item.rb', line 107 def get_kind; end |
#get_margin_width ⇒ Integer Also known as: margin_width
Gets the width of the menu item checkmark bitmap.
Availability: only available for the WXMSW port.
115 |
# File 'lib/wx/doc/gen/menu_item.rb', line 115 def get_margin_width; end |
#get_menu ⇒ Wx::Menu Also known as:
Returns the menu this menu item is in, or NULL if this menu item is not attached.
120 |
# File 'lib/wx/doc/gen/menu_item.rb', line 120 def ; end |
#get_sub_menu ⇒ Wx::Menu Also known as:
Returns the submenu associated with the menu item, or NULL if there isn’t one.
125 |
# File 'lib/wx/doc/gen/menu_item.rb', line 125 def ; end |
#get_text_colour ⇒ Wx::Colour Also known as: text_colour
Returns the text colour associated with the menu item.
Availability: only available for the WXMSW port.
133 |
# File 'lib/wx/doc/gen/menu_item.rb', line 133 def get_text_colour; end |
#is_check ⇒ Boolean Also known as: check?
Returns true if the item is a check item.
Unlike #is_checkable this doesn’t return true for the radio buttons.
146 |
# File 'lib/wx/doc/gen/menu_item.rb', line 146 def is_check; end |
#is_checkable ⇒ Boolean Also known as: checkable?
Returns true if the item is checkable.
Notice that the radio buttons are considered to be checkable as well, so this method returns true for them too. Use #is_check if you want to test for the check items only.
153 |
# File 'lib/wx/doc/gen/menu_item.rb', line 153 def is_checkable; end |
#is_checked ⇒ Boolean Also known as: checked?
Returns true if the item is checked.
158 |
# File 'lib/wx/doc/gen/menu_item.rb', line 158 def is_checked; end |
#is_enabled ⇒ Boolean Also known as: enabled?
Returns true if the item is enabled.
163 |
# File 'lib/wx/doc/gen/menu_item.rb', line 163 def is_enabled; end |
#is_radio ⇒ Boolean Also known as: radio?
Returns true if the item is a radio button.
168 |
# File 'lib/wx/doc/gen/menu_item.rb', line 168 def is_radio; end |
#is_separator ⇒ Boolean Also known as: separator?
Returns true if the item is a separator.
173 |
# File 'lib/wx/doc/gen/menu_item.rb', line 173 def is_separator; end |
#is_sub_menu ⇒ Boolean Also known as:
Returns true if the item is a submenu.
178 |
# File 'lib/wx/doc/gen/menu_item.rb', line 178 def ; end |
#set_accel(accel) ⇒ void Also known as: accel=
This method returns an undefined value.
Set the accel for this item - this may also be done indirectly with set_text
383 |
# File 'lib/wx/doc/gen/menu_item.rb', line 383 def set_accel(accel) end |
#set_background_colour(colour) ⇒ void
This method returns an undefined value.
Sets the background colour associated with the menu item.
Availability: only available for the WXMSW port.
187 |
# File 'lib/wx/doc/gen/menu_item.rb', line 187 def set_background_colour(colour) end |
#set_bitmap(bmp) ⇒ void #set_bitmap(bmp, checked) ⇒ void Also known as: bitmap=
205 |
# File 'lib/wx/doc/gen/menu_item.rb', line 205 def set_bitmap(*args) end |
#set_bitmaps(checked, unchecked = Wx::NULL_BITMAP) ⇒ void
This method returns an undefined value.
Sets the checked/unchecked bitmaps for the menu item.
The first bitmap is also used as the single bitmap for uncheckable menu items. Availability: only available for the WXMSW port.
216 |
# File 'lib/wx/doc/gen/menu_item.rb', line 216 def set_bitmaps(checked, unchecked=Wx::NULL_BITMAP) end |
#set_disabled_bitmap(disabled) ⇒ void
This method returns an undefined value.
Sets the to be used for disabled menu items.
Availability: only available for the WXMSW port.
224 |
# File 'lib/wx/doc/gen/menu_item.rb', line 224 def set_disabled_bitmap(disabled) end |
#set_font(font) ⇒ void
This method returns an undefined value.
Sets the font associated with the menu item.
Availability: only available for the WXMSW port.
232 |
# File 'lib/wx/doc/gen/menu_item.rb', line 232 def set_font(font) end |
#set_help(helpString) ⇒ void Also known as: help=
This method returns an undefined value.
Sets the help string.
237 |
# File 'lib/wx/doc/gen/menu_item.rb', line 237 def set_help(helpString) end |
#set_item_label(label) ⇒ void Also known as: item_label=
This method returns an undefined value.
Sets the label associated with the menu item.
Note that if the ID of this menu item corresponds to a stock ID, then it is not necessary to specify a label: wxWidgets will automatically use the stock item label associated with that ID. See the constructor for more info. The label string for the normal menu items (not separators) may include the accelerator which can be used to activate the menu item from keyboard. An accelerator key can be specified using the ampersand &
character. In order to embed an ampersand character in the menu item text, the ampersand must be doubled. Optionally you can specify also an accelerator string appending a tab character \t
followed by a valid key combination (e.g. CTRL+V
). Its general syntax is any combination of "CTRL"
, "RAWCTRL"
, "ALT"
and "SHIFT"
strings (case doesn’t matter) separated by either '-'
or '+'
characters and followed by the accelerator itself. Notice that CTRL corresponds to the “Ctrl” key on most platforms but not under macOS where it is mapped to “Cmd” key on Mac keyboard. Usually this is exactly what you want in portable code but if you really need to use the (rarely used for this purpose) “Ctrl” key even under Mac, you may use RAWCTRL to prevent this mapping. Under the other platforms RAWCTRL is the same as plain CTRL. The accelerator may be any alphanumeric character, any function key (from F1 to F12), any numpad digit key using KP_ prefix (i.e. from KP_0 to KP_9) or one of the special strings listed below (again, case doesn’t matter) corresponding to the specified key code:
-
Del or Delete: KeyCode::K_DELETE
-
Back: KeyCode::K_BACK
-
Ins or Insert: KeyCode::K_INSERT
-
Enter or Return: KeyCode::K_RETURN
-
PgUp or PageUp: KeyCode::K_PAGEUP
-
PgDn or PageDown: KeyCode::K_PAGEDOWN
-
Left: KeyCode::K_LEFT
-
Right: KeyCode::K_RIGHT
-
Up: KeyCode::K_UP
-
Down: KeyCode::K_DOWN
-
Home: KeyCode::K_HOME
-
End: KeyCode::K_END
-
Space: KeyCode::K_SPACE
-
Tab: KeyCode::K_TAB
-
Esc or Escape: KeyCode::K_ESCAPE
-
Cancel: KeyCode::K_CANCEL
-
Clear: KeyCode::K_CLEAR
-
Menu: KeyCode::K_MENU
-
Pause: KeyCode::K_PAUSE
-
Capital: KeyCode::K_CAPITAL
-
Select: KeyCode::K_SELECT
-
Print: KeyCode::K_PRINT
-
Execute: KeyCode::K_EXECUTE
-
Snapshot: KeyCode::K_SNAPSHOT
-
Help: KeyCode::K_HELP
-
Add: KeyCode::K_ADD
-
Separator: KeyCode::K_SEPARATOR
-
Subtract: KeyCode::K_SUBTRACT
-
Decimal: KeyCode::K_DECIMAL
-
Divide: KeyCode::K_DIVIDE
-
Num_lock: KeyCode::K_NUMLOCK
-
Scroll_lock: KeyCode::K_SCROLL
-
KP_Space: KeyCode::K_NUMPAD_SPACE
-
KP_Tab: KeyCode::K_NUMPAD_TAB
-
KP_Enter: KeyCode::K_NUMPAD_ENTER
-
KP_Home: KeyCode::K_NUMPAD_HOME
-
KP_Left: KeyCode::K_NUMPAD_LEFT
-
KP_Up: KeyCode::K_NUMPAD_UP
-
KP_Right: KeyCode::K_NUMPAD_RIGHT
-
KP_Down: KeyCode::K_NUMPAD_DOWN
-
KP_PageUp: KeyCode::K_NUMPAD_PAGEUP
-
KP_PageDown: KeyCode::K_NUMPAD_PAGEDOWN
-
KP_Prior: KeyCode::K_NUMPAD_PAGEUP
-
KP_Next: KeyCode::K_NUMPAD_PAGEDOWN
-
KP_End: KeyCode::K_NUMPAD_END
-
KP_Begin: KeyCode::K_NUMPAD_BEGIN
-
KP_Insert: KeyCode::K_NUMPAD_INSERT
-
KP_Delete: KeyCode::K_NUMPAD_DELETE
-
KP_Equal: KeyCode::K_NUMPAD_EQUAL
-
KP_Multiply: KeyCode::K_NUMPAD_MULTIPLY
-
KP_Add: KeyCode::K_NUMPAD_ADD
-
KP_Separator: KeyCode::K_NUMPAD_SEPARATOR
-
KP_Subtract: KeyCode::K_NUMPAD_SUBTRACT
-
KP_Decimal: KeyCode::K_NUMPAD_DECIMAL
-
KP_Divide: KeyCode::K_NUMPAD_DIVIDE
-
Windows_Left: KeyCode::K_WINDOWS_LEFT
-
Windows_Right: KeyCode::K_WINDOWS_RIGHT
-
Windows_Menu: KeyCode::K_WINDOWS_MENU
-
Command: KeyCode::K_COMMAND
Examples:
@my_menu_item.set_item_label("My &item\tCTRL+I")
@my_menu_item2.set_item_label("Clean && build\tF7")
@my_menu_item3.set_item_label("Simple item")
@my_menu_item4.set_item_label("Item with &accelerator")
In WXGTK using "SHIFT"
with non-alphabetic characters currently doesn't work, even in combination with other modifiers, due to GTK+ limitation. E.g. Shift+Ctrl+A
works but Shift+Ctrl+1
or Shift+/
do not, so avoid using accelerators of this form in portable code.
In GTk, the left/right/up/down arrow keys do not work as accelerator keys for a menu item unless a modifier key is used. Additionally, the following keycodes are not supported as menu accelerator keys: - KeyCode::K_COMMAND/KeyCode::K_CONTROL - KeyCode::K_SHIFT - KeyCode::K_ALT - KeyCode::K_SCROLL - KeyCode::K_CAPITAL - KeyCode::K_NUMLOCK - KeyCode::K_NUMPAD_TAB - KeyCode::K_TAB - KeyCode::K_WINDOWS_LEFT - KeyCode::K_WINDOWS_RIGHT - KeyCode::K_ADD - KeyCode::K_SEPARATOR - KeyCode::K_SUBTRACT - KeyCode::K_DECIMAL - KeyCode::K_DIVIDE - KeyCode::K_SNAPSHOT
349 |
# File 'lib/wx/doc/gen/menu_item.rb', line 349 def set_item_label(label) end |
#set_margin_width(width) ⇒ void
This method returns an undefined value.
Sets the width of the menu item checkmark bitmap.
Availability: only available for the WXMSW port.
358 |
# File 'lib/wx/doc/gen/menu_item.rb', line 358 def set_margin_width(width) end |
#set_menu(menu) ⇒ void Also known as:
This method returns an undefined value.
Sets the parent menu which will contain this menu item.
363 |
# File 'lib/wx/doc/gen/menu_item.rb', line 363 def () end |
#set_sub_menu(menu) ⇒ void Also known as:
This method returns an undefined value.
Sets the submenu of this menu item.
369 |
# File 'lib/wx/doc/gen/menu_item.rb', line 369 def () end |
#set_text_colour(colour) ⇒ void
This method returns an undefined value.
Sets the text colour associated with the menu item.
Availability: only available for the WXMSW port.
378 |
# File 'lib/wx/doc/gen/menu_item.rb', line 378 def set_text_colour(colour) end |