]>
git.saurik.com Git - wxWidgets.git/blob - interface/menu.h
537679b5ec219ea4ac69245a1747016d9bc1730c
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 "Event handling overview"
21 class wxMenuBar
: public wxWindow
26 Construct a menu bar from arrays of menus and titles.
32 An array of menus. Do not use this array again - it now belongs to the
36 An array of title strings. Deallocate this array after creating the menu bar.
39 If wxMB_DOCKABLE the menu bar can be detached (wxGTK only).
41 wxMenuBar(long style
= 0);
42 wxMenuBar(size_t n
, wxMenu
* menus
[], const wxString titles
[],
47 Destructor, destroying the menu bar and removing it from the parent frame (if
53 Adds the item to the end of the menu bar.
56 The menu to add. Do not deallocate this menu after calling Append.
59 The title of the menu.
61 @returns @true on success, @false if an error occurred.
65 bool Append(wxMenu
* menu
, const wxString
& title
);
68 Checks or unchecks a menu item.
71 The menu item identifier.
74 If @true, checks the menu item, otherwise the item is unchecked.
76 @remarks Only use this when the menu bar has been associated with a
77 frame; otherwise, use the wxMenu equivalent call.
79 void Check(int id
, const bool check
);
82 Enables or disables (greys out) a menu item.
85 The menu item identifier.
88 @true to enable the item, @false to disable it.
90 @remarks Only use this when the menu bar has been associated with a
91 frame; otherwise, use the wxMenu equivalent call.
93 void Enable(int id
, const bool enable
);
96 Enables or disables a whole menu.
99 The position of the menu, starting from zero.
102 @true to enable the menu, @false to disable it.
104 @remarks Only use this when the menu bar has been associated with a frame.
106 void EnableTop(int pos
, const bool enable
);
109 Finds the menu item object associated with the given menu item identifier.
112 Menu item identifier.
115 If not @NULL, menu will get set to the associated menu.
117 @returns The found menu item object, or @NULL if one was not found.
119 wxMenuItem
* FindItem(int id
, wxMenu menu
= @NULL
);
122 Returns the index of the menu with the given @e title or @c wxNOT_FOUND if no
123 such menu exists in this menubar. The @e title parameter may specify either
124 the menu title (with accelerator characters, i.e. @c "File") or just the
125 menu label (@c "File") indifferently.
127 int FindMenu(const wxString
& title
);
130 Finds the menu item id for a menu name/menu item string pair.
138 @returns The menu item identifier, or wxNOT_FOUND if none was found.
140 @remarks Any special menu codes are stripped out of source and target
141 strings before matching.
143 int FindMenuItem(const wxString
& menuString
,
144 const wxString
& itemString
);
147 Gets the help string associated with the menu item identifier.
150 The menu item identifier.
152 @returns The help string, or the empty string if there was no help string
153 or the menu item was not found.
157 wxString
GetHelpString(int id
);
160 Gets the label associated with a menu item.
163 The menu item identifier.
165 @returns The menu item label, or the empty string if the item was not
168 @remarks Use only after the menubar has been associated with a frame.
170 wxString
GetLabel(int id
);
173 Returns the label of a top-level menu. Note that the returned string does not
174 include the accelerator characters which could have been specified in the menu
175 title string during its construction.
178 Position of the menu on the menu bar, starting from zero.
180 @returns The menu label, or the empty string if the menu was not found.
182 @remarks Use only after the menubar has been associated with a frame.
186 wxString
GetLabelTop(int pos
);
189 Returns the menu at @e menuIndex (zero-based).
191 wxMenu
* GetMenu(int menuIndex
);
194 Returns the number of menus in this menubar.
196 size_t GetMenuCount();
199 Returns the label of a top-level menu. Note that the returned string
200 includes the accelerator characters that have been specified in the menu
201 title string during its construction.
204 Position of the menu on the menu bar, starting from zero.
206 @returns The menu label, or the empty string if the menu was not found.
208 @remarks Use only after the menubar has been associated with a frame.
210 @sa GetMenuLabelText(), SetMenuLabel()
212 wxString
GetMenuLabel(int pos
);
215 Returns the label of a top-level menu. Note that the returned string does not
216 include any accelerator characters that may have been specified in the menu
217 title string during its construction.
220 Position of the menu on the menu bar, starting from zero.
222 @returns The menu label, or the empty string if the menu was not found.
224 @remarks Use only after the menubar has been associated with a frame.
226 @sa GetMenuLabel(), SetMenuLabel()
228 wxString
GetMenuLabelText(int pos
);
231 Inserts the menu at the given position into the menu bar. Inserting menu at
232 position 0 will insert it in the very beginning of it, inserting at position
233 GetMenuCount() is the same as calling
237 The position of the new menu in the menu bar
240 The menu to add. wxMenuBar owns the menu and will free it.
243 The title of the menu.
245 @returns @true on success, @false if an error occurred.
249 bool Insert(size_t pos
, wxMenu
* menu
, const wxString
& title
);
252 Determines whether an item is checked.
255 The menu item identifier.
257 @returns @true if the item was found and is checked, @false otherwise.
259 bool IsChecked(int id
);
262 Determines whether an item is enabled.
265 The menu item identifier.
267 @returns @true if the item was found and is enabled, @false otherwise.
269 bool IsEnabled(int id
);
277 Removes the menu from the menu bar and returns the menu object - the caller is
278 responsible for deleting it. This function may be used together with
279 Insert() to change the menubar
284 wxMenu
* Remove(size_t pos
);
287 Replaces the menu at the given position with another one.
290 The position of the new menu in the menu bar
296 The title of the menu.
298 @returns The menu which was previously at position pos. The caller is
299 responsible for deleting it.
301 @sa Insert(), Remove()
303 wxMenu
* Replace(size_t pos
, wxMenu
* menu
,
304 const wxString
& title
);
307 Sets the help string associated with a menu item.
310 Menu item identifier.
313 Help string to associate with the menu item.
317 void SetHelpString(int id
, const wxString
& helpString
);
320 Sets the label of a menu item.
323 Menu item identifier.
328 @remarks Use only after the menubar has been associated with a frame.
332 void SetLabel(int id
, const wxString
& label
);
335 Sets the label of a top-level menu.
338 The position of a menu on the menu bar, starting from zero.
343 @remarks Use only after the menubar has been associated with a frame.
347 void SetLabelTop(int pos
, const wxString
& label
);
350 Sets the label of a top-level menu.
353 The position of a menu on the menu bar, starting from zero.
358 @remarks Use only after the menubar has been associated with a frame.
360 void SetMenuLabel(int pos
, const wxString
& label
);
368 A menu is a popup (or pull down) list of items, one of which may be
369 selected before the menu goes away (clicking elsewhere dismisses the
370 menu). Menus may be used to construct either menu bars or popup menus.
372 A menu item has an integer ID associated with it which can be used to
373 identify the selection, or to change the menu item in some way. A menu item
374 with a special identifier -1 is a separator item and doesn't have an
375 associated command but just makes a separator line appear in the menu.
377 @b NB: Please note that @e wxID_ABOUT and @e wxID_EXIT are
378 predefined by wxWidgets and have a special meaning since entries
379 using these IDs will be taken out of the normal menus under MacOS X
380 and will be inserted into the system menu (following the appropriate
381 MacOS X interface guideline). On PalmOS @e wxID_EXIT is disabled according
382 to Palm OS Companion guidelines.
384 Menu items may be either normal items, check items or radio items. Normal items
385 don't have any special properties while the check items have a boolean flag
386 associated to them and they show a checkmark in the menu when the flag is set.
387 wxWidgets automatically toggles the flag value when the item is clicked and its
388 value may be retrieved using either wxMenu::IsChecked method
389 of wxMenu or wxMenuBar itself or by using
390 wxEvent::IsChecked when you get the menu
391 notification for the item in question.
393 The radio items are similar to the check items except that all the other items
394 in the same radio group are unchecked when a radio item is checked. The radio
395 group is formed by a contiguous range of radio items, i.e. it starts at the
396 first item of this kind and ends with the first item of a different kind (or
397 the end of the menu). Notice that because the radio groups are defined in terms
398 of the item positions inserting or removing the items in the menu containing
399 the radio items risks to not work correctly. Finally note that radio items
400 are not supported under Motif.
406 wxMenuBar, wxWindow::PopupMenu, @ref overview_eventhandlingoverview "Event
407 handling overview", @ref overview_wxfilehistory "wxFileHistory (most recently used files menu)"
409 class wxMenu
: public wxEvtHandler
414 Constructs a wxMenu object.
417 If set to wxMENU_TEAROFF, the menu will be detachable (wxGTK only).
419 wxMenu(const wxString
& title
= "", long style
= 0);
424 Destructor, destroying the menu.
426 Note: under Motif, a popup menu must have a valid parent (the window
427 it was last popped up on) when being destroyed. Therefore, make sure
428 you delete or re-use the popup menu @e before destroying the
429 parent window. Re-use in this context means popping up the menu on
430 a different window from last time, which causes an implicit destruction
431 and recreation of internal data structures.
437 Adds a menu item object. This is the most generic variant of Append() method
438 because it may be used for both items (including separators) and submenus and
439 because you can also specify various extra properties of a menu item this way,
440 such as bitmaps and fonts.
443 The menu command identifier.
446 The string to appear on the menu item.
452 May be wxITEM_SEPARATOR, wxITEM_NORMAL,
453 wxITEM_CHECK or wxITEM_RADIO
456 An optional help string associated with the item.
457 By default, the handler for the wxEVT_MENU_HIGHLIGHT event displays
458 this string in the status line.
461 A menuitem object. It will be owned by the wxMenu object after this function
462 is called, so do not delete it yourself.
464 @remarks This command can be used after the menu has been shown, as well
465 as on initial creation of a menu or menubar.
467 @sa AppendSeparator(), AppendCheckItem(), AppendRadioItem(),
468 AppendSubMenu(), Insert(), SetLabel(),
469 GetHelpString(), SetHelpString(), wxMenuItem
471 wxMenuItem
* Append(int id
, const wxString
& item
= "",
472 const wxString
& helpString
= "",
473 wxItemKind kind
= wxITEM_NORMAL
);
474 wxMenuItem
* Append(int id
, const wxString
& item
,
476 const wxString
& helpString
= "");
477 wxMenuItem
* Append(wxMenuItem
* menuItem
);
481 Adds a checkable item to the end of the menu.
483 @sa Append(), InsertCheckItem()
485 wxMenuItem
* AppendCheckItem(int id
, const wxString
& item
,
486 const wxString
& helpString
= "");
489 Adds a radio item to the end of the menu. All consequent radio items form a
490 group and when an item in the group is checked, all the others are
491 automatically unchecked.
493 @sa Append(), InsertRadioItem()
495 wxMenuItem
* AppendRadioItem(int id
, const wxString
& item
,
496 const wxString
& helpString
= "");
499 Adds a separator to the end of the menu.
501 @sa Append(), InsertSeparator()
503 wxMenuItem
* AppendSeparator();
506 Adds the given @e submenu to this menu. @e text is the text shown in the
507 menu for it and @e help is the help string shown in the status bar when the
508 submenu item is selected.
510 wxMenuItem
* AppendSubMenu(wxMenu
* submenu
,
511 const wxString
& text
,
512 const wxString
& help
= wxEmptyString
);
515 Inserts a break in a menu, causing the next appended item to appear in a new
521 Checks or unchecks the menu item.
524 The menu item identifier.
527 If @true, the item will be checked, otherwise it will be unchecked.
531 void Check(int id
, const bool check
);
535 Deletes the menu item from the menu. If the item is a submenu, it will
536 @b not be deleted. Use Destroy() if you want to
540 Id of the menu item to be deleted.
543 Menu item to be deleted.
545 @sa FindItem(), Destroy(), Remove()
548 void Delete(wxMenuItem
* item
);
553 Deletes the menu item from the menu. If the item is a submenu, it will
554 be deleted. Use Remove() if you want to keep the submenu
555 (for example, to reuse it later).
558 Id of the menu item to be deleted.
561 Menu item to be deleted.
563 @sa FindItem(), Deletes(), Remove()
565 void Destroy(int id
);
566 void Destroy(wxMenuItem
* item
);
570 Enables or disables (greys out) a menu item.
573 The menu item identifier.
576 @true to enable the menu item, @false to disable it.
580 void Enable(int id
, const bool enable
);
584 Finds the menu item object associated with the given menu item identifier and,
585 optionally, the (sub)menu it belongs to.
588 Menu item string to find.
591 Menu item identifier.
594 If the pointer is not @NULL, it will be filled with the item's
595 parent menu (if the item was found)
597 @returns First form: menu item identifier, or wxNOT_FOUND if none is
600 @remarks Any special menu codes are stripped out of source and target
601 strings before matching.
603 int FindItem(const wxString
& itemString
);
604 wxMenuItem
* FindItem(int id
, wxMenu
** menu
= @NULL
);
608 Returns the wxMenuItem given a position in the menu.
610 wxMenuItem
* FindItemByPosition(size_t position
);
613 Returns the help string associated with a menu item.
616 The menu item identifier.
618 @returns The help string, or the empty string if there is no help string
619 or the item was not found.
621 @sa SetHelpString(), Append()
623 wxString
GetHelpString(int id
);
626 Returns a menu item label.
629 The menu item identifier.
631 @returns The item label, or the empty string if the item was not found.
633 @sa GetLabelText(), SetLabel()
635 wxString
GetLabel(int id
);
638 Returns a menu item label, without any of the original mnemonics and
642 The menu item identifier.
644 @returns The item label, or the empty string if the item was not found.
646 @sa GetLabel(), SetLabel()
648 wxString
GetLabelText(int id
);
651 Returns the number of items in the menu.
653 size_t GetMenuItemCount();
656 Returns the list of items in the menu. wxMenuItemList is a pseudo-template
657 list class containing wxMenuItem pointers, see wxList.
659 wxMenuItemList
GetMenuItems();
662 Returns the title of the menu.
664 @remarks This is relevant only to popup menus, use
665 wxMenuBar::GetMenuLabel for the menus in the menubar.
673 Inserts the given @e item before the position @e pos. Inserting the item
674 at position GetMenuItemCount() is the same
677 @sa Append(), Prepend()
679 wxMenuItem
* Insert(size_t pos
, wxMenuItem
* item
);
680 wxMenuItem
* Insert(size_t pos
, int id
,
681 const wxString
& item
= "",
682 const wxString
& helpString
= "",
683 wxItemKind kind
= wxITEM_NORMAL
);
687 Inserts a checkable item at the given position.
689 @sa Insert(), AppendCheckItem()
691 wxMenuItem
* InsertCheckItem(size_t pos
, int id
,
692 const wxString
& item
,
693 const wxString
& helpString
= "");
696 Inserts a radio item at the given position.
698 @sa Insert(), AppendRadioItem()
700 wxMenuItem
* InsertRadioItem(size_t pos
, int id
,
701 const wxString
& item
,
702 const wxString
& helpString
= "");
705 Inserts a separator at the given position.
707 @sa Insert(), AppendSeparator()
709 wxMenuItem
* InsertSeparator(size_t pos
);
712 Determines whether a menu item is checked.
715 The menu item identifier.
717 @returns @true if the menu item is checked, @false otherwise.
721 bool IsChecked(int id
);
724 Determines whether a menu item is enabled.
727 The menu item identifier.
729 @returns @true if the menu item is enabled, @false otherwise.
733 bool IsEnabled(int id
);
737 Inserts the given @e item at position 0, i.e. before all the other
740 @sa Append(), Insert()
742 wxMenuItem
* Prepend(wxMenuItem
* item
);
743 wxMenuItem
* Prepend(int id
, const wxString
& item
= "",
744 const wxString
& helpString
= "",
745 wxItemKind kind
= wxITEM_NORMAL
);
749 Inserts a checkable item at position 0.
751 @sa Prepend(), AppendCheckItem()
753 wxMenuItem
* PrependCheckItem(int id
, const wxString
& item
,
754 const wxString
& helpString
= "");
757 Inserts a radio item at position 0.
759 @sa Prepend(), AppendRadioItem()
761 wxMenuItem
* PrependRadioItem(int id
, const wxString
& item
,
762 const wxString
& helpString
= "");
765 Inserts a separator at position 0.
767 @sa Prepend(), AppendSeparator()
769 wxMenuItem
* PrependSeparator();
773 Removes the menu item from the menu but doesn't delete the associated C++
774 object. This allows to reuse the same item later by adding it back to the menu
775 (especially useful with submenus).
778 The identifier of the menu item to remove.
781 The menu item to remove.
783 @returns The item which was detached from the menu.
785 wxMenuItem
* Remove(int id
);
786 wxMenuItem
* Remove(wxMenuItem
* item
);
790 Sets an item's help string.
793 The menu item identifier.
796 The help string to set.
800 void SetHelpString(int id
, const wxString
& helpString
);
803 Sets the label of a menu item.
806 The menu item identifier.
809 The menu item label to set.
811 @sa Append(), GetLabel()
813 void SetLabel(int id
, const wxString
& label
);
816 Sets the title of the menu.
821 @remarks This is relevant only to popup menus, use
822 wxMenuBar::SetLabelTop for the menus in the menubar.
826 void SetTitle(const wxString
& title
);
829 Sends events to @e source (or owning window if @NULL) to update the
830 menu UI. This is called just before the menu is popped up with
831 wxWindow::PopupMenu, but
832 the application may call it at other times if required.
834 void UpdateUI(wxEvtHandler
* source
= @NULL
);