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