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