contents up previous next

wxmenuitem

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

derived from

wxobject

include files

<wx/menuitem.h>

see also

wxmenubar, wxmenu

members

wxmenuitem::wxmenuitem
wxmenuitem::~wxmenuitem
wxmenuitem::check
wxmenuitem::enable
wxmenuitem::getbackgroundcolour
wxmenuitem::getbitmap
wxmenuitem::getfont
wxmenuitem::gethelp
wxmenuitem::getid
wxmenuitem::getitemlabel
wxmenuitem::getitemlabeltext
wxmenuitem::getkind
wxmenuitem::getlabel
wxmenuitem::getlabeltext
wxmenuitem::getlabelfromtext
wxmenuitem::getmarginwidth
wxmenuitem::getmenu
wxmenuitem::getname
wxmenuitem::gettext
wxmenuitem::getsubmenu
wxmenuitem::gettextcolour
wxmenuitem::ischeckable
wxmenuitem::ischecked
wxmenuitem::isenabled
wxmenuitem::isseparator
wxmenuitem::issubmenu
wxmenuitem::setbackgroundcolour
wxmenuitem::setbitmap
wxmenuitem::setbitmaps
wxmenuitem::setfont
wxmenuitem::sethelp
wxmenuitem::setitemlabel
wxmenuitem::setmarginwidth
wxmenuitem::setmenu
wxmenuitem::setsubmenu
wxmenuitem::settext
wxmenuitem::settextcolour


wxmenuitem::wxmenuitem

wxmenuitem(wxmenu* parentmenu = null, int id = wxid_separator, const wxstring& text = "", const wxstring& helpstring = "", wxitemkind kind = wxitem_normal, wxmenu* submenu = null)

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 stock items for the full list) it is enough to specify just the stock id and leave text and helpstring empty. in fact, leaving at least text empty for the stock menu items is 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(wxid_about, wxemptystring, wxt("my custom help string"));

// use all stock properties except for the bitmap:
wxmenuitem *mymenu = new wxmenuitem(helpmenu, wxid_about);
mymenu->setbitmap(wxartprovider::getbitmap(wxart_warning));
helpmenu->append(mymenu);
that is, stock properties are set independently one from the other.

parameters

parentmenu

id

text

helpstring

kind

submenu


wxmenuitem::~wxmenuitem

~wxmenuitem()

destructor.


wxmenuitem::check

void check(bool check = true)

checks or unchecks the menu item.

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


wxmenuitem::enable

void enable(bool enable = true)

enables or disables the menu item.


wxmenuitem::getbackgroundcolour

wxcolour& getbackgroundcolour() const

returns the background colour associated with the menu item (windows only).


wxmenuitem::getbitmap

wxbitmap& getbitmap(bool checked = true) const

returns the checked or unchecked bitmap (windows only).


wxmenuitem::getfont

wxfont& getfont() const

returns the font associated with the menu item (windows only).


wxmenuitem::gethelp

wxstring gethelp() const

returns the help string associated with the menu item.


wxmenuitem::getid

int getid() const

returns the menu item identifier.


wxmenuitem::getitemlabel

wxstring getitemlabel() const

returns the text associated with the menu item including any accelerator characters that were passed to the constructor or setitemlabel.

see also

getitemlabeltext, getlabeltext


wxmenuitem::getitemlabeltext

wxstring getitemlabeltext() const

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

see also

getitemlabel, getlabeltext


wxmenuitem::getkind

wxitemkind getkind() const

returns the item kind, one of wxitem_separator, wxitem_normal, wxitem_check or wxitem_radio.


wxmenuitem::getlabel

wxstring getlabel() const

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

this function is deprecated in favour of getitemlabeltext.

see also

gettext, getlabelfromtext


wxmenuitem::getlabeltext

static wxstring getlabeltext(const wxstring& text)

strips all accelerator characters and mnemonics from the given text. for example,

wxmenuitem::getlabelfromtext("&hello\tctrl-h");
will return just "hello".

see also

getitemlabeltext, getitemlabel


wxmenuitem::getlabelfromtext

static wxstring getlabelfromtext(const wxstring& text)

strips all accelerator characters and mnemonics from the given text. for example,

wxmenuitem::getlabelfromtext("&hello\tctrl-h");
will return just "hello".

this function is deprecated; please use wxmenuitem::getlabeltext instead.

see also

gettext, getlabel


wxmenuitem::getmarginwidth

int getmarginwidth() const

gets the width of the menu item checkmark bitmap (windows only).


wxmenuitem::getmenu

wxmenu* getmenu() const

returns the menu this menu item is in, or null if this menu item is not attached.


wxmenuitem::getname

wxstring getname() const

returns the text associated with the menu item.

nb: this function is deprecated, please use getitemlabel or getitemlabeltext instead.


wxmenuitem::gettext

wxstring gettext() const

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

this function is deprecated in favour of getitemlabel.

see also

getlabel, getlabelfromtext


wxmenuitem::getsubmenu

wxmenu* getsubmenu() const

returns the submenu associated with the menu item, or null if there isn't one.


wxmenuitem::gettextcolour

wxcolour& gettextcolour() const

returns the text colour associated with the menu item (windows only).


wxmenuitem::ischeckable

bool ischeckable() const

returns true if the item is checkable.


wxmenuitem::ischecked

bool ischecked() const

returns true if the item is checked.


wxmenuitem::isenabled

bool isenabled() const

returns true if the item is enabled.


wxmenuitem::isseparator

bool isseparator() const

returns true if the item is a separator.


wxmenuitem::issubmenu

bool issubmenu() const

returns true if the item is a submenu.


wxmenuitem::setbackgroundcolour

void setbackgroundcolour(const wxcolour& colour) const

sets the background colour associated with the menu item (windows only).


wxmenuitem::setbitmap

void setbitmap(const wxbitmap& bmp)

sets the bitmap for the menu item (windows and gtk+ only). it is equivalent to setbitmaps(bmp, wxnullbitmap).


wxmenuitem::setbitmaps

void setbitmaps(const wxbitmap& checked, const wxbitmap& unchecked = wxnullbitmap)

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.


wxmenuitem::setfont

void setfont(const wxfont& font)

sets the font associated with the menu item (windows only).


wxmenuitem::sethelp

void sethelp(const wxstring& helpstring)

sets the help string.


wxmenuitem::setitemlabel

void setitemlabel(const wxstring& label)

sets the label associated with the menu item.


wxmenuitem::setmarginwidth

void setmarginwidth(int width) const

sets the width of the menu item checkmark bitmap (windows only).


wxmenuitem::setmenu

void setmenu(const wxmenu*menu)

sets the parent menu which will contain this menu item.


wxmenuitem::setsubmenu

void setsubmenu(const wxmenu*menu)

sets the submenu of this menu item.


wxmenuitem::settext

void settext(const wxstring& text)

sets the text associated with the menu item.

this function is deprecated in favour of setitemlabel.


wxmenuitem::settextcolour

void settextcolour(const wxcolour& colour)

sets the text colour associated with the menu item (windows only).