Class: Wx::MenuItem

Inherits:
Object show all
Defined in:
lib/wx/doc/gen/menu_item.rb

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:

Category: Menus

See Also:

Requires:

  • USE_MENUS

Class Method Summary collapse

Instance Method Summary collapse

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:
  mymenu = Wx::MenuItem.new(helpMenu, Wx::ID_ABOUT)
  mymenu.set_bitmap(Wx::ArtProvider.get_bitmap(Wx::ART_WARNING))
  helpMenu.append(mymenu)

that is, stock properties are set independently one from the other.

Parameters:



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

.get_label_text(text) ⇒ String

Strips all accelerator characters and mnemonics from the given text.

For example:

Wx::MenuItem.get_label_text("&Hello\tCtrl-h")

will return just "Hello".

Parameters:

  • text (String)

Returns:

  • (String)

See Also:



457
# File 'lib/wx/doc/gen/menu_item.rb', line 457

def self.get_label_text(text) end

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.

Parameters:

Requires:

  • WXMSW or WXGTK


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.

Parameters:

  • check (Boolean) (defaults to: true)


437
# File 'lib/wx/doc/gen/menu_item.rb', line 437

def check(check=true) end

#clear_extra_accelsvoid

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.

Parameters:

  • enable (Boolean) (defaults to: true)


442
# File 'lib/wx/doc/gen/menu_item.rb', line 442

def enable(enable=true) end

#get_accelWx::AcceleratorEntry Also known as: accel

Get our accelerator or NULL (caller must delete the pointer)

Returns:

Requires:

  • USE_ACCEL


139
# File 'lib/wx/doc/gen/menu_item.rb', line 139

def get_accel; end

#get_background_colourWx::Colour Also known as: background_colour

Returns the background colour associated with the menu item.

Availability: only available for the WXMSW port.

Returns:

Requires:

  • WXMSW


43
# File 'lib/wx/doc/gen/menu_item.rb', line 43

def get_background_colour; end

#get_bitmapWx::Bitmap Also known as: bitmap

Returns the item bitmap.

This method exists only for compatibility, please use #get_bitmap_bundle in the new code.

Returns:



50
# File 'lib/wx/doc/gen/menu_item.rb', line 50

def get_bitmap; end

#get_bitmap_bundleWx::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.

Returns:

See Also:



58
# File 'lib/wx/doc/gen/menu_item.rb', line 58

def get_bitmap_bundle; end

#get_disabled_bitmapWx::Bitmap Also known as: disabled_bitmap

Returns the bitmap used for disabled items.

Availability: only available for the WXMSW port.

Returns:

Requires:

  • WXMSW


66
# File 'lib/wx/doc/gen/menu_item.rb', line 66

def get_disabled_bitmap; end

#get_fontWx::Font Also known as: font

Returns the font associated with the menu item.

Availability: only available for the WXMSW port.

Returns:

Requires:

  • WXMSW


74
# File 'lib/wx/doc/gen/menu_item.rb', line 74

def get_font; end

#get_helpWx::String Also known as: help

Returns the help string associated with the menu item.

Returns:

  • (Wx::String)


79
# File 'lib/wx/doc/gen/menu_item.rb', line 79

def get_help; end

#get_idInteger Also known as: id

Returns the menu item identifier.

Returns:

  • (Integer)


84
# File 'lib/wx/doc/gen/menu_item.rb', line 84

def get_id; end

#get_item_labelString 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.

Returns:

  • (String)

See Also:



93
# File 'lib/wx/doc/gen/menu_item.rb', line 93

def get_item_label; end

#get_item_label_textString Also known as: item_label_text

Returns the text associated with the menu item, without any accelerator characters.

Returns:

  • (String)

See Also:



102
# File 'lib/wx/doc/gen/menu_item.rb', line 102

def get_item_label_text; end

#get_kindWx::ItemKind Also known as: kind

Returns:



107
# File 'lib/wx/doc/gen/menu_item.rb', line 107

def get_kind; end

#get_margin_widthInteger Also known as: margin_width

Gets the width of the menu item checkmark bitmap.

Availability: only available for the WXMSW port.

Returns:

  • (Integer)

Requires:

  • WXMSW


115
# File 'lib/wx/doc/gen/menu_item.rb', line 115

def get_margin_width; end

