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