]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/menu.tex
fix warning
[wxWidgets.git] / docs / latex / wx / menu.tex
CommitLineData
a660d684
KB
1\section{\class{wxMenu}}\label{wxmenu}
2
3A menu is a popup (or pull down) list of items, one of which may be
4selected before the menu goes away (clicking elsewhere dismisses the
0472ece7 5menu). Menus may be used to construct either menu bars or popup menus.
a660d684
KB
6
7A menu item has an integer ID associated with it which can be used to
0472ece7
VZ
8identify the selection, or to change the menu item in some way. A menu item
9with a special identifier $-1$ is a separator item and doesn't have an
10associated command but just makes a separator line appear in the menu.
11
12Menu items may be either normal items, check items or radio items. Normal items
13don't have any special properties while the check items have a boolean flag
14associated to them and they show a checkmark in the menu when the flag is set.
fc2171bd 15wxWidgets automatically toggles the flag value when the item is clicked and its
0472ece7
VZ
16value may be retrieved using either \helpref{IsChecked}{wxmenuischecked} method
17of wxMenu or wxMenuBar itself or by using
18\helpref{wxEvent::IsChecked}{wxcommandeventischecked} when you get the menu
19notification for the item in question.
20
21The radio items are similar to the check items except that all the other items
22in the same radio group are unchecked when a radio item is checked. The radio
23group is formed by a contiguous range of radio items, i.e. it starts at the
24first item of this kind and ends with the first item of a different kind (or
25the end of the menu). Notice that because the radio groups are defined in terms
26of the item positions inserting or removing the items in the menu containing
27the radio items risks to not work correctly. Finally note that the radio items
28are only supported under Windows and GTK+ currently.
a660d684 29
2b5f62a0
VZ
30\wxheading{Allocation strategy}
31
32All menus except the popup ones must be created on the heap. All menus
33attached to a menubar or to another menu will be deleted by their parent when
34it is deleted. As the frame menubar is deleted by the frame itself, it means
35that normally all menus used are deleted automatically.
36
a660d684
KB
37\wxheading{Derived from}
38
39\helpref{wxEvtHandler}{wxevthandler}\\
40\helpref{wxObject}{wxobject}
41
954b8ae6
JS
42\wxheading{Include files}
43
44<wx/menu.h>
45
a660d684
KB
46\wxheading{Event handling}
47
48If the menu is part of a menubar, then \helpref{wxMenuBar}{wxmenubar} event processing is used.
49
50With a popup menu, there is a variety of ways to handle a menu selection event
51(wxEVT\_COMMAND\_MENU\_SELECTED).
52
53\begin{enumerate}\itemsep=0pt
a660d684
KB
54\item Derive a new class from wxMenu and define event table entries using the EVT\_MENU macro.
55\item Set a new event handler for wxMenu, using an object whose class has EVT\_MENU entries.
56\item Provide EVT\_MENU handlers in the window which pops up the menu, or in an ancestor of
57this window.
1aaef614 58\item Define a callback of type wxFunction, which you pass to the wxMenu constructor.
874a1686 59The callback takes a reference to the menu, and a reference to a
1aaef614
VZ
60\helpref{wxCommandEvent}{wxcommandevent}. This method is deprecated and should
61not be used in the new code, it is provided for backwards compatibility only.
a660d684
KB
62\end{enumerate}
63
64\wxheading{See also}
65
66\helpref{wxMenuBar}{wxmenubar}, \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu},\rtfsp
67\helpref{Event handling overview}{eventhandlingoverview}
68
69\latexignore{\rtfignore{\wxheading{Members}}}
70
71\membersection{wxMenu::wxMenu}\label{wxmenuconstr}
72
b1462dfa 73\func{}{wxMenu}{\param{const wxString\& }{title = ""}, \param{long}{ style = 0}}
a660d684
KB
74
75Constructs a wxMenu object.
76
77\wxheading{Parameters}
78
79\docparam{title}{A title for the popup menu: the empty string denotes no title.}
80
809f39fe 81\docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).}
06d20283 82
407f3681 83\func{}{wxMenu}{\param{long}{ style}}
4e986502
KB
84
85Constructs a wxMenu object.
86
87\wxheading{Parameters}
407f3681 88
809f39fe 89\docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).}
4e986502 90
a660d684
KB
91\membersection{wxMenu::\destruct{wxMenu}}
92
93\func{}{\destruct{wxMenu}}{\void}
94
95Destructor, destroying the menu.
96
b412f9be
JS
97Note: under Motif, a popup menu must have a valid parent (the window
98it was last popped up on) when being destroyed. Therefore, make sure
99you delete or re-use the popup menu {\it before} destroying the
100parent window. Re-use in this context means popping up the menu on
101a different window from last time, which causes an implicit destruction
102and recreation of internal data structures.
103
a660d684
KB
104\membersection{wxMenu::Append}\label{wxmenuappend}
105
9add9367 106\func{wxMenuItem*}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
98322660 107\param{wxItemKind}{ kind = wxITEM\_NORMAL}}
a660d684
KB
108
109Adds a string item to the end of the menu.
110
9add9367 111\func{wxMenuItem*}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{wxMenu *}{subMenu},\rtfsp
a660d684
KB
112\param{const wxString\& }{helpString = ""}}
113
2b5f62a0
VZ
114Adds a pull-right submenu to the end of the menu. Append the submenu to the parent
115menu {\it after} you have added your menu items, or accelerators may not be
116registered properly.
a660d684 117
9add9367 118\func{wxMenuItem*}{Append}{\param{wxMenuItem*}{ menuItem}}
a660d684 119
1aaef614
VZ
120Adds a menu item object. This is the most generic variant of Append() method
121because it may be used for both items (including separators) and submenus and
122because you can also specify various extra properties of a menu item this way,
a660d684
KB
123such as bitmaps and fonts.
124
125\wxheading{Parameters}
126
127\docparam{id}{The menu command identifier.}
128
129\docparam{item}{The string to appear on the menu item.}
130
131\docparam{menu}{Pull-right submenu.}
132
98322660
JS
133\docparam{kind}{May be {\tt wxITEM\_SEPARATOR}, {\tt wxITEM\_NORMAL},
134{\tt wxITEM\_CHECK} or {\tt wxITEM\_RADIO}}
a660d684
KB
135
136\docparam{helpString}{An optional help string associated with the item.
684761db 137By default, the handler for the wxEVT\_MENU\_HIGHLIGHT event displays
a660d684
KB
138this string in the status line.}
139
140\docparam{menuItem}{A menuitem object. It will be owned by the wxMenu object after this function
141is called, so do not delete it yourself.}
142
143\wxheading{Remarks}
144
145This command can be used after the menu has been shown, as well as on initial
146creation of a menu or menubar.
147
69440cd2
VZ
148The {\it item} string for the normal menu items (not submenus or separators)
149may include the accelerator which can be used to activate the menu item
150from keyboard. The accelerator string follows the item label and is separated
151from it by a {\tt TAB} character ({\tt '$\backslash$t'}). Its general syntax is
152any combination of {\tt "CTRL"}, {\tt "ALT"} and {\tt "SHIFT"} strings (case
153doesn't matter) separated by either {\tt '-'} or {\tt '+'} characters and
154followed by the accelerator itself. The accelerator may be any alphanumeric
155character, any function key (from {\tt F1} to {\tt F12}) or one of the special
156characters listed in the table below (again, case doesn't matter):
d2c2afc9 157
69440cd2
VZ
158\begin{twocollist}\itemsep=0pt
159\twocolitem{{\tt DEL} or {\tt DELETE}}{Delete key}
160\twocolitem{{\tt INS} or {\tt INSERT}}{Insert key}
161\twocolitem{{\tt ENTER} or {\tt RETURN}}{Enter key}
162\twocolitem{{\tt PGUP}}{PageUp key}
163\twocolitem{{\tt PGDN}}{PageDown key}
164\twocolitem{{\tt LEFT}}{Left cursor arrow key}
165\twocolitem{{\tt RIGHT}}{Right cursor arrow key}
166\twocolitem{{\tt UP}}{Up cursor arrow key}
167\twocolitem{{\tt DOWN}}{Down cursor arrow key}
168\twocolitem{{\tt HOME}}{Home key}
169\twocolitem{{\tt END}}{End key}
170\twocolitem{{\tt SPACE}}{Space}
171\twocolitem{{\tt TAB}}{Tab key}
41b78190 172\twocolitem{{\tt ESC} or {\tt ESCAPE}}{Escape key (Windows only)}
69440cd2
VZ
173\end{twocollist}
174
a660d684
KB
175\wxheading{See also}
176
1aaef614 177\helpref{wxMenu::AppendSeparator}{wxmenuappendseparator},\rtfsp
d65c269b
VZ
178\helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem},\rtfsp
179\helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem},\rtfsp
1aaef614
VZ
180\helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
181\helpref{wxMenu::SetLabel}{wxmenusetlabel}, \helpref{wxMenu::GetHelpString}{wxmenugethelpstring},\rtfsp
a660d684
KB
182\helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenuItem}{wxmenuitem}
183
06d20283 184\pythonnote{In place of a single overloaded method name, wxPython
d2c2afc9
JS
185implements the following methods:
186
06d20283 187\indented{2cm}{\begin{twocollist}
cc81d32f 188\twocolitem{{\bf Append(id, string, helpStr="", checkable=false)}}{}
c9110876
VS
189\twocolitem{{\bf AppendMenu(id, string, aMenu, helpStr="")}}{}
190\twocolitem{{\bf AppendItem(aMenuItem)}}{}
06d20283
RD
191\end{twocollist}}
192}
193
d65c269b
VZ
194\membersection{wxMenu::AppendCheckItem}\label{wxmenuappendcheckitem}
195
9add9367 196\func{wxMenuItem*}{AppendCheckItem}{\param{int}{ id},\rtfsp
d65c269b
VZ
197\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
198
199Adds a checkable item to the end of the menu.
200
201\wxheading{See also}
202
203\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
204\helpref{wxMenu::InsertCheckItem}{wxmenuinsertcheckitem}
205
206\membersection{wxMenu::AppendRadioItem}\label{wxmenuappendradioitem}
207
9add9367 208\func{wxMenuItem*}{AppendRadioItem}{\param{int}{ id},\rtfsp
d65c269b
VZ
209\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
210
211Adds a radio item to the end of the menu. All consequent radio items form a
212group and when an item in the group is checked, all the others are
213automatically unchecked.
214
215{\bf NB:} Currently only implemented under Windows and GTK, use
7af3ca16 216{\tt\#if wxHAS\_RADIO\_MENU\_ITEMS} to test for availability of this feature.
d65c269b
VZ
217
218\wxheading{See also}
219
220\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
221\helpref{wxMenu::InsertRadioItem}{wxmenuinsertradioitem}
222
a660d684
KB
223\membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator}
224
9add9367 225\func{wxMenuItem*}{AppendSeparator}{\void}
a660d684
KB
226
227Adds a separator to the end of the menu.
228
229\wxheading{See also}
230
d65c269b
VZ
231\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
232\helpref{wxMenu::InsertSeparator}{wxmenuinsertseparator}
a660d684
KB
233
234\membersection{wxMenu::Break}\label{wxmenubreak}
235
236\func{void}{Break}{\void}
237
238Inserts a break in a menu, causing the next appended item to appear in a new column.
239
240\membersection{wxMenu::Check}\label{wxmenucheck}
241
eaaa6a06 242\func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
a660d684
KB
243
244Checks or unchecks the menu item.
245
246\wxheading{Parameters}
247
248\docparam{id}{The menu item identifier.}
249
cc81d32f 250\docparam{check}{If true, the item will be checked, otherwise it will be unchecked.}
a660d684
KB
251
252\wxheading{See also}
253
254\helpref{wxMenu::IsChecked}{wxmenuischecked}
255
fc9c7c09
RR
256\membersection{wxMenu::Delete}\label{wxmenudelete}
257
258\func{void}{Delete}{\param{int }{id}}
259
1aaef614
VZ
260\func{void}{Delete}{\param{wxMenuItem *}{item}}
261
874a1686 262Deletes the menu item from the menu. If the item is a submenu, it will
1aaef614
VZ
263{\bf not} be deleted. Use \helpref{Destroy}{wxmenudestroy} if you want to
264delete a submenu.
fc9c7c09
RR
265
266\wxheading{Parameters}
267
1aaef614 268\docparam{id}{Id of the menu item to be deleted.}
fc9c7c09 269
1aaef614
VZ
270\docparam{item}{Menu item to be deleted.}
271
272\wxheading{See also}
273
274\helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp
275\helpref{wxMenu::Destroy}{wxmenudestroy},\rtfsp
276\helpref{wxMenu::Remove}{wxmenuremove}
277
278\membersection{wxMenu::Destroy}\label{wxmenudestroy}
279
280\func{void}{Destroy}{\param{int }{id}}
281
282\func{void}{Destroy}{\param{wxMenuItem *}{item}}
283
874a1686 284Deletes the menu item from the menu. If the item is a submenu, it will
1aaef614
VZ
285be deleted. Use \helpref{Remove}{wxmenuremove} if you want to keep the submenu
286(for example, to reuse it later).
fc9c7c09 287
1aaef614
VZ
288\wxheading{Parameters}
289
290\docparam{id}{Id of the menu item to be deleted.}
291
292\docparam{item}{Menu item to be deleted.}
fc9c7c09
RR
293
294\wxheading{See also}
295
1aaef614
VZ
296\helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp
297\helpref{wxMenu::Deletes}{wxmenudelete},\rtfsp
298\helpref{wxMenu::Remove}{wxmenuremove}
fc9c7c09 299
a660d684
KB
300\membersection{wxMenu::Enable}\label{wxmenuenable}
301
eaaa6a06 302\func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
a660d684
KB
303
304Enables or disables (greys out) a menu item.
305
306\wxheading{Parameters}
307
308\docparam{id}{The menu item identifier.}
309
cc81d32f 310\docparam{enable}{true to enable the menu item, false to disable it.}
a660d684
KB
311
312\wxheading{See also}
313
314\helpref{wxMenu::IsEnabled}{wxmenuisenabled}
315
316\membersection{wxMenu::FindItem}\label{wxmenufinditem}
317
318\constfunc{int}{FindItem}{\param{const wxString\& }{itemString}}
319
320Finds the menu item id for a menu item string.
321
1aaef614 322\constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu **}{menu = NULL}}
407f3681 323
1aaef614
VZ
324Finds the menu item object associated with the given menu item identifier and,
325optionally, the (sub)menu it belongs to.
a660d684 326
5873607e
VZ
327\perlnote{In wxPerl this method takes just the {\tt id} parameter;
328in scalar context it returns the associated {\tt Wx::MenuItem}, in list
9722642d 329context it returns a 2-element list {\tt ( item, submenu )}}
5873607e 330
a660d684
KB
331\wxheading{Parameters}
332
e12be2f7
JS
333\docparam{itemString}{Menu item string to find.}
334
a660d684
KB
335\docparam{id}{Menu item identifier.}
336
1aaef614
VZ
337\docparam{menu}{If the pointer is not NULL, it will be filled with the items
338parent menu (if the item was found)}
339
a660d684
KB
340\wxheading{Return value}
341
e12be2f7 342First form: menu item identifier, or wxNOT\_FOUND if none is found.
a660d684 343
e12be2f7 344Second form: returns the menu item object, or NULL if it is not found.
a660d684 345
e12be2f7
JS
346\wxheading{Remarks}
347
348Any special menu codes are stripped out of source and target strings
349before matching.
a660d684 350
fa482912 351\pythonnote{The name of this method in wxPython is {\tt FindItemById}
874a1686
RD
352and it does not support the second parameter.}
353
bd582574
JS
354\membersection{wxMenu::FindItemByPosition}\label{wxmenufinditembyposition}
355
62313dec 356\constfunc{wxMenuItem*}{FindItemByPosition}{\param{size\_t }{position}}
bd582574
JS
357
358Returns the wxMenuItem given a position in the menu.
359
a660d684
KB
360\membersection{wxMenu::GetHelpString}\label{wxmenugethelpstring}
361
eaaa6a06 362\constfunc{wxString}{GetHelpString}{\param{int}{ id}}
a660d684
KB
363
364Returns the help string associated with a menu item.
365
366\wxheading{Parameters}
367
368\docparam{id}{The menu item identifier.}
369
370\wxheading{Return value}
371
372The help string, or the empty string if there is no help string or the
373item was not found.
374
375\wxheading{See also}
376
377\helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenu::Append}{wxmenuappend}
378
379\membersection{wxMenu::GetLabel}\label{wxmenugetlabel}
380
eaaa6a06 381\constfunc{wxString}{GetLabel}{\param{int}{ id}}
a660d684
KB
382
383Returns a menu item label.
384
385\wxheading{Parameters}
386
387\docparam{id}{The menu item identifier.}
388
389\wxheading{Return value}
390
391The item label, or the empty string if the item was not found.
392
393\wxheading{See also}
394
395\helpref{wxMenu::SetLabel}{wxmenusetlabel}
396
1aaef614
VZ
397\membersection{wxMenu::GetMenuItemCount}\label{wxmenugetmenuitemcount}
398
399\constfunc{size\_t}{GetMenuItemCount}{\void}
400
401Returns the number of items in the menu.
402
403\membersection{wxMenu::GetMenuItems}\label{wxmenugetmenuitems}
404
405\constfunc{wxMenuItemList\&}{GetMenuItems}{\void}
406
407Returns the list of items in the menu. wxMenuItemList is a pseudo-template
408list class containing wxMenuItem pointers.
409
a660d684
KB
410\membersection{wxMenu::GetTitle}\label{wxmenugettitle}
411
412\constfunc{wxString}{GetTitle}{\void}
413
414Returns the title of the menu.
415
416\wxheading{Remarks}
417
706f30f8
VZ
418This is relevant only to popup menus, use
419\helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop} for the menus in the
420menubar.
a660d684
KB
421
422\wxheading{See also}
423
424\helpref{wxMenu::SetTitle}{wxmenusettitle}
425
1aaef614
VZ
426\membersection{wxMenu::Insert}\label{wxmenuinsert}
427
9add9367 428\func{wxMenuItem*}{Insert}{\param{size\_t }{pos}, \param{wxMenuItem *}{item}}
1aaef614 429
9add9367 430\func{wxMenuItem*}{Insert}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
d65c269b 431\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
98322660 432\param{wxItemKind}{ kind = wxITEM\_NORMAL}}
d65c269b 433
1aaef614
VZ
434Inserts the given {\it item} before the position {\it pos}. Inserting the item
435at the position \helpref{GetMenuItemCount}{wxmenugetmenuitemcount} is the same
436as appending it.
437
438\wxheading{See also}
439
d65c269b
VZ
440\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
441\helpref{wxMenu::Prepend}{wxmenuprepend}
442
443\membersection{wxMenu::InsertCheckItem}\label{wxmenuinsertcheckitem}
444
9add9367 445\func{wxMenuItem*}{InsertCheckItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
d65c269b
VZ
446\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
447
448Inserts a checkable item at the given position.
449
450\wxheading{See also}
451
452\helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
453\helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem}
454
455\membersection{wxMenu::InsertRadioItem}\label{wxmenuinsertradioitem}
456
9add9367 457\func{wxMenuItem*}{InsertRadioItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
d65c269b
VZ
458\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
459
460Inserts a radio item at the given position.
461
462\wxheading{See also}
463
464\helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
465\helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem}
466
467\membersection{wxMenu::InsertSeparator}\label{wxmenuinsertseparator}
468
9add9367 469\func{wxMenuItem*}{InsertSeparator}{\param{size\_t }{pos}}
d65c269b
VZ
470
471Inserts a separator at the given position.
472
473\wxheading{See also}
474
475\helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
476\helpref{wxMenu::AppendSeparator}{wxmenuappendseparator}
1aaef614 477
a660d684
KB
478\membersection{wxMenu::IsChecked}\label{wxmenuischecked}
479
eaaa6a06 480\constfunc{bool}{IsChecked}{\param{int}{ id}}
a660d684
KB
481
482Determines whether a menu item is checked.
483
484\wxheading{Parameters}
485
486\docparam{id}{The menu item identifier.}
487
488\wxheading{Return value}
489
cc81d32f 490true if the menu item is checked, false otherwise.
a660d684
KB
491
492\wxheading{See also}
493
494\helpref{wxMenu::Check}{wxmenucheck}
495
496\membersection{wxMenu::IsEnabled}\label{wxmenuisenabled}
497
eaaa6a06 498\constfunc{bool}{IsEnabled}{\param{int}{ id}}
a660d684
KB
499
500Determines whether a menu item is enabled.
501
502\wxheading{Parameters}
503
504\docparam{id}{The menu item identifier.}
505
506\wxheading{Return value}
507
cc81d32f 508true if the menu item is enabled, false otherwise.
a660d684
KB
509
510\wxheading{See also}
511
512\helpref{wxMenu::Enable}{wxmenuenable}
513
d65c269b
VZ
514\membersection{wxMenu::Prepend}\label{wxmenuprepend}
515
9add9367 516\func{wxMenuItem*}{Prepend}{\param{wxMenuItem *}{item}}
d65c269b 517
9add9367 518\func{wxMenuItem*}{Prepend}{\param{int}{ id},\rtfsp
d65c269b 519\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
98322660 520\param{wxItemKind}{ kind = wxITEM\_NORMAL}}
d65c269b 521
0cde01ae
VZ
522Inserts the given {\it item} at the position $0$, i.e. before all the other
523existing items.
d65c269b
VZ
524
525\wxheading{See also}
526
527\helpref{wxMenu::Append}{wxmenuappend},\rtfsp
528\helpref{wxMenu::Inserts}{wxmenuinsert}
529
530\membersection{wxMenu::PrependCheckItem}\label{wxmenuprependcheckitem}
531
9add9367 532\func{wxMenuItem*}{PrependCheckItem}{\param{int}{ id},\rtfsp
d65c269b
VZ
533\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
534
535Inserts a checkable item at the position $0$.
536
537\wxheading{See also}
538
539\helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp
540\helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem}
541
542\membersection{wxMenu::PrependRadioItem}\label{wxmenuprependradioitem}
543
9add9367 544\func{wxMenuItem*}{PrependRadioItem}{\param{int}{ id},\rtfsp
d65c269b
VZ
545\param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
546
547Inserts a radio item at the position $0$.
548
549\wxheading{See also}
550
551\helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp
552\helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem}
553
554\membersection{wxMenu::PrependSeparator}\label{wxmenuprependseparator}
555
9add9367 556\func{wxMenuItem*}{PrependSeparator}{\param{size\_t }{pos}}
d65c269b
VZ
557
558Inserts a separator at the position $0$.
559
560\wxheading{See also}
561
562\helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp
563\helpref{wxMenu::AppendSeparator}{wxmenuappendseparator}
564
1aaef614
VZ
565\membersection{wxMenu::Remove}\label{wxmenuremove}
566
567\func{wxMenuItem *}{Remove}{\param{int }{id}}
568
569\func{wxMenuItem *}{Remove}{\param{wxMenuItem *}{item}}
570
571Removes the menu item from the menu but doesn't delete the associated C++
572object. This allows to reuse the same item later by adding it back to the menu
573(especially useful with submenus).
574
575\wxheading{Parameters}
576
577\docparam{id}{The identifier of the menu item to remove.}
578
579\docparam{item}{The menu item to remove.}
580
581\wxheading{Return value}
582
583The item which was detached from the menu.
584
a660d684
KB
585\membersection{wxMenu::SetHelpString}\label{wxmenusethelpstring}
586
eaaa6a06 587\func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
a660d684
KB
588
589Sets an item's help string.
590
591\wxheading{Parameters}
592
593\docparam{id}{The menu item identifier.}
594
595\docparam{helpString}{The help string to set.}
596
597\wxheading{See also}
598
599\helpref{wxMenu::GetHelpString}{wxmenugethelpstring}
600
601\membersection{wxMenu::SetLabel}\label{wxmenusetlabel}
602
eaaa6a06 603\func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
a660d684
KB
604
605Sets the label of a menu item.
606
607\wxheading{Parameters}
608
609\docparam{id}{The menu item identifier.}
610
611\docparam{label}{The menu item label to set.}
612
613\wxheading{See also}
614
615\helpref{wxMenu::Append}{wxmenuappend}, \helpref{wxMenu::GetLabel}{wxmenugetlabel}
616
617\membersection{wxMenu::SetTitle}\label{wxmenusettitle}
618
619\func{void}{SetTitle}{\param{const wxString\& }{title}}
620
621Sets the title of the menu.
622
623\wxheading{Parameters}
624
625\docparam{title}{The title to set.}
626
627\wxheading{Remarks}
628
706f30f8
VZ
629This is relevant only to popup menus, use
630\helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop} for the menus in the
631menubar.
a660d684
KB
632
633\wxheading{See also}
634
706f30f8 635\helpref{wxMenu::GetTitle}{wxmenugettitle}
a660d684 636
631f1bfe
JS
637\membersection{wxMenu::UpdateUI}\label{wxmenuupdateui}
638
639\constfunc{void}{UpdateUI}{\param{wxEvtHandler*}{ source = NULL}}
640
641Sends events to {\it source} (or owning window if NULL) to update the
642menu UI. This is called just before the menu is popped up with \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu}, but
643the application may call it at other times if required.
644
645\wxheading{See also}
646
647\helpref{wxUpdateUIEvent}{wxupdateuievent}
648
a660d684
KB
649\section{\class{wxMenuBar}}\label{wxmenubar}
650
651A menu bar is a series of menus accessible from the top of a frame.
652
653\wxheading{Derived from}
654
2138129e 655\helpref{wxWindow}{wxwindow}\\
a660d684
KB
656\helpref{wxEvtHandler}{wxevthandler}\\
657\helpref{wxObject}{wxobject}
658
954b8ae6
JS
659\wxheading{Include files}
660
661<wx/menu.h>
662
a660d684
KB
663\wxheading{Event handling}
664
665To respond to a menu selection, provide a handler for EVT\_MENU, in the frame
e702ff0f
JS
666that contains the menu bar. If you have a toolbar which uses the same identifiers
667as your EVT\_MENU entries, events from the toolbar will also be processed by your
668EVT\_MENU event handlers.
669
0ddef74d
JS
670{\bf Tip:} under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu)
671are not working, check any EVT\_CHAR events you are handling in child windows.
672If you are not calling {\tt event.Skip()} for events that you don't process in these event handlers,
673menu shortcuts may cease to work.
674
a660d684
KB
675\wxheading{See also}
676
677\helpref{wxMenu}{wxmenu}, \helpref{Event handling overview}{eventhandlingoverview}
678
679\latexignore{\rtfignore{\wxheading{Members}}}
680
681\membersection{wxMenuBar::wxMenuBar}\label{wxmenubarconstr}
682
17e79918 683\func{void}{wxMenuBar}{\param{long }{style = 0}}
a660d684
KB
684
685Default constructor.
686
eaaa6a06 687\func{void}{wxMenuBar}{\param{int}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}}
a660d684
KB
688
689Construct a menu bar from arrays of menus and titles.
690
691\wxheading{Parameters}
692
693\docparam{n}{The number of menus.}
694
695\docparam{menus}{An array of menus. Do not use this array again - it now belongs to the
696menu bar.}
697
698\docparam{titles}{An array of title strings. Deallocate this array after creating the menu bar.}
699
d17f05af 700\docparam{style}{If {\tt wxMB\_DOCKABLE} the menu bar can be detached (wxGTK only).}
17e79918 701
06d20283
RD
702\pythonnote{Only the default constructor is supported in wxPython.
703Use wxMenuBar.Append instead.}
704
2edb0bde 705\perlnote{wxPerl only supports the first constructor:
5873607e
VZ
706use {\tt Append} instead.}
707
a660d684
KB
708\membersection{wxMenuBar::\destruct{wxMenuBar}}
709
710\func{void}{\destruct{wxMenuBar}}{\void}
711
712Destructor, destroying the menu bar and removing it from the parent frame (if any).
713
714\membersection{wxMenuBar::Append}\label{wxmenubarappend}
715
1aaef614 716\func{bool}{Append}{\param{wxMenu *}{menu}, \param{const wxString\& }{title}}
a660d684
KB
717
718Adds the item to the end of the menu bar.
719
720\wxheading{Parameters}
721
722\docparam{menu}{The menu to add. Do not deallocate this menu after calling {\bf Append}.}
723
724\docparam{title}{The title of the menu.}
725
1aaef614
VZ
726\wxheading{Return value}
727
cc81d32f 728true on success, false if an error occurred.
1aaef614
VZ
729
730\wxheading{See also}
731
732\helpref{wxMenuBar::Insert}{wxmenubarinsert}
733
a660d684
KB
734\membersection{wxMenuBar::Check}\label{wxmenubarcheck}
735
eaaa6a06 736\func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
a660d684
KB
737
738Checks or unchecks a menu item.
739
740\wxheading{Parameters}
741
742\docparam{id}{The menu item identifier.}
743
cc81d32f 744\docparam{check}{If true, checks the menu item, otherwise the item is unchecked.}
a660d684
KB
745
746\wxheading{Remarks}
747
748Only use this when the menu bar has been associated
749with a frame; otherwise, use the wxMenu equivalent call.
750
751\membersection{wxMenuBar::Enable}\label{wxmenubarenable}
752
eaaa6a06 753\func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
a660d684
KB
754
755Enables or disables (greys out) a menu item.
756
757\wxheading{Parameters}
758
759\docparam{id}{The menu item identifier.}
760
cc81d32f 761\docparam{enable}{true to enable the item, false to disable it.}
a660d684
KB
762
763\wxheading{Remarks}
764
765Only use this when the menu bar has been
766associated with a frame; otherwise, use the wxMenu equivalent call.
767
768\membersection{wxMenuBar::EnableTop}\label{wxmenubarenabletop}
769
eaaa6a06 770\func{void}{EnableTop}{\param{int}{ pos}, \param{const bool}{ enable}}
a660d684
KB
771
772Enables or disables a whole menu.
773
774\wxheading{Parameters}
775
776\docparam{pos}{The position of the menu, starting from zero.}
777
cc81d32f 778\docparam{enable}{true to enable the menu, false to disable it.}
a660d684
KB
779
780\wxheading{Remarks}
781
782Only use this when the menu bar has been
783associated with a frame.
784
270e8b6a
VZ
785\membersection{wxMenuBar::FindMenu}\label{wxmenubarfindmenu}
786
787\constfunc{int}{FindMenu}{\param{const wxString\& }{title}}
788
789Returns the index of the menu with the given {\it title} or wxNOT\_FOUND if no
790such menu exists in this menubar. The {\it title} parameter may specify either
791the menu title (with accelerator characters, i.e. {\tt "\&File"}) or just the
792menu label ({\tt "File"}) indifferently.
793
a660d684
KB
794\membersection{wxMenuBar::FindMenuItem}\label{wxmenubarfindmenuitem}
795
796\constfunc{int}{FindMenuItem}{\param{const wxString\& }{menuString}, \param{const wxString\& }{itemString}}
797
798Finds the menu item id for a menu name/menu item string pair.
799
800\wxheading{Parameters}
801
802\docparam{menuString}{Menu title to find.}
803
804\docparam{itemString}{Item to find.}
805
806\wxheading{Return value}
807
1aaef614 808The menu item identifier, or wxNOT\_FOUND if none was found.
a660d684
KB
809
810\wxheading{Remarks}
811
812Any special menu codes are stripped out of source and target strings
813before matching.
814
fc9c7c09 815\membersection{wxMenuBar::FindItem}\label{wxmenubarfinditem}
a660d684 816
407f3681 817\constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu}{ **menu = NULL}}
a660d684 818
fc9c7c09 819Finds the menu item object associated with the given menu item identifier.
a660d684
KB
820
821\wxheading{Parameters}
822
823\docparam{id}{Menu item identifier.}
407f3681 824
fc9c7c09 825\docparam{menu}{If not NULL, menu will get set to the associated menu.}
a660d684
KB
826
827\wxheading{Return value}
828
829The found menu item object, or NULL if one was not found.
830
831\membersection{wxMenuBar::GetHelpString}\label{wxmenubargethelpstring}
832
eaaa6a06 833\constfunc{wxString}{GetHelpString}{\param{int}{ id}}
a660d684 834
2edb0bde 835Gets the help string associated with the menu item identifier.
a660d684
KB
836
837\wxheading{Parameters}
838
839\docparam{id}{The menu item identifier.}
840
841\wxheading{Return value}
842
843The help string, or the empty string if there was no help string or the menu item
844was not found.
845
846\wxheading{See also}
847
848\helpref{wxMenuBar::SetHelpString}{wxmenubarsethelpstring}
849
850\membersection{wxMenuBar::GetLabel}\label{wxmenubargetlabel}
851
eaaa6a06 852\constfunc{wxString}{GetLabel}{\param{int}{ id}}
a660d684
KB
853
854Gets the label associated with a menu item.
855
856\wxheading{Parameters}
857
858\docparam{id}{The menu item identifier.}
859
860\wxheading{Return value}
861
862The menu item label, or the empty string if the item was not found.
863
864\wxheading{Remarks}
865
866Use only after the menubar has been associated with a frame.
867
868\membersection{wxMenuBar::GetLabelTop}\label{wxmenubargetlabeltop}
869
eaaa6a06 870\constfunc{wxString}{GetLabelTop}{\param{int}{ pos}}
a660d684 871
706f30f8
VZ
872Returns the label of a top-level menu. Note that the returned string does not
873include the accelerator characters which could have been specified in the menu
874title string during its construction.
a660d684
KB
875
876\wxheading{Parameters}
877
878\docparam{pos}{Position of the menu on the menu bar, starting from zero.}
879
880\wxheading{Return value}
881
882The menu label, or the empty string if the menu was not found.
883
884\wxheading{Remarks}
885
886Use only after the menubar has been associated with a frame.
887
888\wxheading{See also}
889
890\helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop}
891
7f555861
JS
892\membersection{wxMenuBar::GetMenu}\label{wxmenubargetmenu}
893
894\constfunc{wxMenu*}{GetMenu}{\param{int}{ menuIndex}}
895
896Returns the menu at {\it menuIndex} (zero-based).
897
898\membersection{wxMenuBar::GetMenuCount}\label{wxmenubargetmenucount}
899
900\constfunc{int}{GetMenuCount}{\void}
901
902Returns the number of menus in this menubar.
903
e12be2f7 904\membersection{wxMenuBar::Insert}\label{wxmenubarinsert}
1aaef614
VZ
905
906\func{bool}{Insert}{\param{size\_t }{pos}, \param{wxMenu *}{menu}, \param{const wxString\& }{title}}
907
908Inserts the menu at the given position into the menu bar. Inserting menu at
fa482912
JS
909position $0$ will insert it in the very beginning of it, inserting at position
910\helpref{GetMenuCount()}{wxmenubargetmenucount} is the same as calling
1aaef614
VZ
911\helpref{Append()}{wxmenubarappend}.
912
913\wxheading{Parameters}
914
915\docparam{pos}{The position of the new menu in the menu bar}
916
917\docparam{menu}{The menu to add. wxMenuBar owns the menu and will free it.}
918
919\docparam{title}{The title of the menu.}
920
921\wxheading{Return value}
922
cc81d32f 923true on success, false if an error occurred.
1aaef614
VZ
924
925\wxheading{See also}
926
927\helpref{wxMenuBar::Append}{wxmenubarappend}
928
a660d684
KB
929\membersection{wxMenuBar::IsChecked}\label{wxmenubarischecked}
930
eaaa6a06 931\constfunc{bool}{IsChecked}{\param{int}{ id}}
a660d684
KB
932
933Determines whether an item is checked.
934
935\wxheading{Parameters}
936
937\docparam{id}{The menu item identifier.}
938
939\wxheading{Return value}
940
cc81d32f 941true if the item was found and is checked, false otherwise.
a660d684
KB
942
943\membersection{wxMenuBar::IsEnabled}\label{wxmenubarisenabled}
944
eaaa6a06 945\constfunc{bool}{IsEnabled}{\param{int}{ id}}
a660d684
KB
946
947Determines whether an item is enabled.
948
949\wxheading{Parameters}
950
951\docparam{id}{The menu item identifier.}
952
953\wxheading{Return value}
954
cc81d32f 955true if the item was found and is enabled, false otherwise.
a660d684 956
63dcfc15
PA
957\membersection{wxMenuBar::Refresh}\label{wxmenubarrefresh}
958
959\func{void}{Refresh}{\void}
960
961Redraw the menu bar
962
1aaef614
VZ
963\membersection{wxMenuBar::Remove}\label{wxmenubarremove}
964
965\func{wxMenu *}{Remove}{\param{size\_t }{pos}}
966
967Removes the menu from the menu bar and returns the menu object - the caller is
d7d17624 968responsible for deleting it. This function may be used together with
1aaef614
VZ
969\helpref{wxMenuBar::Insert}{wxmenubarinsert} to change the menubar
970dynamically.
971
972\wxheading{See also}
973
2182e26f 974\helpref{wxMenuBar::Replace}{wxmenubarreplace}
1aaef614
VZ
975
976\membersection{wxMenuBar::Replace}\label{wxmenubarreplace}
977
978\func{wxMenu *}{Replace}{\param{size\_t }{pos}, \param{wxMenu *}{menu}, \param{const wxString\& }{title}}
979
fa482912 980Replaces the menu at the given position with another one.
1aaef614
VZ
981
982\wxheading{Parameters}
983
984\docparam{pos}{The position of the new menu in the menu bar}
985
986\docparam{menu}{The menu to add.}
987
988\docparam{title}{The title of the menu.}
989
990\wxheading{Return value}
991
992The menu which was previously at the position {\it pos}. The caller is
993responsible for deleting it.
994
995\wxheading{See also}
996
997\helpref{wxMenuBar::Insert}{wxmenubarinsert},\rtfsp
998\helpref{wxMenuBar::Remove}{wxmenubarremove}
999
a660d684
KB
1000\membersection{wxMenuBar::SetHelpString}\label{wxmenubarsethelpstring}
1001
eaaa6a06 1002\func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
a660d684
KB
1003
1004Sets the help string associated with a menu item.
1005
1006\wxheading{Parameters}
1007
1008\docparam{id}{Menu item identifier.}
1009
1010\docparam{helpString}{Help string to associate with the menu item.}
1011
1012\wxheading{See also}
1013
1014\helpref{wxMenuBar::GetHelpString}{wxmenubargethelpstring}
1015
1016\membersection{wxMenuBar::SetLabel}\label{wxmenubarsetlabel}
1017
eaaa6a06 1018\func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
a660d684
KB
1019
1020Sets the label of a menu item.
1021
1022\wxheading{Parameters}
1023
1024\docparam{id}{Menu item identifier.}
1025
1026\docparam{label}{Menu item label.}
1027
1028\wxheading{Remarks}
1029
1030Use only after the menubar has been associated with a frame.
1031
1032\wxheading{See also}
1033
1034\helpref{wxMenuBar::GetLabel}{wxmenubargetlabel}
1035
1036\membersection{wxMenuBar::SetLabelTop}\label{wxmenubarsetlabeltop}
1037
eaaa6a06 1038\func{void}{SetLabelTop}{\param{int}{ pos}, \param{const wxString\& }{label}}
a660d684
KB
1039
1040Sets the label of a top-level menu.
1041
1042\wxheading{Parameters}
1043
1044\docparam{pos}{The position of a menu on the menu bar, starting from zero.}
1045
1046\docparam{label}{The menu label.}
1047
1048\wxheading{Remarks}
1049
1050Use only after the menubar has been associated with a frame.
1051
1052\wxheading{See also}
1053
1054\helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop}
1055