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