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