]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/menu.tex
Applied patch [ 730697 ] wxRect::AlignIn member
[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. A menu item
9 with a special identifier $-1$ is a separator item and doesn't have an
10 associated command but just makes a separator line appear in the menu.
11
12 Menu items may be either normal items, check items or radio items. Normal items
13 don't have any special properties while the check items have a boolean flag
14 associated to them and they show a checkmark in the menu when the flag is set.
15 wxWindows automatically toggles the flag value when the item is clicked and its
16 value may be retrieved using either \helpref{IsChecked}{wxmenuischecked} method
17 of wxMenu or wxMenuBar itself or by using
18 \helpref{wxEvent::IsChecked}{wxcommandeventischecked} when you get the menu
19 notification for the item in question.
20
21 The radio items are similar to the check items except that all the other items
22 in the same radio group are unchecked when a radio item is checked. The radio
23 group is formed by a contiguous range of radio items, i.e. it starts at the
24 first item of this kind and ends with the first item of a different kind (or
25 the end of the menu). Notice that because the radio groups are defined in terms
26 of the item positions inserting or removing the items in the menu containing
27 the radio items risks to not work correctly. Finally note that the radio items
28 are only supported under Windows and GTK+ currently.
29
30 \wxheading{Allocation strategy}
31
32 All menus except the popup ones must be created on the heap. All menus
33 attached to a menubar or to another menu will be deleted by their parent when
34 it is deleted. As the frame menubar is deleted by the frame itself, it means
35 that normally all menus used are deleted automatically.
36
37 \wxheading{Derived from}
38
39 \helpref{wxEvtHandler}{wxevthandler}\\
40 \helpref{wxObject}{wxobject}
41
42 \wxheading{Include files}
43
44 <wx/menu.h>
45
46 \wxheading{Event handling}
47
48 If the menu is part of a menubar, then \helpref{wxMenuBar}{wxmenubar} event processing is used.
49
50 With a popup menu, there is a variety of ways to handle a menu selection event
51 (wxEVT\_COMMAND\_MENU\_SELECTED).
52
53 \begin{enumerate}\itemsep=0pt
54 \item Derive a new class from wxMenu and define event table entries using the EVT\_MENU macro.
55 \item Set a new event handler for wxMenu, using an object whose class has EVT\_MENU entries.
56 \item Provide EVT\_MENU handlers in the window which pops up the menu, or in an ancestor of
57 this window.
58 \item Define a callback of type wxFunction, which you pass to the wxMenu constructor.
59 The callback takes a reference to the menu, and a reference to a
60 \helpref{wxCommandEvent}{wxcommandevent}. This method is deprecated and should
61 not be used in the new code, it is provided for backwards compatibility only.
62 \end{enumerate}
63
64 \wxheading{See also}
65
66 \helpref{wxMenuBar}{wxmenubar}, \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu},\rtfsp
67 \helpref{Event handling overview}{eventhandlingoverview}
68
69 \latexignore{\rtfignore{\wxheading{Members}}}
70
71 \membersection{wxMenu::wxMenu}\label{wxmenuconstr}
72
73 \func{}{wxMenu}{\param{const wxString\& }{title = ""}, \param{long}{ style = 0}}
74
75 Constructs a wxMenu object.
76
77 \wxheading{Parameters}
78
79 \docparam{title}{A title for the popup menu: the empty string denotes no title.}
80
81 \docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).}
82
83 \func{}{wxMenu}{\param{long}{ style}}
84
85 Constructs a wxMenu object.
86
87 \wxheading{Parameters}
88
89 \docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).}
90
91 \membersection{wxMenu::\destruct{wxMenu}}
92
93 \func{}{\destruct{wxMenu}}{\void}
94
95 Destructor, destroying the menu.
96
97 Note: under Motif, a popup menu must have a valid parent (the window
98 it was last popped up on) when being destroyed. Therefore, make sure
99 you delete or re-use the popup menu {\it before} destroying the
100 parent window. Re-use in this context means popping up the menu on
101 a different window from last time, which causes an implicit destruction
102 and recreation of internal data structures.
103
104 \membersection{wxMenu::Append}\label{wxmenuappend}
105
106 \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
107 \param{wxItemKind}{ kind = wxITEM\_NORMAL}}
108
109 Adds a string item to the end of the menu.
110
111 \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{wxMenu *}{subMenu},\rtfsp
112 \param{const wxString\& }{helpString = ""}}
113
114 Adds a pull-right submenu to the end of the menu. Append the submenu to the parent
115 menu {\it after} you have added your menu items, or accelerators may not be
116 registered properly.
117
118 \func{void}{Append}{\param{wxMenuItem*}{ menuItem}}
119
120 Adds a menu item object. This is the most generic variant of Append() method
121 because it may be used for both items (including separators) and submenus and
122 because you can also specify various extra properties of a menu item this way,
123 such as bitmaps and fonts.
124
125 \wxheading{Parameters}
126
127 \docparam{id}{The menu command identifier.}
128
129 \docparam{item}{The string to appear on the menu item.}
130
131 \docparam{menu}{Pull-right submenu.}
132
133 \docparam{kind}{May be {\tt wxITEM\_SEPARATOR}, {\tt wxITEM\_NORMAL},
134 {\tt wxITEM\_CHECK} or {\tt wxITEM\_RADIO}}
135
136 \docparam{helpString}{An optional help string associated with the item.
137 By default, \helpref{wxFrame::OnMenuHighlight}{wxframeonmenuhighlight} displays
138 this string in the status line.}
139
140 \docparam{menuItem}{A menuitem object. It will be owned by the wxMenu object after this function
141 is called, so do not delete it yourself.}
142
143 \wxheading{Remarks}
144
145 This command can be used after the menu has been shown, as well as on initial
146 creation of a menu or menubar.
147
148 The {\it item} string for the normal menu items (not submenus or separators)
149 may include the accelerator which can be used to activate the menu item
150 from keyboard. The accelerator string follows the item label and is separated
151 from it by a {\tt TAB} character ({\tt '$\backslash$t'}). Its general syntax is
152 any combination of {\tt "CTRL"}, {\tt "ALT"} and {\tt "SHIFT"} strings (case
153 doesn't matter) separated by either {\tt '-'} or {\tt '+'} characters and
154 followed by the accelerator itself. The accelerator may be any alphanumeric
155 character, any function key (from {\tt F1} to {\tt F12}) or one of the special
156 characters listed in the table below (again, case doesn't matter):
157 \begin{twocollist}\itemsep=0pt
158 \twocolitem{{\tt DEL} or {\tt DELETE}}{Delete key}
159 \twocolitem{{\tt INS} or {\tt INSERT}}{Insert key}
160 \twocolitem{{\tt ENTER} or {\tt RETURN}}{Enter key}
161 \twocolitem{{\tt PGUP}}{PageUp key}
162 \twocolitem{{\tt PGDN}}{PageDown key}
163 \twocolitem{{\tt LEFT}}{Left cursor arrow key}
164 \twocolitem{{\tt RIGHT}}{Right cursor arrow key}
165 \twocolitem{{\tt UP}}{Up cursor arrow key}
166 \twocolitem{{\tt DOWN}}{Down cursor arrow key}
167 \twocolitem{{\tt HOME}}{Home key}
168 \twocolitem{{\tt END}}{End key}
169 \twocolitem{{\tt SPACE}}{Space}
170 \twocolitem{{\tt TAB}}{Tab key}
171 \twocolitem{{\tt ESC} or {\tt ESCAPE}}{Escape key (Windows only)}
172 \end{twocollist}
173
174 \wxheading{See also}
175
176 \helpref{wxMenu::AppendSeparator}{wxmenuappendseparator},\rtfsp
177 \helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem},\rtfsp
178 \helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem},\rtfsp
179 \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
180 \helpref{wxMenu::SetLabel}{wxmenusetlabel}, \helpref{wxMenu::GetHelpString}{wxmenugethelpstring},\rtfsp
181 \helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenuItem}{wxmenuitem}
182
183 \pythonnote{In place of a single overloaded method name, wxPython
184 implements the following methods:\par
185 \indented{2cm}{\begin{twocollist}
186 \twocolitem{{\bf Append(id, string, helpStr="", checkable=false)}}{}
187 \twocolitem{{\bf AppendMenu(id, string, aMenu, helpStr="")}}{}
188 \twocolitem{{\bf AppendItem(aMenuItem)}}{}
189 \end{twocollist}}
190 }
191
192 \membersection{wxMenu::AppendCheckItem}\label{wxmenuappendcheckitem}
193
194 \func{void}{AppendCheckItem}{\param{int}{ id},\rtfsp
195 \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
196
197 Adds a checkable item to the end of the menu.
198
199 \wxheading{See also}
200
201 \helpref{wxMenu::Append}{wxmenuappend},\rtfsp
202 \helpref{wxMenu::InsertCheckItem}{wxmenuinsertcheckitem}
203
204 \membersection{wxMenu::AppendRadioItem}\label{wxmenuappendradioitem}
205
206 \func{void}{AppendRadioItem}{\param{int}{ id},\rtfsp
207 \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
208
209 Adds a radio item to the end of the menu. All consequent radio items form a
210 group and when an item in the group is checked, all the others are
211 automatically unchecked.
212
213 {\bf NB:} Currently only implemented under Windows and GTK, use
214 {\tt\#if wxHAS\_RADIO\_MENU\_ITEMS} to test for availability of this feature.
215
216 \wxheading{See also}
217
218 \helpref{wxMenu::Append}{wxmenuappend},\rtfsp
219 \helpref{wxMenu::InsertRadioItem}{wxmenuinsertradioitem}
220
221 \membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator}
222
223 \func{void}{AppendSeparator}{\void}
224
225 Adds a separator to the end of the menu.
226
227 \wxheading{See also}
228
229 \helpref{wxMenu::Append}{wxmenuappend},\rtfsp
230 \helpref{wxMenu::InsertSeparator}{wxmenuinsertseparator}
231
232 \membersection{wxMenu::Break}\label{wxmenubreak}
233
234 \func{void}{Break}{\void}
235
236 Inserts a break in a menu, causing the next appended item to appear in a new column.
237
238 \membersection{wxMenu::Check}\label{wxmenucheck}
239
240 \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
241
242 Checks or unchecks the menu item.
243
244 \wxheading{Parameters}
245
246 \docparam{id}{The menu item identifier.}
247
248 \docparam{check}{If true, the item will be checked, otherwise it will be unchecked.}
249
250 \wxheading{See also}
251
252 \helpref{wxMenu::IsChecked}{wxmenuischecked}
253
254 \membersection{wxMenu::Delete}\label{wxmenudelete}
255
256 \func{void}{Delete}{\param{int }{id}}
257
258 \func{void}{Delete}{\param{wxMenuItem *}{item}}
259
260 Deletes the menu item from the menu. If the item is a submenu, it will
261 {\bf not} be deleted. Use \helpref{Destroy}{wxmenudestroy} if you want to
262 delete a submenu.
263
264 \wxheading{Parameters}
265
266 \docparam{id}{Id of the menu item to be deleted.}
267
268 \docparam{item}{Menu item to be deleted.}
269
270 \wxheading{See also}
271
272 \helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp
273 \helpref{wxMenu::Destroy}{wxmenudestroy},\rtfsp
274 \helpref{wxMenu::Remove}{wxmenuremove}
275
276 \membersection{wxMenu::Destroy}\label{wxmenudestroy}
277
278 \func{void}{Destroy}{\param{int }{id}}
279
280 \func{void}{Destroy}{\param{wxMenuItem *}{item}}
281
282 Deletes the menu item from the menu. If the item is a submenu, it will
283 be deleted. Use \helpref{Remove}{wxmenuremove} if you want to keep the submenu
284 (for example, to reuse it later).
285
286 \wxheading{Parameters}
287
288 \docparam{id}{Id of the menu item to be deleted.}
289
290 \docparam{item}{Menu item to be deleted.}
291
292 \wxheading{See also}
293
294 \helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp
295 \helpref{wxMenu::Deletes}{wxmenudelete},\rtfsp
296 \helpref{wxMenu::Remove}{wxmenuremove}
297
298 \membersection{wxMenu::Enable}\label{wxmenuenable}
299
300 \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
301
302 Enables or disables (greys out) a menu item.
303
304 \wxheading{Parameters}
305
306 \docparam{id}{The menu item identifier.}
307
308 \docparam{enable}{true to enable the menu item, false to disable it.}
309
310 \wxheading{See also}
311
312 \helpref{wxMenu::IsEnabled}{wxmenuisenabled}
313
314 \membersection{wxMenu::FindItem}\label{wxmenufinditem}
315
316 \constfunc{int}{FindItem}{\param{const wxString\& }{itemString}}
317
318 Finds the menu item id for a menu item string.
319
320 \constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu **}{menu = NULL}}
321
322 Finds the menu item object associated with the given menu item identifier and,
323 optionally, the (sub)menu it belongs to.
324
325 \perlnote{In wxPerl this method takes just the {\tt id} parameter;
326 in scalar context it returns the associated {\tt Wx::MenuItem}, in list
327 context it returns a 2-element list {\tt ( item, submenu )}}
328
329 \wxheading{Parameters}
330
331 \docparam{itemString}{Menu item string to find.}
332
333 \docparam{id}{Menu item identifier.}
334
335 \docparam{menu}{If the pointer is not NULL, it will be filled with the items
336 parent menu (if the item was found)}
337
338 \wxheading{Return value}
339
340 First form: menu item identifier, or wxNOT\_FOUND if none is found.
341
342 Second form: returns the menu item object, or NULL if it is not found.
343
344 \wxheading{Remarks}
345
346 Any special menu codes are stripped out of source and target strings
347 before matching.
348
349 \pythonnote{The name of this method in wxPython is {\tt FindItemById}
350 and it does not support the second parameter.}
351
352 \membersection{wxMenu::GetHelpString}\label{wxmenugethelpstring}
353
354 \constfunc{wxString}{GetHelpString}{\param{int}{ id}}
355
356 Returns the help string associated with a menu item.
357
358 \wxheading{Parameters}
359
360 \docparam{id}{The menu item identifier.}
361
362 \wxheading{Return value}
363
364 The help string, or the empty string if there is no help string or the
365 item was not found.
366
367 \wxheading{See also}
368
369 \helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenu::Append}{wxmenuappend}
370
371 \membersection{wxMenu::GetLabel}\label{wxmenugetlabel}
372
373 \constfunc{wxString}{GetLabel}{\param{int}{ id}}
374
375 Returns a menu item label.
376
377 \wxheading{Parameters}
378
379 \docparam{id}{The menu item identifier.}
380
381 \wxheading{Return value}
382
383 The item label, or the empty string if the item was not found.
384
385 \wxheading{See also}
386
387 \helpref{wxMenu::SetLabel}{wxmenusetlabel}
388
389 \membersection{wxMenu::GetMenuItemCount}\label{wxmenugetmenuitemcount}
390
391 \constfunc{size\_t}{GetMenuItemCount}{\void}
392
393 Returns the number of items in the menu.
394
395 \membersection{wxMenu::GetMenuItems}\label{wxmenugetmenuitems}
396
397 \constfunc{wxMenuItemList\&}{GetMenuItems}{\void}
398
399 Returns the list of items in the menu. wxMenuItemList is a pseudo-template
400 list class containing wxMenuItem pointers.
401
402 \membersection{wxMenu::GetTitle}\label{wxmenugettitle}
403
404 \constfunc{wxString}{GetTitle}{\void}
405
406 Returns the title of the menu.
407
408 \wxheading{Remarks}
409
410 This is relevant only to popup menus, use
411 \helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop} for the menus in the
412 menubar.
413
414 \wxheading{See also}
415
416 \helpref{wxMenu::SetTitle}{wxmenusettitle}
417
418 \membersection{wxMenu::Insert}\label{wxmenuinsert}
419
420 \func{bool}{Insert}{\param{size\_t }{pos}, \param{wxMenuItem *}{item}}
421
422 \func{void}{Insert}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
423 \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
424 \param{wxItemKind}{ kind = wxITEM\_NORMAL}}
425
426 Inserts the given {\it item} before the position {\it pos}. Inserting the item
427 at the position \helpref{GetMenuItemCount}{wxmenugetmenuitemcount} is the same
428 as appending it.
429
430 \wxheading{See also}
431
432 \helpref{wxMenu::Append}{wxmenuappend},\rtfsp
433 \helpref{wxMenu::Prepend}{wxmenuprepend}
434
435 \membersection{wxMenu::InsertCheckItem}\label{wxmenuinsertcheckitem}
436
437 \func{void}{InsertCheckItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
438 \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
439
440 Inserts a checkable item at the given position.
441
442 \wxheading{See also}
443
444 \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
445 \helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem}
446
447 \membersection{wxMenu::InsertRadioItem}\label{wxmenuinsertradioitem}
448
449 \func{void}{InsertRadioItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp
450 \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
451
452 Inserts a radio item at the given position.
453
454 \wxheading{See also}
455
456 \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
457 \helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem}
458
459 \membersection{wxMenu::InsertSeparator}\label{wxmenuinsertseparator}
460
461 \func{void}{InsertSeparator}{\param{size\_t }{pos}}
462
463 Inserts a separator at the given position.
464
465 \wxheading{See also}
466
467 \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp
468 \helpref{wxMenu::AppendSeparator}{wxmenuappendseparator}
469
470 \membersection{wxMenu::IsChecked}\label{wxmenuischecked}
471
472 \constfunc{bool}{IsChecked}{\param{int}{ id}}
473
474 Determines whether a menu item is checked.
475
476 \wxheading{Parameters}
477
478 \docparam{id}{The menu item identifier.}
479
480 \wxheading{Return value}
481
482 true if the menu item is checked, false otherwise.
483
484 \wxheading{See also}
485
486 \helpref{wxMenu::Check}{wxmenucheck}
487
488 \membersection{wxMenu::IsEnabled}\label{wxmenuisenabled}
489
490 \constfunc{bool}{IsEnabled}{\param{int}{ id}}
491
492 Determines whether a menu item is enabled.
493
494 \wxheading{Parameters}
495
496 \docparam{id}{The menu item identifier.}
497
498 \wxheading{Return value}
499
500 true if the menu item is enabled, false otherwise.
501
502 \wxheading{See also}
503
504 \helpref{wxMenu::Enable}{wxmenuenable}
505
506 \membersection{wxMenu::Prepend}\label{wxmenuprepend}
507
508 \func{bool}{Prepend}{\param{wxMenuItem *}{item}}
509
510 \func{void}{Prepend}{\param{int}{ id},\rtfsp
511 \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp
512 \param{wxItemKind}{ kind = wxITEM\_NORMAL}}
513
514 Inserts the given {\it item} at the position $0$, i.e. before all the other
515 existing items.
516
517 \wxheading{See also}
518
519 \helpref{wxMenu::Append}{wxmenuappend},\rtfsp
520 \helpref{wxMenu::Inserts}{wxmenuinsert}
521
522 \membersection{wxMenu::PrependCheckItem}\label{wxmenuprependcheckitem}
523
524 \func{void}{PrependCheckItem}{\param{int}{ id},\rtfsp
525 \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
526
527 Inserts a checkable item at the position $0$.
528
529 \wxheading{See also}
530
531 \helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp
532 \helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem}
533
534 \membersection{wxMenu::PrependRadioItem}\label{wxmenuprependradioitem}
535
536 \func{void}{PrependRadioItem}{\param{int}{ id},\rtfsp
537 \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}}
538
539 Inserts a radio item at the position $0$.
540
541 \wxheading{See also}
542
543 \helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp
544 \helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem}
545
546 \membersection{wxMenu::PrependSeparator}\label{wxmenuprependseparator}
547
548 \func{void}{PrependSeparator}{\param{size\_t }{pos}}
549
550 Inserts a separator at the position $0$.
551
552 \wxheading{See also}
553
554 \helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp
555 \helpref{wxMenu::AppendSeparator}{wxmenuappendseparator}
556
557 \membersection{wxMenu::Remove}\label{wxmenuremove}
558
559 \func{wxMenuItem *}{Remove}{\param{int }{id}}
560
561 \func{wxMenuItem *}{Remove}{\param{wxMenuItem *}{item}}
562
563 Removes the menu item from the menu but doesn't delete the associated C++
564 object. This allows to reuse the same item later by adding it back to the menu
565 (especially useful with submenus).
566
567 \wxheading{Parameters}
568
569 \docparam{id}{The identifier of the menu item to remove.}
570
571 \docparam{item}{The menu item to remove.}
572
573 \wxheading{Return value}
574
575 The item which was detached from the menu.
576
577 \membersection{wxMenu::SetHelpString}\label{wxmenusethelpstring}
578
579 \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
580
581 Sets an item's help string.
582
583 \wxheading{Parameters}
584
585 \docparam{id}{The menu item identifier.}
586
587 \docparam{helpString}{The help string to set.}
588
589 \wxheading{See also}
590
591 \helpref{wxMenu::GetHelpString}{wxmenugethelpstring}
592
593 \membersection{wxMenu::SetLabel}\label{wxmenusetlabel}
594
595 \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
596
597 Sets the label of a menu item.
598
599 \wxheading{Parameters}
600
601 \docparam{id}{The menu item identifier.}
602
603 \docparam{label}{The menu item label to set.}
604
605 \wxheading{See also}
606
607 \helpref{wxMenu::Append}{wxmenuappend}, \helpref{wxMenu::GetLabel}{wxmenugetlabel}
608
609 \membersection{wxMenu::SetTitle}\label{wxmenusettitle}
610
611 \func{void}{SetTitle}{\param{const wxString\& }{title}}
612
613 Sets the title of the menu.
614
615 \wxheading{Parameters}
616
617 \docparam{title}{The title to set.}
618
619 \wxheading{Remarks}
620
621 This is relevant only to popup menus, use
622 \helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop} for the menus in the
623 menubar.
624
625 \wxheading{See also}
626
627 \helpref{wxMenu::GetTitle}{wxmenugettitle}
628
629 \membersection{wxMenu::UpdateUI}\label{wxmenuupdateui}
630
631 \constfunc{void}{UpdateUI}{\param{wxEvtHandler*}{ source = NULL}}
632
633 Sends events to {\it source} (or owning window if NULL) to update the
634 menu UI. This is called just before the menu is popped up with \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu}, but
635 the application may call it at other times if required.
636
637 \wxheading{See also}
638
639 \helpref{wxUpdateUIEvent}{wxupdateuievent}
640
641 \section{\class{wxMenuBar}}\label{wxmenubar}
642
643 A menu bar is a series of menus accessible from the top of a frame.
644
645 \wxheading{Derived from}
646
647 \helpref{wxEvtHandler}{wxevthandler}\\
648 \helpref{wxObject}{wxobject}
649
650 \wxheading{Include files}
651
652 <wx/menu.h>
653
654 \wxheading{Event handling}
655
656 To respond to a menu selection, provide a handler for EVT\_MENU, in the frame
657 that contains the menu bar. If you have a toolbar which uses the same identifiers
658 as your EVT\_MENU entries, events from the toolbar will also be processed by your
659 EVT\_MENU event handlers.
660
661 Note that menu commands (and UI update events for menus) are first sent to
662 the focus window within the frame. If no window within the frame has the focus,
663 then the events are sent directly to the frame. This allows command and UI update
664 handling to be processed by specific windows and controls, and not necessarily
665 by the application frame.
666
667 {\bf Tip:} under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu)
668 are not working, check any EVT\_CHAR events you are handling in child windows.
669 If you are not calling {\tt event.Skip()} for events that you don't process in these event handlers,
670 menu shortcuts may cease to work.
671
672 \wxheading{See also}
673
674 \helpref{wxMenu}{wxmenu}, \helpref{Event handling overview}{eventhandlingoverview}
675
676 \latexignore{\rtfignore{\wxheading{Members}}}
677
678 \membersection{wxMenuBar::wxMenuBar}\label{wxmenubarconstr}
679
680 \func{void}{wxMenuBar}{\param{long }{style = 0}}
681
682 Default constructor.
683
684 \func{void}{wxMenuBar}{\param{int}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}}
685
686 Construct a menu bar from arrays of menus and titles.
687
688 \wxheading{Parameters}
689
690 \docparam{n}{The number of menus.}
691
692 \docparam{menus}{An array of menus. Do not use this array again - it now belongs to the
693 menu bar.}
694
695 \docparam{titles}{An array of title strings. Deallocate this array after creating the menu bar.}
696
697 \docparam{style}{If {\tt wxMB\_DOCKABLE} the menu bar can be detached (wxGTK only).}
698
699 \pythonnote{Only the default constructor is supported in wxPython.
700 Use wxMenuBar.Append instead.}
701
702 \perlnote{wxPerl only supports the first constructor:
703 use {\tt Append} instead.}
704
705 \membersection{wxMenuBar::\destruct{wxMenuBar}}
706
707 \func{void}{\destruct{wxMenuBar}}{\void}
708
709 Destructor, destroying the menu bar and removing it from the parent frame (if any).
710
711 \membersection{wxMenuBar::Append}\label{wxmenubarappend}
712
713 \func{bool}{Append}{\param{wxMenu *}{menu}, \param{const wxString\& }{title}}
714
715 Adds the item to the end of the menu bar.
716
717 \wxheading{Parameters}
718
719 \docparam{menu}{The menu to add. Do not deallocate this menu after calling {\bf Append}.}
720
721 \docparam{title}{The title of the menu.}
722
723 \wxheading{Return value}
724
725 true on success, false if an error occurred.
726
727 \wxheading{See also}
728
729 \helpref{wxMenuBar::Insert}{wxmenubarinsert}
730
731 \membersection{wxMenuBar::Check}\label{wxmenubarcheck}
732
733 \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}}
734
735 Checks or unchecks a menu item.
736
737 \wxheading{Parameters}
738
739 \docparam{id}{The menu item identifier.}
740
741 \docparam{check}{If true, checks the menu item, otherwise the item is unchecked.}
742
743 \wxheading{Remarks}
744
745 Only use this when the menu bar has been associated
746 with a frame; otherwise, use the wxMenu equivalent call.
747
748 \membersection{wxMenuBar::Enable}\label{wxmenubarenable}
749
750 \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}}
751
752 Enables or disables (greys out) a menu item.
753
754 \wxheading{Parameters}
755
756 \docparam{id}{The menu item identifier.}
757
758 \docparam{enable}{true to enable the item, false to disable it.}
759
760 \wxheading{Remarks}
761
762 Only use this when the menu bar has been
763 associated with a frame; otherwise, use the wxMenu equivalent call.
764
765 \membersection{wxMenuBar::EnableTop}\label{wxmenubarenabletop}
766
767 \func{void}{EnableTop}{\param{int}{ pos}, \param{const bool}{ enable}}
768
769 Enables or disables a whole menu.
770
771 \wxheading{Parameters}
772
773 \docparam{pos}{The position of the menu, starting from zero.}
774
775 \docparam{enable}{true to enable the menu, false to disable it.}
776
777 \wxheading{Remarks}
778
779 Only use this when the menu bar has been
780 associated with a frame.
781
782 \membersection{wxMenuBar::FindMenu}\label{wxmenubarfindmenu}
783
784 \constfunc{int}{FindMenu}{\param{const wxString\& }{title}}
785
786 Returns the index of the menu with the given {\it title} or wxNOT\_FOUND if no
787 such menu exists in this menubar. The {\it title} parameter may specify either
788 the menu title (with accelerator characters, i.e. {\tt "\&File"}) or just the
789 menu label ({\tt "File"}) indifferently.
790
791 \membersection{wxMenuBar::FindMenuItem}\label{wxmenubarfindmenuitem}
792
793 \constfunc{int}{FindMenuItem}{\param{const wxString\& }{menuString}, \param{const wxString\& }{itemString}}
794
795 Finds the menu item id for a menu name/menu item string pair.
796
797 \wxheading{Parameters}
798
799 \docparam{menuString}{Menu title to find.}
800
801 \docparam{itemString}{Item to find.}
802
803 \wxheading{Return value}
804
805 The menu item identifier, or wxNOT\_FOUND if none was found.
806
807 \wxheading{Remarks}
808
809 Any special menu codes are stripped out of source and target strings
810 before matching.
811
812 \membersection{wxMenuBar::FindItem}\label{wxmenubarfinditem}
813
814 \constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu}{ **menu = NULL}}
815
816 Finds the menu item object associated with the given menu item identifier.
817
818 \wxheading{Parameters}
819
820 \docparam{id}{Menu item identifier.}
821
822 \docparam{menu}{If not NULL, menu will get set to the associated menu.}
823
824 \wxheading{Return value}
825
826 The found menu item object, or NULL if one was not found.
827
828 \membersection{wxMenuBar::GetHelpString}\label{wxmenubargethelpstring}
829
830 \constfunc{wxString}{GetHelpString}{\param{int}{ id}}
831
832 Gets the help string associated with the menu item identifier.
833
834 \wxheading{Parameters}
835
836 \docparam{id}{The menu item identifier.}
837
838 \wxheading{Return value}
839
840 The help string, or the empty string if there was no help string or the menu item
841 was not found.
842
843 \wxheading{See also}
844
845 \helpref{wxMenuBar::SetHelpString}{wxmenubarsethelpstring}
846
847 \membersection{wxMenuBar::GetLabel}\label{wxmenubargetlabel}
848
849 \constfunc{wxString}{GetLabel}{\param{int}{ id}}
850
851 Gets the label associated with a menu item.
852
853 \wxheading{Parameters}
854
855 \docparam{id}{The menu item identifier.}
856
857 \wxheading{Return value}
858
859 The menu item label, or the empty string if the item was not found.
860
861 \wxheading{Remarks}
862
863 Use only after the menubar has been associated with a frame.
864
865 \membersection{wxMenuBar::GetLabelTop}\label{wxmenubargetlabeltop}
866
867 \constfunc{wxString}{GetLabelTop}{\param{int}{ pos}}
868
869 Returns the label of a top-level menu. Note that the returned string does not
870 include the accelerator characters which could have been specified in the menu
871 title string during its construction.
872
873 \wxheading{Parameters}
874
875 \docparam{pos}{Position of the menu on the menu bar, starting from zero.}
876
877 \wxheading{Return value}
878
879 The menu label, or the empty string if the menu was not found.
880
881 \wxheading{Remarks}
882
883 Use only after the menubar has been associated with a frame.
884
885 \wxheading{See also}
886
887 \helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop}
888
889 \membersection{wxMenuBar::GetMenu}\label{wxmenubargetmenu}
890
891 \constfunc{wxMenu*}{GetMenu}{\param{int}{ menuIndex}}
892
893 Returns the menu at {\it menuIndex} (zero-based).
894
895 \membersection{wxMenuBar::GetMenuCount}\label{wxmenubargetmenucount}
896
897 \constfunc{int}{GetMenuCount}{\void}
898
899 Returns the number of menus in this menubar.
900
901 \membersection{wxMenuBar::Insert}\label{wxmenubarinsert}
902
903 \func{bool}{Insert}{\param{size\_t }{pos}, \param{wxMenu *}{menu}, \param{const wxString\& }{title}}
904
905 Inserts the menu at the given position into the menu bar. Inserting menu at
906 position $0$ will insert it in the very beginning of it, inserting at position
907 \helpref{GetMenuCount()}{wxmenubargetmenucount} is the same as calling
908 \helpref{Append()}{wxmenubarappend}.
909
910 \wxheading{Parameters}
911
912 \docparam{pos}{The position of the new menu in the menu bar}
913
914 \docparam{menu}{The menu to add. wxMenuBar owns the menu and will free it.}
915
916 \docparam{title}{The title of the menu.}
917
918 \wxheading{Return value}
919
920 true on success, false if an error occurred.
921
922 \wxheading{See also}
923
924 \helpref{wxMenuBar::Append}{wxmenubarappend}
925
926 \membersection{wxMenuBar::IsChecked}\label{wxmenubarischecked}
927
928 \constfunc{bool}{IsChecked}{\param{int}{ id}}
929
930 Determines whether an item is checked.
931
932 \wxheading{Parameters}
933
934 \docparam{id}{The menu item identifier.}
935
936 \wxheading{Return value}
937
938 true if the item was found and is checked, false otherwise.
939
940 \membersection{wxMenuBar::IsEnabled}\label{wxmenubarisenabled}
941
942 \constfunc{bool}{IsEnabled}{\param{int}{ id}}
943
944 Determines whether an item is enabled.
945
946 \wxheading{Parameters}
947
948 \docparam{id}{The menu item identifier.}
949
950 \wxheading{Return value}
951
952 true if the item was found and is enabled, false otherwise.
953
954 \membersection{wxMenuBar::Refresh}\label{wxmenubarrefresh}
955
956 \func{void}{Refresh}{\void}
957
958 Redraw the menu bar
959
960 \membersection{wxMenuBar::Remove}\label{wxmenubarremove}
961
962 \func{wxMenu *}{Remove}{\param{size\_t }{pos}}
963
964 Removes the menu from the menu bar and returns the menu object - the caller is
965 responsible for deleting it. This function may be used together with
966 \helpref{wxMenuBar::Insert}{wxmenubarinsert} to change the menubar
967 dynamically.
968
969 \wxheading{See also}
970
971 \helpref{wxMenuBar::Replace}{wxmenubarreplace}
972
973 \membersection{wxMenuBar::Replace}\label{wxmenubarreplace}
974
975 \func{wxMenu *}{Replace}{\param{size\_t }{pos}, \param{wxMenu *}{menu}, \param{const wxString\& }{title}}
976
977 Replaces the menu at the given position with another one.
978
979 \wxheading{Parameters}
980
981 \docparam{pos}{The position of the new menu in the menu bar}
982
983 \docparam{menu}{The menu to add.}
984
985 \docparam{title}{The title of the menu.}
986
987 \wxheading{Return value}
988
989 The menu which was previously at the position {\it pos}. The caller is
990 responsible for deleting it.
991
992 \wxheading{See also}
993
994 \helpref{wxMenuBar::Insert}{wxmenubarinsert},\rtfsp
995 \helpref{wxMenuBar::Remove}{wxmenubarremove}
996
997 \membersection{wxMenuBar::SetHelpString}\label{wxmenubarsethelpstring}
998
999 \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}}
1000
1001 Sets the help string associated with a menu item.
1002
1003 \wxheading{Parameters}
1004
1005 \docparam{id}{Menu item identifier.}
1006
1007 \docparam{helpString}{Help string to associate with the menu item.}
1008
1009 \wxheading{See also}
1010
1011 \helpref{wxMenuBar::GetHelpString}{wxmenubargethelpstring}
1012
1013 \membersection{wxMenuBar::SetLabel}\label{wxmenubarsetlabel}
1014
1015 \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}}
1016
1017 Sets the label of a menu item.
1018
1019 \wxheading{Parameters}
1020
1021 \docparam{id}{Menu item identifier.}
1022
1023 \docparam{label}{Menu item label.}
1024
1025 \wxheading{Remarks}
1026
1027 Use only after the menubar has been associated with a frame.
1028
1029 \wxheading{See also}
1030
1031 \helpref{wxMenuBar::GetLabel}{wxmenubargetlabel}
1032
1033 \membersection{wxMenuBar::SetLabelTop}\label{wxmenubarsetlabeltop}
1034
1035 \func{void}{SetLabelTop}{\param{int}{ pos}, \param{const wxString\& }{label}}
1036
1037 Sets the label of a top-level menu.
1038
1039 \wxheading{Parameters}
1040
1041 \docparam{pos}{The position of a menu on the menu bar, starting from zero.}
1042
1043 \docparam{label}{The menu label.}
1044
1045 \wxheading{Remarks}
1046
1047 Use only after the menubar has been associated with a frame.
1048
1049 \wxheading{See also}
1050
1051 \helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop}
1052