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