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