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