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