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