]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/menu.tex
wxMenu::Insert() seems to work, bug in wxMenuBase::Insert() is corrected
[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
b1462dfa 44\func{}{wxMenu}{\param{const wxString\& }{title = ""}, \param{long}{ style = 0}}
a660d684
KB
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
4e986502
KB
52\docparam{style}{If set to \tt{wxMENU_TEAROFF}, the menu will be detachable.}
53
06d20283 54
407f3681 55\func{}{wxMenu}{\param{long}{ style}}
4e986502
KB
56
57Constructs a wxMenu object.
58
59\wxheading{Parameters}
407f3681 60
4e986502
KB
61\docparam{style}{If set to \tt{wxMENU_TEAROFF}, the menu will be detachable.}
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\pythonnote{In place of a single overloaded method name, wxPython
121implements the following methods:\par
122\indented{2cm}{\begin{twocollist}
123\twocolitem{\bf{Append(id, string, helpStr="", checkable=FALSE)}}{}
124\twocolitem{\bf{AppendMenu(id, string, aMenu, helpStr="")}}{}
125\twocolitem{\bf{AppendItem(aMenuItem)}}{}
126\end{twocollist}}
127}
128
a660d684
KB
129\membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator}
130
131\func{void}{AppendSeparator}{\void}
132
133Adds a separator to the end of the menu.
134
135\wxheading{See also}
136
137\helpref{wxMenu::Append}{wxmenuappend}
138
139\membersection{wxMenu::Break}\label{wxmenubreak}
140
141\func{void}{Break}{\void}
142
143Inserts a break in a menu, causing the next appended item to appear in a new column.
144
145\membersection{wxMenu::Check}\label{wxmenucheck}
146
eaaa6a06 147\func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
a660d684
KB
148
149Checks or unchecks the menu item.
150
151\wxheading{Parameters}
152
153\docparam{id}{The menu item identifier.}
154
155\docparam{check}{If TRUE, the item will be checked, otherwise it will be unchecked.}
156
157\wxheading{See also}
158
159\helpref{wxMenu::IsChecked}{wxmenuischecked}
160
fc9c7c09
RR
161\membersection{wxMenu::Delete}\label{wxmenudelete}
162
163\func{void}{Delete}{\param{int }{id}}
164
165Deletes the menu item from the menu.
166
167\wxheading{Parameters}
168
169\docparam{id}{Menu item to be deleted.}
170
171\wxheading{Remarks}
172
173Does not delete a sub menu, if any.
174
175\wxheading{See also}
176
177\helpref{wxMenu::FindItemForId}{wxmenufinditemforid}
178
a660d684
KB
179\membersection{wxMenu::Enable}\label{wxmenuenable}
180
eaaa6a06 181\func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
a660d684
KB
182
183Enables or disables (greys out) a menu item.
184
185\wxheading{Parameters}
186
187\docparam{id}{The menu item identifier.}
188
189\docparam{enable}{TRUE to enable the menu item, FALSE to disable it.}
190
191\wxheading{See also}
192
193\helpref{wxMenu::IsEnabled}{wxmenuisenabled}
194
195\membersection{wxMenu::FindItem}\label{wxmenufinditem}
196
197\constfunc{int}{FindItem}{\param{const wxString\& }{itemString}}
198
199Finds the menu item id for a menu item string.
200
201\wxheading{Parameters}
202
203\docparam{itemString}{Menu item string to find.}
204
205\wxheading{Return value}
206
fc9c7c09 207Menu item identifier, or wxNOT_FOUND if none is found.
a660d684
KB
208
209\wxheading{Remarks}
210
211Any special menu codes are stripped out of source and target strings
212before matching.
213
214\wxheading{See also}
215
216\helpref{wxMenu::FindItemForId}{wxmenufinditemforid}
217
6776a0b2 218\membersection{wxMenu::FindItemForId}\label{wxmenufinditemforid}
a660d684 219
fc9c7c09 220\constfunc{wxMenuItem*}{FindItemForId}{\param{int}{ id}}
407f3681 221
fc9c7c09 222\constfunc{wxMenuItem*}{FindItem}{\param{int}{ id}}
a660d684
KB
223
224Finds the menu item object associated with the given menu item identifier.
225
226\wxheading{Parameters}
227
228\docparam{id}{Menu item identifier.}
229
230\wxheading{Return value}
231
232Returns the menu item object, or NULL if it is not found.
233
234\wxheading{See also}
235
236\helpref{wxMenu::FindItem}{wxmenufinditem}
237
238\membersection{wxMenu::GetHelpString}\label{wxmenugethelpstring}
239
eaaa6a06 240\constfunc{wxString}{GetHelpString}{\param{int}{ id}}
a660d684
KB
241
242Returns the help string associated with a menu item.
243
244\wxheading{Parameters}
245
246\docparam{id}{The menu item identifier.}
247
248\wxheading{Return value}
249
250The help string, or the empty string if there is no help string or the
251item was not found.
252
253\wxheading{See also}
254
255\helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenu::Append}{wxmenuappend}
256
257\membersection{wxMenu::GetLabel}\label{wxmenugetlabel}
258
eaaa6a06 259\constfunc{wxString}{GetLabel}{\param{int}{ id}}
a660d684
KB
260
261Returns a menu item label.
262
263\wxheading{Parameters}
264
265\docparam{id}{The menu item identifier.}
266
267\wxheading{Return value}
268
269The item label, or the empty string if the item was not found.
270
271\wxheading{See also}
272
273\helpref{wxMenu::SetLabel}{wxmenusetlabel}
274
275\membersection{wxMenu::GetTitle}\label{wxmenugettitle}
276
277\constfunc{wxString}{GetTitle}{\void}
278
279Returns the title of the menu.
280
281\wxheading{Remarks}
282
283This is relevant only to popup menus.
284
285\wxheading{See also}
286
287\helpref{wxMenu::SetTitle}{wxmenusettitle}
288
289\membersection{wxMenu::IsChecked}\label{wxmenuischecked}
290
eaaa6a06 291\constfunc{bool}{IsChecked}{\param{int}{ id}}
a660d684
KB
292
293Determines whether a menu item is checked.
294
295\wxheading{Parameters}
296
297\docparam{id}{The menu item identifier.}
298
299\wxheading{Return value}
300
301TRUE if the menu item is checked, FALSE otherwise.
302
303\wxheading{See also}
304
305\helpref{wxMenu::Check}{wxmenucheck}
306
307\membersection{wxMenu::IsEnabled}\label{wxmenuisenabled}
308
eaaa6a06 309\constfunc{bool}{IsEnabled}{\param{int}{ id}}
a660d684
KB
310
311Determines whether a menu item is enabled.
312
313\wxheading{Parameters}
314
315\docparam{id}{The menu item identifier.}
316
317\wxheading{Return value}
318
319TRUE if the menu item is enabled, FALSE otherwise.
320
321\wxheading{See also}
322
323\helpref{wxMenu::Enable}{wxmenuenable}
324
325\membersection{wxMenu::SetHelpString}\label{wxmenusethelpstring}
326
eaaa6a06 327\func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
a660d684
KB
328
329Sets an item's help string.
330
331\wxheading{Parameters}
332
333\docparam{id}{The menu item identifier.}
334
335\docparam{helpString}{The help string to set.}
336
337\wxheading{See also}
338
339\helpref{wxMenu::GetHelpString}{wxmenugethelpstring}
340
341\membersection{wxMenu::SetLabel}\label{wxmenusetlabel}
342
eaaa6a06 343\func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
a660d684
KB
344
345Sets the label of a menu item.
346
347\wxheading{Parameters}
348
349\docparam{id}{The menu item identifier.}
350
351\docparam{label}{The menu item label to set.}
352
353\wxheading{See also}
354
355\helpref{wxMenu::Append}{wxmenuappend}, \helpref{wxMenu::GetLabel}{wxmenugetlabel}
356
357\membersection{wxMenu::SetTitle}\label{wxmenusettitle}
358
359\func{void}{SetTitle}{\param{const wxString\& }{title}}
360
361Sets the title of the menu.
362
363\wxheading{Parameters}
364
365\docparam{title}{The title to set.}
366
367\wxheading{Remarks}
368
369This is relevant only to popup menus.
370
371\wxheading{See also}
372
373\helpref{wxMenu::SetTitle}{wxmenusettitle}
374
631f1bfe
JS
375\membersection{wxMenu::UpdateUI}\label{wxmenuupdateui}
376
377\constfunc{void}{UpdateUI}{\param{wxEvtHandler*}{ source = NULL}}
378
379Sends events to {\it source} (or owning window if NULL) to update the
380menu UI. This is called just before the menu is popped up with \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu}, but
381the application may call it at other times if required.
382
383\wxheading{See also}
384
385\helpref{wxUpdateUIEvent}{wxupdateuievent}
386
a660d684
KB
387\section{\class{wxMenuBar}}\label{wxmenubar}
388
389A menu bar is a series of menus accessible from the top of a frame.
390
391\wxheading{Derived from}
392
393\helpref{wxEvtHandler}{wxevthandler}\\
394\helpref{wxObject}{wxobject}
395
954b8ae6
JS
396\wxheading{Include files}
397
398<wx/menu.h>
399
a660d684
KB
400\wxheading{Event handling}
401
402To respond to a menu selection, provide a handler for EVT\_MENU, in the frame
e702ff0f
JS
403that contains the menu bar. If you have a toolbar which uses the same identifiers
404as your EVT\_MENU entries, events from the toolbar will also be processed by your
405EVT\_MENU event handlers.
406
407Note that menu commands (and UI update events for menus) are first sent to
408the focus window within the frame. If no window within the frame has the focus,
409then the events are sent directly to the frame. This allows command and UI update
410handling to be processed by specific windows and controls, and not necessarily
411by the application frame.
a660d684
KB
412
413\wxheading{See also}
414
415\helpref{wxMenu}{wxmenu}, \helpref{Event handling overview}{eventhandlingoverview}
416
417\latexignore{\rtfignore{\wxheading{Members}}}
418
419\membersection{wxMenuBar::wxMenuBar}\label{wxmenubarconstr}
420
421\func{void}{wxMenuBar}{\void}
422
423Default constructor.
424
eaaa6a06 425\func{void}{wxMenuBar}{\param{int}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}}
a660d684
KB
426
427Construct a menu bar from arrays of menus and titles.
428
429\wxheading{Parameters}
430
431\docparam{n}{The number of menus.}
432
433\docparam{menus}{An array of menus. Do not use this array again - it now belongs to the
434menu bar.}
435
436\docparam{titles}{An array of title strings. Deallocate this array after creating the menu bar.}
437
06d20283
RD
438\pythonnote{Only the default constructor is supported in wxPython.
439Use wxMenuBar.Append instead.}
440
a660d684
KB
441\membersection{wxMenuBar::\destruct{wxMenuBar}}
442
443\func{void}{\destruct{wxMenuBar}}{\void}
444
445Destructor, destroying the menu bar and removing it from the parent frame (if any).
446
447\membersection{wxMenuBar::Append}\label{wxmenubarappend}
448
449\func{void}{Append}{\param{wxMenu *}{menu}, \param{const wxString\& }{title}}
450
451Adds the item to the end of the menu bar.
452
453\wxheading{Parameters}
454
455\docparam{menu}{The menu to add. Do not deallocate this menu after calling {\bf Append}.}
456
457\docparam{title}{The title of the menu.}
458
459\membersection{wxMenuBar::Check}\label{wxmenubarcheck}
460
eaaa6a06 461\func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
a660d684
KB
462
463Checks or unchecks a menu item.
464
465\wxheading{Parameters}
466
467\docparam{id}{The menu item identifier.}
468
469\docparam{check}{If TRUE, checks the menu item, otherwise the item is unchecked.}
470
471\wxheading{Remarks}
472
473Only use this when the menu bar has been associated
474with a frame; otherwise, use the wxMenu equivalent call.
475
476\membersection{wxMenuBar::Enable}\label{wxmenubarenable}
477
eaaa6a06 478\func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
a660d684
KB
479
480Enables or disables (greys out) a menu item.
481
482\wxheading{Parameters}
483
484\docparam{id}{The menu item identifier.}
485
486\docparam{enable}{TRUE to enable the item, FALSE to disable it.}
487
488\wxheading{Remarks}
489
490Only use this when the menu bar has been
491associated with a frame; otherwise, use the wxMenu equivalent call.
492
493\membersection{wxMenuBar::EnableTop}\label{wxmenubarenabletop}
494
eaaa6a06 495\func{void}{EnableTop}{\param{int}{ pos}, \param{const bool}{ enable}}
a660d684
KB
496
497Enables or disables a whole menu.
498
499\wxheading{Parameters}
500
501\docparam{pos}{The position of the menu, starting from zero.}
502
503\docparam{enable}{TRUE to enable the menu, FALSE to disable it.}
504
505\wxheading{Remarks}
506
507Only use this when the menu bar has been
508associated with a frame.
509
510\membersection{wxMenuBar::FindMenuItem}\label{wxmenubarfindmenuitem}
511
512\constfunc{int}{FindMenuItem}{\param{const wxString\& }{menuString}, \param{const wxString\& }{itemString}}
513
514Finds the menu item id for a menu name/menu item string pair.
515
516\wxheading{Parameters}
517
518\docparam{menuString}{Menu title to find.}
519
520\docparam{itemString}{Item to find.}
521
522\wxheading{Return value}
523
fc9c7c09 524The menu item identifier, or wxNOT_FOUND if none was found.
a660d684
KB
525
526\wxheading{Remarks}
527
528Any special menu codes are stripped out of source and target strings
529before matching.
530
fc9c7c09 531\membersection{wxMenuBar::FindItem}\label{wxmenubarfinditem}
a660d684 532
407f3681 533\constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu}{ **menu = NULL}}
a660d684 534
fc9c7c09 535Finds the menu item object associated with the given menu item identifier.
a660d684
KB
536
537\wxheading{Parameters}
538
539\docparam{id}{Menu item identifier.}
407f3681 540
fc9c7c09 541\docparam{menu}{If not NULL, menu will get set to the associated menu.}
a660d684
KB
542
543\wxheading{Return value}
544
545The found menu item object, or NULL if one was not found.
546
547\membersection{wxMenuBar::GetHelpString}\label{wxmenubargethelpstring}
548
eaaa6a06 549\constfunc{wxString}{GetHelpString}{\param{int}{ id}}
a660d684
KB
550
551Gets the help string associated with the menu item identifer.
552
553\wxheading{Parameters}
554
555\docparam{id}{The menu item identifier.}
556
557\wxheading{Return value}
558
559The help string, or the empty string if there was no help string or the menu item
560was not found.
561
562\wxheading{See also}
563
564\helpref{wxMenuBar::SetHelpString}{wxmenubarsethelpstring}
565
566\membersection{wxMenuBar::GetLabel}\label{wxmenubargetlabel}
567
eaaa6a06 568\constfunc{wxString}{GetLabel}{\param{int}{ id}}
a660d684
KB
569
570Gets the label associated with a menu item.
571
572\wxheading{Parameters}
573
574\docparam{id}{The menu item identifier.}
575
576\wxheading{Return value}
577
578The menu item label, or the empty string if the item was not found.
579
580\wxheading{Remarks}
581
582Use only after the menubar has been associated with a frame.
583
584\membersection{wxMenuBar::GetLabelTop}\label{wxmenubargetlabeltop}
585
eaaa6a06 586\constfunc{wxString}{GetLabelTop}{\param{int}{ pos}}
a660d684
KB
587
588Returns the label of a top-level menu.
589
590\wxheading{Parameters}
591
592\docparam{pos}{Position of the menu on the menu bar, starting from zero.}
593
594\wxheading{Return value}
595
596The menu label, or the empty string if the menu was not found.
597
598\wxheading{Remarks}
599
600Use only after the menubar has been associated with a frame.
601
602\wxheading{See also}
603
604\helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop}
605
7f555861
JS
606\membersection{wxMenuBar::GetMenu}\label{wxmenubargetmenu}
607
608\constfunc{wxMenu*}{GetMenu}{\param{int}{ menuIndex}}
609
610Returns the menu at {\it menuIndex} (zero-based).
611
612\membersection{wxMenuBar::GetMenuCount}\label{wxmenubargetmenucount}
613
614\constfunc{int}{GetMenuCount}{\void}
615
616Returns the number of menus in this menubar.
617
a660d684
KB
618\membersection{wxMenuBar::IsChecked}\label{wxmenubarischecked}
619
eaaa6a06 620\constfunc{bool}{IsChecked}{\param{int}{ id}}
a660d684
KB
621
622Determines whether an item is checked.
623
624\wxheading{Parameters}
625
626\docparam{id}{The menu item identifier.}
627
628\wxheading{Return value}
629
630TRUE if the item was found and is checked, FALSE otherwise.
631
632\membersection{wxMenuBar::IsEnabled}\label{wxmenubarisenabled}
633
eaaa6a06 634\constfunc{bool}{IsEnabled}{\param{int}{ id}}
a660d684
KB
635
636Determines whether an item is enabled.
637
638\wxheading{Parameters}
639
640\docparam{id}{The menu item identifier.}
641
642\wxheading{Return value}
643
644TRUE if the item was found and is enabled, FALSE otherwise.
645
63dcfc15
PA
646\membersection{wxMenuBar::Refresh}\label{wxmenubarrefresh}
647
648\func{void}{Refresh}{\void}
649
650Redraw the menu bar
651
a660d684
KB
652\membersection{wxMenuBar::SetHelpString}\label{wxmenubarsethelpstring}
653
eaaa6a06 654\func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
a660d684
KB
655
656Sets the help string associated with a menu item.
657
658\wxheading{Parameters}
659
660\docparam{id}{Menu item identifier.}
661
662\docparam{helpString}{Help string to associate with the menu item.}
663
664\wxheading{See also}
665
666\helpref{wxMenuBar::GetHelpString}{wxmenubargethelpstring}
667
668\membersection{wxMenuBar::SetLabel}\label{wxmenubarsetlabel}
669
eaaa6a06 670\func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
a660d684
KB
671
672Sets the label of a menu item.
673
674\wxheading{Parameters}
675
676\docparam{id}{Menu item identifier.}
677
678\docparam{label}{Menu item label.}
679
680\wxheading{Remarks}
681
682Use only after the menubar has been associated with a frame.
683
684\wxheading{See also}
685
686\helpref{wxMenuBar::GetLabel}{wxmenubargetlabel}
687
688\membersection{wxMenuBar::SetLabelTop}\label{wxmenubarsetlabeltop}
689
eaaa6a06 690\func{void}{SetLabelTop}{\param{int}{ pos}, \param{const wxString\& }{label}}
a660d684
KB
691
692Sets the label of a top-level menu.
693
694\wxheading{Parameters}
695
696\docparam{pos}{The position of a menu on the menu bar, starting from zero.}
697
698\docparam{label}{The menu label.}
699
700\wxheading{Remarks}
701
702Use only after the menubar has been associated with a frame.
703
704\wxheading{See also}
705
706\helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop}
707