]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/menu.tex
i18n overview
[wxWidgets.git] / docs / latex / wx / menu.tex
CommitLineData
a660d684
KB
1\section{\class{wxMenu}}\label{wxmenu}
2
3A menu is a popup (or pull down) list of items, one of which may be
4selected before the menu goes away (clicking elsewhere dismisses the
5menu). Menus may be used to construct either menu bars or popup menus.
6
7A menu item has an integer ID associated with it which can be used to
8identify the selection, or to change the menu item in some way.
9
10\wxheading{Derived from}
11
12\helpref{wxEvtHandler}{wxevthandler}\\
13\helpref{wxObject}{wxobject}
14
954b8ae6
JS
15\wxheading{Include files}
16
17<wx/menu.h>
18
a660d684
KB
19\wxheading{Event handling}
20
21If the menu is part of a menubar, then \helpref{wxMenuBar}{wxmenubar} event processing is used.
22
23With a popup menu, there is a variety of ways to handle a menu selection event
24(wxEVT\_COMMAND\_MENU\_SELECTED).
25
26\begin{enumerate}\itemsep=0pt
27\item Define a callback of type wxFunction, which you pass to the wxMenu constructor.
b8de493f 28The callback takes a reference to the menu, and a reference to a \helpref{wxCommandEvent}{wxcommandevent}.
a660d684
KB
29\item Derive a new class from wxMenu and define event table entries using the EVT\_MENU macro.
30\item Set a new event handler for wxMenu, using an object whose class has EVT\_MENU entries.
31\item Provide EVT\_MENU handlers in the window which pops up the menu, or in an ancestor of
32this window.
33\end{enumerate}
34
35\wxheading{See also}
36
37\helpref{wxMenuBar}{wxmenubar}, \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu},\rtfsp
38\helpref{Event handling overview}{eventhandlingoverview}
39
40\latexignore{\rtfignore{\wxheading{Members}}}
41
42\membersection{wxMenu::wxMenu}\label{wxmenuconstr}
43
44\func{}{wxMenu}{\param{const wxString\& }{title = ""}, \param{const wxFunction}{ func = NULL}}
45
46Constructs a wxMenu object.
47
48\wxheading{Parameters}
49
50\docparam{title}{A title for the popup menu: the empty string denotes no title.}
51
52\docparam{func}{A callback function if the menu is used as a popup using \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu}.}
53
06d20283
RD
54\pythonnote{The wxPython version of the \tt{wxMenu} constructor
55doesn't accept the callback argument because of reference counting
56issues. There is a specialized wxMenu constructor called
57\tt{wxPyMenu} which does and can be used for PopupMenus when callbacks
58are needed. You must retain a reference to the menu while useing it
59otherwise your callback function will get dereferenced when the menu
60does.
61}
62
a660d684
KB
63\membersection{wxMenu::\destruct{wxMenu}}
64
65\func{}{\destruct{wxMenu}}{\void}
66
67Destructor, destroying the menu.
68
b412f9be
JS
69Note: under Motif, a popup menu must have a valid parent (the window
70it was last popped up on) when being destroyed. Therefore, make sure
71you delete or re-use the popup menu {\it before} destroying the
72parent window. Re-use in this context means popping up the menu on
73a different window from last time, which causes an implicit destruction
74and recreation of internal data structures.
75
a660d684
KB
76\membersection{wxMenu::Append}\label{wxmenuappend}
77
eaaa6a06 78\func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
a660d684
KB
79\param{const bool}{ checkable = FALSE}}
80
81Adds a string item to the end of the menu.
82
eaaa6a06 83\func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{wxMenu *}{subMenu},\rtfsp
a660d684
KB
84\param{const wxString\& }{helpString = ""}}
85
86Adds a pull-right submenu to the end of the menu.
87
88\func{void}{Append}{\param{wxMenuItem*}{ menuItem}}
89
90Adds a menu item object. You can specify various extra properties of a menu item this way,
91such as bitmaps and fonts.
92
93\wxheading{Parameters}
94
95\docparam{id}{The menu command identifier.}
96
97\docparam{item}{The string to appear on the menu item.}
98
99\docparam{menu}{Pull-right submenu.}
100
101\docparam{checkable}{If TRUE, this item is checkable.}
102
103\docparam{helpString}{An optional help string associated with the item.
104By default, \helpref{wxFrame::OnMenuHighlight}{wxframeonmenuhighlight} displays
105this string in the status line.}
106
107\docparam{menuItem}{A menuitem object. It will be owned by the wxMenu object after this function
108is called, so do not delete it yourself.}
109
110\wxheading{Remarks}
111
112This command can be used after the menu has been shown, as well as on initial
113creation of a menu or menubar.
114
115\wxheading{See also}
116
117\helpref{wxMenu::AppendSeparator}{wxmenuappendseparator}, \helpref{wxMenu::SetLabel}{wxmenusetlabel}, \helpref{wxMenu::GetHelpString}{wxmenugethelpstring},\rtfsp
118\helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenuItem}{wxmenuitem}
119
06d20283
RD
120
121\pythonnote{In place of a single overloaded method name, wxPython
122implements the following methods:\par
123\indented{2cm}{\begin{twocollist}
124\twocolitem{\bf{Append(id, string, helpStr="", checkable=FALSE)}}{}
125\twocolitem{\bf{AppendMenu(id, string, aMenu, helpStr="")}}{}
126\twocolitem{\bf{AppendItem(aMenuItem)}}{}
127\end{twocollist}}
128}
129
130
a660d684
KB
131\membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator}
132
133\func{void}{AppendSeparator}{\void}
134
135Adds a separator to the end of the menu.
136
137\wxheading{See also}
138
139\helpref{wxMenu::Append}{wxmenuappend}
140
141\membersection{wxMenu::Break}\label{wxmenubreak}
142
143\func{void}{Break}{\void}
144
145Inserts a break in a menu, causing the next appended item to appear in a new column.
146
147\membersection{wxMenu::Check}\label{wxmenucheck}
148
eaaa6a06 149\func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
a660d684
KB
150
151Checks or unchecks the menu item.
152
153\wxheading{Parameters}
154
155\docparam{id}{The menu item identifier.}
156
157\docparam{check}{If TRUE, the item will be checked, otherwise it will be unchecked.}
158
159\wxheading{See also}
160
161\helpref{wxMenu::IsChecked}{wxmenuischecked}
162
163\membersection{wxMenu::Enable}\label{wxmenuenable}
164
eaaa6a06 165\func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
a660d684
KB
166
167Enables or disables (greys out) a menu item.
168
169\wxheading{Parameters}
170
171\docparam{id}{The menu item identifier.}
172
173\docparam{enable}{TRUE to enable the menu item, FALSE to disable it.}
174
175\wxheading{See also}
176
177\helpref{wxMenu::IsEnabled}{wxmenuisenabled}
178
179\membersection{wxMenu::FindItem}\label{wxmenufinditem}
180
181\constfunc{int}{FindItem}{\param{const wxString\& }{itemString}}
182
183Finds the menu item id for a menu item string.
184
185\wxheading{Parameters}
186
187\docparam{itemString}{Menu item string to find.}
188
189\wxheading{Return value}
190
191Menu item identifier, or -1 if none is found.
192
193\wxheading{Remarks}
194
195Any special menu codes are stripped out of source and target strings
196before matching.
197
198\wxheading{See also}
199
200\helpref{wxMenu::FindItemForId}{wxmenufinditemforid}
201
202\membersection{wxMenu::FindItemForId}\label{wxmenufinditemforid}
203
eaaa6a06 204\constfunc{wxMenuItem*}{FindItemForId}{\param{int}{ id}}
a660d684
KB
205
206Finds the menu item object associated with the given menu item identifier.
207
208\wxheading{Parameters}
209
210\docparam{id}{Menu item identifier.}
211
212\wxheading{Return value}
213
214Returns the menu item object, or NULL if it is not found.
215
216\wxheading{See also}
217
218\helpref{wxMenu::FindItem}{wxmenufinditem}
219
220\membersection{wxMenu::GetHelpString}\label{wxmenugethelpstring}
221
eaaa6a06 222\constfunc{wxString}{GetHelpString}{\param{int}{ id}}
a660d684
KB
223
224Returns the help string associated with a menu item.
225
226\wxheading{Parameters}
227
228\docparam{id}{The menu item identifier.}
229
230\wxheading{Return value}
231
232The help string, or the empty string if there is no help string or the
233item was not found.
234
235\wxheading{See also}
236
237\helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenu::Append}{wxmenuappend}
238
239\membersection{wxMenu::GetLabel}\label{wxmenugetlabel}
240
eaaa6a06 241\constfunc{wxString}{GetLabel}{\param{int}{ id}}
a660d684
KB
242
243Returns a menu item label.
244
245\wxheading{Parameters}
246
247\docparam{id}{The menu item identifier.}
248
249\wxheading{Return value}
250
251The item label, or the empty string if the item was not found.
252
253\wxheading{See also}
254
255\helpref{wxMenu::SetLabel}{wxmenusetlabel}
256
257\membersection{wxMenu::GetTitle}\label{wxmenugettitle}
258
259\constfunc{wxString}{GetTitle}{\void}
260
261Returns the title of the menu.
262
263\wxheading{Remarks}
264
265This is relevant only to popup menus.
266
267\wxheading{See also}
268
269\helpref{wxMenu::SetTitle}{wxmenusettitle}
270
271\membersection{wxMenu::IsChecked}\label{wxmenuischecked}
272
eaaa6a06 273\constfunc{bool}{IsChecked}{\param{int}{ id}}
a660d684
KB
274
275Determines whether a menu item is checked.
276
277\wxheading{Parameters}
278
279\docparam{id}{The menu item identifier.}
280
281\wxheading{Return value}
282
283TRUE if the menu item is checked, FALSE otherwise.
284
285\wxheading{See also}
286
287\helpref{wxMenu::Check}{wxmenucheck}
288
289\membersection{wxMenu::IsEnabled}\label{wxmenuisenabled}
290
eaaa6a06 291\constfunc{bool}{IsEnabled}{\param{int}{ id}}
a660d684
KB
292
293Determines whether a menu item is enabled.
294
295\wxheading{Parameters}
296
297\docparam{id}{The menu item identifier.}
298
299\wxheading{Return value}
300
301TRUE if the menu item is enabled, FALSE otherwise.
302
303\wxheading{See also}
304
305\helpref{wxMenu::Enable}{wxmenuenable}
306
307\membersection{wxMenu::SetHelpString}\label{wxmenusethelpstring}
308
eaaa6a06 309\func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
a660d684
KB
310
311Sets an item's help string.
312
313\wxheading{Parameters}
314
315\docparam{id}{The menu item identifier.}
316
317\docparam{helpString}{The help string to set.}
318
319\wxheading{See also}
320
321\helpref{wxMenu::GetHelpString}{wxmenugethelpstring}
322
323\membersection{wxMenu::SetLabel}\label{wxmenusetlabel}
324
eaaa6a06 325\func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
a660d684
KB
326
327Sets the label of a menu item.
328
329\wxheading{Parameters}
330
331\docparam{id}{The menu item identifier.}
332
333\docparam{label}{The menu item label to set.}
334
335\wxheading{See also}
336
337\helpref{wxMenu::Append}{wxmenuappend}, \helpref{wxMenu::GetLabel}{wxmenugetlabel}
338
339\membersection{wxMenu::SetTitle}\label{wxmenusettitle}
340
341\func{void}{SetTitle}{\param{const wxString\& }{title}}
342
343Sets the title of the menu.
344
345\wxheading{Parameters}
346
347\docparam{title}{The title to set.}
348
349\wxheading{Remarks}
350
351This is relevant only to popup menus.
352
353\wxheading{See also}
354
355\helpref{wxMenu::SetTitle}{wxmenusettitle}
356
631f1bfe
JS
357\membersection{wxMenu::UpdateUI}\label{wxmenuupdateui}
358
359\constfunc{void}{UpdateUI}{\param{wxEvtHandler*}{ source = NULL}}
360
361Sends events to {\it source} (or owning window if NULL) to update the
362menu UI. This is called just before the menu is popped up with \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu}, but
363the application may call it at other times if required.
364
365\wxheading{See also}
366
367\helpref{wxUpdateUIEvent}{wxupdateuievent}
368
a660d684
KB
369\section{\class{wxMenuBar}}\label{wxmenubar}
370
371A menu bar is a series of menus accessible from the top of a frame.
372
373\wxheading{Derived from}
374
375\helpref{wxEvtHandler}{wxevthandler}\\
376\helpref{wxObject}{wxobject}
377
954b8ae6
JS
378\wxheading{Include files}
379
380<wx/menu.h>
381
a660d684
KB
382\wxheading{Event handling}
383
384To respond to a menu selection, provide a handler for EVT\_MENU, in the frame
385that contains the menu bar.
386
387\wxheading{See also}
388
389\helpref{wxMenu}{wxmenu}, \helpref{Event handling overview}{eventhandlingoverview}
390
391\latexignore{\rtfignore{\wxheading{Members}}}
392
393\membersection{wxMenuBar::wxMenuBar}\label{wxmenubarconstr}
394
395\func{void}{wxMenuBar}{\void}
396
397Default constructor.
398
eaaa6a06 399\func{void}{wxMenuBar}{\param{int}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}}
a660d684
KB
400
401Construct a menu bar from arrays of menus and titles.
402
403\wxheading{Parameters}
404
405\docparam{n}{The number of menus.}
406
407\docparam{menus}{An array of menus. Do not use this array again - it now belongs to the
408menu bar.}
409
410\docparam{titles}{An array of title strings. Deallocate this array after creating the menu bar.}
411
06d20283
RD
412\pythonnote{Only the default constructor is supported in wxPython.
413Use wxMenuBar.Append instead.}
414
415
a660d684
KB
416\membersection{wxMenuBar::\destruct{wxMenuBar}}
417
418\func{void}{\destruct{wxMenuBar}}{\void}
419
420Destructor, destroying the menu bar and removing it from the parent frame (if any).
421
422\membersection{wxMenuBar::Append}\label{wxmenubarappend}
423
424\func{void}{Append}{\param{wxMenu *}{menu}, \param{const wxString\& }{title}}
425
426Adds the item to the end of the menu bar.
427
428\wxheading{Parameters}
429
430\docparam{menu}{The menu to add. Do not deallocate this menu after calling {\bf Append}.}
431
432\docparam{title}{The title of the menu.}
433
434\membersection{wxMenuBar::Check}\label{wxmenubarcheck}
435
eaaa6a06 436\func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
a660d684
KB
437
438Checks or unchecks a menu item.
439
440\wxheading{Parameters}
441
442\docparam{id}{The menu item identifier.}
443
444\docparam{check}{If TRUE, checks the menu item, otherwise the item is unchecked.}
445
446\wxheading{Remarks}
447
448Only use this when the menu bar has been associated
449with a frame; otherwise, use the wxMenu equivalent call.
450
451\membersection{wxMenuBar::Enable}\label{wxmenubarenable}
452
eaaa6a06 453\func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
a660d684
KB
454
455Enables or disables (greys out) a menu item.
456
457\wxheading{Parameters}
458
459\docparam{id}{The menu item identifier.}
460
461\docparam{enable}{TRUE to enable the item, FALSE to disable it.}
462
463\wxheading{Remarks}
464
465Only use this when the menu bar has been
466associated with a frame; otherwise, use the wxMenu equivalent call.
467
468\membersection{wxMenuBar::EnableTop}\label{wxmenubarenabletop}
469
eaaa6a06 470\func{void}{EnableTop}{\param{int}{ pos}, \param{const bool}{ enable}}
a660d684
KB
471
472Enables or disables a whole menu.
473
474\wxheading{Parameters}
475
476\docparam{pos}{The position of the menu, starting from zero.}
477
478\docparam{enable}{TRUE to enable the menu, FALSE to disable it.}
479
480\wxheading{Remarks}
481
482Only use this when the menu bar has been
483associated with a frame.
484
485\membersection{wxMenuBar::FindMenuItem}\label{wxmenubarfindmenuitem}
486
487\constfunc{int}{FindMenuItem}{\param{const wxString\& }{menuString}, \param{const wxString\& }{itemString}}
488
489Finds the menu item id for a menu name/menu item string pair.
490
491\wxheading{Parameters}
492
493\docparam{menuString}{Menu title to find.}
494
495\docparam{itemString}{Item to find.}
496
497\wxheading{Return value}
498
499The menu item identifier, or -1 if none was found.
500
501\wxheading{Remarks}
502
503Any special menu codes are stripped out of source and target strings
504before matching.
505
506\membersection{wxMenuBar::FindItemById}\label{wxmenubarfinditembyid}
507
eaaa6a06 508\constfunc{wxMenuItem *}{FindItemById}{\param{int}{ id}}
a660d684
KB
509
510Finds the menu item object associated with the given menu item identifier,
511
512\wxheading{Parameters}
513
514\docparam{id}{Menu item identifier.}
515
516\wxheading{Return value}
517
518The found menu item object, or NULL if one was not found.
519
520\membersection{wxMenuBar::GetHelpString}\label{wxmenubargethelpstring}
521
eaaa6a06 522\constfunc{wxString}{GetHelpString}{\param{int}{ id}}
a660d684
KB
523
524Gets the help string associated with the menu item identifer.
525
526\wxheading{Parameters}
527
528\docparam{id}{The menu item identifier.}
529
530\wxheading{Return value}
531
532The help string, or the empty string if there was no help string or the menu item
533was not found.
534
535\wxheading{See also}
536
537\helpref{wxMenuBar::SetHelpString}{wxmenubarsethelpstring}
538
539\membersection{wxMenuBar::GetLabel}\label{wxmenubargetlabel}
540
eaaa6a06 541\constfunc{wxString}{GetLabel}{\param{int}{ id}}
a660d684
KB
542
543Gets the label associated with a menu item.
544
545\wxheading{Parameters}
546
547\docparam{id}{The menu item identifier.}
548
549\wxheading{Return value}
550
551The menu item label, or the empty string if the item was not found.
552
553\wxheading{Remarks}
554
555Use only after the menubar has been associated with a frame.
556
557\membersection{wxMenuBar::GetLabelTop}\label{wxmenubargetlabeltop}
558
eaaa6a06 559\constfunc{wxString}{GetLabelTop}{\param{int}{ pos}}
a660d684
KB
560
561Returns the label of a top-level menu.
562
563\wxheading{Parameters}
564
565\docparam{pos}{Position of the menu on the menu bar, starting from zero.}
566
567\wxheading{Return value}
568
569The menu label, or the empty string if the menu was not found.
570
571\wxheading{Remarks}
572
573Use only after the menubar has been associated with a frame.
574
575\wxheading{See also}
576
577\helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop}
578
7f555861
JS
579\membersection{wxMenuBar::GetMenu}\label{wxmenubargetmenu}
580
581\constfunc{wxMenu*}{GetMenu}{\param{int}{ menuIndex}}
582
583Returns the menu at {\it menuIndex} (zero-based).
584
585\membersection{wxMenuBar::GetMenuCount}\label{wxmenubargetmenucount}
586
587\constfunc{int}{GetMenuCount}{\void}
588
589Returns the number of menus in this menubar.
590
a660d684
KB
591\membersection{wxMenuBar::IsChecked}\label{wxmenubarischecked}
592
eaaa6a06 593\constfunc{bool}{IsChecked}{\param{int}{ id}}
a660d684
KB
594
595Determines whether an item is checked.
596
597\wxheading{Parameters}
598
599\docparam{id}{The menu item identifier.}
600
601\wxheading{Return value}
602
603TRUE if the item was found and is checked, FALSE otherwise.
604
605\membersection{wxMenuBar::IsEnabled}\label{wxmenubarisenabled}
606
eaaa6a06 607\constfunc{bool}{IsEnabled}{\param{int}{ id}}
a660d684
KB
608
609Determines whether an item is enabled.
610
611\wxheading{Parameters}
612
613\docparam{id}{The menu item identifier.}
614
615\wxheading{Return value}
616
617TRUE if the item was found and is enabled, FALSE otherwise.
618
619\membersection{wxMenuBar::SetHelpString}\label{wxmenubarsethelpstring}
620
eaaa6a06 621\func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
a660d684
KB
622
623Sets the help string associated with a menu item.
624
625\wxheading{Parameters}
626
627\docparam{id}{Menu item identifier.}
628
629\docparam{helpString}{Help string to associate with the menu item.}
630
631\wxheading{See also}
632
633\helpref{wxMenuBar::GetHelpString}{wxmenubargethelpstring}
634
635\membersection{wxMenuBar::SetLabel}\label{wxmenubarsetlabel}
636
eaaa6a06 637\func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
a660d684
KB
638
639Sets the label of a menu item.
640
641\wxheading{Parameters}
642
643\docparam{id}{Menu item identifier.}
644
645\docparam{label}{Menu item label.}
646
647\wxheading{Remarks}
648
649Use only after the menubar has been associated with a frame.
650
651\wxheading{See also}
652
653\helpref{wxMenuBar::GetLabel}{wxmenubargetlabel}
654
655\membersection{wxMenuBar::SetLabelTop}\label{wxmenubarsetlabeltop}
656
eaaa6a06 657\func{void}{SetLabelTop}{\param{int}{ pos}, \param{const wxString\& }{label}}
a660d684
KB
658
659Sets the label of a top-level menu.
660
661\wxheading{Parameters}
662
663\docparam{pos}{The position of a menu on the menu bar, starting from zero.}
664
665\docparam{label}{The menu label.}
666
667\wxheading{Remarks}
668
669Use only after the menubar has been associated with a frame.
670
671\wxheading{See also}
672
673\helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop}
674