]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/menu.tex
Documented wxStopWatch and wxToolBar::AddControl().
[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 = ""}, \param{long}{ style = 0}}
45
46 Constructs a wxMenu object.
47
48 \wxheading{Parameters}
49
50 \docparam{title}{A title for the popup menu: the empty string denotes no title.}
51
52 \docparam{style}{If set to \tt{wxMENU_TEAROFF}, the menu will be detachable.}
53
54
55 \func{}{wxMenu}{\param{long}{ style}}
56
57 Constructs a wxMenu object.
58
59 \wxheading{Parameters}
60
61 \docparam{style}{If set to \tt{wxMENU_TEAROFF}, the menu will be detachable.}
62
63 \membersection{wxMenu::\destruct{wxMenu}}
64
65 \func{}{\destruct{wxMenu}}{\void}
66
67 Destructor, destroying the menu.
68
69 Note: under Motif, a popup menu must have a valid parent (the window
70 it was last popped up on) when being destroyed. Therefore, make sure
71 you delete or re-use the popup menu {\it before} destroying the
72 parent window. Re-use in this context means popping up the menu on
73 a different window from last time, which causes an implicit destruction
74 and recreation of internal data structures.
75
76 \membersection{wxMenu::Append}\label{wxmenuappend}
77
78 \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
79 \param{const bool}{ checkable = FALSE}}
80
81 Adds a string item to the end of the menu.
82
83 \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{wxMenu *}{subMenu},\rtfsp
84 \param{const wxString\& }{helpString = ""}}
85
86 Adds a pull-right submenu to the end of the menu.
87
88 \func{void}{Append}{\param{wxMenuItem*}{ menuItem}}
89
90 Adds a menu item object. You can specify various extra properties of a menu item this way,
91 such 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.
104 By default, \helpref{wxFrame::OnMenuHighlight}{wxframeonmenuhighlight} displays
105 this string in the status line.}
106
107 \docparam{menuItem}{A menuitem object. It will be owned by the wxMenu object after this function
108 is called, so do not delete it yourself.}
109
110 \wxheading{Remarks}
111
112 This command can be used after the menu has been shown, as well as on initial
113 creation 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
120 \pythonnote{In place of a single overloaded method name, wxPython
121 implements 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
129 \membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator}
130
131 \func{void}{AppendSeparator}{\void}
132
133 Adds 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
143 Inserts a break in a menu, causing the next appended item to appear in a new column.
144
145 \membersection{wxMenu::Check}\label{wxmenucheck}
146
147 \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
148
149 Checks 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
161 \membersection{wxMenu::Delete}\label{wxmenudelete}
162
163 \func{void}{Delete}{\param{int }{id}}
164
165 Deletes the menu item from the menu.
166
167 \wxheading{Parameters}
168
169 \docparam{id}{Menu item to be deleted.}
170
171 \wxheading{Remarks}
172
173 Does not delete a sub menu, if any.
174
175 \wxheading{See also}
176
177 \helpref{wxMenu::FindItemForId}{wxmenufinditemforid}
178
179 \membersection{wxMenu::Enable}\label{wxmenuenable}
180
181 \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
182
183 Enables 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
199 Finds 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
207 Menu item identifier, or wxNOT_FOUND if none is found.
208
209 \wxheading{Remarks}
210
211 Any special menu codes are stripped out of source and target strings
212 before matching.
213
214 \wxheading{See also}
215
216 \helpref{wxMenu::FindItemForId}{wxmenufinditemforid}
217
218 \membersection{wxMenu::FindItemForId}\label{wxmenufinditemforid}
219
220 \constfunc{wxMenuItem*}{FindItemForId}{\param{int}{ id}}
221
222 \constfunc{wxMenuItem*}{FindItem}{\param{int}{ id}}
223
224 Finds 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
232 Returns 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
240 \constfunc{wxString}{GetHelpString}{\param{int}{ id}}
241
242 Returns 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
250 The help string, or the empty string if there is no help string or the
251 item 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
259 \constfunc{wxString}{GetLabel}{\param{int}{ id}}
260
261 Returns a menu item label.
262
263 \wxheading{Parameters}
264
265 \docparam{id}{The menu item identifier.}
266
267 \wxheading{Return value}
268
269 The 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
279 Returns the title of the menu.
280
281 \wxheading{Remarks}
282
283 This 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
291 \constfunc{bool}{IsChecked}{\param{int}{ id}}
292
293 Determines whether a menu item is checked.
294
295 \wxheading{Parameters}
296
297 \docparam{id}{The menu item identifier.}
298
299 \wxheading{Return value}
300
301 TRUE 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
309 \constfunc{bool}{IsEnabled}{\param{int}{ id}}
310
311 Determines whether a menu item is enabled.
312
313 \wxheading{Parameters}
314
315 \docparam{id}{The menu item identifier.}
316
317 \wxheading{Return value}
318
319 TRUE 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
327 \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
328
329 Sets 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
343 \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
344
345 Sets 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
361 Sets the title of the menu.
362
363 \wxheading{Parameters}
364
365 \docparam{title}{The title to set.}
366
367 \wxheading{Remarks}
368
369 This is relevant only to popup menus.
370
371 \wxheading{See also}
372
373 \helpref{wxMenu::SetTitle}{wxmenusettitle}
374
375 \membersection{wxMenu::UpdateUI}\label{wxmenuupdateui}
376
377 \constfunc{void}{UpdateUI}{\param{wxEvtHandler*}{ source = NULL}}
378
379 Sends events to {\it source} (or owning window if NULL) to update the
380 menu UI. This is called just before the menu is popped up with \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu}, but
381 the application may call it at other times if required.
382
383 \wxheading{See also}
384
385 \helpref{wxUpdateUIEvent}{wxupdateuievent}
386
387 \section{\class{wxMenuBar}}\label{wxmenubar}
388
389 A 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
396 \wxheading{Include files}
397
398 <wx/menu.h>
399
400 \wxheading{Event handling}
401
402 To respond to a menu selection, provide a handler for EVT\_MENU, in the frame
403 that contains the menu bar. If you have a toolbar which uses the same identifiers
404 as your EVT\_MENU entries, events from the toolbar will also be processed by your
405 EVT\_MENU event handlers.
406
407 Note that menu commands (and UI update events for menus) are first sent to
408 the focus window within the frame. If no window within the frame has the focus,
409 then the events are sent directly to the frame. This allows command and UI update
410 handling to be processed by specific windows and controls, and not necessarily
411 by the application frame.
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
423 Default constructor.
424
425 \func{void}{wxMenuBar}{\param{int}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}}
426
427 Construct 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
434 menu bar.}
435
436 \docparam{titles}{An array of title strings. Deallocate this array after creating the menu bar.}
437
438 \pythonnote{Only the default constructor is supported in wxPython.
439 Use wxMenuBar.Append instead.}
440
441 \membersection{wxMenuBar::\destruct{wxMenuBar}}
442
443 \func{void}{\destruct{wxMenuBar}}{\void}
444
445 Destructor, 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
451 Adds 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
461 \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
462
463 Checks 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
473 Only use this when the menu bar has been associated
474 with a frame; otherwise, use the wxMenu equivalent call.
475
476 \membersection{wxMenuBar::Enable}\label{wxmenubarenable}
477
478 \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
479
480 Enables 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
490 Only use this when the menu bar has been
491 associated with a frame; otherwise, use the wxMenu equivalent call.
492
493 \membersection{wxMenuBar::EnableTop}\label{wxmenubarenabletop}
494
495 \func{void}{EnableTop}{\param{int}{ pos}, \param{const bool}{ enable}}
496
497 Enables 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
507 Only use this when the menu bar has been
508 associated with a frame.
509
510 \membersection{wxMenuBar::FindMenuItem}\label{wxmenubarfindmenuitem}
511
512 \constfunc{int}{FindMenuItem}{\param{const wxString\& }{menuString}, \param{const wxString\& }{itemString}}
513
514 Finds 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
524 The menu item identifier, or wxNOT_FOUND if none was found.
525
526 \wxheading{Remarks}
527
528 Any special menu codes are stripped out of source and target strings
529 before matching.
530
531 \membersection{wxMenuBar::FindItem}\label{wxmenubarfinditem}
532
533 \constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu}{ **menu = NULL}}
534
535 Finds the menu item object associated with the given menu item identifier.
536
537 \wxheading{Parameters}
538
539 \docparam{id}{Menu item identifier.}
540
541 \docparam{menu}{If not NULL, menu will get set to the associated menu.}
542
543 \wxheading{Return value}
544
545 The found menu item object, or NULL if one was not found.
546
547 \membersection{wxMenuBar::GetHelpString}\label{wxmenubargethelpstring}
548
549 \constfunc{wxString}{GetHelpString}{\param{int}{ id}}
550
551 Gets 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
559 The help string, or the empty string if there was no help string or the menu item
560 was not found.
561
562 \wxheading{See also}
563
564 \helpref{wxMenuBar::SetHelpString}{wxmenubarsethelpstring}
565
566 \membersection{wxMenuBar::GetLabel}\label{wxmenubargetlabel}
567
568 \constfunc{wxString}{GetLabel}{\param{int}{ id}}
569
570 Gets 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
578 The menu item label, or the empty string if the item was not found.
579
580 \wxheading{Remarks}
581
582 Use only after the menubar has been associated with a frame.
583
584 \membersection{wxMenuBar::GetLabelTop}\label{wxmenubargetlabeltop}
585
586 \constfunc{wxString}{GetLabelTop}{\param{int}{ pos}}
587
588 Returns 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
596 The menu label, or the empty string if the menu was not found.
597
598 \wxheading{Remarks}
599
600 Use only after the menubar has been associated with a frame.
601
602 \wxheading{See also}
603
604 \helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop}
605
606 \membersection{wxMenuBar::GetMenu}\label{wxmenubargetmenu}
607
608 \constfunc{wxMenu*}{GetMenu}{\param{int}{ menuIndex}}
609
610 Returns the menu at {\it menuIndex} (zero-based).
611
612 \membersection{wxMenuBar::GetMenuCount}\label{wxmenubargetmenucount}
613
614 \constfunc{int}{GetMenuCount}{\void}
615
616 Returns the number of menus in this menubar.
617
618 \membersection{wxMenuBar::IsChecked}\label{wxmenubarischecked}
619
620 \constfunc{bool}{IsChecked}{\param{int}{ id}}
621
622 Determines whether an item is checked.
623
624 \wxheading{Parameters}
625
626 \docparam{id}{The menu item identifier.}
627
628 \wxheading{Return value}
629
630 TRUE if the item was found and is checked, FALSE otherwise.
631
632 \membersection{wxMenuBar::IsEnabled}\label{wxmenubarisenabled}
633
634 \constfunc{bool}{IsEnabled}{\param{int}{ id}}
635
636 Determines whether an item is enabled.
637
638 \wxheading{Parameters}
639
640 \docparam{id}{The menu item identifier.}
641
642 \wxheading{Return value}
643
644 TRUE if the item was found and is enabled, FALSE otherwise.
645
646 \membersection{wxMenuBar::Refresh}\label{wxmenubarrefresh}
647
648 \func{void}{Refresh}{\void}
649
650 Redraw the menu bar
651
652 \membersection{wxMenuBar::SetHelpString}\label{wxmenubarsethelpstring}
653
654 \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
655
656 Sets 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
670 \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
671
672 Sets 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
682 Use 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
690 \func{void}{SetLabelTop}{\param{int}{ pos}, \param{const wxString\& }{label}}
691
692 Sets 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
702 Use only after the menubar has been associated with a frame.
703
704 \wxheading{See also}
705
706 \helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop}
707