]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/menuitem.h
use wxEventType coherently with the docs
[wxWidgets.git] / interface / wx / menuitem.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: menuitem.h
ba1d7a6c 3// Purpose: interface of wxMenu, wxMenuItem
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxMenuItem
7c913512 11
ba1d7a6c
FM
12 A menu item represents an item in a menu.
13
14 Note that you usually don't have to deal with it directly as wxMenu methods
15 usually construct an object of this class for you.
7c913512 16
23324ae1
FM
17 Also please note that the methods related to fonts and bitmaps are currently
18 only implemented for Windows and GTK+.
7c913512 19
23324ae1
FM
20 @library{wxcore}
21 @category{menus}
7c913512 22
e54c96f1 23 @see wxMenuBar, wxMenu
23324ae1
FM
24*/
25class wxMenuItem : public wxObject
26{
27public:
28 /**
29 Constructs a wxMenuItem object.
ba1d7a6c
FM
30
31 Menu items can be standard, or "stock menu items", or custom.
32 For the standard menu items (such as commands to open a file, exit the
33 program and so on, see @ref page_stockitems for the full list) it is enough
34 to specify just the stock ID and leave @a text and @a helpString empty.
35
36 In fact, leaving at least @a text empty for the stock menu items is strongly
23324ae1
FM
37 recommended as they will have appearance and keyboard interface (including
38 standard accelerators) familiar to the user.
ba1d7a6c 39
4cc4bfaf
FM
40 For the custom (non-stock) menu items, @a text must be specified and while
41 @a helpString may be left empty, it's recommended to pass the item
ba1d7a6c
FM
42 description (which is automatically shown by the library in the status bar
43 when the menu item is selected) in this parameter.
44
23324ae1 45 Finally note that you can e.g. use a stock menu label without using its stock
ba1d7a6c
FM
46 help string:
47
48 @code
49 // use all stock properties:
50 helpMenu->Append(wxID_ABOUT);
51
52 // use the stock label and the stock accelerator but not the stock help string:
53 helpMenu->Append(wxID_ABOUT, wxEmptyString, wxT("My custom help string"));
54
55 // use all stock properties except for the bitmap:
56 wxMenuItem *mymenu = new wxMenuItem(helpMenu, wxID_ABOUT);
57 mymenu->SetBitmap(wxArtProvider::GetBitmap(wxART_WARNING));
58 helpMenu->Append(mymenu);
59 @endcode
60
61 that is, stock properties are set independently one from the other.
3c4f71cc 62
7c913512 63 @param parentMenu
9cd28f48
VZ
64 Menu that the menu item belongs to. Can be @NULL if the item is
65 going to be added to the menu later.
7c913512 66 @param id
9cd28f48
VZ
67 Identifier for this menu item. May be @c wxID_SEPARATOR, in which
68 case the given kind is ignored and taken to be @c wxITEM_SEPARATOR
69 instead.
7c913512 70 @param text
ba1d7a6c
FM
71 Text for the menu item, as shown on the menu. An accelerator key can
72 be specified using the ampersand " character. In order to embed an
4cc4bfaf 73 ampersand character in the menu item text, the ampersand must be doubled.
7c913512 74 @param helpString
4cc4bfaf 75 Optional help string that will be shown on the status bar.
7c913512 76 @param kind
ba1d7a6c
FM
77 May be @c wxITEM_SEPARATOR, @c wxITEM_NORMAL, @c wxITEM_CHECK or
78 @c wxITEM_RADIO
7c913512 79 @param subMenu
4cc4bfaf 80 If non-@NULL, indicates that the menu item is a submenu.
23324ae1 81 */
4cc4bfaf 82 wxMenuItem(wxMenu* parentMenu = NULL, int id = wxID_SEPARATOR,
23324ae1
FM
83 const wxString& text = "",
84 const wxString& helpString = "",
85 wxItemKind kind = wxITEM_NORMAL,
4cc4bfaf 86 wxMenu* subMenu = NULL);
23324ae1
FM
87
88 /**
89 Destructor.
90 */
adaaa686 91 virtual ~wxMenuItem();
23324ae1
FM
92
93 /**
94 Checks or unchecks the menu item.
23324ae1
FM
95 Note that this only works when the item is already appended to a menu.
96 */
adaaa686 97 virtual void Check(bool check = true);
23324ae1
FM
98
99 /**
100 Enables or disables the menu item.
101 */
adaaa686 102 virtual void Enable(bool enable = true);
23324ae1
FM
103
104 /**
105 Returns the background colour associated with the menu item (Windows only).
106 */
328f5751 107 wxColour GetBackgroundColour() const;
23324ae1
FM
108
109 /**
110 Returns the checked or unchecked bitmap (Windows only).
111 */
43c48e1e 112 virtual const wxBitmap& GetBitmap() const;
23324ae1
FM
113
114 /**
115 Returns the font associated with the menu item (Windows only).
116 */
328f5751 117 wxFont GetFont() const;
23324ae1
FM
118
119 /**
120 Returns the help string associated with the menu item.
121 */
43c48e1e 122 const wxString& GetHelp() const;
23324ae1
FM
123
124 /**
125 Returns the menu item identifier.
126 */
328f5751 127 int GetId() const;
23324ae1
FM
128
129 /**
130 Returns the text associated with the menu item including any accelerator
ba1d7a6c 131 characters that were passed to the constructor or SetItemLabel().
3c4f71cc 132
4cc4bfaf 133 @see GetItemLabelText(), GetLabelText()
23324ae1 134 */
adaaa686 135 virtual wxString GetItemLabel() const;
23324ae1
FM
136
137 /**
138 Returns the text associated with the menu item, without any accelerator
139 characters.
3c4f71cc 140
4cc4bfaf 141 @see GetItemLabel(), GetLabelText()
23324ae1 142 */
adaaa686 143 virtual wxString GetItemLabelText() const;
23324ae1
FM
144
145 /**
7c913512 146 Returns the item kind, one of @c wxITEM_SEPARATOR, @c wxITEM_NORMAL,
23324ae1
FM
147 @c wxITEM_CHECK or @c wxITEM_RADIO.
148 */
328f5751 149 wxItemKind GetKind() const;
23324ae1
FM
150
151 /**
152 Returns the text associated with the menu item without any accelerator
153 characters it might contain.
ba1d7a6c 154
5dfae0ad 155 @deprecated This function is deprecated in favour of GetItemLabelText().
ba1d7a6c 156
4cc4bfaf 157 @see GetText(), GetLabelFromText()
23324ae1 158 */
328f5751 159 wxString GetLabel() const;
23324ae1
FM
160
161 /**
5dfae0ad 162 @deprecated This function is deprecated; please use GetLabelText() instead.
ba1d7a6c 163
4cc4bfaf 164 @see GetText(), GetLabel()
23324ae1
FM
165 */
166 static wxString GetLabelFromText(const wxString& text);
167
168 /**
ba1d7a6c 169 Strips all accelerator characters and mnemonics from the given @a text.
3b3026ca
RR
170 For example:
171
172 @code
ba1d7a6c 173 wxMenuItem::GetLabelfromText("&Hello\tCtrl-h");
3b3026ca 174 @endcode
3c4f71cc 175
23324ae1 176 will return just @c "Hello".
3c4f71cc 177
4cc4bfaf 178 @see GetItemLabelText(), GetItemLabel()
23324ae1
FM
179 */
180 static wxString GetLabelText(const wxString& text);
181
182 /**
183 Gets the width of the menu item checkmark bitmap (Windows only).
184 */
328f5751 185 int GetMarginWidth() const;
23324ae1
FM
186
187 /**
188 Returns the menu this menu item is in, or @NULL if this menu item is not
189 attached.
190 */
328f5751 191 wxMenu* GetMenu() const;
23324ae1
FM
192
193 /**
194 Returns the text associated with the menu item.
ba1d7a6c 195
5dfae0ad 196 @deprecated This function is deprecated. Please use
ba1d7a6c 197
5dfae0ad 198 GetItemLabel() or GetItemLabelText() instead.
23324ae1 199 */
328f5751 200 wxString GetName() const;
23324ae1
FM
201
202 /**
203 Returns the submenu associated with the menu item, or @NULL if there isn't one.
204 */
328f5751 205 wxMenu* GetSubMenu() const;
23324ae1
FM
206
207 /**
208 Returns the text associated with the menu item, such as it was passed to the
209 wxMenuItem constructor, i.e. with any accelerator characters it may contain.
ba1d7a6c 210
5dfae0ad 211 @deprecated This function is deprecated in favour of GetItemLabel().
ba1d7a6c 212
4cc4bfaf 213 @see GetLabel(), GetLabelFromText()
23324ae1 214 */
43c48e1e 215 const wxString& GetText() const;
23324ae1
FM
216
217 /**
218 Returns the text colour associated with the menu item (Windows only).
219 */
328f5751 220 wxColour GetTextColour() const;
23324ae1
FM
221
222 /**
223 Returns @true if the item is checkable.
224 */
328f5751 225 bool IsCheckable() const;
23324ae1
FM
226
227 /**
228 Returns @true if the item is checked.
229 */
adaaa686 230 virtual bool IsChecked() const;
23324ae1
FM
231
232 /**
233 Returns @true if the item is enabled.
234 */
adaaa686 235 virtual bool IsEnabled() const;
23324ae1
FM
236
237 /**
238 Returns @true if the item is a separator.
239 */
328f5751 240 bool IsSeparator() const;
23324ae1
FM
241
242 /**
243 Returns @true if the item is a submenu.
244 */
328f5751 245 bool IsSubMenu() const;
23324ae1
FM
246
247 /**
248 Sets the background colour associated with the menu item (Windows only).
249 */
328f5751 250 void SetBackgroundColour(const wxColour& colour) const;
23324ae1
FM
251
252 /**
ba1d7a6c
FM
253 Sets the bitmap for the menu item (Windows and GTK+ only).
254 It is equivalent to wxMenuItem::SetBitmaps(bmp, wxNullBitmap).
23324ae1 255 */
adaaa686 256 virtual void SetBitmap(const wxBitmap& bmp);
23324ae1
FM
257
258 /**
ba1d7a6c
FM
259 Sets the checked/unchecked bitmaps for the menu item (Windows only).
260 The first bitmap is also used as the single bitmap for uncheckable menu items.
23324ae1
FM
261 */
262 void SetBitmaps(const wxBitmap& checked,
263 const wxBitmap& unchecked = wxNullBitmap);
264
265 /**
266 Sets the font associated with the menu item (Windows only).
267 */
268 void SetFont(const wxFont& font);
269
270 /**
271 Sets the help string.
272 */
273 void SetHelp(const wxString& helpString);
274
275 /**
276 Sets the label associated with the menu item.
277 */
adaaa686 278 virtual void SetItemLabel(const wxString& label);
23324ae1
FM
279
280 /**
281 Sets the width of the menu item checkmark bitmap (Windows only).
282 */
328f5751 283 void SetMarginWidth(int width) const;
23324ae1
FM
284
285 /**
286 Sets the parent menu which will contain this menu item.
287 */
43c48e1e 288 void SetMenu(wxMenu* menu);
23324ae1
FM
289
290 /**
291 Sets the submenu of this menu item.
292 */
43c48e1e 293 void SetSubMenu(wxMenu* menu);
23324ae1
FM
294
295 /**
296 Sets the text associated with the menu item.
ba1d7a6c 297
5dfae0ad 298 @deprecated This function is deprecated in favour of SetItemLabel().
23324ae1 299 */
adaaa686 300 virtual void SetText(const wxString& text);
23324ae1
FM
301
302 /**
303 Sets the text colour associated with the menu item (Windows only).
304 */
305 void SetTextColour(const wxColour& colour);
306};
e54c96f1 307