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{long
}{ style =
0}}
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{style
}{If set to
\tt{wxMENU_TEAROFF
}, the menu will be detachable.
}
55 \func{}{wxMenu
}{\param{long
}{ style
}}
57 Constructs a wxMenu object.
59 \wxheading{Parameters
}
61 \docparam{style
}{If set to
\tt{wxMENU_TEAROFF
}, the menu will be detachable.
}
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
}
120 \pythonnote{In place of a single overloaded method name, wxPython
121 implements the following methods:
\par
122 \indented{2cm
}{\begin{twocollist
}
123 \twocolitem{\bf{Append(id, string, helpStr="", checkable=FALSE)
}}{}
124 \twocolitem{\bf{AppendMenu(id, string, aMenu, helpStr="")
}}{}
125 \twocolitem{\bf{AppendItem(aMenuItem)
}}{}
129 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
131 \func{void
}{AppendSeparator
}{\void}
133 Adds a separator to the end of the menu.
137 \helpref{wxMenu::Append
}{wxmenuappend
}
139 \membersection{wxMenu::Break
}\label{wxmenubreak
}
141 \func{void
}{Break
}{\void}
143 Inserts a break in a menu, causing the next appended item to appear in a new column.
145 \membersection{wxMenu::Check
}\label{wxmenucheck
}
147 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
149 Checks or unchecks the menu item.
151 \wxheading{Parameters
}
153 \docparam{id
}{The menu item identifier.
}
155 \docparam{check
}{If TRUE, the item will be checked, otherwise it will be unchecked.
}
159 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
161 \membersection{wxMenu::Delete
}\label{wxmenudelete
}
163 \func{void
}{Delete
}{\param{int
}{id
}}
165 Deletes the menu item from the menu.
167 \wxheading{Parameters
}
169 \docparam{id
}{Menu item to be deleted.
}
173 Does not delete a sub menu, if any.
177 \helpref{wxMenu::FindItemForId
}{wxmenufinditemforid
}
179 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
181 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
183 Enables or disables (greys out) a menu item.
185 \wxheading{Parameters
}
187 \docparam{id
}{The menu item identifier.
}
189 \docparam{enable
}{TRUE to enable the menu item, FALSE to disable it.
}
193 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
195 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
197 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
199 Finds the menu item id for a menu item string.
201 \wxheading{Parameters
}
203 \docparam{itemString
}{Menu item string to find.
}
205 \wxheading{Return value
}
207 Menu item identifier, or wxNOT_FOUND if none is found.
211 Any special menu codes are stripped out of source and target strings
216 \helpref{wxMenu::FindItemForId
}{wxmenufinditemforid
}
218 \membersection{wxMenu::FindItemForId
}\label{wxmenufinditemforid
}
220 \constfunc{wxMenuItem*
}{FindItemForId
}{\param{int
}{ id
}}
222 \constfunc{wxMenuItem*
}{FindItem
}{\param{int
}{ id
}}
224 Finds the menu item object associated with the given menu item identifier.
226 \wxheading{Parameters
}
228 \docparam{id
}{Menu item identifier.
}
230 \wxheading{Return value
}
232 Returns the menu item object, or NULL if it is not found.
236 \helpref{wxMenu::FindItem
}{wxmenufinditem
}
238 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
240 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
242 Returns the help string associated with a menu item.
244 \wxheading{Parameters
}
246 \docparam{id
}{The menu item identifier.
}
248 \wxheading{Return value
}
250 The help string, or the empty string if there is no help string or the
255 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
257 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
259 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
261 Returns a menu item label.
263 \wxheading{Parameters
}
265 \docparam{id
}{The menu item identifier.
}
267 \wxheading{Return value
}
269 The item label, or the empty string if the item was not found.
273 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
275 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
277 \constfunc{wxString
}{GetTitle
}{\void}
279 Returns the title of the menu.
283 This is relevant only to popup menus.
287 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
289 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
291 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
293 Determines whether a menu item is checked.
295 \wxheading{Parameters
}
297 \docparam{id
}{The menu item identifier.
}
299 \wxheading{Return value
}
301 TRUE if the menu item is checked, FALSE otherwise.
305 \helpref{wxMenu::Check
}{wxmenucheck
}
307 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
309 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
311 Determines whether a menu item is enabled.
313 \wxheading{Parameters
}
315 \docparam{id
}{The menu item identifier.
}
317 \wxheading{Return value
}
319 TRUE if the menu item is enabled, FALSE otherwise.
323 \helpref{wxMenu::Enable
}{wxmenuenable
}
325 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
327 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
329 Sets an item's help string.
331 \wxheading{Parameters
}
333 \docparam{id
}{The menu item identifier.
}
335 \docparam{helpString
}{The help string to set.
}
339 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
341 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
343 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
345 Sets the label of a menu item.
347 \wxheading{Parameters
}
349 \docparam{id
}{The menu item identifier.
}
351 \docparam{label
}{The menu item label to set.
}
355 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
357 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
359 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
361 Sets the title of the menu.
363 \wxheading{Parameters
}
365 \docparam{title
}{The title to set.
}
369 This is relevant only to popup menus.
373 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
375 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
377 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
379 Sends events to
{\it source
} (or owning window if NULL) to update the
380 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
381 the application may call it at other times if required.
385 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
387 \section{\class{wxMenuBar
}}\label{wxmenubar
}
389 A menu bar is a series of menus accessible from the top of a frame.
391 \wxheading{Derived from
}
393 \helpref{wxEvtHandler
}{wxevthandler
}\\
394 \helpref{wxObject
}{wxobject
}
396 \wxheading{Include files
}
400 \wxheading{Event handling
}
402 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
403 that contains the menu bar. If you have a toolbar which uses the same identifiers
404 as your EVT
\_MENU entries, events from the toolbar will also be processed by your
405 EVT
\_MENU event handlers.
407 Note that menu commands (and UI update events for menus) are first sent to
408 the focus window within the frame. If no window within the frame has the focus,
409 then the events are sent directly to the frame. This allows command and UI update
410 handling to be processed by specific windows and controls, and not necessarily
411 by the application frame.
415 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
417 \latexignore{\rtfignore{\wxheading{Members
}}}
419 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarconstr
}
421 \func{void
}{wxMenuBar
}{\void}
425 \func{void
}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
427 Construct a menu bar from arrays of menus and titles.
429 \wxheading{Parameters
}
431 \docparam{n
}{The number of menus.
}
433 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
436 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
438 \pythonnote{Only the default constructor is supported in wxPython.
439 Use wxMenuBar.Append instead.
}
441 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}
443 \func{void
}{\destruct{wxMenuBar
}}{\void}
445 Destructor, destroying the menu bar and removing it from the parent frame (if any).
447 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
449 \func{void
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
451 Adds the item to the end of the menu bar.
453 \wxheading{Parameters
}
455 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
457 \docparam{title
}{The title of the menu.
}
459 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
461 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
463 Checks or unchecks a menu item.
465 \wxheading{Parameters
}
467 \docparam{id
}{The menu item identifier.
}
469 \docparam{check
}{If TRUE, checks the menu item, otherwise the item is unchecked.
}
473 Only use this when the menu bar has been associated
474 with a frame; otherwise, use the wxMenu equivalent call.
476 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
478 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
480 Enables or disables (greys out) a menu item.
482 \wxheading{Parameters
}
484 \docparam{id
}{The menu item identifier.
}
486 \docparam{enable
}{TRUE to enable the item, FALSE to disable it.
}
490 Only use this when the menu bar has been
491 associated with a frame; otherwise, use the wxMenu equivalent call.
493 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
495 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
497 Enables or disables a whole menu.
499 \wxheading{Parameters
}
501 \docparam{pos
}{The position of the menu, starting from zero.
}
503 \docparam{enable
}{TRUE to enable the menu, FALSE to disable it.
}
507 Only use this when the menu bar has been
508 associated with a frame.
510 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
512 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
514 Finds the menu item id for a menu name/menu item string pair.
516 \wxheading{Parameters
}
518 \docparam{menuString
}{Menu title to find.
}
520 \docparam{itemString
}{Item to find.
}
522 \wxheading{Return value
}
524 The menu item identifier, or wxNOT_FOUND if none was found.
528 Any special menu codes are stripped out of source and target strings
531 \membersection{wxMenuBar::FindItem
}\label{wxmenubarfinditem
}
533 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu
}{ **menu = NULL
}}
535 Finds the menu item object associated with the given menu item identifier.
537 \wxheading{Parameters
}
539 \docparam{id
}{Menu item identifier.
}
541 \docparam{menu
}{If not NULL, menu will get set to the associated menu.
}
543 \wxheading{Return value
}
545 The found menu item object, or NULL if one was not found.
547 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
549 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
551 Gets the help string associated with the menu item identifer.
553 \wxheading{Parameters
}
555 \docparam{id
}{The menu item identifier.
}
557 \wxheading{Return value
}
559 The help string, or the empty string if there was no help string or the menu item
564 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
566 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
568 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
570 Gets the label associated with a menu item.
572 \wxheading{Parameters
}
574 \docparam{id
}{The menu item identifier.
}
576 \wxheading{Return value
}
578 The menu item label, or the empty string if the item was not found.
582 Use only after the menubar has been associated with a frame.
584 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
586 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
588 Returns the label of a top-level menu.
590 \wxheading{Parameters
}
592 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
594 \wxheading{Return value
}
596 The menu label, or the empty string if the menu was not found.
600 Use only after the menubar has been associated with a frame.
604 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
606 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
608 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
610 Returns the menu at
{\it menuIndex
} (zero-based).
612 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
614 \constfunc{int
}{GetMenuCount
}{\void}
616 Returns the number of menus in this menubar.
618 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
620 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
622 Determines whether an item is checked.
624 \wxheading{Parameters
}
626 \docparam{id
}{The menu item identifier.
}
628 \wxheading{Return value
}
630 TRUE if the item was found and is checked, FALSE otherwise.
632 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
634 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
636 Determines whether an item is enabled.
638 \wxheading{Parameters
}
640 \docparam{id
}{The menu item identifier.
}
642 \wxheading{Return value
}
644 TRUE if the item was found and is enabled, FALSE otherwise.
646 \membersection{wxMenuBar::Refresh
}\label{wxmenubarrefresh
}
648 \func{void
}{Refresh
}{\void}
652 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
654 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
656 Sets the help string associated with a menu item.
658 \wxheading{Parameters
}
660 \docparam{id
}{Menu item identifier.
}
662 \docparam{helpString
}{Help string to associate with the menu item.
}
666 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
668 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
670 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
672 Sets the label of a menu item.
674 \wxheading{Parameters
}
676 \docparam{id
}{Menu item identifier.
}
678 \docparam{label
}{Menu item label.
}
682 Use only after the menubar has been associated with a frame.
686 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
688 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
690 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
692 Sets the label of a top-level menu.
694 \wxheading{Parameters
}
696 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
698 \docparam{label
}{The menu label.
}
702 Use only after the menubar has been associated with a frame.
706 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}