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