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 \membersection{wxMenu::
\destruct{wxMenu
}}
56 \func{}{\destruct{wxMenu
}}{\void}
58 Destructor, destroying the menu.
60 Note: under Motif, a popup menu must have a valid parent (the window
61 it was last popped up on) when being destroyed. Therefore, make sure
62 you delete or re-use the popup menu
{\it before
} destroying the
63 parent window. Re-use in this context means popping up the menu on
64 a different window from last time, which causes an implicit destruction
65 and recreation of internal data structures.
67 \membersection{wxMenu::Append
}\label{wxmenuappend
}
69 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
70 \param{const bool
}{ checkable = FALSE
}}
72 Adds a string item to the end of the menu.
74 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
75 \param{const wxString\&
}{helpString = ""
}}
77 Adds a pull-right submenu to the end of the menu.
79 \func{void
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
81 Adds a menu item object. You can specify various extra properties of a menu item this way,
82 such as bitmaps and fonts.
84 \wxheading{Parameters
}
86 \docparam{id
}{The menu command identifier.
}
88 \docparam{item
}{The string to appear on the menu item.
}
90 \docparam{menu
}{Pull-right submenu.
}
92 \docparam{checkable
}{If TRUE, this item is checkable.
}
94 \docparam{helpString
}{An optional help string associated with the item.
95 By default,
\helpref{wxFrame::OnMenuHighlight
}{wxframeonmenuhighlight
} displays
96 this string in the status line.
}
98 \docparam{menuItem
}{A menuitem object. It will be owned by the wxMenu object after this function
99 is called, so do not delete it yourself.
}
103 This command can be used after the menu has been shown, as well as on initial
104 creation of a menu or menubar.
108 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
},
\helpref{wxMenu::SetLabel
}{wxmenusetlabel
},
\helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
},
\rtfsp
109 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenuItem
}{wxmenuitem
}
111 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
113 \func{void
}{AppendSeparator
}{\void}
115 Adds a separator to the end of the menu.
119 \helpref{wxMenu::Append
}{wxmenuappend
}
121 \membersection{wxMenu::Break
}\label{wxmenubreak
}
123 \func{void
}{Break
}{\void}
125 Inserts a break in a menu, causing the next appended item to appear in a new column.
127 \membersection{wxMenu::Check
}\label{wxmenucheck
}
129 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
131 Checks or unchecks the menu item.
133 \wxheading{Parameters
}
135 \docparam{id
}{The menu item identifier.
}
137 \docparam{check
}{If TRUE, the item will be checked, otherwise it will be unchecked.
}
141 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
143 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
145 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
147 Enables or disables (greys out) a menu item.
149 \wxheading{Parameters
}
151 \docparam{id
}{The menu item identifier.
}
153 \docparam{enable
}{TRUE to enable the menu item, FALSE to disable it.
}
157 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
159 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
161 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
163 Finds the menu item id for a menu item string.
165 \wxheading{Parameters
}
167 \docparam{itemString
}{Menu item string to find.
}
169 \wxheading{Return value
}
171 Menu item identifier, or -
1 if none is found.
175 Any special menu codes are stripped out of source and target strings
180 \helpref{wxMenu::FindItemForId
}{wxmenufinditemforid
}
182 \membersection{wxMenu::FindItemForId
}\label{wxmenufinditemforid
}
184 \constfunc{wxMenuItem*
}{FindItemForId
}{\param{int
}{ id
}}
186 Finds the menu item object associated with the given menu item identifier.
188 \wxheading{Parameters
}
190 \docparam{id
}{Menu item identifier.
}
192 \wxheading{Return value
}
194 Returns the menu item object, or NULL if it is not found.
198 \helpref{wxMenu::FindItem
}{wxmenufinditem
}
200 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
202 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
204 Returns the help string associated with a menu item.
206 \wxheading{Parameters
}
208 \docparam{id
}{The menu item identifier.
}
210 \wxheading{Return value
}
212 The help string, or the empty string if there is no help string or the
217 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
219 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
221 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
223 Returns a menu item label.
225 \wxheading{Parameters
}
227 \docparam{id
}{The menu item identifier.
}
229 \wxheading{Return value
}
231 The item label, or the empty string if the item was not found.
235 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
237 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
239 \constfunc{wxString
}{GetTitle
}{\void}
241 Returns the title of the menu.
245 This is relevant only to popup menus.
249 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
251 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
253 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
255 Determines whether a menu item is checked.
257 \wxheading{Parameters
}
259 \docparam{id
}{The menu item identifier.
}
261 \wxheading{Return value
}
263 TRUE if the menu item is checked, FALSE otherwise.
267 \helpref{wxMenu::Check
}{wxmenucheck
}
269 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
271 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
273 Determines whether a menu item is enabled.
275 \wxheading{Parameters
}
277 \docparam{id
}{The menu item identifier.
}
279 \wxheading{Return value
}
281 TRUE if the menu item is enabled, FALSE otherwise.
285 \helpref{wxMenu::Enable
}{wxmenuenable
}
287 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
289 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
291 Sets an item's help string.
293 \wxheading{Parameters
}
295 \docparam{id
}{The menu item identifier.
}
297 \docparam{helpString
}{The help string to set.
}
301 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
303 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
305 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
307 Sets the label of a menu item.
309 \wxheading{Parameters
}
311 \docparam{id
}{The menu item identifier.
}
313 \docparam{label
}{The menu item label to set.
}
317 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
319 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
321 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
323 Sets the title of the menu.
325 \wxheading{Parameters
}
327 \docparam{title
}{The title to set.
}
331 This is relevant only to popup menus.
335 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
337 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
339 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
341 Sends events to
{\it source
} (or owning window if NULL) to update the
342 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
343 the application may call it at other times if required.
347 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
349 \section{\class{wxMenuBar
}}\label{wxmenubar
}
351 A menu bar is a series of menus accessible from the top of a frame.
353 \wxheading{Derived from
}
355 \helpref{wxEvtHandler
}{wxevthandler
}\\
356 \helpref{wxObject
}{wxobject
}
358 \wxheading{Include files
}
362 \wxheading{Event handling
}
364 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
365 that contains the menu bar.
369 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
371 \latexignore{\rtfignore{\wxheading{Members
}}}
373 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarconstr
}
375 \func{void
}{wxMenuBar
}{\void}
379 \func{void
}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
381 Construct a menu bar from arrays of menus and titles.
383 \wxheading{Parameters
}
385 \docparam{n
}{The number of menus.
}
387 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
390 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
392 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}
394 \func{void
}{\destruct{wxMenuBar
}}{\void}
396 Destructor, destroying the menu bar and removing it from the parent frame (if any).
398 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
400 \func{void
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
402 Adds the item to the end of the menu bar.
404 \wxheading{Parameters
}
406 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
408 \docparam{title
}{The title of the menu.
}
410 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
412 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
414 Checks or unchecks a menu item.
416 \wxheading{Parameters
}
418 \docparam{id
}{The menu item identifier.
}
420 \docparam{check
}{If TRUE, checks the menu item, otherwise the item is unchecked.
}
424 Only use this when the menu bar has been associated
425 with a frame; otherwise, use the wxMenu equivalent call.
427 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
429 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
431 Enables or disables (greys out) a menu item.
433 \wxheading{Parameters
}
435 \docparam{id
}{The menu item identifier.
}
437 \docparam{enable
}{TRUE to enable the item, FALSE to disable it.
}
441 Only use this when the menu bar has been
442 associated with a frame; otherwise, use the wxMenu equivalent call.
444 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
446 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
448 Enables or disables a whole menu.
450 \wxheading{Parameters
}
452 \docparam{pos
}{The position of the menu, starting from zero.
}
454 \docparam{enable
}{TRUE to enable the menu, FALSE to disable it.
}
458 Only use this when the menu bar has been
459 associated with a frame.
461 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
463 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
465 Finds the menu item id for a menu name/menu item string pair.
467 \wxheading{Parameters
}
469 \docparam{menuString
}{Menu title to find.
}
471 \docparam{itemString
}{Item to find.
}
473 \wxheading{Return value
}
475 The menu item identifier, or -
1 if none was found.
479 Any special menu codes are stripped out of source and target strings
482 \membersection{wxMenuBar::FindItemById
}\label{wxmenubarfinditembyid
}
484 \constfunc{wxMenuItem *
}{FindItemById
}{\param{int
}{ id
}}
486 Finds the menu item object associated with the given menu item identifier,
488 \wxheading{Parameters
}
490 \docparam{id
}{Menu item identifier.
}
492 \wxheading{Return value
}
494 The found menu item object, or NULL if one was not found.
496 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
498 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
500 Gets the help string associated with the menu item identifer.
502 \wxheading{Parameters
}
504 \docparam{id
}{The menu item identifier.
}
506 \wxheading{Return value
}
508 The help string, or the empty string if there was no help string or the menu item
513 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
515 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
517 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
519 Gets the label associated with a menu item.
521 \wxheading{Parameters
}
523 \docparam{id
}{The menu item identifier.
}
525 \wxheading{Return value
}
527 The menu item label, or the empty string if the item was not found.
531 Use only after the menubar has been associated with a frame.
533 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
535 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
537 Returns the label of a top-level menu.
539 \wxheading{Parameters
}
541 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
543 \wxheading{Return value
}
545 The menu label, or the empty string if the menu was not found.
549 Use only after the menubar has been associated with a frame.
553 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
555 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
557 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
559 Returns the menu at
{\it menuIndex
} (zero-based).
561 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
563 \constfunc{int
}{GetMenuCount
}{\void}
565 Returns the number of menus in this menubar.
567 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
569 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
571 Determines whether an item is checked.
573 \wxheading{Parameters
}
575 \docparam{id
}{The menu item identifier.
}
577 \wxheading{Return value
}
579 TRUE if the item was found and is checked, FALSE otherwise.
581 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
583 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
585 Determines whether an item is enabled.
587 \wxheading{Parameters
}
589 \docparam{id
}{The menu item identifier.
}
591 \wxheading{Return value
}
593 TRUE if the item was found and is enabled, FALSE otherwise.
595 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
597 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
599 Sets the help string associated with a menu item.
601 \wxheading{Parameters
}
603 \docparam{id
}{Menu item identifier.
}
605 \docparam{helpString
}{Help string to associate with the menu item.
}
609 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
611 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
613 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
615 Sets the label of a menu item.
617 \wxheading{Parameters
}
619 \docparam{id
}{Menu item identifier.
}
621 \docparam{label
}{Menu item label.
}
625 Use only after the menubar has been associated with a frame.
629 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
631 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
633 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
635 Sets the label of a top-level menu.
637 \wxheading{Parameters
}
639 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
641 \docparam{label
}{The menu label.
}
645 Use only after the menubar has been associated with a frame.
649 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}