wxRuby Documentation Home

# Wx::MenuItem

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 and GTK+.

## Derived from

Object

## See also

MenuBar, Menu

## Methods

- MenuItem.new
- MenuItem#check
- MenuItem#enable
- MenuItem#get_background_colour
- MenuItem#get_bitmap
- MenuItem#get_font
- MenuItem#get_help
- MenuItem#get_id
- MenuItem#get_kind
- MenuItem#get_label
- MenuItem#get_label_from_text
- MenuItem#get_margin_width
- MenuItem#get_menu
- MenuItem#get_name
- MenuItem#get_text
- MenuItem#get_sub_menu
- MenuItem#get_text_colour
- MenuItem#is_checkable
- MenuItem#is_checked
- MenuItem#is_enabled
- MenuItem#is_separator
- MenuItem#is_sub_menu
- MenuItem#set_background_colour
- MenuItem#set_bitmap
- MenuItem#set_bitmaps
- MenuItem#set_font
- MenuItem#set_help
- MenuItem#set_margin_width
- MenuItem#set_menu
- MenuItem#set_sub_menu
- MenuItem#set_text
- MenuItem#set_text_colour

### MenuItem.new

MenuItem.new(%(arg-type)Menu% parentMenu = nil, Integer id = ID_SEPARATOR, String text = "", String helpString = "", ItemKind kind = ITEM_NORMAL, Menu subMenu = nil)

Constructs a MenuItem object.

#### Parameters

- parentMenu Menu that the menu item belongs to.
- id Identifier for this menu item, or ID_SEPARATOR to indicate a separator.
- text Text for the menu item, as shown on the menu. 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.
- helpString Optional help string that will be shown on the status bar.
- kind May be `ITEM_SEPARATOR`, `ITEM_NORMAL`,
  `ITEM_CHECK` or `ITEM_RADIO`
- subMenu If non-NULL, indicates that the menu item is a submenu.

destructor()

Destructor.

### MenuItem#check

check(%(arg-type)Boolean% check = true)

Checks or unchecks the menu item.

Note that this only works when the item is already appended to a menu.

### MenuItem#enable

enable(%(arg-type)Boolean% enable = true)

Enables or disables the menu item.

### MenuItem#get_background_colour

Colour get_background_colour()

Returns the background colour associated with the menu item (Windows only).

### MenuItem#get_bitmap

Bitmap get_bitmap(%(arg-type)Boolean% checked = true)

Returns the checked or unchecked bitmap (Windows only).

### MenuItem#get_font

Font get_font()

Returns the font associated with the menu item (Windows only).

### MenuItem#get_help

String get_help()

Returns the help string associated with the menu item.

### MenuItem#get_id

Integer get_id()

Returns the menu item identifier.

### MenuItem#get_kind

ItemKind get_kind()

Returns the item kind, one of `ITEM_SEPARATOR`, `ITEM_NORMAL`,
`ITEM_CHECK` or `ITEM_RADIO`.

### MenuItem#get_label

String get_label()

Returns the text associated with the menu item without any accelerator
characters it might contain.

#### See also

get_text,
get_label_from_text

### MenuItem#get_label_from_text

String get_label_from_text(%(arg-type)String% text)

Strips all accelerator characters and mnemonics from the given text.
For example,

MenuItem::GetLabelFromText(“&Hello\tCtrl-H”);

will return just `"Hello"`.

#### See also

get_text,
get_label

### MenuItem#get_margin_width

Integer get_margin_width()

Gets the width of the menu item checkmark bitmap (Windows only).

### MenuItem#get_menu

Menu get_menu()

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

### MenuItem#get_name

String get_name()

Returns the text associated with the menu item.

NB: this function is deprecated, please use
get_text or get_label
instead.

### MenuItem#get_text

String get_text()

Returns the text associated with the menu item, such as it was passed to the
MenuItem constructor, i.e. with any accelerator characters it may contain.

#### See also

get_label,
get_label_from_text

### MenuItem#get_sub_menu

Menu get_sub_menu()

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

### MenuItem#get_text_colour

Colour get_text_colour()

Returns the text colour associated with the menu item (Windows only).

### MenuItem#is_checkable

Boolean is_checkable()

Returns true if the item is checkable.

### MenuItem#is_checked

Boolean is_checked()

Returns true if the item is checked.

### MenuItem#is_enabled

Boolean is_enabled()

Returns true if the item is enabled.

### MenuItem#is_separator

Boolean is_separator()

Returns true if the item is a separator.

### MenuItem#is_sub_menu

Boolean is_sub_menu()

Returns true if the item is a submenu.

### MenuItem#set_background_colour

set_background_colour(%(arg-type)Colour% colour)

Sets the background colour associated with the menu item (Windows only).

### MenuItem#set_bitmap

set_bitmap(%(arg-type)Bitmap% bmp)

Sets the bitmap for the menu item (Windows and GTK+ only). It is
equivalent to set_bitmaps, NullBitmap).

### MenuItem#set_bitmaps

set_bitmaps(%(arg-type)Bitmap% checked, Bitmap unchecked = NullBitmap)

Sets the checked/unchecked bitmaps for the menu item (Windows only). The first bitmap
is also used as the single bitmap for uncheckable menu items.

### MenuItem#set_font

set_font(%(arg-type)Font% font)

Sets the font associated with the menu item (Windows only).

### MenuItem#set_help

set_help(%(arg-type)String% helpString)

Sets the help string.

### MenuItem#set_margin_width

set_margin_width(%(arg-type)Integer% width)

Sets the width of the menu item checkmark bitmap (Windows only).

### MenuItem#set_menu

set_menu(%(arg-type)Menu% menu)

Sets the parent menu which will contain this menu item.

### MenuItem#set_sub_menu

set_sub_menu(%(arg-type)Menu% menu)

Sets the submenu of this menu item.

### MenuItem#set_text

set_text(%(arg-type)String% text)

Sets the text associated with the menu item.

### MenuItem#set_text_colour

set_text_colour(%(arg-type)Colour% colour)

Sets the text colour associated with the menu item (Windows only).

[This page automatically generated from the Textile source at 2023-06-09 00:45:27 +0000]