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.
10 \wxheading{Derived from
}
12 \helpref{wxEvtHandler
}{wxevthandler
}\\
13 \helpref{wxObject
}{wxobject
}
15 \wxheading{Include files
}
19 \wxheading{Event handling
}
21 If the menu is part of a menubar, then
\helpref{wxMenuBar
}{wxmenubar
} event processing is used.
23 With a popup menu, there is a variety of ways to handle a menu selection event
24 (wxEVT
\_COMMAND\_MENU\_SELECTED).
26 \begin{enumerate
}\itemsep=
0pt
27 \item Define a callback of type wxFunction, which you pass to the wxMenu constructor.
28 The callback takes a reference to the menu, and a reference to a
\helpref{wxCommandEvent
}{wxcommandevent
}.
29 \item Derive a new class from wxMenu and define event table entries using the EVT
\_MENU macro.
30 \item Set a new event handler for wxMenu, using an object whose class has EVT
\_MENU entries.
31 \item Provide EVT
\_MENU handlers in the window which pops up the menu, or in an ancestor of
37 \helpref{wxMenuBar
}{wxmenubar
},
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
},
\rtfsp
38 \helpref{Event handling overview
}{eventhandlingoverview
}
40 \latexignore{\rtfignore{\wxheading{Members
}}}
42 \membersection{wxMenu::wxMenu
}\label{wxmenuconstr
}
44 \func{}{wxMenu
}{\param{const wxString\&
}{title = ""
},
45 \param{const wxFunction
}{ func = NULL
},
\param{long
}{ style =
0}}
47 Constructs a wxMenu object.
49 \wxheading{Parameters
}
51 \docparam{title
}{A title for the popup menu: the empty string denotes no title.
}
53 \docparam{func
}{A callback function if the menu is used as a popup using
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}.
}
55 \docparam{style
}{If set to
\tt{wxMENU_TEAROFF
}, the menu will be detachable.
}
57 \pythonnote{The wxPython version of the
\tt{wxMenu
} constructor
58 doesn't accept the callback argument because of reference counting
59 issues. There is a specialized wxMenu constructor called
60 \tt{wxPyMenu
} which does and can be used for PopupMenus when callbacks
61 are needed. You must retain a reference to the menu while useing it
62 otherwise your callback function will get dereferenced when the menu
66 \func{}{wxMenu
}{\param{long
}{ style
}}
68 Constructs a wxMenu object.
70 \wxheading{Parameters
}
72 \docparam{style
}{If set to
\tt{wxMENU_TEAROFF
}, the menu will be detachable.
}
74 \membersection{wxMenu::
\destruct{wxMenu
}}
76 \func{}{\destruct{wxMenu
}}{\void}
78 Destructor, destroying the menu.
80 Note: under Motif, a popup menu must have a valid parent (the window
81 it was last popped up on) when being destroyed. Therefore, make sure
82 you delete or re-use the popup menu
{\it before
} destroying the
83 parent window. Re-use in this context means popping up the menu on
84 a different window from last time, which causes an implicit destruction
85 and recreation of internal data structures.
87 \membersection{wxMenu::Append
}\label{wxmenuappend
}
89 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
90 \param{const bool
}{ checkable = FALSE
}}
92 Adds a string item to the end of the menu.
94 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
95 \param{const wxString\&
}{helpString = ""
}}
97 Adds a pull-right submenu to the end of the menu.
99 \func{void
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
101 Adds a menu item object. You can specify various extra properties of a menu item this way,
102 such as bitmaps and fonts.
104 \wxheading{Parameters
}
106 \docparam{id
}{The menu command identifier.
}
108 \docparam{item
}{The string to appear on the menu item.
}
110 \docparam{menu
}{Pull-right submenu.
}
112 \docparam{checkable
}{If TRUE, this item is checkable.
}
114 \docparam{helpString
}{An optional help string associated with the item.
115 By default,
\helpref{wxFrame::OnMenuHighlight
}{wxframeonmenuhighlight
} displays
116 this string in the status line.
}
118 \docparam{menuItem
}{A menuitem object. It will be owned by the wxMenu object after this function
119 is called, so do not delete it yourself.
}
123 This command can be used after the menu has been shown, as well as on initial
124 creation of a menu or menubar.
128 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
},
\helpref{wxMenu::SetLabel
}{wxmenusetlabel
},
\helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
},
\rtfsp
129 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenuItem
}{wxmenuitem
}
131 \pythonnote{In place of a single overloaded method name, wxPython
132 implements the following methods:
\par
133 \indented{2cm
}{\begin{twocollist
}
134 \twocolitem{\bf{Append(id, string, helpStr="", checkable=FALSE)
}}{}
135 \twocolitem{\bf{AppendMenu(id, string, aMenu, helpStr="")
}}{}
136 \twocolitem{\bf{AppendItem(aMenuItem)
}}{}
140 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
142 \func{void
}{AppendSeparator
}{\void}
144 Adds a separator to the end of the menu.
148 \helpref{wxMenu::Append
}{wxmenuappend
}
150 \membersection{wxMenu::Break
}\label{wxmenubreak
}
152 \func{void
}{Break
}{\void}
154 Inserts a break in a menu, causing the next appended item to appear in a new column.
156 \membersection{wxMenu::Check
}\label{wxmenucheck
}
158 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
160 Checks or unchecks the menu item.
162 \wxheading{Parameters
}
164 \docparam{id
}{The menu item identifier.
}
166 \docparam{check
}{If TRUE, the item will be checked, otherwise it will be unchecked.
}
170 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
172 \membersection{wxMenu::Delete
}\label{wxmenudelete
}
174 \func{void
}{Delete
}{\param{int
}{id
}}
176 Deletes the menu item from the menu.
178 \wxheading{Parameters
}
180 \docparam{id
}{Menu item to be deleted.
}
184 Does not delete a sub menu, if any.
188 \helpref{wxMenu::FindItemForId
}{wxmenufinditemforid
}
190 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
192 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
194 Enables or disables (greys out) a menu item.
196 \wxheading{Parameters
}
198 \docparam{id
}{The menu item identifier.
}
200 \docparam{enable
}{TRUE to enable the menu item, FALSE to disable it.
}
204 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
206 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
208 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
210 Finds the menu item id for a menu item string.
212 \wxheading{Parameters
}
214 \docparam{itemString
}{Menu item string to find.
}
216 \wxheading{Return value
}
218 Menu item identifier, or wxNOT_FOUND if none is found.
222 Any special menu codes are stripped out of source and target strings
227 \helpref{wxMenu::FindItemForId
}{wxmenufinditemforid
}
229 \membersection{wxMenu::FindItemForId
}\label{wxmenufinditemforid
}
231 \constfunc{wxMenuItem*
}{FindItemForId
}{\param{int
}{ id
}}
233 \constfunc{wxMenuItem*
}{FindItem
}{\param{int
}{ id
}}
235 Finds the menu item object associated with the given menu item identifier.
237 \wxheading{Parameters
}
239 \docparam{id
}{Menu item identifier.
}
241 \wxheading{Return value
}
243 Returns the menu item object, or NULL if it is not found.
247 \helpref{wxMenu::FindItem
}{wxmenufinditem
}
249 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
251 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
253 Returns the help string associated with a menu item.
255 \wxheading{Parameters
}
257 \docparam{id
}{The menu item identifier.
}
259 \wxheading{Return value
}
261 The help string, or the empty string if there is no help string or the
266 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
268 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
270 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
272 Returns a menu item label.
274 \wxheading{Parameters
}
276 \docparam{id
}{The menu item identifier.
}
278 \wxheading{Return value
}
280 The item label, or the empty string if the item was not found.
284 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
286 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
288 \constfunc{wxString
}{GetTitle
}{\void}
290 Returns the title of the menu.
294 This is relevant only to popup menus.
298 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
300 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
302 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
304 Determines whether a menu item is checked.
306 \wxheading{Parameters
}
308 \docparam{id
}{The menu item identifier.
}
310 \wxheading{Return value
}
312 TRUE if the menu item is checked, FALSE otherwise.
316 \helpref{wxMenu::Check
}{wxmenucheck
}
318 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
320 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
322 Determines whether a menu item is enabled.
324 \wxheading{Parameters
}
326 \docparam{id
}{The menu item identifier.
}
328 \wxheading{Return value
}
330 TRUE if the menu item is enabled, FALSE otherwise.
334 \helpref{wxMenu::Enable
}{wxmenuenable
}
336 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
338 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
340 Sets an item's help string.
342 \wxheading{Parameters
}
344 \docparam{id
}{The menu item identifier.
}
346 \docparam{helpString
}{The help string to set.
}
350 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
352 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
354 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
356 Sets the label of a menu item.
358 \wxheading{Parameters
}
360 \docparam{id
}{The menu item identifier.
}
362 \docparam{label
}{The menu item label to set.
}
366 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
368 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
370 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
372 Sets the title of the menu.
374 \wxheading{Parameters
}
376 \docparam{title
}{The title to set.
}
380 This is relevant only to popup menus.
384 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
386 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
388 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
390 Sends events to
{\it source
} (or owning window if NULL) to update the
391 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
392 the application may call it at other times if required.
396 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
398 \section{\class{wxMenuBar
}}\label{wxmenubar
}
400 A menu bar is a series of menus accessible from the top of a frame.
402 \wxheading{Derived from
}
404 \helpref{wxEvtHandler
}{wxevthandler
}\\
405 \helpref{wxObject
}{wxobject
}
407 \wxheading{Include files
}
411 \wxheading{Event handling
}
413 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
414 that contains the menu bar. If you have a toolbar which uses the same identifiers
415 as your EVT
\_MENU entries, events from the toolbar will also be processed by your
416 EVT
\_MENU event handlers.
418 Note that menu commands (and UI update events for menus) are first sent to
419 the focus window within the frame. If no window within the frame has the focus,
420 then the events are sent directly to the frame. This allows command and UI update
421 handling to be processed by specific windows and controls, and not necessarily
422 by the application frame.
426 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
428 \latexignore{\rtfignore{\wxheading{Members
}}}
430 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarconstr
}
432 \func{void
}{wxMenuBar
}{\void}
436 \func{void
}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
438 Construct a menu bar from arrays of menus and titles.
440 \wxheading{Parameters
}
442 \docparam{n
}{The number of menus.
}
444 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
447 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
449 \pythonnote{Only the default constructor is supported in wxPython.
450 Use wxMenuBar.Append instead.
}
452 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}
454 \func{void
}{\destruct{wxMenuBar
}}{\void}
456 Destructor, destroying the menu bar and removing it from the parent frame (if any).
458 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
460 \func{void
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
462 Adds the item to the end of the menu bar.
464 \wxheading{Parameters
}
466 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
468 \docparam{title
}{The title of the menu.
}
470 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
472 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
474 Checks or unchecks a menu item.
476 \wxheading{Parameters
}
478 \docparam{id
}{The menu item identifier.
}
480 \docparam{check
}{If TRUE, checks the menu item, otherwise the item is unchecked.
}
484 Only use this when the menu bar has been associated
485 with a frame; otherwise, use the wxMenu equivalent call.
487 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
489 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
491 Enables or disables (greys out) a menu item.
493 \wxheading{Parameters
}
495 \docparam{id
}{The menu item identifier.
}
497 \docparam{enable
}{TRUE to enable the item, FALSE to disable it.
}
501 Only use this when the menu bar has been
502 associated with a frame; otherwise, use the wxMenu equivalent call.
504 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
506 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
508 Enables or disables a whole menu.
510 \wxheading{Parameters
}
512 \docparam{pos
}{The position of the menu, starting from zero.
}
514 \docparam{enable
}{TRUE to enable the menu, FALSE to disable it.
}
518 Only use this when the menu bar has been
519 associated with a frame.
521 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
523 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
525 Finds the menu item id for a menu name/menu item string pair.
527 \wxheading{Parameters
}
529 \docparam{menuString
}{Menu title to find.
}
531 \docparam{itemString
}{Item to find.
}
533 \wxheading{Return value
}
535 The menu item identifier, or wxNOT_FOUND if none was found.
539 Any special menu codes are stripped out of source and target strings
542 \membersection{wxMenuBar::FindItem
}\label{wxmenubarfinditem
}
544 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu
}{ **menu = NULL
}}
546 Finds the menu item object associated with the given menu item identifier.
548 \wxheading{Parameters
}
550 \docparam{id
}{Menu item identifier.
}
552 \docparam{menu
}{If not NULL, menu will get set to the associated menu.
}
554 \wxheading{Return value
}
556 The found menu item object, or NULL if one was not found.
558 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
560 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
562 Gets the help string associated with the menu item identifer.
564 \wxheading{Parameters
}
566 \docparam{id
}{The menu item identifier.
}
568 \wxheading{Return value
}
570 The help string, or the empty string if there was no help string or the menu item
575 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
577 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
579 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
581 Gets the label associated with a menu item.
583 \wxheading{Parameters
}
585 \docparam{id
}{The menu item identifier.
}
587 \wxheading{Return value
}
589 The menu item label, or the empty string if the item was not found.
593 Use only after the menubar has been associated with a frame.
595 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
597 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
599 Returns the label of a top-level menu.
601 \wxheading{Parameters
}
603 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
605 \wxheading{Return value
}
607 The menu label, or the empty string if the menu was not found.
611 Use only after the menubar has been associated with a frame.
615 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
617 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
619 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
621 Returns the menu at
{\it menuIndex
} (zero-based).
623 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
625 \constfunc{int
}{GetMenuCount
}{\void}
627 Returns the number of menus in this menubar.
629 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
631 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
633 Determines whether an item is checked.
635 \wxheading{Parameters
}
637 \docparam{id
}{The menu item identifier.
}
639 \wxheading{Return value
}
641 TRUE if the item was found and is checked, FALSE otherwise.
643 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
645 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
647 Determines whether an item is enabled.
649 \wxheading{Parameters
}
651 \docparam{id
}{The menu item identifier.
}
653 \wxheading{Return value
}
655 TRUE if the item was found and is enabled, FALSE otherwise.
657 \membersection{wxMenuBar::Refresh
}\label{wxmenubarrefresh
}
659 \func{void
}{Refresh
}{\void}
663 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
665 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
667 Sets the help string associated with a menu item.
669 \wxheading{Parameters
}
671 \docparam{id
}{Menu item identifier.
}
673 \docparam{helpString
}{Help string to associate with the menu item.
}
677 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
679 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
681 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
683 Sets the label of a menu item.
685 \wxheading{Parameters
}
687 \docparam{id
}{Menu item identifier.
}
689 \docparam{label
}{Menu item label.
}
693 Use only after the menubar has been associated with a frame.
697 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
699 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
701 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
703 Sets the label of a top-level menu.
705 \wxheading{Parameters
}
707 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
709 \docparam{label
}{The menu label.
}
713 Use only after the menubar has been associated with a frame.
717 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}