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
}
71 \docparam{style
}{If set to
\tt{wxMENU_TEAROFF
}, the menu will be detachable.
}
73 \membersection{wxMenu::
\destruct{wxMenu
}}
75 \func{}{\destruct{wxMenu
}}{\void}
77 Destructor, destroying the menu.
79 Note: under Motif, a popup menu must have a valid parent (the window
80 it was last popped up on) when being destroyed. Therefore, make sure
81 you delete or re-use the popup menu
{\it before
} destroying the
82 parent window. Re-use in this context means popping up the menu on
83 a different window from last time, which causes an implicit destruction
84 and recreation of internal data structures.
86 \membersection{wxMenu::Append
}\label{wxmenuappend
}
88 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
89 \param{const bool
}{ checkable = FALSE
}}
91 Adds a string item to the end of the menu.
93 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
94 \param{const wxString\&
}{helpString = ""
}}
96 Adds a pull-right submenu to the end of the menu.
98 \func{void
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
100 Adds a menu item object. You can specify various extra properties of a menu item this way,
101 such as bitmaps and fonts.
103 \wxheading{Parameters
}
105 \docparam{id
}{The menu command identifier.
}
107 \docparam{item
}{The string to appear on the menu item.
}
109 \docparam{menu
}{Pull-right submenu.
}
111 \docparam{checkable
}{If TRUE, this item is checkable.
}
113 \docparam{helpString
}{An optional help string associated with the item.
114 By default,
\helpref{wxFrame::OnMenuHighlight
}{wxframeonmenuhighlight
} displays
115 this string in the status line.
}
117 \docparam{menuItem
}{A menuitem object. It will be owned by the wxMenu object after this function
118 is called, so do not delete it yourself.
}
122 This command can be used after the menu has been shown, as well as on initial
123 creation of a menu or menubar.
127 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
},
\helpref{wxMenu::SetLabel
}{wxmenusetlabel
},
\helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
},
\rtfsp
128 \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)
}}{}
141 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
143 \func{void
}{AppendSeparator
}{\void}
145 Adds a separator to the end of the menu.
149 \helpref{wxMenu::Append
}{wxmenuappend
}
151 \membersection{wxMenu::Break
}\label{wxmenubreak
}
153 \func{void
}{Break
}{\void}
155 Inserts a break in a menu, causing the next appended item to appear in a new column.
157 \membersection{wxMenu::Check
}\label{wxmenucheck
}
159 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
161 Checks or unchecks the menu item.
163 \wxheading{Parameters
}
165 \docparam{id
}{The menu item identifier.
}
167 \docparam{check
}{If TRUE, the item will be checked, otherwise it will be unchecked.
}
171 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
173 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
175 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
177 Enables or disables (greys out) a menu item.
179 \wxheading{Parameters
}
181 \docparam{id
}{The menu item identifier.
}
183 \docparam{enable
}{TRUE to enable the menu item, FALSE to disable it.
}
187 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
189 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
191 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
193 Finds the menu item id for a menu item string.
195 \wxheading{Parameters
}
197 \docparam{itemString
}{Menu item string to find.
}
199 \wxheading{Return value
}
201 Menu item identifier, or -
1 if none is found.
205 Any special menu codes are stripped out of source and target strings
210 \helpref{wxMenu::FindItemForId
}{wxmenufinditemforid
}
212 \membersection{wxMenu::FindItemForId
}\label{wxmenufinditemforid
}
214 \constfunc{wxMenuItem*
}{FindItemForId
}{\param{int
}{ id
},
\param{wxMenu **
}{ menuForItem = NULL
}}
216 Finds the menu item object associated with the given menu item identifier.
218 \wxheading{Parameters
}
220 \docparam{id
}{Menu item identifier.
}
221 \docparam{menuForItem
}{will be filled with the menu for this item if not NULL.
}
223 \wxheading{Return value
}
225 Returns the menu item object, or NULL if it is not found.
229 \helpref{wxMenu::FindItem
}{wxmenufinditem
}
231 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
233 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
235 Returns the help string associated with a menu item.
237 \wxheading{Parameters
}
239 \docparam{id
}{The menu item identifier.
}
241 \wxheading{Return value
}
243 The help string, or the empty string if there is no help string or the
248 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
250 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
252 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
254 Returns a menu item label.
256 \wxheading{Parameters
}
258 \docparam{id
}{The menu item identifier.
}
260 \wxheading{Return value
}
262 The item label, or the empty string if the item was not found.
266 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
268 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
270 \constfunc{wxString
}{GetTitle
}{\void}
272 Returns the title of the menu.
276 This is relevant only to popup menus.
280 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
282 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
284 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
286 Determines whether a menu item is checked.
288 \wxheading{Parameters
}
290 \docparam{id
}{The menu item identifier.
}
292 \wxheading{Return value
}
294 TRUE if the menu item is checked, FALSE otherwise.
298 \helpref{wxMenu::Check
}{wxmenucheck
}
300 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
302 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
304 Determines whether a menu item is enabled.
306 \wxheading{Parameters
}
308 \docparam{id
}{The menu item identifier.
}
310 \wxheading{Return value
}
312 TRUE if the menu item is enabled, FALSE otherwise.
316 \helpref{wxMenu::Enable
}{wxmenuenable
}
318 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
320 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
322 Sets an item's help string.
324 \wxheading{Parameters
}
326 \docparam{id
}{The menu item identifier.
}
328 \docparam{helpString
}{The help string to set.
}
332 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
334 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
336 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
338 Sets the label of a menu item.
340 \wxheading{Parameters
}
342 \docparam{id
}{The menu item identifier.
}
344 \docparam{label
}{The menu item label to set.
}
348 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
350 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
352 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
354 Sets the title of the menu.
356 \wxheading{Parameters
}
358 \docparam{title
}{The title to set.
}
362 This is relevant only to popup menus.
366 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
368 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
370 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
372 Sends events to
{\it source
} (or owning window if NULL) to update the
373 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
374 the application may call it at other times if required.
378 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
380 \section{\class{wxMenuBar
}}\label{wxmenubar
}
382 A menu bar is a series of menus accessible from the top of a frame.
384 \wxheading{Derived from
}
386 \helpref{wxEvtHandler
}{wxevthandler
}\\
387 \helpref{wxObject
}{wxobject
}
389 \wxheading{Include files
}
393 \wxheading{Event handling
}
395 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
396 that contains the menu bar. If you have a toolbar which uses the same identifiers
397 as your EVT
\_MENU entries, events from the toolbar will also be processed by your
398 EVT
\_MENU event handlers.
400 Note that menu commands (and UI update events for menus) are first sent to
401 the focus window within the frame. If no window within the frame has the focus,
402 then the events are sent directly to the frame. This allows command and UI update
403 handling to be processed by specific windows and controls, and not necessarily
404 by the application frame.
408 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
410 \latexignore{\rtfignore{\wxheading{Members
}}}
412 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarconstr
}
414 \func{void
}{wxMenuBar
}{\void}
418 \func{void
}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
420 Construct a menu bar from arrays of menus and titles.
422 \wxheading{Parameters
}
424 \docparam{n
}{The number of menus.
}
426 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
429 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
431 \pythonnote{Only the default constructor is supported in wxPython.
432 Use wxMenuBar.Append instead.
}
435 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}
437 \func{void
}{\destruct{wxMenuBar
}}{\void}
439 Destructor, destroying the menu bar and removing it from the parent frame (if any).
441 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
443 \func{void
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
445 Adds the item to the end of the menu bar.
447 \wxheading{Parameters
}
449 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
451 \docparam{title
}{The title of the menu.
}
453 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
455 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
457 Checks or unchecks a menu item.
459 \wxheading{Parameters
}
461 \docparam{id
}{The menu item identifier.
}
463 \docparam{check
}{If TRUE, checks the menu item, otherwise the item is unchecked.
}
467 Only use this when the menu bar has been associated
468 with a frame; otherwise, use the wxMenu equivalent call.
470 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
472 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
474 Enables or disables (greys out) a menu item.
476 \wxheading{Parameters
}
478 \docparam{id
}{The menu item identifier.
}
480 \docparam{enable
}{TRUE to enable the item, FALSE to disable it.
}
484 Only use this when the menu bar has been
485 associated with a frame; otherwise, use the wxMenu equivalent call.
487 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
489 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
491 Enables or disables a whole menu.
493 \wxheading{Parameters
}
495 \docparam{pos
}{The position of the menu, starting from zero.
}
497 \docparam{enable
}{TRUE to enable the menu, FALSE to disable it.
}
501 Only use this when the menu bar has been
502 associated with a frame.
504 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
506 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
508 Finds the menu item id for a menu name/menu item string pair.
510 \wxheading{Parameters
}
512 \docparam{menuString
}{Menu title to find.
}
514 \docparam{itemString
}{Item to find.
}
516 \wxheading{Return value
}
518 The menu item identifier, or -
1 if none was found.
522 Any special menu codes are stripped out of source and target strings
525 \membersection{wxMenuBar::FindItemForId
}\label{wxmenubarfinditemforid
}
527 \constfunc{wxMenuItem *
}{FindItemForId
}{\param{int
}{ id
}}
529 Finds the menu item object associated with the given menu item identifier,
531 \wxheading{Parameters
}
533 \docparam{id
}{Menu item identifier.
}
535 \wxheading{Return value
}
537 The found menu item object, or NULL if one was not found.
539 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
541 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
543 Gets the help string associated with the menu item identifer.
545 \wxheading{Parameters
}
547 \docparam{id
}{The menu item identifier.
}
549 \wxheading{Return value
}
551 The help string, or the empty string if there was no help string or the menu item
556 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
558 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
560 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
562 Gets the label associated with a menu item.
564 \wxheading{Parameters
}
566 \docparam{id
}{The menu item identifier.
}
568 \wxheading{Return value
}
570 The menu item label, or the empty string if the item was not found.
574 Use only after the menubar has been associated with a frame.
576 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
578 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
580 Returns the label of a top-level menu.
582 \wxheading{Parameters
}
584 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
586 \wxheading{Return value
}
588 The menu label, or the empty string if the menu was not found.
592 Use only after the menubar has been associated with a frame.
596 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
598 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
600 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
602 Returns the menu at
{\it menuIndex
} (zero-based).
604 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
606 \constfunc{int
}{GetMenuCount
}{\void}
608 Returns the number of menus in this menubar.
610 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
612 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
614 Determines whether an item is checked.
616 \wxheading{Parameters
}
618 \docparam{id
}{The menu item identifier.
}
620 \wxheading{Return value
}
622 TRUE if the item was found and is checked, FALSE otherwise.
624 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
626 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
628 Determines whether an item is enabled.
630 \wxheading{Parameters
}
632 \docparam{id
}{The menu item identifier.
}
634 \wxheading{Return value
}
636 TRUE if the item was found and is enabled, FALSE otherwise.
638 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
640 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
642 Sets the help string associated with a menu item.
644 \wxheading{Parameters
}
646 \docparam{id
}{Menu item identifier.
}
648 \docparam{helpString
}{Help string to associate with the menu item.
}
652 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
654 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
656 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
658 Sets the label of a menu item.
660 \wxheading{Parameters
}
662 \docparam{id
}{Menu item identifier.
}
664 \docparam{label
}{Menu item label.
}
668 Use only after the menubar has been associated with a frame.
672 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
674 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
676 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
678 Sets the label of a top-level menu.
680 \wxheading{Parameters
}
682 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
684 \docparam{label
}{The menu label.
}
688 Use only after the menubar has been associated with a frame.
692 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}