]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/menu.h
make wxRearrangeDialog more customizable and add an example of customizing it to...
[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
ba1d7a6c 30 @see wxMenu, @ref overview_eventhandling
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
430 connection; see @ref overview_eventhandling_connect.
ba1d7a6c 431
23324ae1
FM
432 @library{wxcore}
433 @category{menus}
7c913512 434
ba1d7a6c
FM
435 @see wxMenuBar, wxWindow::PopupMenu, @ref overview_eventhandling,
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
23324ae1 681 /**
ff58644a 682 Finds the menu id for a menu item string.
3c4f71cc 683
7c913512 684 @param itemString
4cc4bfaf 685 Menu item string to find.
ff58644a 686
d29a9a8a 687 @return Menu item identifier, or wxNOT_FOUND if none is found.
ff58644a
RR
688
689 @remarks Any special menu codes are stripped out of source and target
690 strings before matching.
691 */
adaaa686 692 virtual int FindItem(const wxString& itemString) const;
ff58644a
RR
693
694 /**
695 Finds the menu item object associated with the given menu item identifier and,
696 optionally, the (sub)menu it belongs to.
697
7c913512 698 @param id
4cc4bfaf 699 Menu item identifier.
7c913512 700 @param menu
4cc4bfaf
FM
701 If the pointer is not @NULL, it will be filled with the item's
702 parent menu (if the item was found)
3c4f71cc 703
d29a9a8a 704 @return Menu item object or NULL if none is found.
23324ae1 705 */
0a98423e 706 wxMenuItem* FindItem(int id, wxMenu** menu = NULL) const;
23324ae1
FM
707
708 /**
709 Returns the wxMenuItem given a position in the menu.
710 */
328f5751 711 wxMenuItem* FindItemByPosition(size_t position) const;
23324ae1
FM
712
713 /**
714 Returns the help string associated with a menu item.
3c4f71cc 715
7c913512 716 @param id
4cc4bfaf 717 The menu item identifier.
3c4f71cc 718
d29a9a8a
BP
719 @return The help string, or the empty string if there is no help string
720 or the item was not found.
3c4f71cc 721
4cc4bfaf 722 @see SetHelpString(), Append()
23324ae1 723 */
adaaa686 724 virtual wxString GetHelpString(int id) const;
23324ae1
FM
725
726 /**
727 Returns a menu item label.
3c4f71cc 728
7c913512 729 @param id
4cc4bfaf 730 The menu item identifier.
3c4f71cc 731
d29a9a8a 732 @return The item label, or the empty string if the item was not found.
3c4f71cc 733
4cc4bfaf 734 @see GetLabelText(), SetLabel()
23324ae1 735 */
328f5751 736 wxString GetLabel(int id) const;
23324ae1
FM
737
738 /**
739 Returns a menu item label, without any of the original mnemonics and
740 accelerators.
3c4f71cc 741
7c913512 742 @param id
4cc4bfaf 743 The menu item identifier.
3c4f71cc 744
d29a9a8a 745 @return The item label, or the empty string if the item was not found.
3c4f71cc 746
4cc4bfaf 747 @see GetLabel(), SetLabel()
23324ae1 748 */
328f5751 749 wxString GetLabelText(int id) const;
23324ae1
FM
750
751 /**
752 Returns the number of items in the menu.
753 */
328f5751 754 size_t GetMenuItemCount() const;
23324ae1 755
0a98423e 756 //@{
23324ae1 757 /**
ba1d7a6c
FM
758 Returns the list of items in the menu.
759
760 wxMenuItemList is a pseudo-template list class containing wxMenuItem
761 pointers, see wxList.
23324ae1 762 */
0a98423e
FM
763 wxMenuItemList& GetMenuItems() const;
764 const wxMenuItemList& GetMenuItems() const;
765 //@}
23324ae1
FM
766
767 /**
768 Returns the title of the menu.
3c4f71cc 769
7c913512 770 @remarks This is relevant only to popup menus, use
4cc4bfaf 771 wxMenuBar::GetMenuLabel for the menus in the menubar.
3c4f71cc 772
4cc4bfaf 773 @see SetTitle()
23324ae1 774 */
43c48e1e 775 const wxString& GetTitle() const;
23324ae1 776
23324ae1 777 /**
ba1d7a6c
FM
778 Inserts the given @a item before the position @a pos.
779
780 Inserting the item at position GetMenuItemCount() is the same
23324ae1 781 as appending it.
3c4f71cc 782
4cc4bfaf 783 @see Append(), Prepend()
23324ae1 784 */
4cc4bfaf 785 wxMenuItem* Insert(size_t pos, wxMenuItem* item);
ba1d7a6c 786
ff58644a 787 /**
ba1d7a6c
FM
788 Inserts the given @a item before the position @a pos.
789
790 Inserting the item at position GetMenuItemCount() is the same
ff58644a
RR
791 as appending it.
792
793 @see Append(), Prepend()
794 */
7c913512 795 wxMenuItem* Insert(size_t pos, int id,
0a98423e
FM
796 const wxString& item = wxEmptyString,
797 const wxString& helpString = wxEmptyString,
7c913512 798 wxItemKind kind = wxITEM_NORMAL);
23324ae1
FM
799
800 /**
801 Inserts a checkable item at the given position.
3c4f71cc 802
4cc4bfaf 803 @see Insert(), AppendCheckItem()
23324ae1 804 */
43c48e1e
FM
805 wxMenuItem* InsertCheckItem(size_t pos, int id, const wxString& item,
806 const wxString& helpString = wxEmptyString);
23324ae1
FM
807
808 /**
809 Inserts a radio item at the given position.
3c4f71cc 810
4cc4bfaf 811 @see Insert(), AppendRadioItem()
23324ae1 812 */
43c48e1e
FM
813 wxMenuItem* InsertRadioItem(size_t pos, int id, const wxString& item,
814 const wxString& helpString = wxEmptyString);
23324ae1
FM
815
816 /**
817 Inserts a separator at the given position.
3c4f71cc 818
4cc4bfaf 819 @see Insert(), AppendSeparator()
23324ae1
FM
820 */
821 wxMenuItem* InsertSeparator(size_t pos);
822
823 /**
824 Determines whether a menu item is checked.
3c4f71cc 825
7c913512 826 @param id
4cc4bfaf 827 The menu item identifier.
3c4f71cc 828
d29a9a8a 829 @return @true if the menu item is checked, @false otherwise.
3c4f71cc 830
4cc4bfaf 831 @see Check()
23324ae1 832 */
328f5751 833 bool IsChecked(int id) const;
23324ae1
FM
834
835 /**
836 Determines whether a menu item is enabled.
3c4f71cc 837
7c913512 838 @param id
4cc4bfaf 839 The menu item identifier.
3c4f71cc 840
d29a9a8a 841 @return @true if the menu item is enabled, @false otherwise.
3c4f71cc 842
4cc4bfaf 843 @see Enable()
23324ae1 844 */
328f5751 845 bool IsEnabled(int id) const;
23324ae1 846
23324ae1 847 /**
4cc4bfaf 848 Inserts the given @a item at position 0, i.e. before all the other
23324ae1 849 existing items.
3c4f71cc 850
4cc4bfaf 851 @see Append(), Insert()
23324ae1 852 */
4cc4bfaf 853 wxMenuItem* Prepend(wxMenuItem* item);
ff58644a
RR
854
855 /**
856 Inserts the given @a item at position 0, i.e. before all the other
857 existing items.
858
859 @see Append(), Insert()
860 */
0a98423e
FM
861 wxMenuItem* Prepend(int id, const wxString& item = wxEmptyString,
862 const wxString& helpString = wxEmptyString,
7c913512 863 wxItemKind kind = wxITEM_NORMAL);
23324ae1
FM
864
865 /**
866 Inserts a checkable item at position 0.
3c4f71cc 867
4cc4bfaf 868 @see Prepend(), AppendCheckItem()
23324ae1
FM
869 */
870 wxMenuItem* PrependCheckItem(int id, const wxString& item,
43c48e1e 871 const wxString& helpString = wxEmptyString);
23324ae1
FM
872
873 /**
874 Inserts a radio item at position 0.
3c4f71cc 875
4cc4bfaf 876 @see Prepend(), AppendRadioItem()
23324ae1
FM
877 */
878 wxMenuItem* PrependRadioItem(int id, const wxString& item,
43c48e1e 879 const wxString& helpString = wxEmptyString);
23324ae1
FM
880
881 /**
882 Inserts a separator at position 0.
3c4f71cc 883
4cc4bfaf 884 @see Prepend(), AppendSeparator()
23324ae1
FM
885 */
886 wxMenuItem* PrependSeparator();
887
23324ae1
FM
888 /**
889 Removes the menu item from the menu but doesn't delete the associated C++
ba1d7a6c
FM
890 object. This allows you to reuse the same item later by adding it back to
891 the menu (especially useful with submenus).
3c4f71cc 892
7c913512 893 @param id
4cc4bfaf 894 The identifier of the menu item to remove.
ff58644a 895
5dfae0ad 896 @return A pointer to the item which was detached from the menu.
ff58644a
RR
897 */
898 wxMenuItem* Remove(int id);
ba1d7a6c 899
ff58644a
RR
900 /**
901 Removes the menu item from the menu but doesn't delete the associated C++
ba1d7a6c
FM
902 object. This allows you to reuse the same item later by adding it back to
903 the menu (especially useful with submenus).
ff58644a 904
7c913512 905 @param item
4cc4bfaf 906 The menu item to remove.
3c4f71cc 907
5dfae0ad 908 @return A pointer to the item which was detached from the menu.
23324ae1 909 */
4cc4bfaf 910 wxMenuItem* Remove(wxMenuItem* item);
23324ae1
FM
911
912 /**
913 Sets an item's help string.
3c4f71cc 914
7c913512 915 @param id
4cc4bfaf 916 The menu item identifier.
7c913512 917 @param helpString
4cc4bfaf 918 The help string to set.
3c4f71cc 919
4cc4bfaf 920 @see GetHelpString()
23324ae1 921 */
adaaa686 922 virtual void SetHelpString(int id, const wxString& helpString);
23324ae1
FM
923
924 /**
925 Sets the label of a menu item.
3c4f71cc 926
7c913512 927 @param id
4cc4bfaf 928 The menu item identifier.
7c913512 929 @param label
4cc4bfaf 930 The menu item label to set.
3c4f71cc 931
4cc4bfaf 932 @see Append(), GetLabel()
23324ae1
FM
933 */
934 void SetLabel(int id, const wxString& label);
935
936 /**
937 Sets the title of the menu.
3c4f71cc 938
7c913512 939 @param title
4cc4bfaf 940 The title to set.
3c4f71cc 941
7c913512 942 @remarks This is relevant only to popup menus, use
4cc4bfaf 943 wxMenuBar::SetLabelTop for the menus in the menubar.
3c4f71cc 944
4cc4bfaf 945 @see GetTitle()
23324ae1 946 */
adaaa686 947 virtual void SetTitle(const wxString& title);
23324ae1
FM
948
949 /**
4cc4bfaf 950 Sends events to @a source (or owning window if @NULL) to update the
ba1d7a6c
FM
951 menu UI.
952
953 This is called just before the menu is popped up with wxWindow::PopupMenu,
954 but the application may call it at other times if required.
23324ae1 955 */
adaaa686 956 void UpdateUI(wxEvtHandler* source = NULL);
23324ae1 957};
e54c96f1 958