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