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
}}
206 Finds the menu item object associated with the given menu item identifier.
208 \wxheading{Parameters
}
210 \docparam{id
}{Menu item identifier.
}
212 \wxheading{Return value
}
214 Returns the menu item object, or NULL if it is not found.
218 \helpref{wxMenu::FindItem
}{wxmenufinditem
}
220 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
222 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
224 Returns the help string associated with a menu item.
226 \wxheading{Parameters
}
228 \docparam{id
}{The menu item identifier.
}
230 \wxheading{Return value
}
232 The help string, or the empty string if there is no help string or the
237 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
239 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
241 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
243 Returns a menu item label.
245 \wxheading{Parameters
}
247 \docparam{id
}{The menu item identifier.
}
249 \wxheading{Return value
}
251 The item label, or the empty string if the item was not found.
255 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
257 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
259 \constfunc{wxString
}{GetTitle
}{\void}
261 Returns the title of the menu.
265 This is relevant only to popup menus.
269 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
271 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
273 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
275 Determines whether a menu item is checked.
277 \wxheading{Parameters
}
279 \docparam{id
}{The menu item identifier.
}
281 \wxheading{Return value
}
283 TRUE if the menu item is checked, FALSE otherwise.
287 \helpref{wxMenu::Check
}{wxmenucheck
}
289 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
291 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
293 Determines whether a menu item is enabled.
295 \wxheading{Parameters
}
297 \docparam{id
}{The menu item identifier.
}
299 \wxheading{Return value
}
301 TRUE if the menu item is enabled, FALSE otherwise.
305 \helpref{wxMenu::Enable
}{wxmenuenable
}
307 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
309 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
311 Sets an item's help string.
313 \wxheading{Parameters
}
315 \docparam{id
}{The menu item identifier.
}
317 \docparam{helpString
}{The help string to set.
}
321 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
323 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
325 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
327 Sets the label of a menu item.
329 \wxheading{Parameters
}
331 \docparam{id
}{The menu item identifier.
}
333 \docparam{label
}{The menu item label to set.
}
337 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
339 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
341 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
343 Sets the title of the menu.
345 \wxheading{Parameters
}
347 \docparam{title
}{The title to set.
}
351 This is relevant only to popup menus.
355 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
357 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
359 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
361 Sends events to
{\it source
} (or owning window if NULL) to update the
362 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
363 the application may call it at other times if required.
367 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
369 \section{\class{wxMenuBar
}}\label{wxmenubar
}
371 A menu bar is a series of menus accessible from the top of a frame.
373 \wxheading{Derived from
}
375 \helpref{wxEvtHandler
}{wxevthandler
}\\
376 \helpref{wxObject
}{wxobject
}
378 \wxheading{Include files
}
382 \wxheading{Event handling
}
384 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
385 that contains the menu bar.
389 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
391 \latexignore{\rtfignore{\wxheading{Members
}}}
393 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarconstr
}
395 \func{void
}{wxMenuBar
}{\void}
399 \func{void
}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
401 Construct a menu bar from arrays of menus and titles.
403 \wxheading{Parameters
}
405 \docparam{n
}{The number of menus.
}
407 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
410 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
412 \pythonnote{Only the default constructor is supported in wxPython.
413 Use wxMenuBar.Append instead.
}
416 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}
418 \func{void
}{\destruct{wxMenuBar
}}{\void}
420 Destructor, destroying the menu bar and removing it from the parent frame (if any).
422 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
424 \func{void
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
426 Adds the item to the end of the menu bar.
428 \wxheading{Parameters
}
430 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
432 \docparam{title
}{The title of the menu.
}
434 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
436 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
438 Checks or unchecks a menu item.
440 \wxheading{Parameters
}
442 \docparam{id
}{The menu item identifier.
}
444 \docparam{check
}{If TRUE, checks the menu item, otherwise the item is unchecked.
}
448 Only use this when the menu bar has been associated
449 with a frame; otherwise, use the wxMenu equivalent call.
451 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
453 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
455 Enables or disables (greys out) a menu item.
457 \wxheading{Parameters
}
459 \docparam{id
}{The menu item identifier.
}
461 \docparam{enable
}{TRUE to enable the item, FALSE to disable it.
}
465 Only use this when the menu bar has been
466 associated with a frame; otherwise, use the wxMenu equivalent call.
468 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
470 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
472 Enables or disables a whole menu.
474 \wxheading{Parameters
}
476 \docparam{pos
}{The position of the menu, starting from zero.
}
478 \docparam{enable
}{TRUE to enable the menu, FALSE to disable it.
}
482 Only use this when the menu bar has been
483 associated with a frame.
485 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
487 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
489 Finds the menu item id for a menu name/menu item string pair.
491 \wxheading{Parameters
}
493 \docparam{menuString
}{Menu title to find.
}
495 \docparam{itemString
}{Item to find.
}
497 \wxheading{Return value
}
499 The menu item identifier, or -
1 if none was found.
503 Any special menu codes are stripped out of source and target strings
506 \membersection{wxMenuBar::FindItemById
}\label{wxmenubarfinditembyid
}
508 \constfunc{wxMenuItem *
}{FindItemById
}{\param{int
}{ id
}}
510 Finds the menu item object associated with the given menu item identifier,
512 \wxheading{Parameters
}
514 \docparam{id
}{Menu item identifier.
}
516 \wxheading{Return value
}
518 The found menu item object, or NULL if one was not found.
520 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
522 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
524 Gets the help string associated with the menu item identifer.
526 \wxheading{Parameters
}
528 \docparam{id
}{The menu item identifier.
}
530 \wxheading{Return value
}
532 The help string, or the empty string if there was no help string or the menu item
537 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
539 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
541 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
543 Gets the label associated with a menu item.
545 \wxheading{Parameters
}
547 \docparam{id
}{The menu item identifier.
}
549 \wxheading{Return value
}
551 The menu item label, or the empty string if the item was not found.
555 Use only after the menubar has been associated with a frame.
557 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
559 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
561 Returns the label of a top-level menu.
563 \wxheading{Parameters
}
565 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
567 \wxheading{Return value
}
569 The menu label, or the empty string if the menu was not found.
573 Use only after the menubar has been associated with a frame.
577 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
579 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
581 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
583 Returns the menu at
{\it menuIndex
} (zero-based).
585 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
587 \constfunc{int
}{GetMenuCount
}{\void}
589 Returns the number of menus in this menubar.
591 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
593 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
595 Determines whether an item is checked.
597 \wxheading{Parameters
}
599 \docparam{id
}{The menu item identifier.
}
601 \wxheading{Return value
}
603 TRUE if the item was found and is checked, FALSE otherwise.
605 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
607 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
609 Determines whether an item is enabled.
611 \wxheading{Parameters
}
613 \docparam{id
}{The menu item identifier.
}
615 \wxheading{Return value
}
617 TRUE if the item was found and is enabled, FALSE otherwise.
619 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
621 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
623 Sets the help string associated with a menu item.
625 \wxheading{Parameters
}
627 \docparam{id
}{Menu item identifier.
}
629 \docparam{helpString
}{Help string to associate with the menu item.
}
633 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
635 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
637 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
639 Sets the label of a menu item.
641 \wxheading{Parameters
}
643 \docparam{id
}{Menu item identifier.
}
645 \docparam{label
}{Menu item label.
}
649 Use only after the menubar has been associated with a frame.
653 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
655 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
657 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
659 Sets the label of a top-level menu.
661 \wxheading{Parameters
}
663 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
665 \docparam{label
}{The menu label.
}
669 Use only after the menubar has been associated with a frame.
673 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}