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