]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/menuitem.h
Minor corrections to wxFlexGridSizer ctor documentation.
[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 17 Also please note that the methods related to fonts and bitmaps are currently
30f23bcc 18 only implemented for Windows, Mac and GTK+.
7c913512 19
3051a44a 20 @beginEventEmissionTable{wxCommandEvent,wxMenuEvent}
558e89e7
FM
21 @event{EVT_MENU(id, func)}
22 Process a @c wxEVT_COMMAND_MENU_SELECTED command, which is generated by a menu item.
23 This type of event is sent as wxCommandEvent.
24 @event{EVT_MENU_RANGE(id1, id2, func)}
25 Process a @c wxEVT_COMMAND_MENU_RANGE command, which is generated by a range of menu items.
26 This type of event is sent as wxCommandEvent.
27 @event{EVT_MENU_OPEN(func)}
28 A menu is about to be opened. On Windows, this is only sent once for each
29 navigation of the menubar (up until all menus have closed).
30 This type of event is sent as wxMenuEvent.
31 @event{EVT_MENU_CLOSE(func)}
32 A menu has been just closed.
33 This type of event is sent as wxMenuEvent.
34 @event{EVT_MENU_HIGHLIGHT(id, func)}
35 The menu item with the specified id has been highlighted: used to show
36 help prompts in the status bar by wxFrame
37 This type of event is sent as wxMenuEvent.
38 @event{EVT_MENU_HIGHLIGHT_ALL(func)}
39 A menu item has been highlighted, i.e. the currently selected menu item has changed.
40 This type of event is sent as wxMenuEvent.
41 @endEventTable
42
23324ae1
FM
43 @library{wxcore}
44 @category{menus}
7c913512 45
e54c96f1 46 @see wxMenuBar, wxMenu
23324ae1
FM
47*/
48class wxMenuItem : public wxObject
49{
50public:
51 /**
52 Constructs a wxMenuItem object.
ba1d7a6c
FM
53
54 Menu items can be standard, or "stock menu items", or custom.
55 For the standard menu items (such as commands to open a file, exit the
56 program and so on, see @ref page_stockitems for the full list) it is enough
57 to specify just the stock ID and leave @a text and @a helpString empty.
58
59 In fact, leaving at least @a text empty for the stock menu items is strongly
23324ae1
FM
60 recommended as they will have appearance and keyboard interface (including
61 standard accelerators) familiar to the user.
ba1d7a6c 62
4cc4bfaf
FM
63 For the custom (non-stock) menu items, @a text must be specified and while
64 @a helpString may be left empty, it's recommended to pass the item
ba1d7a6c
FM
65 description (which is automatically shown by the library in the status bar
66 when the menu item is selected) in this parameter.
67
23324ae1 68 Finally note that you can e.g. use a stock menu label without using its stock
ba1d7a6c
FM
69 help string:
70
71 @code
72 // use all stock properties:
73 helpMenu->Append(wxID_ABOUT);
74
75 // use the stock label and the stock accelerator but not the stock help string:
f8ebb70d 76 helpMenu->Append(wxID_ABOUT, wxEmptyString, "My custom help string");
ba1d7a6c
FM
77
78 // use all stock properties except for the bitmap:
79 wxMenuItem *mymenu = new wxMenuItem(helpMenu, wxID_ABOUT);
80 mymenu->SetBitmap(wxArtProvider::GetBitmap(wxART_WARNING));
81 helpMenu->Append(mymenu);
82 @endcode
83
84 that is, stock properties are set independently one from the other.
3c4f71cc 85
7c913512 86 @param parentMenu
9cd28f48
VZ
87 Menu that the menu item belongs to. Can be @NULL if the item is
88 going to be added to the menu later.
7c913512 89 @param id
9cd28f48
VZ
90 Identifier for this menu item. May be @c wxID_SEPARATOR, in which
91 case the given kind is ignored and taken to be @c wxITEM_SEPARATOR
92 instead.
7c913512 93 @param text
7145bcfc
FM
94 Text for the menu item, as shown on the menu.
95 See SetItemLabel() for more info.
7c913512 96 @param helpString
4cc4bfaf 97 Optional help string that will be shown on the status bar.
7c913512 98 @param kind
ba1d7a6c 99 May be @c wxITEM_SEPARATOR, @c wxITEM_NORMAL, @c wxITEM_CHECK or
30f23bcc 100 @c wxITEM_RADIO.
7c913512 101 @param subMenu
4cc4bfaf 102 If non-@NULL, indicates that the menu item is a submenu.
23324ae1 103 */
4cc4bfaf 104 wxMenuItem(wxMenu* parentMenu = NULL, int id = wxID_SEPARATOR,
0a98423e
FM
105 const wxString& text = wxEmptyString,
106 const wxString& helpString = wxEmptyString,
23324ae1 107 wxItemKind kind = wxITEM_NORMAL,
4cc4bfaf 108 wxMenu* subMenu = NULL);
23324ae1
FM
109
110 /**
111 Destructor.
112 */
adaaa686 113 virtual ~wxMenuItem();
23324ae1
FM
114
115 /**
116 Checks or unchecks the menu item.
23324ae1
FM
117 Note that this only works when the item is already appended to a menu.
118 */
adaaa686 119 virtual void Check(bool check = true);
23324ae1
FM
120
121 /**
122 Enables or disables the menu item.
123 */
adaaa686 124 virtual void Enable(bool enable = true);
23324ae1
FM
125
126 /**
7145bcfc
FM
127 @deprecated This function is deprecated; please use GetLabelText() instead.
128
129 @see GetLabelText()
130 */
131 static wxString GetLabelFromText(const wxString& text);
132
133 /**
134 Strips all accelerator characters and mnemonics from the given @a text.
135 For example:
136
137 @code
138 wxMenuItem::GetLabelfromText("&Hello\tCtrl-h");
139 @endcode
140
141 will return just @c "Hello".
142
143 @see GetItemLabelText(), GetItemLabel()
144 */
145 static wxString GetLabelText(const wxString& text);
146
147
148 /**
149 @name Getters
150 */
151 //@{
152
153 /**
154 Returns the background colour associated with the menu item.
155
156 @onlyfor{wxmsw}
23324ae1 157 */
328f5751 158 wxColour GetBackgroundColour() const;
23324ae1
FM
159
160 /**
7145bcfc
FM
161 Returns the checked or unchecked bitmap.
162
163 @onlyfor{wxmsw}
23324ae1 164 */
43c48e1e 165 virtual const wxBitmap& GetBitmap() const;
23324ae1
FM
166
167 /**
7145bcfc
FM
168 Returns the font associated with the menu item.
169
170 @onlyfor{wxmsw}
23324ae1 171 */
328f5751 172 wxFont GetFont() const;
23324ae1
FM
173
174 /**
175 Returns the help string associated with the menu item.
176 */
43c48e1e 177 const wxString& GetHelp() const;
23324ae1
FM
178
179 /**
180 Returns the menu item identifier.
181 */
328f5751 182 int GetId() const;
23324ae1
FM
183
184 /**
185 Returns the text associated with the menu item including any accelerator
ba1d7a6c 186 characters that were passed to the constructor or SetItemLabel().
3c4f71cc 187
4cc4bfaf 188 @see GetItemLabelText(), GetLabelText()
23324ae1 189 */
adaaa686 190 virtual wxString GetItemLabel() const;
23324ae1
FM
191
192 /**
193 Returns the text associated with the menu item, without any accelerator
194 characters.
3c4f71cc 195
4cc4bfaf 196 @see GetItemLabel(), GetLabelText()
23324ae1 197 */
adaaa686 198 virtual wxString GetItemLabelText() const;
23324ae1
FM
199
200 /**
7c913512 201 Returns the item kind, one of @c wxITEM_SEPARATOR, @c wxITEM_NORMAL,
23324ae1
FM
202 @c wxITEM_CHECK or @c wxITEM_RADIO.
203 */
328f5751 204 wxItemKind GetKind() const;
23324ae1
FM
205
206 /**
207 Returns the text associated with the menu item without any accelerator
208 characters it might contain.
ba1d7a6c 209
5dfae0ad 210 @deprecated This function is deprecated in favour of GetItemLabelText().
ba1d7a6c 211
7145bcfc 212 @see GetItemLabelText()
23324ae1 213 */
328f5751 214 wxString GetLabel() const;
23324ae1
FM
215
216 /**
7145bcfc
FM
217 Gets the width of the menu item checkmark bitmap.
218
219 @onlyfor{wxmsw}
23324ae1 220 */
328f5751 221 int GetMarginWidth() const;
23324ae1
FM
222
223 /**
224 Returns the menu this menu item is in, or @NULL if this menu item is not
225 attached.
226 */
328f5751 227 wxMenu* GetMenu() const;
23324ae1
FM
228
229 /**
230 Returns the text associated with the menu item.
ba1d7a6c 231
7145bcfc
FM
232 @deprecated This function is deprecated. Please use GetItemLabel() or GetItemLabelText() instead.
233
234 @see GetItemLabel(), GetItemLabelText()
23324ae1 235 */
328f5751 236 wxString GetName() const;
23324ae1
FM
237
238 /**
239 Returns the submenu associated with the menu item, or @NULL if there isn't one.
240 */
328f5751 241 wxMenu* GetSubMenu() const;
23324ae1
FM
242
243 /**
244 Returns the text associated with the menu item, such as it was passed to the
245 wxMenuItem constructor, i.e. with any accelerator characters it may contain.
ba1d7a6c 246
5dfae0ad 247 @deprecated This function is deprecated in favour of GetItemLabel().
ba1d7a6c 248
7145bcfc 249 @see GetLabelFromText()
23324ae1 250 */
43c48e1e 251 const wxString& GetText() const;
23324ae1
FM
252
253 /**
7145bcfc
FM
254 Returns the text colour associated with the menu item.
255
256 @onlyfor{wxmsw}
23324ae1 257 */
328f5751 258 wxColour GetTextColour() const;
7145bcfc
FM
259
260 //@}
261
262
263
264 /**
265 @name Checkers
266 */
267 //@{
23324ae1
FM
268
269 /**
270 Returns @true if the item is checkable.
271 */
328f5751 272 bool IsCheckable() const;
23324ae1
FM
273
274 /**
275 Returns @true if the item is checked.
276 */
adaaa686 277 virtual bool IsChecked() const;
23324ae1
FM
278
279 /**
280 Returns @true if the item is enabled.
281 */
adaaa686 282 virtual bool IsEnabled() const;
23324ae1
FM
283
284 /**
285 Returns @true if the item is a separator.
286 */
328f5751 287 bool IsSeparator() const;
23324ae1
FM
288
289 /**
290 Returns @true if the item is a submenu.
291 */
328f5751 292 bool IsSubMenu() const;
7145bcfc
FM
293
294 //@}
295
296
297
298 /**
299 @name Setters
300 */
301 //@{
23324ae1
FM
302
303 /**
7145bcfc
FM
304 Sets the background colour associated with the menu item.
305
306 @onlyfor{wxmsw}
23324ae1 307 */
328f5751 308 void SetBackgroundColour(const wxColour& colour) const;
23324ae1
FM
309
310 /**
30f23bcc 311 Sets the bitmap for the menu item.
4d273001 312
7145bcfc
FM
313 It is equivalent to wxMenuItem::SetBitmaps(bmp, wxNullBitmap) if
314 @a checked is @true (default value) or SetBitmaps(wxNullBitmap, bmp)
4d273001 315 otherwise.
30f23bcc 316
0f6c9085 317 @onlyfor{wxmsw,wxosx,wxgtk}
23324ae1 318 */
4d273001 319 virtual void SetBitmap(const wxBitmap& bmp, bool checked = true);
23324ae1
FM
320
321 /**
30f23bcc 322 Sets the checked/unchecked bitmaps for the menu item.
ba1d7a6c 323 The first bitmap is also used as the single bitmap for uncheckable menu items.
30f23bcc
FM
324
325 @onlyfor{wxmsw}
23324ae1
FM
326 */
327 void SetBitmaps(const wxBitmap& checked,
328 const wxBitmap& unchecked = wxNullBitmap);
329
330 /**
7145bcfc
FM
331 Sets the font associated with the menu item.
332
333 @onlyfor{wxmsw}
23324ae1
FM
334 */
335 void SetFont(const wxFont& font);
336
337 /**
338 Sets the help string.
339 */
340 void SetHelp(const wxString& helpString);
341
342 /**
343 Sets the label associated with the menu item.
7145bcfc
FM
344
345 Note that if the ID of this menu item corrisponds to a stock ID, then it is
346 not necessary to specify a label: wxWidgets will automatically use the stock
347 item label associated with that ID. See the @ref wxMenuItem::wxMenuItem "constructor"
348 for more info.
349
350 The label string for the normal menu items (not separators) may include the
351 accelerator which can be used to activate the menu item from keyboard.
352 An accelerator key can be specified using the ampersand <tt>&</tt> character.
353 In order to embed an ampersand character in the menu item text, the ampersand
354 must be doubled.
355
356 Optionally you can specify also an accelerator string appending a tab character
357 <tt>\\t</tt> followed by a valid key combination (e.g. <tt>CTRL+V</tt>).
358 Its general syntax is any combination of @c "CTRL", @c "ALT" and @c "SHIFT" strings
359 (case doesn't matter) separated by either @c '-' or @c '+' characters and followed
360 by the accelerator itself.
361 The accelerator may be any alphanumeric character, any function key
362 (from F1 to F12) or one of the special characters listed in the table
363 below (again, case doesn't matter):
364 - @c DEL or @c DELETE: Delete key
365 - @c INS or @c INSERT: Insert key
366 - @c ENTER or @c RETURN: Enter key
367 - @c PGUP: PageUp key
368 - @c PGDN: PageDown key
369 - @c LEFT: Left cursor arrow key
370 - @c RIGHT: Right cursor arrow key
371 - @c UP: Up cursor arrow key
372 - @c DOWN: Down cursor arrow key
373 - @c HOME: Home key
374 - @c END: End key
375 - @c SPACE: Space
376 - @c TAB: Tab key
377 - @c ESC or @c ESCAPE: Escape key (Windows only)
378
379 Examples:
380
381 @code
382 m_pMyMenuItem->SetItemLabel("My &item\tCTRL+I");
383 m_pMyMenuItem2->SetItemLabel("Clean && build\tF7");
384 m_pMyMenuItem3->SetItemLabel("Simple item");
385 m_pMyMenuItem4->SetItemLabel("Item with &accelerator");
386 @endcode
387
388 @see GetItemLabel(), GetItemLabelText()
23324ae1 389 */
adaaa686 390 virtual void SetItemLabel(const wxString& label);
23324ae1
FM
391
392 /**
7145bcfc
FM
393 Sets the width of the menu item checkmark bitmap.
394
395 @onlyfor{wxmsw}
23324ae1 396 */
328f5751 397 void SetMarginWidth(int width) const;
23324ae1
FM
398
399 /**
400 Sets the parent menu which will contain this menu item.
401 */
43c48e1e 402 void SetMenu(wxMenu* menu);
23324ae1
FM
403
404 /**
405 Sets the submenu of this menu item.
406 */
43c48e1e 407 void SetSubMenu(wxMenu* menu);
23324ae1
FM
408
409 /**
410 Sets the text associated with the menu item.
ba1d7a6c 411
5dfae0ad 412 @deprecated This function is deprecated in favour of SetItemLabel().
7145bcfc
FM
413
414 @see SetItemLabel().
23324ae1 415 */
adaaa686 416 virtual void SetText(const wxString& text);
23324ae1
FM
417
418 /**
7145bcfc
FM
419 Sets the text colour associated with the menu item.
420
421 @onlyfor{wxmsw}
23324ae1
FM
422 */
423 void SetTextColour(const wxColour& colour);
7145bcfc
FM
424
425 //@}
23324ae1 426};
e54c96f1 427