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