]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/menu.tex
Various; wxRadioButton::GetValue corrected
[wxWidgets.git] / docs / latex / wx / menu.tex
1 \section{\class{wxMenu}}\label{wxmenu}
2
3 A menu is a popup (or pull down) list of items, one of which may be
4 selected before the menu goes away (clicking elsewhere dismisses the
5 menu). Menus may be used to construct either menu bars or popup menus.
6
7 A menu item has an integer ID associated with it which can be used to
8 identify 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
17 If the menu is part of a menubar, then \helpref{wxMenuBar}{wxmenubar} event processing is used.
18
19 With 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.
24 The callback takes a reference to the menu, and a reference to a \helpref{wxCommandEvent}{wxcommandevent}.
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
28 this 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
42 Constructs 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
54 Destructor, destroying the menu.
55
56 \membersection{wxMenu::Append}\label{wxmenuappend}
57
58 \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
59 \param{const bool}{ checkable = FALSE}}
60
61 Adds a string item to the end of the menu.
62
63 \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{wxMenu *}{subMenu},\rtfsp
64 \param{const wxString\& }{helpString = ""}}
65
66 Adds a pull-right submenu to the end of the menu.
67
68 \func{void}{Append}{\param{wxMenuItem*}{ menuItem}}
69
70 Adds a menu item object. You can specify various extra properties of a menu item this way,
71 such 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.
84 By default, \helpref{wxFrame::OnMenuHighlight}{wxframeonmenuhighlight} displays
85 this string in the status line.}
86
87 \docparam{menuItem}{A menuitem object. It will be owned by the wxMenu object after this function
88 is called, so do not delete it yourself.}
89
90 \wxheading{Remarks}
91
92 This command can be used after the menu has been shown, as well as on initial
93 creation 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
104 Adds 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
114 Inserts a break in a menu, causing the next appended item to appear in a new column.
115
116 \membersection{wxMenu::Check}\label{wxmenucheck}
117
118 \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
119
120 Checks 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
134 \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
135
136 Enables 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
152 Finds 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
160 Menu item identifier, or -1 if none is found.
161
162 \wxheading{Remarks}
163
164 Any special menu codes are stripped out of source and target strings
165 before matching.
166
167 \wxheading{See also}
168
169 \helpref{wxMenu::FindItemForId}{wxmenufinditemforid}
170
171 \membersection{wxMenu::FindItemForId}\label{wxmenufinditemforid}
172
173 \constfunc{wxMenuItem*}{FindItemForId}{\param{int}{ id}}
174
175 Finds 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
183 Returns 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
191 \constfunc{wxString}{GetHelpString}{\param{int}{ id}}
192
193 Returns 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
201 The help string, or the empty string if there is no help string or the
202 item 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
210 \constfunc{wxString}{GetLabel}{\param{int}{ id}}
211
212 Returns a menu item label.
213
214 \wxheading{Parameters}
215
216 \docparam{id}{The menu item identifier.}
217
218 \wxheading{Return value}
219
220 The 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
230 Returns the title of the menu.
231
232 \wxheading{Remarks}
233
234 This 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
242 \constfunc{bool}{IsChecked}{\param{int}{ id}}
243
244 Determines whether a menu item is checked.
245
246 \wxheading{Parameters}
247
248 \docparam{id}{The menu item identifier.}
249
250 \wxheading{Return value}
251
252 TRUE 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
260 \constfunc{bool}{IsEnabled}{\param{int}{ id}}
261
262 Determines whether a menu item is enabled.
263
264 \wxheading{Parameters}
265
266 \docparam{id}{The menu item identifier.}
267
268 \wxheading{Return value}
269
270 TRUE 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
278 \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
279
280 Sets 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
294 \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
295
296 Sets 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
312 Sets the title of the menu.
313
314 \wxheading{Parameters}
315
316 \docparam{title}{The title to set.}
317
318 \wxheading{Remarks}
319
320 This 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
328 A 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
337 To respond to a menu selection, provide a handler for EVT\_MENU, in the frame
338 that 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
350 Default constructor.
351
352 \func{void}{wxMenuBar}{\param{int}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}}
353
354 Construct 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
361 menu 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
369 Destructor, 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
375 Adds 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
385 \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
386
387 Checks 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
397 Only use this when the menu bar has been associated
398 with a frame; otherwise, use the wxMenu equivalent call.
399
400 \membersection{wxMenuBar::Enable}\label{wxmenubarenable}
401
402 \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
403
404 Enables 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
414 Only use this when the menu bar has been
415 associated with a frame; otherwise, use the wxMenu equivalent call.
416
417 \membersection{wxMenuBar::EnableTop}\label{wxmenubarenabletop}
418
419 \func{void}{EnableTop}{\param{int}{ pos}, \param{const bool}{ enable}}
420
421 Enables 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
431 Only use this when the menu bar has been
432 associated with a frame.
433
434 \membersection{wxMenuBar::FindMenuItem}\label{wxmenubarfindmenuitem}
435
436 \constfunc{int}{FindMenuItem}{\param{const wxString\& }{menuString}, \param{const wxString\& }{itemString}}
437
438 Finds 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
448 The menu item identifier, or -1 if none was found.
449
450 \wxheading{Remarks}
451
452 Any special menu codes are stripped out of source and target strings
453 before matching.
454
455 \membersection{wxMenuBar::FindItemById}\label{wxmenubarfinditembyid}
456
457 \constfunc{wxMenuItem *}{FindItemById}{\param{int}{ id}}
458
459 Finds 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
467 The found menu item object, or NULL if one was not found.
468
469 \membersection{wxMenuBar::GetHelpString}\label{wxmenubargethelpstring}
470
471 \constfunc{wxString}{GetHelpString}{\param{int}{ id}}
472
473 Gets 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
481 The help string, or the empty string if there was no help string or the menu item
482 was not found.
483
484 \wxheading{See also}
485
486 \helpref{wxMenuBar::SetHelpString}{wxmenubarsethelpstring}
487
488 \membersection{wxMenuBar::GetLabel}\label{wxmenubargetlabel}
489
490 \constfunc{wxString}{GetLabel}{\param{int}{ id}}
491
492 Gets 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
500 The menu item label, or the empty string if the item was not found.
501
502 \wxheading{Remarks}
503
504 Use only after the menubar has been associated with a frame.
505
506 \membersection{wxMenuBar::GetLabelTop}\label{wxmenubargetlabeltop}
507
508 \constfunc{wxString}{GetLabelTop}{\param{int}{ pos}}
509
510 Returns 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
518 The menu label, or the empty string if the menu was not found.
519
520 \wxheading{Remarks}
521
522 Use only after the menubar has been associated with a frame.
523
524 \wxheading{See also}
525
526 \helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop}
527
528 \membersection{wxMenuBar::GetMenu}\label{wxmenubargetmenu}
529
530 \constfunc{wxMenu*}{GetMenu}{\param{int}{ menuIndex}}
531
532 Returns the menu at {\it menuIndex} (zero-based).
533
534 \membersection{wxMenuBar::GetMenuCount}\label{wxmenubargetmenucount}
535
536 \constfunc{int}{GetMenuCount}{\void}
537
538 Returns the number of menus in this menubar.
539
540 \membersection{wxMenuBar::IsChecked}\label{wxmenubarischecked}
541
542 \constfunc{bool}{IsChecked}{\param{int}{ id}}
543
544 Determines whether an item is checked.
545
546 \wxheading{Parameters}
547
548 \docparam{id}{The menu item identifier.}
549
550 \wxheading{Return value}
551
552 TRUE if the item was found and is checked, FALSE otherwise.
553
554 \membersection{wxMenuBar::IsEnabled}\label{wxmenubarisenabled}
555
556 \constfunc{bool}{IsEnabled}{\param{int}{ id}}
557
558 Determines whether an item is enabled.
559
560 \wxheading{Parameters}
561
562 \docparam{id}{The menu item identifier.}
563
564 \wxheading{Return value}
565
566 TRUE if the item was found and is enabled, FALSE otherwise.
567
568 \membersection{wxMenuBar::SetHelpString}\label{wxmenubarsethelpstring}
569
570 \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
571
572 Sets 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
586 \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
587
588 Sets 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
598 Use 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
606 \func{void}{SetLabelTop}{\param{int}{ pos}, \param{const wxString\& }{label}}
607
608 Sets 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
618 Use only after the menubar has been associated with a frame.
619
620 \wxheading{See also}
621
622 \helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop}
623