1 \section{\class{wxMenu
}}\label{wxmenu
}
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.
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.
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.
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.
30 \wxheading{Allocation strategy
}
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.
37 \wxheading{Derived from
}
39 \helpref{wxEvtHandler
}{wxevthandler
}\\
40 \helpref{wxObject
}{wxobject
}
42 \wxheading{Include files
}
46 \wxheading{Event handling
}
48 If the menu is part of a menubar, then
\helpref{wxMenuBar
}{wxmenubar
} event processing is used.
50 With a popup menu, there is a variety of ways to handle a menu selection event
51 (wxEVT
\_COMMAND\_MENU\_SELECTED).
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
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.
66 \helpref{wxMenuBar
}{wxmenubar
},
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
},
\rtfsp
67 \helpref{Event handling overview
}{eventhandlingoverview
}
69 \latexignore{\rtfignore{\wxheading{Members
}}}
71 \membersection{wxMenu::wxMenu
}\label{wxmenuconstr
}
73 \func{}{wxMenu
}{\param{const wxString\&
}{title = ""
},
\param{long
}{ style =
0}}
75 Constructs a wxMenu object.
77 \wxheading{Parameters
}
79 \docparam{title
}{A title for the popup menu: the empty string denotes no title.
}
81 \docparam{style
}{If set to
{\tt wxMENU
\_TEAROFF}, the menu will be detachable (wxGTK only).
}
83 \func{}{wxMenu
}{\param{long
}{ style
}}
85 Constructs a wxMenu object.
87 \wxheading{Parameters
}
89 \docparam{style
}{If set to
{\tt wxMENU
\_TEAROFF}, the menu will be detachable (wxGTK only).
}
91 \membersection{wxMenu::
\destruct{wxMenu
}}
93 \func{}{\destruct{wxMenu
}}{\void}
95 Destructor, destroying the menu.
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.
104 \membersection{wxMenu::Append
}\label{wxmenuappend
}
106 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
107 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
109 Adds a string item to the end of the menu.
111 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
112 \param{const wxString\&
}{helpString = ""
}}
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
118 \func{void
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
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.
125 \wxheading{Parameters
}
127 \docparam{id
}{The menu command identifier.
}
129 \docparam{item
}{The string to appear on the menu item.
}
131 \docparam{menu
}{Pull-right submenu.
}
133 \docparam{kind
}{May be
{\tt wxITEM
\_SEPARATOR},
{\tt wxITEM
\_NORMAL},
134 {\tt wxITEM
\_CHECK} or
{\tt wxITEM
\_RADIO}}
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.
}
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.
}
145 This command can be used after the menu has been shown, as well as on initial
146 creation of a menu or menubar.
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)
}
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
}
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)
}}{}
192 \membersection{wxMenu::AppendCheckItem
}\label{wxmenuappendcheckitem
}
194 \func{void
}{AppendCheckItem
}{\param{int
}{ id
},
\rtfsp
195 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
197 Adds a checkable item to the end of the menu.
201 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
202 \helpref{wxMenu::InsertCheckItem
}{wxmenuinsertcheckitem
}
204 \membersection{wxMenu::AppendRadioItem
}\label{wxmenuappendradioitem
}
206 \func{void
}{AppendRadioItem
}{\param{int
}{ id
},
\rtfsp
207 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
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.
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.
218 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
219 \helpref{wxMenu::InsertRadioItem
}{wxmenuinsertradioitem
}
221 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
223 \func{void
}{AppendSeparator
}{\void}
225 Adds a separator to the end of the menu.
229 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
230 \helpref{wxMenu::InsertSeparator
}{wxmenuinsertseparator
}
232 \membersection{wxMenu::Break
}\label{wxmenubreak
}
234 \func{void
}{Break
}{\void}
236 Inserts a break in a menu, causing the next appended item to appear in a new column.
238 \membersection{wxMenu::Check
}\label{wxmenucheck
}
240 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
242 Checks or unchecks the menu item.
244 \wxheading{Parameters
}
246 \docparam{id
}{The menu item identifier.
}
248 \docparam{check
}{If true, the item will be checked, otherwise it will be unchecked.
}
252 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
254 \membersection{wxMenu::Delete
}\label{wxmenudelete
}
256 \func{void
}{Delete
}{\param{int
}{id
}}
258 \func{void
}{Delete
}{\param{wxMenuItem *
}{item
}}
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
264 \wxheading{Parameters
}
266 \docparam{id
}{Id of the menu item to be deleted.
}
268 \docparam{item
}{Menu item to be deleted.
}
272 \helpref{wxMenu::FindItem
}{wxmenufinditem
},
\rtfsp
273 \helpref{wxMenu::Destroy
}{wxmenudestroy
},
\rtfsp
274 \helpref{wxMenu::Remove
}{wxmenuremove
}
276 \membersection{wxMenu::Destroy
}\label{wxmenudestroy
}
278 \func{void
}{Destroy
}{\param{int
}{id
}}
280 \func{void
}{Destroy
}{\param{wxMenuItem *
}{item
}}
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).
286 \wxheading{Parameters
}
288 \docparam{id
}{Id of the menu item to be deleted.
}
290 \docparam{item
}{Menu item to be deleted.
}
294 \helpref{wxMenu::FindItem
}{wxmenufinditem
},
\rtfsp
295 \helpref{wxMenu::Deletes
}{wxmenudelete
},
\rtfsp
296 \helpref{wxMenu::Remove
}{wxmenuremove
}
298 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
300 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
302 Enables or disables (greys out) a menu item.
304 \wxheading{Parameters
}
306 \docparam{id
}{The menu item identifier.
}
308 \docparam{enable
}{true to enable the menu item, false to disable it.
}
312 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
314 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
316 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
318 Finds the menu item id for a menu item string.
320 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu **
}{menu = NULL
}}
322 Finds the menu item object associated with the given menu item identifier and,
323 optionally, the (sub)menu it belongs to.
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 )
}}
329 \wxheading{Parameters
}
331 \docparam{itemString
}{Menu item string to find.
}
333 \docparam{id
}{Menu item identifier.
}
335 \docparam{menu
}{If the pointer is not NULL, it will be filled with the items
336 parent menu (if the item was found)
}
338 \wxheading{Return value
}
340 First form: menu item identifier, or wxNOT
\_FOUND if none is found.
342 Second form: returns the menu item object, or NULL if it is not found.
346 Any special menu codes are stripped out of source and target strings
349 \pythonnote{The name of this method in wxPython is
{\tt FindItemById
}
350 and it does not support the second parameter.
}
352 \membersection{wxMenu::FindItemByPosition
}\label{wxmenufinditembyposition
}
354 \constfunc{wxMenuItem*
}{FindItemByPosition
}{\param{size
\_t }{position
}}
356 Returns the wxMenuItem given a position in the menu.
358 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
360 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
362 Returns the help string associated with a menu item.
364 \wxheading{Parameters
}
366 \docparam{id
}{The menu item identifier.
}
368 \wxheading{Return value
}
370 The help string, or the empty string if there is no help string or the
375 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
377 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
379 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
381 Returns a menu item label.
383 \wxheading{Parameters
}
385 \docparam{id
}{The menu item identifier.
}
387 \wxheading{Return value
}
389 The item label, or the empty string if the item was not found.
393 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
395 \membersection{wxMenu::GetMenuItemCount
}\label{wxmenugetmenuitemcount
}
397 \constfunc{size
\_t}{GetMenuItemCount
}{\void}
399 Returns the number of items in the menu.
401 \membersection{wxMenu::GetMenuItems
}\label{wxmenugetmenuitems
}
403 \constfunc{wxMenuItemList\&
}{GetMenuItems
}{\void}
405 Returns the list of items in the menu. wxMenuItemList is a pseudo-template
406 list class containing wxMenuItem pointers.
408 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
410 \constfunc{wxString
}{GetTitle
}{\void}
412 Returns the title of the menu.
416 This is relevant only to popup menus, use
417 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
} for the menus in the
422 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
424 \membersection{wxMenu::Insert
}\label{wxmenuinsert
}
426 \func{bool
}{Insert
}{\param{size
\_t }{pos
},
\param{wxMenuItem *
}{item
}}
428 \func{void
}{Insert
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
429 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
430 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
432 Inserts the given
{\it item
} before the position
{\it pos
}. Inserting the item
433 at the position
\helpref{GetMenuItemCount
}{wxmenugetmenuitemcount
} is the same
438 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
439 \helpref{wxMenu::Prepend
}{wxmenuprepend
}
441 \membersection{wxMenu::InsertCheckItem
}\label{wxmenuinsertcheckitem
}
443 \func{void
}{InsertCheckItem
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
444 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
446 Inserts a checkable item at the given position.
450 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
451 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
}
453 \membersection{wxMenu::InsertRadioItem
}\label{wxmenuinsertradioitem
}
455 \func{void
}{InsertRadioItem
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
456 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
458 Inserts a radio item at the given position.
462 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
463 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
}
465 \membersection{wxMenu::InsertSeparator
}\label{wxmenuinsertseparator
}
467 \func{void
}{InsertSeparator
}{\param{size
\_t }{pos
}}
469 Inserts a separator at the given position.
473 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
474 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
}
476 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
478 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
480 Determines whether a menu item is checked.
482 \wxheading{Parameters
}
484 \docparam{id
}{The menu item identifier.
}
486 \wxheading{Return value
}
488 true if the menu item is checked, false otherwise.
492 \helpref{wxMenu::Check
}{wxmenucheck
}
494 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
496 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
498 Determines whether a menu item is enabled.
500 \wxheading{Parameters
}
502 \docparam{id
}{The menu item identifier.
}
504 \wxheading{Return value
}
506 true if the menu item is enabled, false otherwise.
510 \helpref{wxMenu::Enable
}{wxmenuenable
}
512 \membersection{wxMenu::Prepend
}\label{wxmenuprepend
}
514 \func{bool
}{Prepend
}{\param{wxMenuItem *
}{item
}}
516 \func{void
}{Prepend
}{\param{int
}{ id
},
\rtfsp
517 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
518 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
520 Inserts the given
{\it item
} at the position $
0$, i.e. before all the other
525 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
526 \helpref{wxMenu::Inserts
}{wxmenuinsert
}
528 \membersection{wxMenu::PrependCheckItem
}\label{wxmenuprependcheckitem
}
530 \func{void
}{PrependCheckItem
}{\param{int
}{ id
},
\rtfsp
531 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
533 Inserts a checkable item at the position $
0$.
537 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
538 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
}
540 \membersection{wxMenu::PrependRadioItem
}\label{wxmenuprependradioitem
}
542 \func{void
}{PrependRadioItem
}{\param{int
}{ id
},
\rtfsp
543 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
545 Inserts a radio item at the position $
0$.
549 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
550 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
}
552 \membersection{wxMenu::PrependSeparator
}\label{wxmenuprependseparator
}
554 \func{void
}{PrependSeparator
}{\param{size
\_t }{pos
}}
556 Inserts a separator at the position $
0$.
560 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
561 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
}
563 \membersection{wxMenu::Remove
}\label{wxmenuremove
}
565 \func{wxMenuItem *
}{Remove
}{\param{int
}{id
}}
567 \func{wxMenuItem *
}{Remove
}{\param{wxMenuItem *
}{item
}}
569 Removes the menu item from the menu but doesn't delete the associated C++
570 object. This allows to reuse the same item later by adding it back to the menu
571 (especially useful with submenus).
573 \wxheading{Parameters
}
575 \docparam{id
}{The identifier of the menu item to remove.
}
577 \docparam{item
}{The menu item to remove.
}
579 \wxheading{Return value
}
581 The item which was detached from the menu.
583 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
585 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
587 Sets an item's help string.
589 \wxheading{Parameters
}
591 \docparam{id
}{The menu item identifier.
}
593 \docparam{helpString
}{The help string to set.
}
597 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
599 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
601 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
603 Sets the label of a menu item.
605 \wxheading{Parameters
}
607 \docparam{id
}{The menu item identifier.
}
609 \docparam{label
}{The menu item label to set.
}
613 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
615 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
617 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
619 Sets the title of the menu.
621 \wxheading{Parameters
}
623 \docparam{title
}{The title to set.
}
627 This is relevant only to popup menus, use
628 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
} for the menus in the
633 \helpref{wxMenu::GetTitle
}{wxmenugettitle
}
635 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
637 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
639 Sends events to
{\it source
} (or owning window if NULL) to update the
640 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
641 the application may call it at other times if required.
645 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
647 \section{\class{wxMenuBar
}}\label{wxmenubar
}
649 A menu bar is a series of menus accessible from the top of a frame.
651 \wxheading{Derived from
}
653 \helpref{wxEvtHandler
}{wxevthandler
}\\
654 \helpref{wxObject
}{wxobject
}
656 \wxheading{Include files
}
660 \wxheading{Event handling
}
662 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
663 that contains the menu bar. If you have a toolbar which uses the same identifiers
664 as your EVT
\_MENU entries, events from the toolbar will also be processed by your
665 EVT
\_MENU event handlers.
667 Note that menu commands (and UI update events for menus) are first sent to
668 the focus window within the frame. If no window within the frame has the focus,
669 then the events are sent directly to the frame. This allows command and UI update
670 handling to be processed by specific windows and controls, and not necessarily
671 by the application frame.
673 {\bf Tip:
} under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu)
674 are not working, check any EVT
\_CHAR events you are handling in child windows.
675 If you are not calling
{\tt event.Skip()
} for events that you don't process in these event handlers,
676 menu shortcuts may cease to work.
680 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
682 \latexignore{\rtfignore{\wxheading{Members
}}}
684 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarconstr
}
686 \func{void
}{wxMenuBar
}{\param{long
}{style =
0}}
690 \func{void
}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
692 Construct a menu bar from arrays of menus and titles.
694 \wxheading{Parameters
}
696 \docparam{n
}{The number of menus.
}
698 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
701 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
703 \docparam{style
}{If
{\tt wxMB
\_DOCKABLE} the menu bar can be detached (wxGTK only).
}
705 \pythonnote{Only the default constructor is supported in wxPython.
706 Use wxMenuBar.Append instead.
}
708 \perlnote{wxPerl only supports the first constructor:
709 use
{\tt Append
} instead.
}
711 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}
713 \func{void
}{\destruct{wxMenuBar
}}{\void}
715 Destructor, destroying the menu bar and removing it from the parent frame (if any).
717 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
719 \func{bool
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
721 Adds the item to the end of the menu bar.
723 \wxheading{Parameters
}
725 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
727 \docparam{title
}{The title of the menu.
}
729 \wxheading{Return value
}
731 true on success, false if an error occurred.
735 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
}
737 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
739 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
741 Checks or unchecks a menu item.
743 \wxheading{Parameters
}
745 \docparam{id
}{The menu item identifier.
}
747 \docparam{check
}{If true, checks the menu item, otherwise the item is unchecked.
}
751 Only use this when the menu bar has been associated
752 with a frame; otherwise, use the wxMenu equivalent call.
754 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
756 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
758 Enables or disables (greys out) a menu item.
760 \wxheading{Parameters
}
762 \docparam{id
}{The menu item identifier.
}
764 \docparam{enable
}{true to enable the item, false to disable it.
}
768 Only use this when the menu bar has been
769 associated with a frame; otherwise, use the wxMenu equivalent call.
771 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
773 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
775 Enables or disables a whole menu.
777 \wxheading{Parameters
}
779 \docparam{pos
}{The position of the menu, starting from zero.
}
781 \docparam{enable
}{true to enable the menu, false to disable it.
}
785 Only use this when the menu bar has been
786 associated with a frame.
788 \membersection{wxMenuBar::FindMenu
}\label{wxmenubarfindmenu
}
790 \constfunc{int
}{FindMenu
}{\param{const wxString\&
}{title
}}
792 Returns the index of the menu with the given
{\it title
} or wxNOT
\_FOUND if no
793 such menu exists in this menubar. The
{\it title
} parameter may specify either
794 the menu title (with accelerator characters, i.e.
{\tt "\&File"
}) or just the
795 menu label (
{\tt "File"
}) indifferently.
797 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
799 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
801 Finds the menu item id for a menu name/menu item string pair.
803 \wxheading{Parameters
}
805 \docparam{menuString
}{Menu title to find.
}
807 \docparam{itemString
}{Item to find.
}
809 \wxheading{Return value
}
811 The menu item identifier, or wxNOT
\_FOUND if none was found.
815 Any special menu codes are stripped out of source and target strings
818 \membersection{wxMenuBar::FindItem
}\label{wxmenubarfinditem
}
820 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu
}{ **menu = NULL
}}
822 Finds the menu item object associated with the given menu item identifier.
824 \wxheading{Parameters
}
826 \docparam{id
}{Menu item identifier.
}
828 \docparam{menu
}{If not NULL, menu will get set to the associated menu.
}
830 \wxheading{Return value
}
832 The found menu item object, or NULL if one was not found.
834 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
836 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
838 Gets the help string associated with the menu item identifier.
840 \wxheading{Parameters
}
842 \docparam{id
}{The menu item identifier.
}
844 \wxheading{Return value
}
846 The help string, or the empty string if there was no help string or the menu item
851 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
853 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
855 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
857 Gets the label associated with a menu item.
859 \wxheading{Parameters
}
861 \docparam{id
}{The menu item identifier.
}
863 \wxheading{Return value
}
865 The menu item label, or the empty string if the item was not found.
869 Use only after the menubar has been associated with a frame.
871 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
873 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
875 Returns the label of a top-level menu. Note that the returned string does not
876 include the accelerator characters which could have been specified in the menu
877 title string during its construction.
879 \wxheading{Parameters
}
881 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
883 \wxheading{Return value
}
885 The menu label, or the empty string if the menu was not found.
889 Use only after the menubar has been associated with a frame.
893 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
895 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
897 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
899 Returns the menu at
{\it menuIndex
} (zero-based).
901 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
903 \constfunc{int
}{GetMenuCount
}{\void}
905 Returns the number of menus in this menubar.
907 \membersection{wxMenuBar::Insert
}\label{wxmenubarinsert
}
909 \func{bool
}{Insert
}{\param{size
\_t }{pos
},
\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
911 Inserts the menu at the given position into the menu bar. Inserting menu at
912 position $
0$ will insert it in the very beginning of it, inserting at position
913 \helpref{GetMenuCount()
}{wxmenubargetmenucount
} is the same as calling
914 \helpref{Append()
}{wxmenubarappend
}.
916 \wxheading{Parameters
}
918 \docparam{pos
}{The position of the new menu in the menu bar
}
920 \docparam{menu
}{The menu to add. wxMenuBar owns the menu and will free it.
}
922 \docparam{title
}{The title of the menu.
}
924 \wxheading{Return value
}
926 true on success, false if an error occurred.
930 \helpref{wxMenuBar::Append
}{wxmenubarappend
}
932 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
934 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
936 Determines whether an item is checked.
938 \wxheading{Parameters
}
940 \docparam{id
}{The menu item identifier.
}
942 \wxheading{Return value
}
944 true if the item was found and is checked, false otherwise.
946 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
948 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
950 Determines whether an item is enabled.
952 \wxheading{Parameters
}
954 \docparam{id
}{The menu item identifier.
}
956 \wxheading{Return value
}
958 true if the item was found and is enabled, false otherwise.
960 \membersection{wxMenuBar::Refresh
}\label{wxmenubarrefresh
}
962 \func{void
}{Refresh
}{\void}
966 \membersection{wxMenuBar::Remove
}\label{wxmenubarremove
}
968 \func{wxMenu *
}{Remove
}{\param{size
\_t }{pos
}}
970 Removes the menu from the menu bar and returns the menu object - the caller is
971 responsible for deleting it. This function may be used together with
972 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
} to change the menubar
977 \helpref{wxMenuBar::Replace
}{wxmenubarreplace
}
979 \membersection{wxMenuBar::Replace
}\label{wxmenubarreplace
}
981 \func{wxMenu *
}{Replace
}{\param{size
\_t }{pos
},
\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
983 Replaces the menu at the given position with another one.
985 \wxheading{Parameters
}
987 \docparam{pos
}{The position of the new menu in the menu bar
}
989 \docparam{menu
}{The menu to add.
}
991 \docparam{title
}{The title of the menu.
}
993 \wxheading{Return value
}
995 The menu which was previously at the position
{\it pos
}. The caller is
996 responsible for deleting it.
1000 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
},
\rtfsp
1001 \helpref{wxMenuBar::Remove
}{wxmenubarremove
}
1003 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
1005 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
1007 Sets the help string associated with a menu item.
1009 \wxheading{Parameters
}
1011 \docparam{id
}{Menu item identifier.
}
1013 \docparam{helpString
}{Help string to associate with the menu item.
}
1015 \wxheading{See also
}
1017 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
1019 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
1021 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
1023 Sets the label of a menu item.
1025 \wxheading{Parameters
}
1027 \docparam{id
}{Menu item identifier.
}
1029 \docparam{label
}{Menu item label.
}
1033 Use only after the menubar has been associated with a frame.
1035 \wxheading{See also
}
1037 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
1039 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
1041 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
1043 Sets the label of a top-level menu.
1045 \wxheading{Parameters
}
1047 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
1049 \docparam{label
}{The menu label.
}
1053 Use only after the menubar has been associated with a frame.
1055 \wxheading{See also
}
1057 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}