1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxMenu documentation
4 %% Author: wxWidgets Team
8 %% Copyright: (c) wxWidgets Team
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxMenu
}}\label{wxmenu
}
14 A menu is a popup (or pull down) list of items, one of which may be
15 selected before the menu goes away (clicking elsewhere dismisses the
16 menu). Menus may be used to construct either menu bars or popup menus.
18 A menu item has an integer ID associated with it which can be used to
19 identify the selection, or to change the menu item in some way. A menu item
20 with a special identifier $-
1$ is a separator item and doesn't have an
21 associated command but just makes a separator line appear in the menu.
23 {\bf NB:
} Please note that
{\it wxID
\_ABOUT} and
{\it wxID
\_EXIT} are
24 predefined by wxWidgets and have a special meaning since entries
25 using these IDs will be taken out of the normal menus under MacOS X
26 and will be inserted into the system menu (following the appropriate
27 MacOS X interface guideline). On PalmOS
{\it wxID
\_EXIT} is disabled according
28 to Palm OS Companion guidelines.
30 Menu items may be either normal items, check items or radio items. Normal items
31 don't have any special properties while the check items have a boolean flag
32 associated to them and they show a checkmark in the menu when the flag is set.
33 wxWidgets automatically toggles the flag value when the item is clicked and its
34 value may be retrieved using either
\helpref{IsChecked
}{wxmenuischecked
} method
35 of wxMenu or wxMenuBar itself or by using
36 \helpref{wxEvent::IsChecked
}{wxcommandeventischecked
} when you get the menu
37 notification for the item in question.
39 The radio items are similar to the check items except that all the other items
40 in the same radio group are unchecked when a radio item is checked. The radio
41 group is formed by a contiguous range of radio items, i.e. it starts at the
42 first item of this kind and ends with the first item of a different kind (or
43 the end of the menu). Notice that because the radio groups are defined in terms
44 of the item positions inserting or removing the items in the menu containing
45 the radio items risks to not work correctly. Finally note that radio items
46 are not supported under Motif.
48 \wxheading{Allocation strategy
}
50 All menus except the popup ones must be created on the heap. All menus
51 attached to a menubar or to another menu will be deleted by their parent when
52 it is deleted. As the frame menubar is deleted by the frame itself, it means
53 that normally all menus used are deleted automatically.
55 \wxheading{Derived from
}
57 \helpref{wxEvtHandler
}{wxevthandler
}\\
58 \helpref{wxObject
}{wxobject
}
60 \wxheading{Include files
}
64 \wxheading{Event handling
}
66 If the menu is part of a menubar, then
\helpref{wxMenuBar
}{wxmenubar
} event processing is used.
68 With a popup menu, there is a variety of ways to handle a menu selection event
69 (wxEVT
\_COMMAND\_MENU\_SELECTED).
71 \begin{enumerate
}\itemsep=
0pt
72 \item Derive a new class from wxMenu and define event table entries using the EVT
\_MENU macro.
73 \item Set a new event handler for wxMenu, using an object whose class has EVT
\_MENU entries.
74 \item Provide EVT
\_MENU handlers in the window which pops up the menu, or in an ancestor of
76 \item Define a callback of type wxFunction, which you pass to the wxMenu constructor.
77 The callback takes a reference to the menu, and a reference to a
78 \helpref{wxCommandEvent
}{wxcommandevent
}. This method is deprecated and should
79 not be used in the new code, it is provided for backwards compatibility only.
84 \helpref{wxMenuBar
}{wxmenubar
},
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
},
\rtfsp
85 \helpref{Event handling overview
}{eventhandlingoverview
}
87 \latexignore{\rtfignore{\wxheading{Members
}}}
89 \membersection{wxMenu::wxMenu
}\label{wxmenuctor
}
91 \func{}{wxMenu
}{\param{const wxString\&
}{title = ""
},
\param{long
}{ style =
0}}
93 Constructs a wxMenu object.
95 \wxheading{Parameters
}
97 \docparam{title
}{A title for the popup menu: the empty string denotes no title.
}
99 \docparam{style
}{If set to
{\tt wxMENU
\_TEAROFF}, the menu will be detachable (wxGTK only).
}
101 \func{}{wxMenu
}{\param{long
}{ style
}}
103 Constructs a wxMenu object.
105 \wxheading{Parameters
}
107 \docparam{style
}{If set to
{\tt wxMENU
\_TEAROFF}, the menu will be detachable (wxGTK only).
}
109 \membersection{wxMenu::
\destruct{wxMenu
}}\label{wxmenudtor
}
111 \func{}{\destruct{wxMenu
}}{\void}
113 Destructor, destroying the menu.
115 Note: under Motif, a popup menu must have a valid parent (the window
116 it was last popped up on) when being destroyed. Therefore, make sure
117 you delete or re-use the popup menu
{\it before
} destroying the
118 parent window. Re-use in this context means popping up the menu on
119 a different window from last time, which causes an implicit destruction
120 and recreation of internal data structures.
122 \membersection{wxMenu::Append
}\label{wxmenuappend
}
124 \func{wxMenuItem*
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
125 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
127 Adds a string item to the end of the menu.
129 \func{wxMenuItem*
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
130 \param{const wxString\&
}{helpString = ""
}}
132 Adds a pull-right submenu to the end of the menu. Append the submenu to the parent
133 menu
{\it after
} you have added your menu items, or accelerators may not be
136 \func{wxMenuItem*
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
138 Adds a menu item object. This is the most generic variant of Append() method
139 because it may be used for both items (including separators) and submenus and
140 because you can also specify various extra properties of a menu item this way,
141 such as bitmaps and fonts.
143 \wxheading{Parameters
}
145 \docparam{id
}{The menu command identifier.
}
147 \docparam{item
}{The string to appear on the menu item.
}
149 \docparam{menu
}{Pull-right submenu.
}
151 \docparam{kind
}{May be
{\tt wxITEM
\_SEPARATOR},
{\tt wxITEM
\_NORMAL},
152 {\tt wxITEM
\_CHECK} or
{\tt wxITEM
\_RADIO}}
154 \docparam{helpString
}{An optional help string associated with the item.
155 By default, the handler for the wxEVT
\_MENU\_HIGHLIGHT event displays
156 this string in the status line.
}
158 \docparam{menuItem
}{A menuitem object. It will be owned by the wxMenu object after this function
159 is called, so do not delete it yourself.
}
163 This command can be used after the menu has been shown, as well as on initial
164 creation of a menu or menubar.
166 The
{\it item
} string for the normal menu items (not submenus or separators)
167 may include the accelerator which can be used to activate the menu item
168 from keyboard. The accelerator string follows the item label and is separated
169 from it by a
{\tt TAB
} character (
{\tt '$
\backslash$t'
}). Its general syntax is
170 any combination of
{\tt "CTRL"
},
{\tt "ALT"
} and
{\tt "SHIFT"
} strings (case
171 doesn't matter) separated by either
{\tt '-'
} or
{\tt '+'
} characters and
172 followed by the accelerator itself. The accelerator may be any alphanumeric
173 character, any function key (from
{\tt F1
} to
{\tt F12
}) or one of the special
174 characters listed in the table below (again, case doesn't matter):
176 \begin{twocollist
}\itemsep=
0pt
177 \twocolitem{{\tt DEL
} or
{\tt DELETE
}}{Delete key
}
178 \twocolitem{{\tt INS
} or
{\tt INSERT
}}{Insert key
}
179 \twocolitem{{\tt ENTER
} or
{\tt RETURN
}}{Enter key
}
180 \twocolitem{{\tt PGUP
}}{PageUp key
}
181 \twocolitem{{\tt PGDN
}}{PageDown key
}
182 \twocolitem{{\tt LEFT
}}{Left cursor arrow key
}
183 \twocolitem{{\tt RIGHT
}}{Right cursor arrow key
}
184 \twocolitem{{\tt UP
}}{Up cursor arrow key
}
185 \twocolitem{{\tt DOWN
}}{Down cursor arrow key
}
186 \twocolitem{{\tt HOME
}}{Home key
}
187 \twocolitem{{\tt END
}}{End key
}
188 \twocolitem{{\tt SPACE
}}{Space
}
189 \twocolitem{{\tt TAB
}}{Tab key
}
190 \twocolitem{{\tt ESC
} or
{\tt ESCAPE
}}{Escape key (Windows only)
}
195 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
},
\rtfsp
196 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
},
\rtfsp
197 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
},
\rtfsp
198 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
199 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
},
\helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
},
\rtfsp
200 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenuItem
}{wxmenuitem
}
202 \pythonnote{In place of a single overloaded method name, wxPython
203 implements the following methods:
205 \indented{2cm
}{\begin{twocollist
}
206 \twocolitem{{\bf Append(id, string, helpStr="", checkable=false)
}}{}
207 \twocolitem{{\bf AppendMenu(id, string, aMenu, helpStr="")
}}{}
208 \twocolitem{{\bf AppendItem(aMenuItem)
}}{}
212 \membersection{wxMenu::AppendCheckItem
}\label{wxmenuappendcheckitem
}
214 \func{wxMenuItem*
}{AppendCheckItem
}{\param{int
}{ id
},
\rtfsp
215 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
217 Adds a checkable item to the end of the menu.
221 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
222 \helpref{wxMenu::InsertCheckItem
}{wxmenuinsertcheckitem
}
224 \membersection{wxMenu::AppendRadioItem
}\label{wxmenuappendradioitem
}
226 \func{wxMenuItem*
}{AppendRadioItem
}{\param{int
}{ id
},
\rtfsp
227 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
229 Adds a radio item to the end of the menu. All consequent radio items form a
230 group and when an item in the group is checked, all the others are
231 automatically unchecked.
233 {\bf NB:
} Currently only implemented under Windows and GTK, use
234 {\tt\#if wxHAS
\_RADIO\_MENU\_ITEMS} to test for availability of this feature.
238 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
239 \helpref{wxMenu::InsertRadioItem
}{wxmenuinsertradioitem
}
241 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
243 \func{wxMenuItem*
}{AppendSeparator
}{\void}
245 Adds a separator to the end of the menu.
249 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
250 \helpref{wxMenu::InsertSeparator
}{wxmenuinsertseparator
}
252 \membersection{wxMenu::Break
}\label{wxmenubreak
}
254 \func{void
}{Break
}{\void}
256 Inserts a break in a menu, causing the next appended item to appear in a new column.
258 \membersection{wxMenu::Check
}\label{wxmenucheck
}
260 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
262 Checks or unchecks the menu item.
264 \wxheading{Parameters
}
266 \docparam{id
}{The menu item identifier.
}
268 \docparam{check
}{If true, the item will be checked, otherwise it will be unchecked.
}
272 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
274 \membersection{wxMenu::Delete
}\label{wxmenudelete
}
276 \func{void
}{Delete
}{\param{int
}{id
}}
278 \func{void
}{Delete
}{\param{wxMenuItem *
}{item
}}
280 Deletes the menu item from the menu. If the item is a submenu, it will
281 {\bf not
} be deleted. Use
\helpref{Destroy
}{wxmenudestroy
} if you want to
284 \wxheading{Parameters
}
286 \docparam{id
}{Id of the menu item to be deleted.
}
288 \docparam{item
}{Menu item to be deleted.
}
292 \helpref{wxMenu::FindItem
}{wxmenufinditem
},
\rtfsp
293 \helpref{wxMenu::Destroy
}{wxmenudestroy
},
\rtfsp
294 \helpref{wxMenu::Remove
}{wxmenuremove
}
296 \membersection{wxMenu::Destroy
}\label{wxmenudestroy
}
298 \func{void
}{Destroy
}{\param{int
}{id
}}
300 \func{void
}{Destroy
}{\param{wxMenuItem *
}{item
}}
302 Deletes the menu item from the menu. If the item is a submenu, it will
303 be deleted. Use
\helpref{Remove
}{wxmenuremove
} if you want to keep the submenu
304 (for example, to reuse it later).
306 \wxheading{Parameters
}
308 \docparam{id
}{Id of the menu item to be deleted.
}
310 \docparam{item
}{Menu item to be deleted.
}
314 \helpref{wxMenu::FindItem
}{wxmenufinditem
},
\rtfsp
315 \helpref{wxMenu::Deletes
}{wxmenudelete
},
\rtfsp
316 \helpref{wxMenu::Remove
}{wxmenuremove
}
318 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
320 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
322 Enables or disables (greys out) a menu item.
324 \wxheading{Parameters
}
326 \docparam{id
}{The menu item identifier.
}
328 \docparam{enable
}{true to enable the menu item, false to disable it.
}
332 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
334 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
336 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
338 Finds the menu item id for a menu item string.
340 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu **
}{menu = NULL
}}
342 Finds the menu item object associated with the given menu item identifier and,
343 optionally, the (sub)menu it belongs to.
345 \perlnote{In wxPerl this method takes just the
{\tt id
} parameter;
346 in scalar context it returns the associated
{\tt Wx::MenuItem
}, in list
347 context it returns a
2-element list
{\tt ( item, submenu )
}}
349 \wxheading{Parameters
}
351 \docparam{itemString
}{Menu item string to find.
}
353 \docparam{id
}{Menu item identifier.
}
355 \docparam{menu
}{If the pointer is not NULL, it will be filled with the item's
356 parent menu (if the item was found)
}
358 \wxheading{Return value
}
360 First form: menu item identifier, or
{\tt wxNOT
\_FOUND} if none is found.
362 Second form: returns the menu item object, or NULL if it is not found.
366 Any special menu codes are stripped out of source and target strings
369 \pythonnote{The name of this method in wxPython is
{\tt FindItemById
}
370 and it does not support the second parameter.
}
372 \membersection{wxMenu::FindItemByPosition
}\label{wxmenufinditembyposition
}
374 \constfunc{wxMenuItem*
}{FindItemByPosition
}{\param{size
\_t }{position
}}
376 Returns the wxMenuItem given a position in the menu.
378 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
380 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
382 Returns the help string associated with a menu item.
384 \wxheading{Parameters
}
386 \docparam{id
}{The menu item identifier.
}
388 \wxheading{Return value
}
390 The help string, or the empty string if there is no help string or the
395 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
397 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
399 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
401 Returns a menu item label.
403 \wxheading{Parameters
}
405 \docparam{id
}{The menu item identifier.
}
407 \wxheading{Return value
}
409 The item label, or the empty string if the item was not found.
413 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
415 \membersection{wxMenu::GetMenuItemCount
}\label{wxmenugetmenuitemcount
}
417 \constfunc{size
\_t}{GetMenuItemCount
}{\void}
419 Returns the number of items in the menu.
421 \membersection{wxMenu::GetMenuItems
}\label{wxmenugetmenuitems
}
423 \constfunc{wxMenuItemList\&
}{GetMenuItems
}{\void}
425 Returns the list of items in the menu. wxMenuItemList is a pseudo-template
426 list class containing wxMenuItem pointers.
428 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
430 \constfunc{wxString
}{GetTitle
}{\void}
432 Returns the title of the menu.
436 This is relevant only to popup menus, use
437 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
} for the menus in the
442 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
444 \membersection{wxMenu::Insert
}\label{wxmenuinsert
}
446 \func{wxMenuItem*
}{Insert
}{\param{size
\_t }{pos
},
\param{wxMenuItem *
}{item
}}
448 \func{wxMenuItem*
}{Insert
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
449 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
450 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
452 Inserts the given
{\it item
} before the position
{\it pos
}. Inserting the item
453 at position
\helpref{GetMenuItemCount
}{wxmenugetmenuitemcount
} is the same
458 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
459 \helpref{wxMenu::Prepend
}{wxmenuprepend
}
461 \membersection{wxMenu::InsertCheckItem
}\label{wxmenuinsertcheckitem
}
463 \func{wxMenuItem*
}{InsertCheckItem
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
464 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
466 Inserts a checkable item at the given position.
470 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
471 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
}
473 \membersection{wxMenu::InsertRadioItem
}\label{wxmenuinsertradioitem
}
475 \func{wxMenuItem*
}{InsertRadioItem
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
476 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
478 Inserts a radio item at the given position.
482 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
483 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
}
485 \membersection{wxMenu::InsertSeparator
}\label{wxmenuinsertseparator
}
487 \func{wxMenuItem*
}{InsertSeparator
}{\param{size
\_t }{pos
}}
489 Inserts a separator at the given position.
493 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
494 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
}
496 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
498 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
500 Determines whether a menu item is checked.
502 \wxheading{Parameters
}
504 \docparam{id
}{The menu item identifier.
}
506 \wxheading{Return value
}
508 true if the menu item is checked, false otherwise.
512 \helpref{wxMenu::Check
}{wxmenucheck
}
514 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
516 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
518 Determines whether a menu item is enabled.
520 \wxheading{Parameters
}
522 \docparam{id
}{The menu item identifier.
}
524 \wxheading{Return value
}
526 true if the menu item is enabled, false otherwise.
530 \helpref{wxMenu::Enable
}{wxmenuenable
}
532 \membersection{wxMenu::Prepend
}\label{wxmenuprepend
}
534 \func{wxMenuItem*
}{Prepend
}{\param{wxMenuItem *
}{item
}}
536 \func{wxMenuItem*
}{Prepend
}{\param{int
}{ id
},
\rtfsp
537 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
538 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
540 Inserts the given
{\it item
} at position $
0$, i.e. before all the other
545 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
546 \helpref{wxMenu::Insert
}{wxmenuinsert
}
548 \membersection{wxMenu::PrependCheckItem
}\label{wxmenuprependcheckitem
}
550 \func{wxMenuItem*
}{PrependCheckItem
}{\param{int
}{ id
},
\rtfsp
551 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
553 Inserts a checkable item at position $
0$.
557 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
558 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
}
560 \membersection{wxMenu::PrependRadioItem
}\label{wxmenuprependradioitem
}
562 \func{wxMenuItem*
}{PrependRadioItem
}{\param{int
}{ id
},
\rtfsp
563 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
565 Inserts a radio item at position $
0$.
569 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
570 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
}
572 \membersection{wxMenu::PrependSeparator
}\label{wxmenuprependseparator
}
574 \func{wxMenuItem*
}{PrependSeparator
}{\void}
576 Inserts a separator at position $
0$.
580 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
581 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
}
583 \membersection{wxMenu::Remove
}\label{wxmenuremove
}
585 \func{wxMenuItem *
}{Remove
}{\param{int
}{id
}}
587 \func{wxMenuItem *
}{Remove
}{\param{wxMenuItem *
}{item
}}
589 Removes the menu item from the menu but doesn't delete the associated C++
590 object. This allows to reuse the same item later by adding it back to the menu
591 (especially useful with submenus).
593 \wxheading{Parameters
}
595 \docparam{id
}{The identifier of the menu item to remove.
}
597 \docparam{item
}{The menu item to remove.
}
599 \wxheading{Return value
}
601 The item which was detached from the menu.
603 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
605 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
607 Sets an item's help string.
609 \wxheading{Parameters
}
611 \docparam{id
}{The menu item identifier.
}
613 \docparam{helpString
}{The help string to set.
}
617 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
619 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
621 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
623 Sets the label of a menu item.
625 \wxheading{Parameters
}
627 \docparam{id
}{The menu item identifier.
}
629 \docparam{label
}{The menu item label to set.
}
633 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
635 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
637 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
639 Sets the title of the menu.
641 \wxheading{Parameters
}
643 \docparam{title
}{The title to set.
}
647 This is relevant only to popup menus, use
648 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
} for the menus in the
653 \helpref{wxMenu::GetTitle
}{wxmenugettitle
}
655 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
657 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
659 Sends events to
{\it source
} (or owning window if NULL) to update the
660 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
661 the application may call it at other times if required.
665 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
667 \section{\class{wxMenuBar
}}\label{wxmenubar
}
669 A menu bar is a series of menus accessible from the top of a frame.
671 \wxheading{Derived from
}
673 \helpref{wxWindow
}{wxwindow
}\\
674 \helpref{wxEvtHandler
}{wxevthandler
}\\
675 \helpref{wxObject
}{wxobject
}
677 \wxheading{Include files
}
681 \wxheading{Event handling
}
683 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
684 that contains the menu bar. If you have a toolbar which uses the same identifiers
685 as your EVT
\_MENU entries, events from the toolbar will also be processed by your
686 EVT
\_MENU event handlers.
688 {\bf Tip:
} under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu)
689 are not working, check any EVT
\_CHAR events you are handling in child windows.
690 If you are not calling
{\tt event.Skip()
} for events that you don't process in these event handlers,
691 menu shortcuts may cease to work.
695 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
697 \latexignore{\rtfignore{\wxheading{Members
}}}
699 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarctor
}
701 \func{}{wxMenuBar
}{\param{long
}{style =
0}}
705 \func{}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
707 Construct a menu bar from arrays of menus and titles.
709 \wxheading{Parameters
}
711 \docparam{n
}{The number of menus.
}
713 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
716 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
718 \docparam{style
}{If
{\tt wxMB
\_DOCKABLE} the menu bar can be detached (wxGTK only).
}
720 \pythonnote{Only the default constructor is supported in wxPython.
721 Use wxMenuBar.Append instead.
}
723 \perlnote{wxPerl only supports the first constructor:
724 use
{\tt Append
} instead.
}
726 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}\label{wxmenubardtor
}
728 \func{void
}{\destruct{wxMenuBar
}}{\void}
730 Destructor, destroying the menu bar and removing it from the parent frame (if any).
732 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
734 \func{bool
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
736 Adds the item to the end of the menu bar.
738 \wxheading{Parameters
}
740 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
742 \docparam{title
}{The title of the menu.
}
744 \wxheading{Return value
}
746 true on success, false if an error occurred.
750 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
}
752 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
754 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
756 Checks or unchecks a menu item.
758 \wxheading{Parameters
}
760 \docparam{id
}{The menu item identifier.
}
762 \docparam{check
}{If true, checks the menu item, otherwise the item is unchecked.
}
766 Only use this when the menu bar has been associated
767 with a frame; otherwise, use the wxMenu equivalent call.
769 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
771 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
773 Enables or disables (greys out) a menu item.
775 \wxheading{Parameters
}
777 \docparam{id
}{The menu item identifier.
}
779 \docparam{enable
}{true to enable the item, false to disable it.
}
783 Only use this when the menu bar has been
784 associated with a frame; otherwise, use the wxMenu equivalent call.
786 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
788 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
790 Enables or disables a whole menu.
792 \wxheading{Parameters
}
794 \docparam{pos
}{The position of the menu, starting from zero.
}
796 \docparam{enable
}{true to enable the menu, false to disable it.
}
800 Only use this when the menu bar has been
801 associated with a frame.
803 \membersection{wxMenuBar::FindMenu
}\label{wxmenubarfindmenu
}
805 \constfunc{int
}{FindMenu
}{\param{const wxString\&
}{title
}}
807 Returns the index of the menu with the given
{\it title
} or
{\tt wxNOT
\_FOUND} if no
808 such menu exists in this menubar. The
{\it title
} parameter may specify either
809 the menu title (with accelerator characters, i.e.
{\tt "\&File"
}) or just the
810 menu label (
{\tt "File"
}) indifferently.
812 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
814 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
816 Finds the menu item id for a menu name/menu item string pair.
818 \wxheading{Parameters
}
820 \docparam{menuString
}{Menu title to find.
}
822 \docparam{itemString
}{Item to find.
}
824 \wxheading{Return value
}
826 The menu item identifier, or
{\tt wxNOT
\_FOUND} if none was found.
830 Any special menu codes are stripped out of source and target strings
833 \membersection{wxMenuBar::FindItem
}\label{wxmenubarfinditem
}
835 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu
}{ **menu = NULL
}}
837 Finds the menu item object associated with the given menu item identifier.
839 \wxheading{Parameters
}
841 \docparam{id
}{Menu item identifier.
}
843 \docparam{menu
}{If not NULL, menu will get set to the associated menu.
}
845 \wxheading{Return value
}
847 The found menu item object, or NULL if one was not found.
849 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
851 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
853 Gets the help string associated with the menu item identifier.
855 \wxheading{Parameters
}
857 \docparam{id
}{The menu item identifier.
}
859 \wxheading{Return value
}
861 The help string, or the empty string if there was no help string or the menu item
866 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
868 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
870 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
872 Gets the label associated with a menu item.
874 \wxheading{Parameters
}
876 \docparam{id
}{The menu item identifier.
}
878 \wxheading{Return value
}
880 The menu item label, or the empty string if the item was not found.
884 Use only after the menubar has been associated with a frame.
886 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
888 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
890 Returns the label of a top-level menu. Note that the returned string does not
891 include the accelerator characters which could have been specified in the menu
892 title string during its construction.
894 \wxheading{Parameters
}
896 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
898 \wxheading{Return value
}
900 The menu label, or the empty string if the menu was not found.
904 Use only after the menubar has been associated with a frame.
908 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
910 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
912 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
914 Returns the menu at
{\it menuIndex
} (zero-based).
916 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
918 \constfunc{int
}{GetMenuCount
}{\void}
920 Returns the number of menus in this menubar.
922 \membersection{wxMenuBar::Insert
}\label{wxmenubarinsert
}
924 \func{bool
}{Insert
}{\param{size
\_t }{pos
},
\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
926 Inserts the menu at the given position into the menu bar. Inserting menu at
927 position $
0$ will insert it in the very beginning of it, inserting at position
928 \helpref{GetMenuCount()
}{wxmenubargetmenucount
} is the same as calling
929 \helpref{Append()
}{wxmenubarappend
}.
931 \wxheading{Parameters
}
933 \docparam{pos
}{The position of the new menu in the menu bar
}
935 \docparam{menu
}{The menu to add. wxMenuBar owns the menu and will free it.
}
937 \docparam{title
}{The title of the menu.
}
939 \wxheading{Return value
}
941 true on success, false if an error occurred.
945 \helpref{wxMenuBar::Append
}{wxmenubarappend
}
947 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
949 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
951 Determines whether an item is checked.
953 \wxheading{Parameters
}
955 \docparam{id
}{The menu item identifier.
}
957 \wxheading{Return value
}
959 true if the item was found and is checked, false otherwise.
961 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
963 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
965 Determines whether an item is enabled.
967 \wxheading{Parameters
}
969 \docparam{id
}{The menu item identifier.
}
971 \wxheading{Return value
}
973 true if the item was found and is enabled, false otherwise.
975 \membersection{wxMenuBar::Refresh
}\label{wxmenubarrefresh
}
977 \func{void
}{Refresh
}{\void}
981 \membersection{wxMenuBar::Remove
}\label{wxmenubarremove
}
983 \func{wxMenu *
}{Remove
}{\param{size
\_t }{pos
}}
985 Removes the menu from the menu bar and returns the menu object - the caller is
986 responsible for deleting it. This function may be used together with
987 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
} to change the menubar
992 \helpref{wxMenuBar::Replace
}{wxmenubarreplace
}
994 \membersection{wxMenuBar::Replace
}\label{wxmenubarreplace
}
996 \func{wxMenu *
}{Replace
}{\param{size
\_t }{pos
},
\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
998 Replaces the menu at the given position with another one.
1000 \wxheading{Parameters
}
1002 \docparam{pos
}{The position of the new menu in the menu bar
}
1004 \docparam{menu
}{The menu to add.
}
1006 \docparam{title
}{The title of the menu.
}
1008 \wxheading{Return value
}
1010 The menu which was previously at position
{\it pos
}. The caller is
1011 responsible for deleting it.
1013 \wxheading{See also
}
1015 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
},
\rtfsp
1016 \helpref{wxMenuBar::Remove
}{wxmenubarremove
}
1018 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
1020 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
1022 Sets the help string associated with a menu item.
1024 \wxheading{Parameters
}
1026 \docparam{id
}{Menu item identifier.
}
1028 \docparam{helpString
}{Help string to associate with the menu item.
}
1030 \wxheading{See also
}
1032 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
1034 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
1036 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
1038 Sets the label of a menu item.
1040 \wxheading{Parameters
}
1042 \docparam{id
}{Menu item identifier.
}
1044 \docparam{label
}{Menu item label.
}
1048 Use only after the menubar has been associated with a frame.
1050 \wxheading{See also
}
1052 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
1054 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
1056 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
1058 Sets the label of a top-level menu.
1060 \wxheading{Parameters
}
1062 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
1064 \docparam{label
}{The menu label.
}
1068 Use only after the menubar has been associated with a frame.
1070 \wxheading{See also
}
1072 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}