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 = ""
},
\param{const wxFunction
}{ func = NULL
}}
46 Constructs a wxMenu object.
48 \wxheading{Parameters
}
50 \docparam{title
}{A title for the popup menu: the empty string denotes no title.
}
52 \docparam{func
}{A callback function if the menu is used as a popup using
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}.
}
54 \pythonnote{The wxPython version of the
\tt{wxMenu
} constructor
55 doesn't accept the callback argument because of reference counting
56 issues. There is a specialized wxMenu constructor called
57 \tt{wxPyMenu
} which does and can be used for PopupMenus when callbacks
58 are needed. You must retain a reference to the menu while useing it
59 otherwise your callback function will get dereferenced when the menu
63 \membersection{wxMenu::
\destruct{wxMenu
}}
65 \func{}{\destruct{wxMenu
}}{\void}
67 Destructor, destroying the menu.
69 Note: under Motif, a popup menu must have a valid parent (the window
70 it was last popped up on) when being destroyed. Therefore, make sure
71 you delete or re-use the popup menu
{\it before
} destroying the
72 parent window. Re-use in this context means popping up the menu on
73 a different window from last time, which causes an implicit destruction
74 and recreation of internal data structures.
76 \membersection{wxMenu::Append
}\label{wxmenuappend
}
78 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
79 \param{const bool
}{ checkable = FALSE
}}
81 Adds a string item to the end of the menu.
83 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
84 \param{const wxString\&
}{helpString = ""
}}
86 Adds a pull-right submenu to the end of the menu.
88 \func{void
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
90 Adds a menu item object. You can specify various extra properties of a menu item this way,
91 such as bitmaps and fonts.
93 \wxheading{Parameters
}
95 \docparam{id
}{The menu command identifier.
}
97 \docparam{item
}{The string to appear on the menu item.
}
99 \docparam{menu
}{Pull-right submenu.
}
101 \docparam{checkable
}{If TRUE, this item is checkable.
}
103 \docparam{helpString
}{An optional help string associated with the item.
104 By default,
\helpref{wxFrame::OnMenuHighlight
}{wxframeonmenuhighlight
} displays
105 this string in the status line.
}
107 \docparam{menuItem
}{A menuitem object. It will be owned by the wxMenu object after this function
108 is called, so do not delete it yourself.
}
112 This command can be used after the menu has been shown, as well as on initial
113 creation of a menu or menubar.
117 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
},
\helpref{wxMenu::SetLabel
}{wxmenusetlabel
},
\helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
},
\rtfsp
118 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenuItem
}{wxmenuitem
}
121 \pythonnote{In place of a single overloaded method name, wxPython
122 implements the following methods:
\par
123 \indented{2cm
}{\begin{twocollist
}
124 \twocolitem{\bf{Append(id, string, helpStr="", checkable=FALSE)
}}{}
125 \twocolitem{\bf{AppendMenu(id, string, aMenu, helpStr="")
}}{}
126 \twocolitem{\bf{AppendItem(aMenuItem)
}}{}
131 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
133 \func{void
}{AppendSeparator
}{\void}
135 Adds a separator to the end of the menu.
139 \helpref{wxMenu::Append
}{wxmenuappend
}
141 \membersection{wxMenu::Break
}\label{wxmenubreak
}
143 \func{void
}{Break
}{\void}
145 Inserts a break in a menu, causing the next appended item to appear in a new column.
147 \membersection{wxMenu::Check
}\label{wxmenucheck
}
149 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
151 Checks or unchecks the menu item.
153 \wxheading{Parameters
}
155 \docparam{id
}{The menu item identifier.
}
157 \docparam{check
}{If TRUE, the item will be checked, otherwise it will be unchecked.
}
161 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
163 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
165 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
167 Enables or disables (greys out) a menu item.
169 \wxheading{Parameters
}
171 \docparam{id
}{The menu item identifier.
}
173 \docparam{enable
}{TRUE to enable the menu item, FALSE to disable it.
}
177 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
179 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
181 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
183 Finds the menu item id for a menu item string.
185 \wxheading{Parameters
}
187 \docparam{itemString
}{Menu item string to find.
}
189 \wxheading{Return value
}
191 Menu item identifier, or -
1 if none is found.
195 Any special menu codes are stripped out of source and target strings
200 \helpref{wxMenu::FindItemForId
}{wxmenufinditemforid
}
202 \membersection{wxMenu::FindItemForId
}\label{wxmenufinditemforid
}
204 \constfunc{wxMenuItem*
}{FindItemForId
}{\param{int
}{ id
},
\param{wxMenu **
}{ menuForItem = NULL
}}
206 Finds the menu item object associated with the given menu item identifier.
208 \wxheading{Parameters
}
210 \docparam{id
}{Menu item identifier.
}
211 \docparam{menuForItem
}{will be filled with the menu for this item if not NULL.
}
213 \wxheading{Return value
}
215 Returns the menu item object, or NULL if it is not found.
219 \helpref{wxMenu::FindItem
}{wxmenufinditem
}
221 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
223 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
225 Returns the help string associated with a menu item.
227 \wxheading{Parameters
}
229 \docparam{id
}{The menu item identifier.
}
231 \wxheading{Return value
}
233 The help string, or the empty string if there is no help string or the
238 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
240 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
242 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
244 Returns a menu item label.
246 \wxheading{Parameters
}
248 \docparam{id
}{The menu item identifier.
}
250 \wxheading{Return value
}
252 The item label, or the empty string if the item was not found.
256 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
258 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
260 \constfunc{wxString
}{GetTitle
}{\void}
262 Returns the title of the menu.
266 This is relevant only to popup menus.
270 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
272 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
274 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
276 Determines whether a menu item is checked.
278 \wxheading{Parameters
}
280 \docparam{id
}{The menu item identifier.
}
282 \wxheading{Return value
}
284 TRUE if the menu item is checked, FALSE otherwise.
288 \helpref{wxMenu::Check
}{wxmenucheck
}
290 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
292 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
294 Determines whether a menu item is enabled.
296 \wxheading{Parameters
}
298 \docparam{id
}{The menu item identifier.
}
300 \wxheading{Return value
}
302 TRUE if the menu item is enabled, FALSE otherwise.
306 \helpref{wxMenu::Enable
}{wxmenuenable
}
308 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
310 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
312 Sets an item's help string.
314 \wxheading{Parameters
}
316 \docparam{id
}{The menu item identifier.
}
318 \docparam{helpString
}{The help string to set.
}
322 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
324 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
326 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
328 Sets the label of a menu item.
330 \wxheading{Parameters
}
332 \docparam{id
}{The menu item identifier.
}
334 \docparam{label
}{The menu item label to set.
}
338 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
340 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
342 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
344 Sets the title of the menu.
346 \wxheading{Parameters
}
348 \docparam{title
}{The title to set.
}
352 This is relevant only to popup menus.
356 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
358 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
360 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
362 Sends events to
{\it source
} (or owning window if NULL) to update the
363 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
364 the application may call it at other times if required.
368 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
370 \section{\class{wxMenuBar
}}\label{wxmenubar
}
372 A menu bar is a series of menus accessible from the top of a frame.
374 \wxheading{Derived from
}
376 \helpref{wxEvtHandler
}{wxevthandler
}\\
377 \helpref{wxObject
}{wxobject
}
379 \wxheading{Include files
}
383 \wxheading{Event handling
}
385 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
386 that contains the menu bar. If you have a toolbar which uses the same identifiers
387 as your EVT
\_MENU entries, events from the toolbar will also be processed by your
388 EVT
\_MENU event handlers.
390 Note that menu commands (and UI update events for menus) are first sent to
391 the focus window within the frame. If no window within the frame has the focus,
392 then the events are sent directly to the frame. This allows command and UI update
393 handling to be processed by specific windows and controls, and not necessarily
394 by the application frame.
398 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
400 \latexignore{\rtfignore{\wxheading{Members
}}}
402 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarconstr
}
404 \func{void
}{wxMenuBar
}{\void}
408 \func{void
}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
410 Construct a menu bar from arrays of menus and titles.
412 \wxheading{Parameters
}
414 \docparam{n
}{The number of menus.
}
416 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
419 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
421 \pythonnote{Only the default constructor is supported in wxPython.
422 Use wxMenuBar.Append instead.
}
425 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}
427 \func{void
}{\destruct{wxMenuBar
}}{\void}
429 Destructor, destroying the menu bar and removing it from the parent frame (if any).
431 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
433 \func{void
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
435 Adds the item to the end of the menu bar.
437 \wxheading{Parameters
}
439 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
441 \docparam{title
}{The title of the menu.
}
443 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
445 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
447 Checks or unchecks a menu item.
449 \wxheading{Parameters
}
451 \docparam{id
}{The menu item identifier.
}
453 \docparam{check
}{If TRUE, checks the menu item, otherwise the item is unchecked.
}
457 Only use this when the menu bar has been associated
458 with a frame; otherwise, use the wxMenu equivalent call.
460 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
462 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
464 Enables or disables (greys out) a menu item.
466 \wxheading{Parameters
}
468 \docparam{id
}{The menu item identifier.
}
470 \docparam{enable
}{TRUE to enable the item, FALSE to disable it.
}
474 Only use this when the menu bar has been
475 associated with a frame; otherwise, use the wxMenu equivalent call.
477 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
479 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
481 Enables or disables a whole menu.
483 \wxheading{Parameters
}
485 \docparam{pos
}{The position of the menu, starting from zero.
}
487 \docparam{enable
}{TRUE to enable the menu, FALSE to disable it.
}
491 Only use this when the menu bar has been
492 associated with a frame.
494 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
496 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
498 Finds the menu item id for a menu name/menu item string pair.
500 \wxheading{Parameters
}
502 \docparam{menuString
}{Menu title to find.
}
504 \docparam{itemString
}{Item to find.
}
506 \wxheading{Return value
}
508 The menu item identifier, or -
1 if none was found.
512 Any special menu codes are stripped out of source and target strings
515 \membersection{wxMenuBar::FindItemForId
}\label{wxmenubarfinditemforid
}
517 \constfunc{wxMenuItem *
}{FindItemForId
}{\param{int
}{ id
}}
519 Finds the menu item object associated with the given menu item identifier,
521 \wxheading{Parameters
}
523 \docparam{id
}{Menu item identifier.
}
525 \wxheading{Return value
}
527 The found menu item object, or NULL if one was not found.
529 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
531 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
533 Gets the help string associated with the menu item identifer.
535 \wxheading{Parameters
}
537 \docparam{id
}{The menu item identifier.
}
539 \wxheading{Return value
}
541 The help string, or the empty string if there was no help string or the menu item
546 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
548 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
550 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
552 Gets the label associated with a menu item.
554 \wxheading{Parameters
}
556 \docparam{id
}{The menu item identifier.
}
558 \wxheading{Return value
}
560 The menu item label, or the empty string if the item was not found.
564 Use only after the menubar has been associated with a frame.
566 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
568 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
570 Returns the label of a top-level menu.
572 \wxheading{Parameters
}
574 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
576 \wxheading{Return value
}
578 The menu label, or the empty string if the menu was not found.
582 Use only after the menubar has been associated with a frame.
586 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
588 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
590 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
592 Returns the menu at
{\it menuIndex
} (zero-based).
594 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
596 \constfunc{int
}{GetMenuCount
}{\void}
598 Returns the number of menus in this menubar.
600 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
602 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
604 Determines whether an item is checked.
606 \wxheading{Parameters
}
608 \docparam{id
}{The menu item identifier.
}
610 \wxheading{Return value
}
612 TRUE if the item was found and is checked, FALSE otherwise.
614 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
616 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
618 Determines whether an item is enabled.
620 \wxheading{Parameters
}
622 \docparam{id
}{The menu item identifier.
}
624 \wxheading{Return value
}
626 TRUE if the item was found and is enabled, FALSE otherwise.
628 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
630 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
632 Sets the help string associated with a menu item.
634 \wxheading{Parameters
}
636 \docparam{id
}{Menu item identifier.
}
638 \docparam{helpString
}{Help string to associate with the menu item.
}
642 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
644 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
646 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
648 Sets the label of a menu item.
650 \wxheading{Parameters
}
652 \docparam{id
}{Menu item identifier.
}
654 \docparam{label
}{Menu item label.
}
658 Use only after the menubar has been associated with a frame.
662 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
664 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
666 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
668 Sets the label of a top-level menu.
670 \wxheading{Parameters
}
672 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
674 \docparam{label
}{The menu label.
}
678 Use only after the menubar has been associated with a frame.
682 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}