]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/menu.h
Use wxCOMPtr throughout wxWebViewIE to simplify the code and reduce the chance of...
[wxWidgets.git] / interface / wx / menu.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: menu.h
e54c96f1 3// Purpose: interface of wxMenuBar
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxMenuBar
7c913512 11
23324ae1 12 A menu bar is a series of menus accessible from the top of a frame.
7c913512 13
ba1d7a6c
FM
14 @remarks
15 To respond to a menu selection, provide a handler for EVT_MENU, in the frame
16 that contains the menu bar.
17
18 If you have a toolbar which uses the same identifiers as your EVT_MENU entries,
19 events from the toolbar will also be processed by your EVT_MENU event handlers.
20
21 Tip: under Windows, if you discover that menu shortcuts (for example, Alt-F
22 to show the file menu) are not working, check any EVT_CHAR events you are
23 handling in child windows.
24 If you are not calling event.Skip() for events that you don't process in
25 these event handlers, menu shortcuts may cease to work.
26
23324ae1
FM
27 @library{wxcore}
28 @category{menus}
7c913512 29
3e083d65 30 @see wxMenu, @ref overview_events
23324ae1
FM
31*/
32class wxMenuBar : public wxWindow
33{
34public:
ff58644a 35 /**
ba1d7a6c 36 Construct an empty menu bar.
ff58644a
RR
37
38 @param style
39 If wxMB_DOCKABLE the menu bar can be detached (wxGTK only).
40 */
41 wxMenuBar(long style = 0);
ba1d7a6c 42
23324ae1
FM
43 /**
44 Construct a menu bar from arrays of menus and titles.
3c4f71cc 45
7c913512 46 @param n
4cc4bfaf 47 The number of menus.
7c913512 48 @param menus
ff58644a
RR
49 An array of menus. Do not use this array again - it now belongs to
50 the menu bar.
7c913512 51 @param titles
ff58644a
RR
52 An array of title strings. Deallocate this array after creating
53 the menu bar.
7c913512 54 @param style
4cc4bfaf 55 If wxMB_DOCKABLE the menu bar can be detached (wxGTK only).
1058f652
MB
56
57 @beginWxPerlOnly
58 Not supported by wxPerl.
59 @endWxPerlOnly
23324ae1 60 */
7c913512
FM
61 wxMenuBar(size_t n, wxMenu* menus[], const wxString titles[],
62 long style = 0);
23324ae1
FM
63
64 /**
ba1d7a6c
FM
65 Destructor, destroying the menu bar and removing it from the parent
66 frame (if any).
23324ae1 67 */
adaaa686 68 virtual ~wxMenuBar();
23324ae1
FM
69
70 /**
71 Adds the item to the end of the menu bar.
3c4f71cc 72
7c913512 73 @param menu
ba1d7a6c 74 The menu to add. Do not deallocate this menu after calling Append().
7c913512 75 @param title
b871bb95 76 The title of the menu, must be non-empty.
3c4f71cc 77
d29a9a8a 78 @return @true on success, @false if an error occurred.
3c4f71cc 79
4cc4bfaf 80 @see Insert()
23324ae1 81 */
adaaa686 82 virtual bool Append(wxMenu* menu, const wxString& title);
23324ae1
FM
83
84 /**
85 Checks or unchecks a menu item.
3c4f71cc 86
7c913512 87 @param id
4cc4bfaf 88 The menu item identifier.
7c913512 89 @param check
4cc4bfaf 90 If @true, checks the menu item, otherwise the item is unchecked.
3c4f71cc 91
23324ae1 92 @remarks Only use this when the menu bar has been associated with a
4cc4bfaf 93 frame; otherwise, use the wxMenu equivalent call.
23324ae1 94 */
43c48e1e 95 void Check(int id, bool check);
23324ae1
FM
96
97 /**
98 Enables or disables (greys out) a menu item.
3c4f71cc 99
7c913512 100 @param id
4cc4bfaf 101 The menu item identifier.
7c913512 102 @param enable
4cc4bfaf 103 @true to enable the item, @false to disable it.
3c4f71cc 104
23324ae1 105 @remarks Only use this when the menu bar has been associated with a
4cc4bfaf 106 frame; otherwise, use the wxMenu equivalent call.
23324ae1 107 */
0a98423e 108 void Enable(int id, bool enable);
23324ae1 109
e4a23857
VZ
110 /**
111 Returns true if the menu with the given index is enabled.
112
113 @param pos
114 The menu position (0-based)
115
116 @since 2.9.4
117 */
118 bool IsEnabledTop(size_t pos) const;
119
23324ae1
FM
120 /**
121 Enables or disables a whole menu.
3c4f71cc 122
7c913512 123 @param pos
4cc4bfaf 124 The position of the menu, starting from zero.
7c913512 125 @param enable
4cc4bfaf 126 @true to enable the menu, @false to disable it.
3c4f71cc 127
23324ae1
FM
128 @remarks Only use this when the menu bar has been associated with a frame.
129 */
43c48e1e 130 virtual void EnableTop(size_t pos, bool enable);
23324ae1
FM
131
132 /**
133 Finds the menu item object associated with the given menu item identifier.
3c4f71cc 134
7c913512 135 @param id
4cc4bfaf 136 Menu item identifier.
7c913512 137 @param menu
4cc4bfaf 138 If not @NULL, menu will get set to the associated menu.
3c4f71cc 139
d29a9a8a 140 @return The found menu item object, or @NULL if one was not found.
1058f652
MB
141
142 @beginWxPerlOnly
143 In wxPerl this method takes just the @a id parameter;
144 in scalar context it returns the associated @c Wx::MenuItem, in list
145 context it returns a 2-element list (item, submenu).
146 @endWxPerlOnly
23324ae1 147 */
86381d42 148 virtual wxMenuItem* FindItem(int id, wxMenu** menu = NULL) const;
23324ae1
FM
149
150 /**
4cc4bfaf 151 Returns the index of the menu with the given @a title or @c wxNOT_FOUND if no
ba1d7a6c
FM
152 such menu exists in this menubar.
153
154 The @a title parameter may specify either the menu title
155 (with accelerator characters, i.e. @c "&File") or just the
23324ae1
FM
156 menu label (@c "File") indifferently.
157 */
328f5751 158 int FindMenu(const wxString& title) const;
23324ae1
FM
159
160 /**
161 Finds the menu item id for a menu name/menu item string pair.
3c4f71cc 162
7c913512 163 @param menuString
4cc4bfaf 164 Menu title to find.
7c913512 165 @param itemString
4cc4bfaf 166 Item to find.
3c4f71cc 167
d29a9a8a 168 @return The menu item identifier, or wxNOT_FOUND if none was found.
3c4f71cc 169
23324ae1 170 @remarks Any special menu codes are stripped out of source and target
4cc4bfaf 171 strings before matching.
23324ae1 172 */
fadc2df6
FM
173 virtual int FindMenuItem(const wxString& menuString,
174 const wxString& itemString) const;
23324ae1
FM
175
176 /**
177 Gets the help string associated with the menu item identifier.
3c4f71cc 178
7c913512 179 @param id
4cc4bfaf 180 The menu item identifier.
3c4f71cc 181
d29a9a8a
BP
182 @return The help string, or the empty string if there was no help string
183 or the menu item was not found.
3c4f71cc 184
4cc4bfaf 185 @see SetHelpString()
23324ae1 186 */
328f5751 187 wxString GetHelpString(int id) const;
23324ae1
FM
188
189 /**
190 Gets the label associated with a menu item.
3c4f71cc 191
7c913512 192 @param id
4cc4bfaf 193 The menu item identifier.
3c4f71cc 194
d29a9a8a
BP
195 @return The menu item label, or the empty string if the item was not
196 found.
3c4f71cc 197
23324ae1
FM
198 @remarks Use only after the menubar has been associated with a frame.
199 */
328f5751 200 wxString GetLabel(int id) const;
23324ae1
FM
201
202 /**
203 Returns the label of a top-level menu. Note that the returned string does not
204 include the accelerator characters which could have been specified in the menu
205 title string during its construction.
3c4f71cc 206
7c913512 207 @param pos
4cc4bfaf 208 Position of the menu on the menu bar, starting from zero.
3c4f71cc 209
d29a9a8a 210 @return The menu label, or the empty string if the menu was not found.
3c4f71cc 211
23324ae1 212 @remarks Use only after the menubar has been associated with a frame.
3c4f71cc 213
ba1d7a6c
FM
214 @deprecated
215 This function is deprecated in favour of GetMenuLabel() and GetMenuLabelText().
216
4cc4bfaf 217 @see SetLabelTop()
23324ae1 218 */
43c48e1e 219 wxString GetLabelTop(size_t pos) const;
23324ae1
FM
220
221 /**
4cc4bfaf 222 Returns the menu at @a menuIndex (zero-based).
23324ae1 223 */
43c48e1e 224 wxMenu* GetMenu(size_t menuIndex) const;
23324ae1
FM
225
226 /**
227 Returns the number of menus in this menubar.
228 */
328f5751 229 size_t GetMenuCount() const;
23324ae1
FM
230
231 /**
232 Returns the label of a top-level menu. Note that the returned string
233 includes the accelerator characters that have been specified in the menu
234 title string during its construction.
3c4f71cc 235
7c913512 236 @param pos
4cc4bfaf 237 Position of the menu on the menu bar, starting from zero.
3c4f71cc 238
d29a9a8a 239 @return The menu label, or the empty string if the menu was not found.
3c4f71cc 240
23324ae1 241 @remarks Use only after the menubar has been associated with a frame.
3c4f71cc 242
4cc4bfaf 243 @see GetMenuLabelText(), SetMenuLabel()
23324ae1 244 */
43c48e1e 245 virtual wxString GetMenuLabel(size_t pos) const;
23324ae1
FM
246
247 /**
248 Returns the label of a top-level menu. Note that the returned string does not
249 include any accelerator characters that may have been specified in the menu
250 title string during its construction.
3c4f71cc 251
7c913512 252 @param pos
4cc4bfaf 253 Position of the menu on the menu bar, starting from zero.
3c4f71cc 254
d29a9a8a 255 @return The menu label, or the empty string if the menu was not found.
3c4f71cc 256
23324ae1 257 @remarks Use only after the menubar has been associated with a frame.
3c4f71cc 258
4cc4bfaf 259 @see GetMenuLabel(), SetMenuLabel()
23324ae1 260 */
43c48e1e 261 virtual wxString GetMenuLabelText(size_t pos) const;
23324ae1
FM
262
263 /**
264 Inserts the menu at the given position into the menu bar. Inserting menu at
7c913512 265 position 0 will insert it in the very beginning of it, inserting at position
ba1d7a6c 266 GetMenuCount() is the same as calling Append().
3c4f71cc 267
7c913512 268 @param pos
4cc4bfaf 269 The position of the new menu in the menu bar
7c913512 270 @param menu
4cc4bfaf 271 The menu to add. wxMenuBar owns the menu and will free it.
7c913512 272 @param title
4cc4bfaf 273 The title of the menu.
3c4f71cc 274
d29a9a8a 275 @return @true on success, @false if an error occurred.
3c4f71cc 276
4cc4bfaf 277 @see Append()
23324ae1 278 */
adaaa686 279 virtual bool Insert(size_t pos, wxMenu* menu, const wxString& title);
23324ae1
FM
280
281 /**
282 Determines whether an item is checked.
3c4f71cc 283
7c913512 284 @param id
4cc4bfaf 285 The menu item identifier.
3c4f71cc 286
d29a9a8a 287 @return @true if the item was found and is checked, @false otherwise.
23324ae1 288 */
328f5751 289 bool IsChecked(int id) const;
23324ae1
FM
290
291 /**
292 Determines whether an item is enabled.
3c4f71cc 293
7c913512 294 @param id
4cc4bfaf 295 The menu item identifier.
3c4f71cc 296
d29a9a8a 297 @return @true if the item was found and is enabled, @false otherwise.
23324ae1 298 */
328f5751 299 bool IsEnabled(int id) const;
23324ae1
FM
300
301 /**
302 Redraw the menu bar
303 */
43c48e1e 304 virtual void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
23324ae1
FM
305
306 /**
ba1d7a6c
FM
307 Removes the menu from the menu bar and returns the menu object - the caller
308 is responsible for deleting it. This function may be used together with
309 Insert() to change the menubar dynamically.
3c4f71cc 310
4cc4bfaf 311 @see Replace()
23324ae1 312 */
adaaa686 313 virtual wxMenu* Remove(size_t pos);
23324ae1
FM
314
315 /**
316 Replaces the menu at the given position with another one.
3c4f71cc 317
7c913512 318 @param pos
4cc4bfaf 319 The position of the new menu in the menu bar
7c913512 320 @param menu
4cc4bfaf 321 The menu to add.
7c913512 322 @param title
4cc4bfaf 323 The title of the menu.
3c4f71cc 324
ba1d7a6c
FM
325 @return The menu which was previously at position pos.
326 The caller is responsible for deleting it.
3c4f71cc 327
4cc4bfaf 328 @see Insert(), Remove()
23324ae1 329 */
adaaa686 330 virtual wxMenu* Replace(size_t pos, wxMenu* menu, const wxString& title);
23324ae1
FM
331
332 /**
333 Sets the help string associated with a menu item.
3c4f71cc 334
7c913512 335 @param id
4cc4bfaf 336 Menu item identifier.
7c913512 337 @param helpString
4cc4bfaf 338 Help string to associate with the menu item.
3c4f71cc 339
4cc4bfaf 340 @see GetHelpString()
23324ae1
FM
341 */
342 void SetHelpString(int id, const wxString& helpString);
343
344 /**
345 Sets the label of a menu item.
3c4f71cc 346
7c913512 347 @param id
4cc4bfaf 348 Menu item identifier.
7c913512 349 @param label
4cc4bfaf 350 Menu item label.
3c4f71cc 351
23324ae1 352 @remarks Use only after the menubar has been associated with a frame.
3c4f71cc 353
4cc4bfaf 354 @see GetLabel()
23324ae1
FM
355 */
356 void SetLabel(int id, const wxString& label);
357
358 /**
359 Sets the label of a top-level menu.
3c4f71cc 360
7c913512 361 @param pos
4cc4bfaf 362 The position of a menu on the menu bar, starting from zero.
7c913512 363 @param label
4cc4bfaf 364 The menu label.
3c4f71cc 365
23324ae1 366 @remarks Use only after the menubar has been associated with a frame.
3c4f71cc 367
ba1d7a6c
FM
368 @deprecated
369 This function has been deprecated in favour of SetMenuLabel().
370
4cc4bfaf 371 @see GetLabelTop()
23324ae1 372 */
43c48e1e 373 void SetLabelTop(size_t pos, const wxString& label);
23324ae1
FM
374
375 /**
376 Sets the label of a top-level menu.
3c4f71cc 377
7c913512 378 @param pos
4cc4bfaf 379 The position of a menu on the menu bar, starting from zero.
7c913512 380 @param label
4cc4bfaf 381 The menu label.
3c4f71cc 382
23324ae1
FM
383 @remarks Use only after the menubar has been associated with a frame.
384 */
43c48e1e 385 virtual void SetMenuLabel(size_t pos, const wxString& label);
e9321277
RD
386
387 /**
388 Enables you to set the global menubar on Mac, that is, the menubar displayed
389 when the app is running without any frames open.
390
391 @param menubar
392 The menubar to set.
393
394 @remarks Only exists on Mac, other platforms do not have this method.
9b026e31
VZ
395
396 @onlyfor{wxosx}
e9321277
RD
397 */
398 static void MacSetCommonMenuBar(wxMenuBar* menubar);
399
400 /**
401 Enables you to get the global menubar on Mac, that is, the menubar displayed
402 when the app is running without any frames open.
403
404 @return The global menubar.
405
406 @remarks Only exists on Mac, other platforms do not have this method.
9b026e31
VZ
407
408 @onlyfor{wxosx}
e9321277
RD
409 */
410 static wxMenuBar* MacGetCommonMenuBar();
dbac5ccc
RD
411
412 wxFrame *GetFrame() const;
413 bool IsAttached() const;
414 virtual void Attach(wxFrame *frame);
415 virtual void Detach();
416
23324ae1
FM
417};
418
419
e54c96f1 420
23324ae1
FM
421/**
422 @class wxMenu
7c913512 423
23324ae1
FM
424 A menu is a popup (or pull down) list of items, one of which may be
425 selected before the menu goes away (clicking elsewhere dismisses the
426 menu). Menus may be used to construct either menu bars or popup menus.
7c913512 427
23324ae1
FM
428 A menu item has an integer ID associated with it which can be used to
429 identify the selection, or to change the menu item in some way. A menu item
0c466250
VZ
430 with a special identifier @e wxID_SEPARATOR is a separator item and doesn't
431 have an associated command but just makes a separator line appear in the
432 menu.
7c913512 433
ba1d7a6c
FM
434 @note
435 Please note that @e wxID_ABOUT and @e wxID_EXIT are predefined by wxWidgets
436 and have a special meaning since entries using these IDs will be taken out
437 of the normal menus under MacOS X and will be inserted into the system menu
438 (following the appropriate MacOS X interface guideline).
ba1d7a6c 439
c7e52709 440 Menu items may be either @e normal items, @e check items or @e radio items.
ba1d7a6c
FM
441 Normal items don't have any special properties while the check items have a
442 boolean flag associated to them and they show a checkmark in the menu when
443 the flag is set.
23324ae1 444 wxWidgets automatically toggles the flag value when the item is clicked and its
ba1d7a6c
FM
445 value may be retrieved using either wxMenu::IsChecked method of wxMenu or
446 wxMenuBar itself or by using wxEvent::IsChecked when you get the menu
23324ae1 447 notification for the item in question.
7c913512 448
23324ae1
FM
449 The radio items are similar to the check items except that all the other items
450 in the same radio group are unchecked when a radio item is checked. The radio
451 group is formed by a contiguous range of radio items, i.e. it starts at the
452 first item of this kind and ends with the first item of a different kind (or
453 the end of the menu). Notice that because the radio groups are defined in terms
454 of the item positions inserting or removing the items in the menu containing
c7e52709 455 the radio items risks to not work correctly.
7c913512 456
ba1d7a6c
FM
457
458 @section menu_allocation Allocation strategy
459
d16ba464
VZ
460 All menus must be created on the @b heap because all menus attached to a
461 menubar or to another menu will be deleted by their parent when it is
462 deleted. The only exception to this rule are the popup menus (i.e. menus
463 used with wxWindow::PopupMenu()) as wxWidgets does not destroy them to
464 allow reusing the same menu more than once. But the exception applies only
465 to the menus themselves and not to any submenus of popup menus which are
466 still destroyed by wxWidgets as usual and so must be heap-allocated.
c7e52709 467
ba1d7a6c
FM
468 As the frame menubar is deleted by the frame itself, it means that normally
469 all menus used are deleted automatically.
470
471
472 @section menu_eventhandling Event handling
473
474 If the menu is part of a menubar, then wxMenuBar event processing is used.
ba1d7a6c 475
c7e52709
FM
476 With a popup menu (see wxWindow::PopupMenu), there is a variety of ways to
477 handle a menu selection event (@c wxEVT_COMMAND_MENU_SELECTED):
478 - Provide @c EVT_MENU handlers in the window which pops up the menu, or in an
479 ancestor of that window (the simplest method);
480 - Derive a new class from wxMenu and define event table entries using the @c EVT_MENU macro;
481 - Set a new event handler for wxMenu, through wxEvtHandler::SetNextHandler,
482 specifying an object whose class has @c EVT_MENU entries;
483
484 Note that instead of static @c EVT_MENU macros you can also use dynamic
8d2d37d2 485 connection; see @ref overview_events_bind.
ba1d7a6c 486
23324ae1
FM
487 @library{wxcore}
488 @category{menus}
7c913512 489
3e083d65 490 @see wxMenuBar, wxWindow::PopupMenu, @ref overview_events,
ba1d7a6c 491 @ref wxFileHistory "wxFileHistory (most recently used files menu)"
23324ae1
FM
492*/
493class wxMenu : public wxEvtHandler
494{
495public:
8ff9b17d
RD
496
497 /**
498 Constructs a wxMenu object.
499 */
500 wxMenu();
501
23324ae1
FM
502 /**
503 Constructs a wxMenu object.
3c4f71cc 504
7c913512 505 @param style
4cc4bfaf 506 If set to wxMENU_TEAROFF, the menu will be detachable (wxGTK only).
23324ae1 507 */
7c913512 508 wxMenu(long style);
23324ae1 509
ff58644a 510 /**
ba1d7a6c 511 Constructs a wxMenu object with a title.
ff58644a
RR
512
513 @param title
514 Title at the top of the menu (not always supported).
515 @param style
516 If set to wxMENU_TEAROFF, the menu will be detachable (wxGTK only).
517 */
0a98423e 518 wxMenu(const wxString& title, long style = 0);
ba1d7a6c 519
23324ae1
FM
520 /**
521 Destructor, destroying the menu.
ba1d7a6c
FM
522
523 @note
524 Under Motif, a popup menu must have a valid parent (the window
525 it was last popped up on) when being destroyed. Therefore, make sure
526 you delete or re-use the popup menu @e before destroying the parent
527 window. Re-use in this context means popping up the menu on a different
528 window from last time, which causes an implicit destruction and
529 recreation of internal data structures.
23324ae1 530 */
adaaa686 531 virtual ~wxMenu();
23324ae1 532
23324ae1 533 /**
ba1d7a6c 534 Adds a menu item.
3c4f71cc 535
7c913512 536 @param id
4cc4bfaf 537 The menu command identifier.
7c913512 538 @param item
4cc4bfaf 539 The string to appear on the menu item.
7145bcfc 540 See wxMenuItem::SetItemLabel() for more details.
7c913512 541 @param helpString
4cc4bfaf 542 An optional help string associated with the item.
7145bcfc 543 By default, the handler for the @c wxEVT_MENU_HIGHLIGHT event displays
4cc4bfaf 544 this string in the status line.
54c49fab 545 @param kind
7145bcfc 546 May be @c wxITEM_SEPARATOR, @c wxITEM_NORMAL, @c wxITEM_CHECK or @c wxITEM_RADIO.
b871bb95 547
7145bcfc
FM
548 Example:
549 @code
550 m_pFileMenu->Append(ID_NEW_FILE, "&New file\tCTRL+N", "Creates a new XYZ document");
551 @endcode
552 or even better for stock menu items (see wxMenuItem::wxMenuItem):
553 @code
554 m_pFileMenu->Append(wxID_NEW, "", "Creates a new XYZ document");
555 @endcode
ba1d7a6c
FM
556
557 @remarks
558 This command can be used after the menu has been shown, as well as on
559 initial creation of a menu or menubar.
560
4cc4bfaf 561 @see AppendSeparator(), AppendCheckItem(), AppendRadioItem(),
ba1d7a6c
FM
562 AppendSubMenu(), Insert(), SetLabel(), GetHelpString(),
563 SetHelpString(), wxMenuItem
23324ae1 564 */
54c49fab
VZ
565 wxMenuItem* Append(int id, const wxString& item = wxEmptyString,
566 const wxString& helpString = wxEmptyString,
23324ae1 567 wxItemKind kind = wxITEM_NORMAL);
ba1d7a6c 568
ff58644a
RR
569 /**
570 Adds a submenu.
571
5dfae0ad 572 @deprecated This function is deprecated, use AppendSubMenu() instead.
54c49fab 573
ff58644a
RR
574 @param id
575 The menu command identifier.
576 @param item
577 The string to appear on the menu item.
54c49fab 578 @param subMenu
ff58644a
RR
579 Pull-right submenu.
580 @param helpString
581 An optional help string associated with the item.
3a194bda 582 By default, the handler for the @c wxEVT_MENU_HIGHLIGHT event displays
ff58644a
RR
583 this string in the status line.
584
585 @see AppendSeparator(), AppendCheckItem(), AppendRadioItem(),
ba1d7a6c
FM
586 AppendSubMenu(), Insert(), SetLabel(), GetHelpString(),
587 SetHelpString(), wxMenuItem
ff58644a 588 */
adaaa686 589 wxMenuItem* Append(int id, const wxString& item, wxMenu* subMenu,
54c49fab 590 const wxString& helpString = wxEmptyString);
ba1d7a6c 591
ff58644a 592 /**
ba1d7a6c
FM
593 Adds a menu item object.
594
595 This is the most generic variant of Append() method because it may be
596 used for both items (including separators) and submenus and because
597 you can also specify various extra properties of a menu item this way,
ff58644a
RR
598 such as bitmaps and fonts.
599
600 @param menuItem
ba1d7a6c
FM
601 A menuitem object. It will be owned by the wxMenu object after this
602 function is called, so do not delete it yourself.
603
604 @remarks
605 See the remarks for the other Append() overloads.
ff58644a
RR
606
607 @see AppendSeparator(), AppendCheckItem(), AppendRadioItem(),
ba1d7a6c
FM
608 AppendSubMenu(), Insert(), SetLabel(), GetHelpString(),
609 SetHelpString(), wxMenuItem
ff58644a 610 */
7c913512 611 wxMenuItem* Append(wxMenuItem* menuItem);
23324ae1
FM
612
613 /**
614 Adds a checkable item to the end of the menu.
3c4f71cc 615
4cc4bfaf 616 @see Append(), InsertCheckItem()
23324ae1
FM
617 */
618 wxMenuItem* AppendCheckItem(int id, const wxString& item,
43c48e1e 619 const wxString& help = wxEmptyString);
23324ae1
FM
620
621 /**
ba1d7a6c
FM
622 Adds a radio item to the end of the menu.
623 All consequent radio items form a group and when an item in the group is
624 checked, all the others are automatically unchecked.
3c4f71cc 625
c7e52709
FM
626 @note Radio items are not supported under wxMotif.
627
4cc4bfaf 628 @see Append(), InsertRadioItem()
23324ae1
FM
629 */
630 wxMenuItem* AppendRadioItem(int id, const wxString& item,
43c48e1e 631 const wxString& help = wxEmptyString);
23324ae1
FM
632
633 /**
634 Adds a separator to the end of the menu.
3c4f71cc 635
4cc4bfaf 636 @see Append(), InsertSeparator()
23324ae1
FM
637 */
638 wxMenuItem* AppendSeparator();
639
640 /**
4cc4bfaf
FM
641 Adds the given @a submenu to this menu. @a text is the text shown in the
642 menu for it and @a help is the help string shown in the status bar when the
23324ae1
FM
643 submenu item is selected.
644 */
4cc4bfaf
FM
645 wxMenuItem* AppendSubMenu(wxMenu* submenu, const wxString& text,
646 const wxString& help = wxEmptyString);
23324ae1
FM
647
648 /**
ba1d7a6c
FM
649 Inserts a break in a menu, causing the next appended item to appear in
650 a new column.
23324ae1 651 */
adaaa686 652 virtual void Break();
23324ae1
FM
653
654 /**
655 Checks or unchecks the menu item.
3c4f71cc 656
7c913512 657 @param id
4cc4bfaf 658 The menu item identifier.
7c913512 659 @param check
4cc4bfaf 660 If @true, the item will be checked, otherwise it will be unchecked.
3c4f71cc 661
4cc4bfaf 662 @see IsChecked()
23324ae1 663 */
43c48e1e 664 void Check(int id, bool check);
23324ae1 665
23324ae1
FM
666 /**
667 Deletes the menu item from the menu. If the item is a submenu, it will
ff58644a 668 @b not be deleted. Use Destroy() if you want to delete a submenu.
3c4f71cc 669
7c913512 670 @param id
4cc4bfaf 671 Id of the menu item to be deleted.
ff58644a
RR
672
673 @see FindItem(), Destroy(), Remove()
674 */
0a98423e 675 bool Delete(int id);
ff58644a
RR
676
677 /**
678 Deletes the menu item from the menu. If the item is a submenu, it will
679 @b not be deleted. Use Destroy() if you want to delete a submenu.
680
7c913512 681 @param item
4cc4bfaf 682 Menu item to be deleted.
3c4f71cc 683
4cc4bfaf 684 @see FindItem(), Destroy(), Remove()
23324ae1 685 */
0a98423e 686 bool Delete(wxMenuItem* item);
23324ae1 687
23324ae1
FM
688 /**
689 Deletes the menu item from the menu. If the item is a submenu, it will
ff58644a
RR
690 be deleted. Use Remove() if you want to keep the submenu (for example,
691 to reuse it later).
3c4f71cc 692
7c913512 693 @param id
4cc4bfaf 694 Id of the menu item to be deleted.
ff58644a 695
0c466250 696 @see FindItem(), Delete(), Remove()
ff58644a 697 */
0a98423e 698 bool Destroy(int id);
ff58644a
RR
699
700 /**
701 Deletes the menu item from the menu. If the item is a submenu, it will
702 be deleted. Use Remove() if you want to keep the submenu (for example,
703 to reuse it later).
704
7c913512 705 @param item
4cc4bfaf 706 Menu item to be deleted.
3c4f71cc 707
0c466250 708 @see FindItem(), Delete(), Remove()
23324ae1 709 */
0a98423e 710 bool Destroy(wxMenuItem* item);
23324ae1
FM
711
712 /**
713 Enables or disables (greys out) a menu item.
3c4f71cc 714
7c913512 715 @param id
4cc4bfaf 716 The menu item identifier.
7c913512 717 @param enable
4cc4bfaf 718 @true to enable the menu item, @false to disable it.
3c4f71cc 719
4cc4bfaf 720 @see IsEnabled()
23324ae1 721 */
43c48e1e 722 void Enable(int id, bool enable);
23324ae1 723
7b2e024e
VZ
724 /**
725 Finds the menu item object associated with the given menu item identifier
726 and, optionally, the position of the item in the menu.
727
728 Unlike FindItem(), this function doesn't recurse but only looks at the
729 direct children of this menu.
730
731 @param id
732 The identifier of the menu item to find.
733 @param pos
734 If the pointer is not @NULL, it is filled with the item's position if
735 it was found or @c (size_t)wxNOT_FOUND otherwise.
736 @return
737 Menu item object or @NULL if not found.
738 */
739 wxMenuItem *FindChildItem(int id, size_t *pos = NULL) const;
740
23324ae1 741 /**
ff58644a 742 Finds the menu id for a menu item string.
3c4f71cc 743
7c913512 744 @param itemString
4cc4bfaf 745 Menu item string to find.
ff58644a 746
d29a9a8a 747 @return Menu item identifier, or wxNOT_FOUND if none is found.
ff58644a
RR
748
749 @remarks Any special menu codes are stripped out of source and target
750 strings before matching.
751 */
adaaa686 752 virtual int FindItem(const wxString& itemString) const;
ff58644a
RR
753
754 /**
755 Finds the menu item object associated with the given menu item identifier and,
756 optionally, the (sub)menu it belongs to.
757
7c913512 758 @param id
4cc4bfaf 759 Menu item identifier.
7c913512 760 @param menu
4cc4bfaf
FM
761 If the pointer is not @NULL, it will be filled with the item's
762 parent menu (if the item was found)
3c4f71cc 763
d29a9a8a 764 @return Menu item object or NULL if none is found.
23324ae1 765 */
0a98423e 766 wxMenuItem* FindItem(int id, wxMenu** menu = NULL) const;
23324ae1
FM
767
768 /**
769 Returns the wxMenuItem given a position in the menu.
770 */
328f5751 771 wxMenuItem* FindItemByPosition(size_t position) const;
23324ae1
FM
772
773 /**
774 Returns the help string associated with a menu item.
3c4f71cc 775
7c913512 776 @param id
4cc4bfaf 777 The menu item identifier.
3c4f71cc 778
d29a9a8a
BP
779 @return The help string, or the empty string if there is no help string
780 or the item was not found.
3c4f71cc 781
4cc4bfaf 782 @see SetHelpString(), Append()
23324ae1 783 */
adaaa686 784 virtual wxString GetHelpString(int id) const;
23324ae1
FM
785
786 /**
787 Returns a menu item label.
3c4f71cc 788
7c913512 789 @param id
4cc4bfaf 790 The menu item identifier.
3c4f71cc 791
d29a9a8a 792 @return The item label, or the empty string if the item was not found.
3c4f71cc 793
4cc4bfaf 794 @see GetLabelText(), SetLabel()
23324ae1 795 */
328f5751 796 wxString GetLabel(int id) const;
23324ae1
FM
797
798 /**
799 Returns a menu item label, without any of the original mnemonics and
800 accelerators.
3c4f71cc 801
7c913512 802 @param id
4cc4bfaf 803 The menu item identifier.
3c4f71cc 804
d29a9a8a 805 @return The item label, or the empty string if the item was not found.
3c4f71cc 806
4cc4bfaf 807 @see GetLabel(), SetLabel()
23324ae1 808 */
328f5751 809 wxString GetLabelText(int id) const;
23324ae1
FM
810
811 /**
812 Returns the number of items in the menu.
813 */
328f5751 814 size_t GetMenuItemCount() const;
23324ae1 815
0a98423e 816 //@{
23324ae1 817 /**
ba1d7a6c
FM
818 Returns the list of items in the menu.
819
820 wxMenuItemList is a pseudo-template list class containing wxMenuItem
821 pointers, see wxList.
23324ae1 822 */
db414879 823 wxMenuItemList& GetMenuItems();
0a98423e
FM
824 const wxMenuItemList& GetMenuItems() const;
825 //@}
23324ae1
FM
826
827 /**
828 Returns the title of the menu.
3c4f71cc 829
4cc4bfaf 830 @see SetTitle()
23324ae1 831 */
43c48e1e 832 const wxString& GetTitle() const;
23324ae1 833
23324ae1 834 /**
ba1d7a6c
FM
835 Inserts the given @a item before the position @a pos.
836
837 Inserting the item at position GetMenuItemCount() is the same
23324ae1 838 as appending it.
3c4f71cc 839
4cc4bfaf 840 @see Append(), Prepend()
23324ae1 841 */
e9321277 842 wxMenuItem* Insert(size_t pos, wxMenuItem* menuItem);
ba1d7a6c 843
ff58644a 844 /**
ba1d7a6c
FM
845 Inserts the given @a item before the position @a pos.
846
847 Inserting the item at position GetMenuItemCount() is the same
ff58644a
RR
848 as appending it.
849
850 @see Append(), Prepend()
851 */
7c913512 852 wxMenuItem* Insert(size_t pos, int id,
0a98423e
FM
853 const wxString& item = wxEmptyString,
854 const wxString& helpString = wxEmptyString,
7c913512 855 wxItemKind kind = wxITEM_NORMAL);
23324ae1
FM
856
857 /**
858 Inserts a checkable item at the given position.
3c4f71cc 859
4cc4bfaf 860 @see Insert(), AppendCheckItem()
23324ae1 861 */
43c48e1e
FM
862 wxMenuItem* InsertCheckItem(size_t pos, int id, const wxString& item,
863 const wxString& helpString = wxEmptyString);
23324ae1
FM
864
865 /**
866 Inserts a radio item at the given position.
3c4f71cc 867
4cc4bfaf 868 @see Insert(), AppendRadioItem()
23324ae1 869 */
43c48e1e
FM
870 wxMenuItem* InsertRadioItem(size_t pos, int id, const wxString& item,
871 const wxString& helpString = wxEmptyString);
23324ae1
FM
872
873 /**
874 Inserts a separator at the given position.
3c4f71cc 875
4cc4bfaf 876 @see Insert(), AppendSeparator()
23324ae1
FM
877 */
878 wxMenuItem* InsertSeparator(size_t pos);
879
880 /**
881 Determines whether a menu item is checked.
3c4f71cc 882
7c913512 883 @param id
4cc4bfaf 884 The menu item identifier.
3c4f71cc 885
d29a9a8a 886 @return @true if the menu item is checked, @false otherwise.
3c4f71cc 887
4cc4bfaf 888 @see Check()
23324ae1 889 */
328f5751 890 bool IsChecked(int id) const;
23324ae1
FM
891
892 /**
893 Determines whether a menu item is enabled.
3c4f71cc 894
7c913512 895 @param id
4cc4bfaf 896 The menu item identifier.
3c4f71cc 897
d29a9a8a 898 @return @true if the menu item is enabled, @false otherwise.
3c4f71cc 899
4cc4bfaf 900 @see Enable()
23324ae1 901 */
328f5751 902 bool IsEnabled(int id) const;
23324ae1 903
23324ae1 904 /**
4cc4bfaf 905 Inserts the given @a item at position 0, i.e. before all the other
23324ae1 906 existing items.
3c4f71cc 907
4cc4bfaf 908 @see Append(), Insert()
23324ae1 909 */
4cc4bfaf 910 wxMenuItem* Prepend(wxMenuItem* item);
ff58644a
RR
911
912 /**
913 Inserts the given @a item at position 0, i.e. before all the other
914 existing items.
915
916 @see Append(), Insert()
917 */
0a98423e
FM
918 wxMenuItem* Prepend(int id, const wxString& item = wxEmptyString,
919 const wxString& helpString = wxEmptyString,
7c913512 920 wxItemKind kind = wxITEM_NORMAL);
23324ae1
FM
921
922 /**
923 Inserts a checkable item at position 0.
3c4f71cc 924
4cc4bfaf 925 @see Prepend(), AppendCheckItem()
23324ae1
FM
926 */
927 wxMenuItem* PrependCheckItem(int id, const wxString& item,
43c48e1e 928 const wxString& helpString = wxEmptyString);
23324ae1
FM
929
930 /**
931 Inserts a radio item at position 0.
3c4f71cc 932
4cc4bfaf 933 @see Prepend(), AppendRadioItem()
23324ae1
FM
934 */
935 wxMenuItem* PrependRadioItem(int id, const wxString& item,
43c48e1e 936 const wxString& helpString = wxEmptyString);
23324ae1
FM
937
938 /**
939 Inserts a separator at position 0.
3c4f71cc 940
4cc4bfaf 941 @see Prepend(), AppendSeparator()
23324ae1
FM
942 */
943 wxMenuItem* PrependSeparator();
944
23324ae1
FM
945 /**
946 Removes the menu item from the menu but doesn't delete the associated C++
ba1d7a6c
FM
947 object. This allows you to reuse the same item later by adding it back to
948 the menu (especially useful with submenus).
3c4f71cc 949
7c913512 950 @param id
4cc4bfaf 951 The identifier of the menu item to remove.
ff58644a 952
5dfae0ad 953 @return A pointer to the item which was detached from the menu.
ff58644a
RR
954 */
955 wxMenuItem* Remove(int id);
ba1d7a6c 956
ff58644a
RR
957 /**
958 Removes the menu item from the menu but doesn't delete the associated C++
ba1d7a6c
FM
959 object. This allows you to reuse the same item later by adding it back to
960 the menu (especially useful with submenus).
ff58644a 961
7c913512 962 @param item
4cc4bfaf 963 The menu item to remove.
3c4f71cc 964
5dfae0ad 965 @return A pointer to the item which was detached from the menu.
23324ae1 966 */
4cc4bfaf 967 wxMenuItem* Remove(wxMenuItem* item);
23324ae1
FM
968
969 /**
970 Sets an item's help string.
3c4f71cc 971
7c913512 972 @param id
4cc4bfaf 973 The menu item identifier.
7c913512 974 @param helpString
4cc4bfaf 975 The help string to set.
3c4f71cc 976
4cc4bfaf 977 @see GetHelpString()
23324ae1 978 */
adaaa686 979 virtual void SetHelpString(int id, const wxString& helpString);
23324ae1
FM
980
981 /**
982 Sets the label of a menu item.
3c4f71cc 983
7c913512 984 @param id
4cc4bfaf 985 The menu item identifier.
7c913512 986 @param label
4cc4bfaf 987 The menu item label to set.
3c4f71cc 988
4cc4bfaf 989 @see Append(), GetLabel()
23324ae1
FM
990 */
991 void SetLabel(int id, const wxString& label);
992
993 /**
994 Sets the title of the menu.
3c4f71cc 995
7c913512 996 @param title
4cc4bfaf 997 The title to set.
3c4f71cc 998
a302a5ca
VZ
999 @remarks Notice that you can only call this method directly for the
1000 popup menus, to change the title of a menu that is part of a menu
1001 bar you need to use wxMenuBar::SetLabelTop().
3c4f71cc 1002
4cc4bfaf 1003 @see GetTitle()
23324ae1 1004 */
adaaa686 1005 virtual void SetTitle(const wxString& title);
23324ae1
FM
1006
1007 /**
4cc4bfaf 1008 Sends events to @a source (or owning window if @NULL) to update the
ba1d7a6c
FM
1009 menu UI.
1010
1011 This is called just before the menu is popped up with wxWindow::PopupMenu,
1012 but the application may call it at other times if required.
23324ae1 1013 */
adaaa686 1014 void UpdateUI(wxEvtHandler* source = NULL);
dbac5ccc
RD
1015
1016
1017 void SetInvokingWindow(wxWindow *win);
1018 wxWindow *GetInvokingWindow() const;
1019 wxWindow *GetWindow() const;
1020 long GetStyle() const;
1021 void SetParent(wxMenu *parent);
1022 wxMenu *GetParent() const;
1023
1024 virtual void Attach(wxMenuBar *menubar);
1025 virtual void Detach();
1026 bool IsAttached() const;
1027
23324ae1 1028};
e54c96f1 1029