#get_menuWx::Menu Also known as: menu

Returns the menu this menu item is in, or NULL if this menu item is not attached.

Returns:



120
# File 'lib/wx/doc/gen/menu_item.rb', line 120

def get_menu; end

#get_sub_menuWx::Menu Also known as: sub_menu

Returns the submenu associated with the menu item, or NULL if there isn’t one.

Returns:



125
# File 'lib/wx/doc/gen/menu_item.rb', line 125

def get_sub_menu; end

#get_text_colourWx::Colour Also known as: text_colour

Returns the text colour associated with the menu item.

Availability: only available for the WXMSW port.

Returns:

Requires:

  • WXMSW


133
# File 'lib/wx/doc/gen/menu_item.rb', line 133

def get_text_colour; end

#is_checkBoolean 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.

Returns:

  • (Boolean)


146
# File 'lib/wx/doc/gen/menu_item.rb', line 146

def is_check; end

#is_checkableBoolean 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.

Returns:

  • (Boolean)


153
# File 'lib/wx/doc/gen/menu_item.rb', line 153

def is_checkable; end

#is_checkedBoolean Also known as: checked?

Returns true if the item is checked.

Returns:

  • (Boolean)


158
# File 'lib/wx/doc/gen/menu_item.rb', line 158

def is_checked; end

#is_enabledBoolean Also known as: enabled?

Returns true if the item is enabled.

Returns:

  • (Boolean)


163
# File 'lib/wx/doc/gen/menu_item.rb', line 163

def is_enabled; end

#is_radioBoolean Also known as: radio?

Returns true if the item is a radio button.

Returns:

  • (Boolean)


168
# File 'lib/wx/doc/gen/menu_item.rb', line 168

def is_radio; end

#is_separatorBoolean Also known as: separator?

Returns true if the item is a separator.

Returns:

  • (Boolean)


173
# File 'lib/wx/doc/gen/menu_item.rb', line 173

def is_separator; end

#is_sub_menuBoolean Also known as: sub_menu?

Returns true if the item is a submenu.

Returns:

  • (Boolean)


178
# File 'lib/wx/doc/gen/menu_item.rb', line 178

def is_sub_menu; 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

Parameters:



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.

Parameters:

Requires:

  • WXMSW


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=

Overloads:

  • #set_bitmap(bmp) ⇒ void

    This method returns an undefined value.

    Sets the bitmap for the menu item.

    Notice that GTK+ uses a global setting called gtk-menu-images to determine if the images should be shown in the menus at all. If it is off (which is the case in e.g. Gnome 2.28 by default), no images will be shown, consistently with the native behaviour.

  • #set_bitmap(bmp, checked) ⇒ void

    This method returns an undefined value.

    Sets the checked or unchecked bitmap for the menu item.

    It is equivalent to #set_bitmaps(bmp,wxNullBitmap) if checked is true or SetBitmaps(NULL_BITMAP, bmp) otherwise. Note that different bitmaps for checked and unchecked item states are not supported in most ports, while setting just a single bitmap using the overload above is supported in all of them. Availability: only available for the WXMSW port.

    Parameters:

    Requires:

    • WXMSW


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.

Parameters:

Requires:

  • WXMSW


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.

Parameters:

Requires:

  • WXMSW


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.

Parameters:

Requires:

  • WXMSW


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.

Parameters:

  • helpString (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:

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")
Note:

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.

Note:

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

Parameters:

  • label (String)

See Also:



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.

Parameters:

  • width (Integer)

Requires:

  • WXMSW


358
# File 'lib/wx/doc/gen/menu_item.rb', line 358

def set_margin_width(width) end

#set_menu(menu) ⇒ void Also known as: menu=

This method returns an undefined value.

Sets the parent menu which will contain this menu item.

Parameters:



363
# File 'lib/wx/doc/gen/menu_item.rb', line 363

def set_menu(menu) end

#set_sub_menu(menu) ⇒ void Also known as: sub_menu=

This method returns an undefined value.

Sets the submenu of this menu item.

Parameters:



369
# File 'lib/wx/doc/gen/menu_item.rb', line 369

def set_sub_menu(menu) 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.

Parameters:

Requires:

  • WXMSW


378
# File 'lib/wx/doc/gen/menu_item.rb', line 378

def set_text_colour(colour) end