View Source wxMenuItem (wx v2.4.3)
A menu item represents an item in a menu.
Note that you usually don't have to deal with it directly as wxMenu
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+.
See:
wxWidgets docs: wxMenuItem
Events
Event types emitted from this class:
Summary
Functions
Equivalent to check(This, [])
.
Checks or unchecks the menu item.
Destroys the object
Equivalent to enable(This, [])
.
Enables or disables the menu item.
Returns the checked or unchecked bitmap.
Returns the help string associated with the menu item.
Returns the menu item identifier.
Returns the text associated with the menu item including any accelerator characters that
were passed to the constructor or setItemLabel/2
.
Returns the text associated with the menu item, without any accelerator characters.
Returns the item kind, one of wxITEM_SEPARATOR
, wxITEM_NORMAL
, wxITEM_CHECK
or wxITEM_RADIO
.
Equivalent to: getItemLabelText/1
Equivalent to: getLabelText/1
Strips all accelerator characters and mnemonics from the given text
.
Returns the menu this menu item is in, or NULL if this menu item is not attached.
Returns the submenu associated with the menu item, or NULL if there isn't one.
Equivalent to: getItemLabel/1
Returns true if the item is checkable.
Returns true if the item is checked.
Returns true if the item is enabled.
Returns true if the item is a separator.
Returns true if the item is a submenu.
Constructs a wxMenuItem
object.
Sets the bitmap for the menu item.
Sets the help string.
Sets the label associated with the menu item.
Sets the parent menu which will contain this menu item.
Sets the submenu of this menu item.
Equivalent to: setItemLabel/2
Types
-type wxMenuItem() :: wx:wx_object().
Functions
-spec check(This) -> ok when This :: wxMenuItem().
Equivalent to check(This, [])
.
-spec check(This, [Option]) -> ok when This :: wxMenuItem(), Option :: {check, boolean()}.
Checks or unchecks the menu item.
Note that this only works when the item is already appended to a menu.
-spec destroy(This :: wxMenuItem()) -> ok.
Destroys the object
-spec enable(This) -> ok when This :: wxMenuItem().
Equivalent to enable(This, [])
.
-spec enable(This, [Option]) -> ok when This :: wxMenuItem(), Option :: {enable, boolean()}.
Enables or disables the menu item.
-spec getBitmap(This) -> wxBitmap:wxBitmap() when This :: wxMenuItem().
Returns the checked or unchecked bitmap.
Only for:wxmsw
-spec getHelp(This) -> unicode:charlist() when This :: wxMenuItem().
Returns the help string associated with the menu item.
-spec getId(This) -> integer() when This :: wxMenuItem().
Returns the menu item identifier.
-spec getItemLabel(This) -> unicode:charlist() when This :: wxMenuItem().
Returns the text associated with the menu item including any accelerator characters that
were passed to the constructor or setItemLabel/2
.
See:
-spec getItemLabelText(This) -> unicode:charlist() when This :: wxMenuItem().
Returns the text associated with the menu item, without any accelerator characters.
See:
-spec getKind(This) -> wx:wx_enum() when This :: wxMenuItem().
Returns the item kind, one of wxITEM_SEPARATOR
, wxITEM_NORMAL
, wxITEM_CHECK
or wxITEM_RADIO
.
-spec getLabel(This) -> unicode:charlist() when This :: wxMenuItem().
Equivalent to: getItemLabelText/1
-spec getLabelFromText(Text) -> unicode:charlist() when Text :: unicode:chardata().
Equivalent to: getLabelText/1
-spec getLabelText(Text) -> unicode:charlist() when Text :: unicode:chardata().
Strips all accelerator characters and mnemonics from the given text
.
For example:
will return just "Hello"
.
See:
-spec getMenu(This) -> wxMenu:wxMenu() when This :: wxMenuItem().
Returns the menu this menu item is in, or NULL if this menu item is not attached.
-spec getSubMenu(This) -> wxMenu:wxMenu() when This :: wxMenuItem().
Returns the submenu associated with the menu item, or NULL if there isn't one.
-spec getText(This) -> unicode:charlist() when This :: wxMenuItem().
Equivalent to: getItemLabel/1
-spec isCheckable(This) -> boolean() when This :: wxMenuItem().
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 IsCheck()
(not implemented in wx) if you want to test for
the check items only.
-spec isChecked(This) -> boolean() when This :: wxMenuItem().
Returns true if the item is checked.
-spec isEnabled(This) -> boolean() when This :: wxMenuItem().
Returns true if the item is enabled.
-spec isSeparator(This) -> boolean() when This :: wxMenuItem().
Returns true if the item is a separator.
-spec isSubMenu(This) -> boolean() when This :: wxMenuItem().
Returns true if the item is a submenu.
-spec new() -> wxMenuItem().
Equivalent to new([])
.
-spec new([Option]) -> wxMenuItem() when Option :: {parentMenu, wxMenu:wxMenu()} | {id, integer()} | {text, unicode:chardata()} | {help, unicode:chardata()} | {kind, wx:wx_enum()} | {subMenu, wxMenu:wxMenu()}.
Constructs a wxMenuItem
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 page_stockitems for the
full list) it is enough to specify just the stock ID and leave text
and help
string
empty. Some platforms (currently wxGTK only, and see the remark in setBitmap/2
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 help
string
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:
that is, stock properties are set independently one from the other.
-spec setBitmap(This, Bmp) -> ok when This :: wxMenuItem(), Bmp :: wxBitmap:wxBitmap().
Sets the bitmap for the menu item.
It is equivalent to wxMenuItem::SetBitmaps(bmp, wxNullBitmap) if checked
is true
(default value) or SetBitmaps(wxNullBitmap, bmp) otherwise.
setBitmap/2
must be called before the item is appended to the menu, i.e. appending the item without
a bitmap and setting one later is not guaranteed to work. But the bitmap can be changed or
reset later if it had been set up initially.
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.
Only for:wxmsw,wxosx,wxgtk
-spec setHelp(This, HelpString) -> ok when This :: wxMenuItem(), HelpString :: unicode:chardata().
Sets the help string.
-spec setItemLabel(This, Label) -> ok when This :: wxMenuItem(), Label :: unicode:chardata().
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 new/1
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
orDelete:
WXK_DELETEBack:
WXK_BACKIns
orInsert:
WXK_INSERTEnter
orReturn:
WXK_RETURNPgUp
orPageUp:
WXK_PAGEUPPgDn
orPageDown:
WXK_PAGEDOWNLeft:
WXK_LEFTRight:
WXK_RIGHTUp:
WXK_UPDown:
WXK_DOWNHome:
WXK_HOMEEnd:
WXK_ENDSpace:
WXK_SPACETab:
WXK_TABEsc
orEscape:
WXK_ESCAPECancel:
WXK_CANCELClear:
WXK_CLEARMenu:
WXK_MENUPause:
WXK_PAUSECapital:
WXK_CAPITALSelect:
WXK_SELECTPrint:
WXK_PRINTExecute:
WXK_EXECUTESnapshot:
WXK_SNAPSHOTHelp:
WXK_HELPAdd:
WXK_ADDSeparator:
WXK_SEPARATORSubtract:
WXK_SUBTRACTDecimal:
WXK_DECIMALDivide:
WXK_DIVIDENum_lock:
WXK_NUMLOCKScroll_lock:
WXK_SCROLLKP_Space:
WXK_NUMPAD_SPACEKP_Tab:
WXK_NUMPAD_TABKP_Enter:
WXK_NUMPAD_ENTERKP_Home:
WXK_NUMPAD_HOMEKP_Left:
WXK_NUMPAD_LEFTKP_Up:
WXK_NUMPAD_UPKP_Right:
WXK_NUMPAD_RIGHTKP_Down:
WXK_NUMPAD_DOWNKP_PageUp:
WXK_NUMPAD_PAGEUPKP_PageDown:
WXK_NUMPAD_PAGEDOWNKP_Prior:
WXK_NUMPAD_PAGEUPKP_Next:
WXK_NUMPAD_PAGEDOWNKP_End:
WXK_NUMPAD_ENDKP_Begin:
WXK_NUMPAD_BEGINKP_Insert:
WXK_NUMPAD_INSERTKP_Delete:
WXK_NUMPAD_DELETEKP_Equal:
WXK_NUMPAD_EQUALKP_Multiply:
WXK_NUMPAD_MULTIPLYKP_Add:
WXK_NUMPAD_ADDKP_Separator:
WXK_NUMPAD_SEPARATORKP_Subtract:
WXK_NUMPAD_SUBTRACTKP_Decimal:
WXK_NUMPAD_DECIMALKP_Divide:
WXK_NUMPAD_DIVIDEWindows_Left:
WXK_WINDOWS_LEFTWindows_Right:
WXK_WINDOWS_RIGHTWindows_Menu:
WXK_WINDOWS_MENUCommand:
WXK_COMMAND
Examples:
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 wxGTk, 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:
WXK_COMMAND/WXK_CONTROL
WXK_SHIFT
WXK_ALT
WXK_SCROLL
WXK_CAPITAL
WXK_NUMLOCK
WXK_NUMPAD_TAB
WXK_TAB
WXK_WINDOWS_LEFT
WXK_WINDOWS_RIGHT
WXK_ADD
WXK_SEPARATOR
WXK_SUBTRACT
WXK_DECIMAL
WXK_DIVIDE
WXK_SNAPSHOT
See:
-spec setMenu(This, Menu) -> ok when This :: wxMenuItem(), Menu :: wxMenu:wxMenu().
Sets the parent menu which will contain this menu item.
-spec setSubMenu(This, Menu) -> ok when This :: wxMenuItem(), Menu :: wxMenu:wxMenu().
Sets the submenu of this menu item.
-spec setText(This, Label) -> ok when This :: wxMenuItem(), Label :: unicode:chardata().
Equivalent to: setItemLabel/2