]>
git.saurik.com Git - wxWidgets.git/blob - interface/menu.h
3bb63333616f567a68d1c24ffb8aaec48acccc96
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxMenuBar class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 A menu bar is a series of menus accessible from the top of a frame.
19 wxMenu, @ref overview_eventhandlingoverview
21 class wxMenuBar
: public wxWindow
26 Construct a menu bar from arrays of menus and titles.
31 An array of menus. Do not use this array again - it now belongs to the
34 An array of title strings. Deallocate this array after creating the menu
37 If wxMB_DOCKABLE the menu bar can be detached (wxGTK only).
39 wxMenuBar(long style
= 0);
40 wxMenuBar(size_t n
, wxMenu
* menus
[], const wxString titles
[],
45 Destructor, destroying the menu bar and removing it from the parent frame (if
51 Adds the item to the end of the menu bar.
54 The menu to add. Do not deallocate this menu after calling Append.
56 The title of the menu.
58 @returns @true on success, @false if an error occurred.
62 bool Append(wxMenu
* menu
, const wxString
& title
);
65 Checks or unchecks a menu item.
68 The menu item identifier.
70 If @true, checks the menu item, otherwise the item is unchecked.
72 @remarks Only use this when the menu bar has been associated with a
73 frame; otherwise, use the wxMenu equivalent call.
75 void Check(int id
, const bool check
);
78 Enables or disables (greys out) a menu item.
81 The menu item identifier.
83 @true to enable the item, @false to disable it.
85 @remarks Only use this when the menu bar has been associated with a
86 frame; otherwise, use the wxMenu equivalent call.
88 void Enable(int id
, const bool enable
);
91 Enables or disables a whole menu.
94 The position of the menu, starting from zero.
96 @true to enable the menu, @false to disable it.
98 @remarks Only use this when the menu bar has been associated with a frame.
100 void EnableTop(int pos
, const bool enable
);
103 Finds the menu item object associated with the given menu item identifier.
106 Menu item identifier.
108 If not @NULL, menu will get set to the associated menu.
110 @returns The found menu item object, or @NULL if one was not found.
112 wxMenuItem
* FindItem(int id
, wxMenu menu
= NULL
) const;
115 Returns the index of the menu with the given @a title or @c wxNOT_FOUND if no
116 such menu exists in this menubar. The @a title parameter may specify either
117 the menu title (with accelerator characters, i.e. @c "File") or just the
118 menu label (@c "File") indifferently.
120 int FindMenu(const wxString
& title
) const;
123 Finds the menu item id for a menu name/menu item string pair.
130 @returns The menu item identifier, or wxNOT_FOUND if none was found.
132 @remarks Any special menu codes are stripped out of source and target
133 strings before matching.
135 int FindMenuItem(const wxString
& menuString
,
136 const wxString
& itemString
) const;
139 Gets the help string associated with the menu item identifier.
142 The menu item identifier.
144 @returns The help string, or the empty string if there was no help string
145 or the menu item was not found.
149 wxString
GetHelpString(int id
) const;
152 Gets the label associated with a menu item.
155 The menu item identifier.
157 @returns The menu item label, or the empty string if the item was not
160 @remarks Use only after the menubar has been associated with a frame.
162 wxString
GetLabel(int id
) const;
165 Returns the label of a top-level menu. Note that the returned string does not
166 include the accelerator characters which could have been specified in the menu
167 title string during its construction.
170 Position of the menu on the menu bar, starting from zero.
172 @returns The menu label, or the empty string if the menu was not found.
174 @remarks Use only after the menubar has been associated with a frame.
178 wxString
GetLabelTop(int pos
) const;
181 Returns the menu at @a menuIndex (zero-based).
183 wxMenu
* GetMenu(int menuIndex
) const;
186 Returns the number of menus in this menubar.
188 size_t GetMenuCount() const;
191 Returns the label of a top-level menu. Note that the returned string
192 includes the accelerator characters that have been specified in the menu
193 title string during its construction.
196 Position of the menu on the menu bar, starting from zero.
198 @returns The menu label, or the empty string if the menu was not found.
200 @remarks Use only after the menubar has been associated with a frame.
202 @see GetMenuLabelText(), SetMenuLabel()
204 wxString
GetMenuLabel(int pos
) const;
207 Returns the label of a top-level menu. Note that the returned string does not
208 include any accelerator characters that may have been specified in the menu
209 title string during its construction.
212 Position of the menu on the menu bar, starting from zero.
214 @returns The menu label, or the empty string if the menu was not found.
216 @remarks Use only after the menubar has been associated with a frame.
218 @see GetMenuLabel(), SetMenuLabel()
220 wxString
GetMenuLabelText(int pos
) const;
223 Inserts the menu at the given position into the menu bar. Inserting menu at
224 position 0 will insert it in the very beginning of it, inserting at position
225 GetMenuCount() is the same as calling
229 The position of the new menu in the menu bar
231 The menu to add. wxMenuBar owns the menu and will free it.
233 The title of the menu.
235 @returns @true on success, @false if an error occurred.
239 bool Insert(size_t pos
, wxMenu
* menu
, const wxString
& title
);
242 Determines whether an item is checked.
245 The menu item identifier.
247 @returns @true if the item was found and is checked, @false otherwise.
249 bool IsChecked(int id
) const;
252 Determines whether an item is enabled.
255 The menu item identifier.
257 @returns @true if the item was found and is enabled, @false otherwise.
259 bool IsEnabled(int id
) const;
267 Removes the menu from the menu bar and returns the menu object - the caller is
268 responsible for deleting it. This function may be used together with
269 Insert() to change the menubar
274 wxMenu
* Remove(size_t pos
);
277 Replaces the menu at the given position with another one.
280 The position of the new menu in the menu bar
284 The title of the menu.
286 @returns The menu which was previously at position pos. The caller is
287 responsible for deleting it.
289 @see Insert(), Remove()
291 wxMenu
* Replace(size_t pos
, wxMenu
* menu
, const wxString
& title
);
294 Sets the help string associated with a menu item.
297 Menu item identifier.
299 Help string to associate with the menu item.
303 void SetHelpString(int id
, const wxString
& helpString
);
306 Sets the label of a menu item.
309 Menu item identifier.
313 @remarks Use only after the menubar has been associated with a frame.
317 void SetLabel(int id
, const wxString
& label
);
320 Sets the label of a top-level menu.
323 The position of a menu on the menu bar, starting from zero.
327 @remarks Use only after the menubar has been associated with a frame.
331 void SetLabelTop(int pos
, const wxString
& label
);
334 Sets the label of a top-level menu.
337 The position of a menu on the menu bar, starting from zero.
341 @remarks Use only after the menubar has been associated with a frame.
343 void SetMenuLabel(int pos
, const wxString
& label
);
351 A menu is a popup (or pull down) list of items, one of which may be
352 selected before the menu goes away (clicking elsewhere dismisses the
353 menu). Menus may be used to construct either menu bars or popup menus.
355 A menu item has an integer ID associated with it which can be used to
356 identify the selection, or to change the menu item in some way. A menu item
357 with a special identifier -1 is a separator item and doesn't have an
358 associated command but just makes a separator line appear in the menu.
360 @b NB: Please note that @e wxID_ABOUT and @e wxID_EXIT are
361 predefined by wxWidgets and have a special meaning since entries
362 using these IDs will be taken out of the normal menus under MacOS X
363 and will be inserted into the system menu (following the appropriate
364 MacOS X interface guideline). On PalmOS @e wxID_EXIT is disabled according
365 to Palm OS Companion guidelines.
367 Menu items may be either normal items, check items or radio items. Normal items
368 don't have any special properties while the check items have a boolean flag
369 associated to them and they show a checkmark in the menu when the flag is set.
370 wxWidgets automatically toggles the flag value when the item is clicked and its
371 value may be retrieved using either wxMenu::IsChecked method
372 of wxMenu or wxMenuBar itself or by using
373 wxEvent::IsChecked when you get the menu
374 notification for the item in question.
376 The radio items are similar to the check items except that all the other items
377 in the same radio group are unchecked when a radio item is checked. The radio
378 group is formed by a contiguous range of radio items, i.e. it starts at the
379 first item of this kind and ends with the first item of a different kind (or
380 the end of the menu). Notice that because the radio groups are defined in terms
381 of the item positions inserting or removing the items in the menu containing
382 the radio items risks to not work correctly. Finally note that radio items
383 are not supported under Motif.
389 wxMenuBar, wxWindow::PopupMenu, @ref overview_eventhandlingoverview, @ref
390 overview_wxfilehistory "wxFileHistory (most recently used files menu)"
392 class wxMenu
: public wxEvtHandler
397 Constructs a wxMenu object.
400 If set to wxMENU_TEAROFF, the menu will be detachable (wxGTK only).
402 wxMenu(const wxString
& title
= "", long style
= 0);
407 Destructor, destroying the menu.
408 Note: under Motif, a popup menu must have a valid parent (the window
409 it was last popped up on) when being destroyed. Therefore, make sure
410 you delete or re-use the popup menu @e before destroying the
411 parent window. Re-use in this context means popping up the menu on
412 a different window from last time, which causes an implicit destruction
413 and recreation of internal data structures.
419 Adds a menu item object. This is the most generic variant of Append() method
420 because it may be used for both items (including separators) and submenus and
421 because you can also specify various extra properties of a menu item this way,
422 such as bitmaps and fonts.
425 The menu command identifier.
427 The string to appear on the menu item.
431 May be wxITEM_SEPARATOR, wxITEM_NORMAL,
432 wxITEM_CHECK or wxITEM_RADIO
434 An optional help string associated with the item.
435 By default, the handler for the wxEVT_MENU_HIGHLIGHT event displays
436 this string in the status line.
438 A menuitem object. It will be owned by the wxMenu object after this function
439 is called, so do not delete it yourself.
441 @remarks This command can be used after the menu has been shown, as well
442 as on initial creation of a menu or menubar.
444 @see AppendSeparator(), AppendCheckItem(), AppendRadioItem(),
445 AppendSubMenu(), Insert(), SetLabel(),
446 GetHelpString(), SetHelpString(), wxMenuItem
448 wxMenuItem
* Append(int id
, const wxString
& item
= "",
449 const wxString
& helpString
= "",
450 wxItemKind kind
= wxITEM_NORMAL
);
451 wxMenuItem
* Append(int id
, const wxString
& item
,
453 const wxString
& helpString
= "");
454 wxMenuItem
* Append(wxMenuItem
* menuItem
);
458 Adds a checkable item to the end of the menu.
460 @see Append(), InsertCheckItem()
462 wxMenuItem
* AppendCheckItem(int id
, const wxString
& item
,
463 const wxString
& helpString
= "");
466 Adds a radio item to the end of the menu. All consequent radio items form a
467 group and when an item in the group is checked, all the others are
468 automatically unchecked.
470 @see Append(), InsertRadioItem()
472 wxMenuItem
* AppendRadioItem(int id
, const wxString
& item
,
473 const wxString
& helpString
= "");
476 Adds a separator to the end of the menu.
478 @see Append(), InsertSeparator()
480 wxMenuItem
* AppendSeparator();
483 Adds the given @a submenu to this menu. @a text is the text shown in the
484 menu for it and @a help is the help string shown in the status bar when the
485 submenu item is selected.
487 wxMenuItem
* AppendSubMenu(wxMenu
* submenu
, const wxString
& text
,
488 const wxString
& help
= wxEmptyString
);
491 Inserts a break in a menu, causing the next appended item to appear in a new
497 Checks or unchecks the menu item.
500 The menu item identifier.
502 If @true, the item will be checked, otherwise it will be unchecked.
506 void Check(int id
, const bool check
);
510 Deletes the menu item from the menu. If the item is a submenu, it will
511 @b not be deleted. Use Destroy() if you want to
515 Id of the menu item to be deleted.
517 Menu item to be deleted.
519 @see FindItem(), Destroy(), Remove()
522 void Delete(wxMenuItem
* item
);
527 Deletes the menu item from the menu. If the item is a submenu, it will
528 be deleted. Use Remove() if you want to keep the submenu
529 (for example, to reuse it later).
532 Id of the menu item to be deleted.
534 Menu item to be deleted.
536 @see FindItem(), Deletes(), Remove()
538 void Destroy(int id
);
539 void Destroy(wxMenuItem
* item
);
543 Enables or disables (greys out) a menu item.
546 The menu item identifier.
548 @true to enable the menu item, @false to disable it.
552 void Enable(int id
, const bool enable
);
556 Finds the menu item object associated with the given menu item identifier and,
557 optionally, the (sub)menu it belongs to.
560 Menu item string to find.
562 Menu item identifier.
564 If the pointer is not @NULL, it will be filled with the item's
565 parent menu (if the item was found)
567 @returns First form: menu item identifier, or wxNOT_FOUND if none is
570 @remarks Any special menu codes are stripped out of source and target
571 strings before matching.
573 int FindItem(const wxString
& itemString
) const;
574 const wxMenuItem
* FindItem(int id
, wxMenu
** menu
= NULL
) const;
578 Returns the wxMenuItem given a position in the menu.
580 wxMenuItem
* FindItemByPosition(size_t position
) const;
583 Returns the help string associated with a menu item.
586 The menu item identifier.
588 @returns The help string, or the empty string if there is no help string
589 or the item was not found.
591 @see SetHelpString(), Append()
593 wxString
GetHelpString(int id
) const;
596 Returns a menu item label.
599 The menu item identifier.
601 @returns The item label, or the empty string if the item was not found.
603 @see GetLabelText(), SetLabel()
605 wxString
GetLabel(int id
) const;
608 Returns a menu item label, without any of the original mnemonics and
612 The menu item identifier.
614 @returns The item label, or the empty string if the item was not found.
616 @see GetLabel(), SetLabel()
618 wxString
GetLabelText(int id
) const;
621 Returns the number of items in the menu.
623 size_t GetMenuItemCount() const;
626 Returns the list of items in the menu. wxMenuItemList is a pseudo-template
627 list class containing wxMenuItem pointers, see wxList.
629 wxMenuItemList
GetMenuItems() const;
632 Returns the title of the menu.
634 @remarks This is relevant only to popup menus, use
635 wxMenuBar::GetMenuLabel for the menus in the menubar.
639 wxString
GetTitle() const;
643 Inserts the given @a item before the position @e pos. Inserting the item
644 at position GetMenuItemCount() is the same
647 @see Append(), Prepend()
649 wxMenuItem
* Insert(size_t pos
, wxMenuItem
* item
);
650 wxMenuItem
* Insert(size_t pos
, int id
,
651 const wxString
& item
= "",
652 const wxString
& helpString
= "",
653 wxItemKind kind
= wxITEM_NORMAL
);
657 Inserts a checkable item at the given position.
659 @see Insert(), AppendCheckItem()
661 wxMenuItem
* InsertCheckItem(size_t pos
, int id
,
662 const wxString
& item
,
663 const wxString
& helpString
= "");
666 Inserts a radio item at the given position.
668 @see Insert(), AppendRadioItem()
670 wxMenuItem
* InsertRadioItem(size_t pos
, int id
,
671 const wxString
& item
,
672 const wxString
& helpString
= "");
675 Inserts a separator at the given position.
677 @see Insert(), AppendSeparator()
679 wxMenuItem
* InsertSeparator(size_t pos
);
682 Determines whether a menu item is checked.
685 The menu item identifier.
687 @returns @true if the menu item is checked, @false otherwise.
691 bool IsChecked(int id
) const;
694 Determines whether a menu item is enabled.
697 The menu item identifier.
699 @returns @true if the menu item is enabled, @false otherwise.
703 bool IsEnabled(int id
) const;
707 Inserts the given @a item at position 0, i.e. before all the other
710 @see Append(), Insert()
712 wxMenuItem
* Prepend(wxMenuItem
* item
);
713 wxMenuItem
* Prepend(int id
, const wxString
& item
= "",
714 const wxString
& helpString
= "",
715 wxItemKind kind
= wxITEM_NORMAL
);
719 Inserts a checkable item at position 0.
721 @see Prepend(), AppendCheckItem()
723 wxMenuItem
* PrependCheckItem(int id
, const wxString
& item
,
724 const wxString
& helpString
= "");
727 Inserts a radio item at position 0.
729 @see Prepend(), AppendRadioItem()
731 wxMenuItem
* PrependRadioItem(int id
, const wxString
& item
,
732 const wxString
& helpString
= "");
735 Inserts a separator at position 0.
737 @see Prepend(), AppendSeparator()
739 wxMenuItem
* PrependSeparator();
743 Removes the menu item from the menu but doesn't delete the associated C++
744 object. This allows to reuse the same item later by adding it back to the menu
745 (especially useful with submenus).
748 The identifier of the menu item to remove.
750 The menu item to remove.
752 @returns The item which was detached from the menu.
754 wxMenuItem
* Remove(int id
);
755 wxMenuItem
* Remove(wxMenuItem
* item
);
759 Sets an item's help string.
762 The menu item identifier.
764 The help string to set.
768 void SetHelpString(int id
, const wxString
& helpString
);
771 Sets the label of a menu item.
774 The menu item identifier.
776 The menu item label to set.
778 @see Append(), GetLabel()
780 void SetLabel(int id
, const wxString
& label
);
783 Sets the title of the menu.
788 @remarks This is relevant only to popup menus, use
789 wxMenuBar::SetLabelTop for the menus in the menubar.
793 void SetTitle(const wxString
& title
);
796 Sends events to @a source (or owning window if @NULL) to update the
797 menu UI. This is called just before the menu is popped up with
798 wxWindow::PopupMenu, but
799 the application may call it at other times if required.
801 void UpdateUI(wxEvtHandler
* source
= NULL
) const;