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