]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/menu.tex
new wxMenu stuff and thread implementations
[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 \docparam{style}{If set to \tt{wxMENU_TEAROFF}, the menu will be detachable.}
72
73 \membersection{wxMenu::\destruct{wxMenu}}
74
75 \func{}{\destruct{wxMenu}}{\void}
76
77 Destructor, destroying the menu.
78
79 Note: under Motif, a popup menu must have a valid parent (the window
80 it was last popped up on) when being destroyed. Therefore, make sure
81 you delete or re-use the popup menu {\it before} destroying the
82 parent window. Re-use in this context means popping up the menu on
83 a different window from last time, which causes an implicit destruction
84 and recreation of internal data structures.
85
86 \membersection{wxMenu::Append}\label{wxmenuappend}
87
88 \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
89 \param{const bool}{ checkable = FALSE}}
90
91 Adds a string item to the end of the menu.
92
93 \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{wxMenu *}{subMenu},\rtfsp
94 \param{const wxString\& }{helpString = ""}}
95
96 Adds a pull-right submenu to the end of the menu.
97
98 \func{void}{Append}{\param{wxMenuItem*}{ menuItem}}
99
100 Adds a menu item object. You can specify various extra properties of a menu item this way,
101 such as bitmaps and fonts.
102
103 \wxheading{Parameters}
104
105 \docparam{id}{The menu command identifier.}
106
107 \docparam{item}{The string to appear on the menu item.}
108
109 \docparam{menu}{Pull-right submenu.}
110
111 \docparam{checkable}{If TRUE, this item is checkable.}
112
113 \docparam{helpString}{An optional help string associated with the item.
114 By default, \helpref{wxFrame::OnMenuHighlight}{wxframeonmenuhighlight} displays
115 this string in the status line.}
116
117 \docparam{menuItem}{A menuitem object. It will be owned by the wxMenu object after this function
118 is called, so do not delete it yourself.}
119
120 \wxheading{Remarks}
121
122 This command can be used after the menu has been shown, as well as on initial
123 creation of a menu or menubar.
124
125 \wxheading{See also}
126
127 \helpref{wxMenu::AppendSeparator}{wxmenuappendseparator}, \helpref{wxMenu::SetLabel}{wxmenusetlabel}, \helpref{wxMenu::GetHelpString}{wxmenugethelpstring},\rtfsp
128 \helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenuItem}{wxmenuitem}
129
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
141 \membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator}
142
143 \func{void}{AppendSeparator}{\void}
144
145 Adds a separator to the end of the menu.
146
147 \wxheading{See also}
148
149 \helpref{wxMenu::Append}{wxmenuappend}
150
151 \membersection{wxMenu::Break}\label{wxmenubreak}
152
153 \func{void}{Break}{\void}
154
155 Inserts a break in a menu, causing the next appended item to appear in a new column.
156
157 \membersection{wxMenu::Check}\label{wxmenucheck}
158
159 \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
160
161 Checks or unchecks the menu item.
162
163 \wxheading{Parameters}
164
165 \docparam{id}{The menu item identifier.}
166
167 \docparam{check}{If TRUE, the item will be checked, otherwise it will be unchecked.}
168
169 \wxheading{See also}
170
171 \helpref{wxMenu::IsChecked}{wxmenuischecked}
172
173 \membersection{wxMenu::Delete}\label{wxmenudelete}
174
175 \func{void}{Delete}{\param{int }{id}}
176
177 Deletes the menu item from the menu.
178
179 \wxheading{Parameters}
180
181 \docparam{id}{Menu item to be deleted.}
182
183 \wxheading{Remarks}
184
185 Does not delete a sub menu, if any.
186
187 \wxheading{See also}
188
189 \helpref{wxMenu::FindItemForId}{wxmenufinditemforid}
190
191 \membersection{wxMenu::Enable}\label{wxmenuenable}
192
193 \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
194
195 Enables or disables (greys out) a menu item.
196
197 \wxheading{Parameters}
198
199 \docparam{id}{The menu item identifier.}
200
201 \docparam{enable}{TRUE to enable the menu item, FALSE to disable it.}
202
203 \wxheading{See also}
204
205 \helpref{wxMenu::IsEnabled}{wxmenuisenabled}
206
207 \membersection{wxMenu::FindItem}\label{wxmenufinditem}
208
209 \constfunc{int}{FindItem}{\param{const wxString\& }{itemString}}
210
211 Finds the menu item id for a menu item string.
212
213 \wxheading{Parameters}
214
215 \docparam{itemString}{Menu item string to find.}
216
217 \wxheading{Return value}
218
219 Menu item identifier, or wxNOT_FOUND if none is found.
220
221 \wxheading{Remarks}
222
223 Any special menu codes are stripped out of source and target strings
224 before matching.
225
226 \wxheading{See also}
227
228 \helpref{wxMenu::FindItemForId}{wxmenufinditemforid}
229
230 \membersection{wxMenu::FindItemForId}\label{wxmenufinditemforid}
231
232 \constfunc{wxMenuItem*}{FindItemForId}{\param{int}{ id}}
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
453 \membersection{wxMenuBar::\destruct{wxMenuBar}}
454
455 \func{void}{\destruct{wxMenuBar}}{\void}
456
457 Destructor, destroying the menu bar and removing it from the parent frame (if any).
458
459 \membersection{wxMenuBar::Append}\label{wxmenubarappend}
460
461 \func{void}{Append}{\param{wxMenu *}{menu}, \param{const wxString\& }{title}}
462
463 Adds the item to the end of the menu bar.
464
465 \wxheading{Parameters}
466
467 \docparam{menu}{The menu to add. Do not deallocate this menu after calling {\bf Append}.}
468
469 \docparam{title}{The title of the menu.}
470
471 \membersection{wxMenuBar::Check}\label{wxmenubarcheck}
472
473 \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
474
475 Checks or unchecks a menu item.
476
477 \wxheading{Parameters}
478
479 \docparam{id}{The menu item identifier.}
480
481 \docparam{check}{If TRUE, checks the menu item, otherwise the item is unchecked.}
482
483 \wxheading{Remarks}
484
485 Only use this when the menu bar has been associated
486 with a frame; otherwise, use the wxMenu equivalent call.
487
488 \membersection{wxMenuBar::Enable}\label{wxmenubarenable}
489
490 \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
491
492 Enables or disables (greys out) a menu item.
493
494 \wxheading{Parameters}
495
496 \docparam{id}{The menu item identifier.}
497
498 \docparam{enable}{TRUE to enable the item, FALSE to disable it.}
499
500 \wxheading{Remarks}
501
502 Only use this when the menu bar has been
503 associated with a frame; otherwise, use the wxMenu equivalent call.
504
505 \membersection{wxMenuBar::EnableTop}\label{wxmenubarenabletop}
506
507 \func{void}{EnableTop}{\param{int}{ pos}, \param{const bool}{ enable}}
508
509 Enables or disables a whole menu.
510
511 \wxheading{Parameters}
512
513 \docparam{pos}{The position of the menu, starting from zero.}
514
515 \docparam{enable}{TRUE to enable the menu, FALSE to disable it.}
516
517 \wxheading{Remarks}
518
519 Only use this when the menu bar has been
520 associated with a frame.
521
522 \membersection{wxMenuBar::FindMenuItem}\label{wxmenubarfindmenuitem}
523
524 \constfunc{int}{FindMenuItem}{\param{const wxString\& }{menuString}, \param{const wxString\& }{itemString}}
525
526 Finds the menu item id for a menu name/menu item string pair.
527
528 \wxheading{Parameters}
529
530 \docparam{menuString}{Menu title to find.}
531
532 \docparam{itemString}{Item to find.}
533
534 \wxheading{Return value}
535
536 The menu item identifier, or wxNOT_FOUND if none was found.
537
538 \wxheading{Remarks}
539
540 Any special menu codes are stripped out of source and target strings
541 before matching.
542
543 \membersection{wxMenuBar::FindItem}\label{wxmenubarfinditem}
544
545 \constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu}{ **menu = NULL}
546
547 Finds the menu item object associated with the given menu item identifier.
548
549 \wxheading{Parameters}
550
551 \docparam{id}{Menu item identifier.}
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
719
720 %%% Local Variables:
721 %%% mode: latex
722 %%% TeX-master: t
723 %%% End: