]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/menuitem.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxMenuItem
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 A menu item represents an item in a menu. Note that you usually don't have to
13 deal with it directly as wxMenu methods usually construct an
14 object of this class for you.
16 Also please note that the methods related to fonts and bitmaps are currently
17 only implemented for Windows and GTK+.
22 @see wxMenuBar, wxMenu
24 class wxMenuItem
: public wxObject
28 Constructs a wxMenuItem object.
29 Menu items can be standard, or "stock menu items", or custom. For the
30 standard menu items (such as commands to open a file, exit the program and so
31 on, see @ref page_stockitems "Stock Items" for the full list) it is enough
32 to specify just the stock ID and leave @a text and @a helpString empty. In
33 fact, leaving at least @a text empty for the stock menu items is strongly
34 recommended as they will have appearance and keyboard interface (including
35 standard accelerators) familiar to the user.
36 For the custom (non-stock) menu items, @a text must be specified and while
37 @a helpString may be left empty, it's recommended to pass the item
38 description (which is automatically shown by the library in the status bar when
39 the menu item is selected) in this parameter.
40 Finally note that you can e.g. use a stock menu label without using its stock
41 help string; that is, stock properties are set independently one from the other.
44 Menu that the menu item belongs to. Can be @NULL if the item is
45 going to be added to the menu later.
47 Identifier for this menu item. May be @c wxID_SEPARATOR, in which
48 case the given kind is ignored and taken to be @c wxITEM_SEPARATOR
51 Text for the menu item, as shown on the menu. An accelerator
52 key can be specified using the ampersand " character. In order to embed an
53 ampersand character in the menu item text, the ampersand must be doubled.
55 Optional help string that will be shown on the status bar.
57 May be @c wxITEM_SEPARATOR, @c wxITEM_NORMAL, @c wxITEM_CHECK or @c
60 If non-@NULL, indicates that the menu item is a submenu.
62 wxMenuItem(wxMenu
* parentMenu
= NULL
, int id
= wxID_SEPARATOR
,
63 const wxString
& text
= "",
64 const wxString
& helpString
= "",
65 wxItemKind kind
= wxITEM_NORMAL
,
66 wxMenu
* subMenu
= NULL
);
74 Checks or unchecks the menu item.
75 Note that this only works when the item is already appended to a menu.
77 void Check(bool check
= true);
80 Enables or disables the menu item.
82 void Enable(bool enable
= true);
85 Returns the background colour associated with the menu item (Windows only).
87 wxColour
GetBackgroundColour() const;
90 Returns the checked or unchecked bitmap (Windows only).
92 wxBitmap
GetBitmap(bool checked
= true) const;
95 Returns the font associated with the menu item (Windows only).
97 wxFont
GetFont() const;
100 Returns the help string associated with the menu item.
102 wxString
GetHelp() const;
105 Returns the menu item identifier.
110 Returns the text associated with the menu item including any accelerator
111 characters that were passed to the constructor or SetItemLabel.
113 @see GetItemLabelText(), GetLabelText()
115 wxString
GetItemLabel() const;
118 Returns the text associated with the menu item, without any accelerator
121 @see GetItemLabel(), GetLabelText()
123 wxString
GetItemLabelText() const;
126 Returns the item kind, one of @c wxITEM_SEPARATOR, @c wxITEM_NORMAL,
127 @c wxITEM_CHECK or @c wxITEM_RADIO.
129 wxItemKind
GetKind() const;
132 Returns the text associated with the menu item without any accelerator
133 characters it might contain.
134 @deprecated This function is deprecated in favour of GetItemLabelText().
135 @see GetText(), GetLabelFromText()
137 wxString
GetLabel() const;
140 @deprecated This function is deprecated; please use GetLabelText() instead.
141 @see GetText(), GetLabel()
143 static wxString
GetLabelFromText(const wxString
& text
);
146 Strips all accelerator characters and mnemonics from the given @e text.
150 wxMenuItem::GetLabelfromText( "&Hello\tCtrl-h");
153 will return just @c "Hello".
155 @see GetItemLabelText(), GetItemLabel()
157 static wxString
GetLabelText(const wxString
& text
);
160 Gets the width of the menu item checkmark bitmap (Windows only).
162 int GetMarginWidth() const;
165 Returns the menu this menu item is in, or @NULL if this menu item is not
168 wxMenu
* GetMenu() const;
171 Returns the text associated with the menu item.
172 @deprecated This function is deprecated. Please use
173 GetItemLabel() or GetItemLabelText() instead.
175 wxString
GetName() const;
178 Returns the submenu associated with the menu item, or @NULL if there isn't one.
180 wxMenu
* GetSubMenu() const;
183 Returns the text associated with the menu item, such as it was passed to the
184 wxMenuItem constructor, i.e. with any accelerator characters it may contain.
185 @deprecated This function is deprecated in favour of GetItemLabel().
186 @see GetLabel(), GetLabelFromText()
188 wxString
GetText() const;
191 Returns the text colour associated with the menu item (Windows only).
193 wxColour
GetTextColour() const;
196 Returns @true if the item is checkable.
198 bool IsCheckable() const;
201 Returns @true if the item is checked.
203 bool IsChecked() const;
206 Returns @true if the item is enabled.
208 bool IsEnabled() const;
211 Returns @true if the item is a separator.
213 bool IsSeparator() const;
216 Returns @true if the item is a submenu.
218 bool IsSubMenu() const;
221 Sets the background colour associated with the menu item (Windows only).
223 void SetBackgroundColour(const wxColour
& colour
) const;
226 Sets the bitmap for the menu item (Windows and GTK+ only). It is
227 equivalent to wxMenuItem::SetBitmaps(bmp, wxNullBitmap).
229 void SetBitmap(const wxBitmap
& bmp
);
232 Sets the checked/unchecked bitmaps for the menu item (Windows only). The first
234 is also used as the single bitmap for uncheckable menu items.
236 void SetBitmaps(const wxBitmap
& checked
,
237 const wxBitmap
& unchecked
= wxNullBitmap
);
240 Sets the font associated with the menu item (Windows only).
242 void SetFont(const wxFont
& font
);
245 Sets the help string.
247 void SetHelp(const wxString
& helpString
);
250 Sets the label associated with the menu item.
252 void SetItemLabel(const wxString
& label
);
255 Sets the width of the menu item checkmark bitmap (Windows only).
257 void SetMarginWidth(int width
) const;
260 Sets the parent menu which will contain this menu item.
262 void SetMenu(const wxMenu
* menu
);
265 Sets the submenu of this menu item.
267 void SetSubMenu(const wxMenu
* menu
);
270 Sets the text associated with the menu item.
271 @deprecated This function is deprecated in favour of SetItemLabel().
273 void SetText(const wxString
& text
);
276 Sets the text colour associated with the menu item (Windows only).
278 void SetTextColour(const wxColour
& colour
);