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{Event handling
}
17 If the menu is part of a menubar, then
\helpref{wxMenuBar
}{wxmenubar
} event processing is used.
19 With a popup menu, there is a variety of ways to handle a menu selection event
20 (wxEVT
\_COMMAND\_MENU\_SELECTED).
22 \begin{enumerate
}\itemsep=
0pt
23 \item Define a callback of type wxFunction, which you pass to the wxMenu constructor.
24 The callback takes a reference to the menu, and a reference to a
\helpref{wxCommandEvent
}{wxcommandevent
}.
25 \item Derive a new class from wxMenu and define event table entries using the EVT
\_MENU macro.
26 \item Set a new event handler for wxMenu, using an object whose class has EVT
\_MENU entries.
27 \item Provide EVT
\_MENU handlers in the window which pops up the menu, or in an ancestor of
33 \helpref{wxMenuBar
}{wxmenubar
},
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
},
\rtfsp
34 \helpref{Event handling overview
}{eventhandlingoverview
}
36 \latexignore{\rtfignore{\wxheading{Members
}}}
38 \membersection{wxMenu::wxMenu
}\label{wxmenuconstr
}
40 \func{}{wxMenu
}{\param{const wxString\&
}{title = ""
},
\param{const wxFunction
}{ func = NULL
}}
42 Constructs a wxMenu object.
44 \wxheading{Parameters
}
46 \docparam{title
}{A title for the popup menu: the empty string denotes no title.
}
48 \docparam{func
}{A callback function if the menu is used as a popup using
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}.
}
50 \membersection{wxMenu::
\destruct{wxMenu
}}
52 \func{}{\destruct{wxMenu
}}{\void}
54 Destructor, destroying the menu.
56 Note: under Motif, a popup menu must have a valid parent (the window
57 it was last popped up on) when being destroyed. Therefore, make sure
58 you delete or re-use the popup menu
{\it before
} destroying the
59 parent window. Re-use in this context means popping up the menu on
60 a different window from last time, which causes an implicit destruction
61 and recreation of internal data structures.
63 \membersection{wxMenu::Append
}\label{wxmenuappend
}
65 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
66 \param{const bool
}{ checkable = FALSE
}}
68 Adds a string item to the end of the menu.
70 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
71 \param{const wxString\&
}{helpString = ""
}}
73 Adds a pull-right submenu to the end of the menu.
75 \func{void
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
77 Adds a menu item object. You can specify various extra properties of a menu item this way,
78 such as bitmaps and fonts.
80 \wxheading{Parameters
}
82 \docparam{id
}{The menu command identifier.
}
84 \docparam{item
}{The string to appear on the menu item.
}
86 \docparam{menu
}{Pull-right submenu.
}
88 \docparam{checkable
}{If TRUE, this item is checkable.
}
90 \docparam{helpString
}{An optional help string associated with the item.
91 By default,
\helpref{wxFrame::OnMenuHighlight
}{wxframeonmenuhighlight
} displays
92 this string in the status line.
}
94 \docparam{menuItem
}{A menuitem object. It will be owned by the wxMenu object after this function
95 is called, so do not delete it yourself.
}
99 This command can be used after the menu has been shown, as well as on initial
100 creation of a menu or menubar.
104 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
},
\helpref{wxMenu::SetLabel
}{wxmenusetlabel
},
\helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
},
\rtfsp
105 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenuItem
}{wxmenuitem
}
107 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
109 \func{void
}{AppendSeparator
}{\void}
111 Adds a separator to the end of the menu.
115 \helpref{wxMenu::Append
}{wxmenuappend
}
117 \membersection{wxMenu::Break
}\label{wxmenubreak
}
119 \func{void
}{Break
}{\void}
121 Inserts a break in a menu, causing the next appended item to appear in a new column.
123 \membersection{wxMenu::Check
}\label{wxmenucheck
}
125 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
127 Checks or unchecks the menu item.
129 \wxheading{Parameters
}
131 \docparam{id
}{The menu item identifier.
}
133 \docparam{check
}{If TRUE, the item will be checked, otherwise it will be unchecked.
}
137 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
139 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
141 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
143 Enables or disables (greys out) a menu item.
145 \wxheading{Parameters
}
147 \docparam{id
}{The menu item identifier.
}
149 \docparam{enable
}{TRUE to enable the menu item, FALSE to disable it.
}
153 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
155 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
157 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
159 Finds the menu item id for a menu item string.
161 \wxheading{Parameters
}
163 \docparam{itemString
}{Menu item string to find.
}
165 \wxheading{Return value
}
167 Menu item identifier, or -
1 if none is found.
171 Any special menu codes are stripped out of source and target strings
176 \helpref{wxMenu::FindItemForId
}{wxmenufinditemforid
}
178 \membersection{wxMenu::FindItemForId
}\label{wxmenufinditemforid
}
180 \constfunc{wxMenuItem*
}{FindItemForId
}{\param{int
}{ id
}}
182 Finds the menu item object associated with the given menu item identifier.
184 \wxheading{Parameters
}
186 \docparam{id
}{Menu item identifier.
}
188 \wxheading{Return value
}
190 Returns the menu item object, or NULL if it is not found.
194 \helpref{wxMenu::FindItem
}{wxmenufinditem
}
196 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
198 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
200 Returns the help string associated with a menu item.
202 \wxheading{Parameters
}
204 \docparam{id
}{The menu item identifier.
}
206 \wxheading{Return value
}
208 The help string, or the empty string if there is no help string or the
213 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
215 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
217 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
219 Returns a menu item label.
221 \wxheading{Parameters
}
223 \docparam{id
}{The menu item identifier.
}
225 \wxheading{Return value
}
227 The item label, or the empty string if the item was not found.
231 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
233 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
235 \constfunc{wxString
}{GetTitle
}{\void}
237 Returns the title of the menu.
241 This is relevant only to popup menus.
245 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
247 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
249 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
251 Determines whether a menu item is checked.
253 \wxheading{Parameters
}
255 \docparam{id
}{The menu item identifier.
}
257 \wxheading{Return value
}
259 TRUE if the menu item is checked, FALSE otherwise.
263 \helpref{wxMenu::Check
}{wxmenucheck
}
265 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
267 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
269 Determines whether a menu item is enabled.
271 \wxheading{Parameters
}
273 \docparam{id
}{The menu item identifier.
}
275 \wxheading{Return value
}
277 TRUE if the menu item is enabled, FALSE otherwise.
281 \helpref{wxMenu::Enable
}{wxmenuenable
}
283 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
285 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
287 Sets an item's help string.
289 \wxheading{Parameters
}
291 \docparam{id
}{The menu item identifier.
}
293 \docparam{helpString
}{The help string to set.
}
297 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
299 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
301 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
303 Sets the label of a menu item.
305 \wxheading{Parameters
}
307 \docparam{id
}{The menu item identifier.
}
309 \docparam{label
}{The menu item label to set.
}
313 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
315 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
317 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
319 Sets the title of the menu.
321 \wxheading{Parameters
}
323 \docparam{title
}{The title to set.
}
327 This is relevant only to popup menus.
331 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
333 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
335 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
337 Sends events to
{\it source
} (or owning window if NULL) to update the
338 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
339 the application may call it at other times if required.
343 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
345 \section{\class{wxMenuBar
}}\label{wxmenubar
}
347 A menu bar is a series of menus accessible from the top of a frame.
349 \wxheading{Derived from
}
351 \helpref{wxEvtHandler
}{wxevthandler
}\\
352 \helpref{wxObject
}{wxobject
}
354 \wxheading{Event handling
}
356 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
357 that contains the menu bar.
361 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
363 \latexignore{\rtfignore{\wxheading{Members
}}}
365 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarconstr
}
367 \func{void
}{wxMenuBar
}{\void}
371 \func{void
}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
373 Construct a menu bar from arrays of menus and titles.
375 \wxheading{Parameters
}
377 \docparam{n
}{The number of menus.
}
379 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
382 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
384 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}
386 \func{void
}{\destruct{wxMenuBar
}}{\void}
388 Destructor, destroying the menu bar and removing it from the parent frame (if any).
390 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
392 \func{void
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
394 Adds the item to the end of the menu bar.
396 \wxheading{Parameters
}
398 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
400 \docparam{title
}{The title of the menu.
}
402 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
404 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
406 Checks or unchecks a menu item.
408 \wxheading{Parameters
}
410 \docparam{id
}{The menu item identifier.
}
412 \docparam{check
}{If TRUE, checks the menu item, otherwise the item is unchecked.
}
416 Only use this when the menu bar has been associated
417 with a frame; otherwise, use the wxMenu equivalent call.
419 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
421 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
423 Enables or disables (greys out) a menu item.
425 \wxheading{Parameters
}
427 \docparam{id
}{The menu item identifier.
}
429 \docparam{enable
}{TRUE to enable the item, FALSE to disable it.
}
433 Only use this when the menu bar has been
434 associated with a frame; otherwise, use the wxMenu equivalent call.
436 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
438 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
440 Enables or disables a whole menu.
442 \wxheading{Parameters
}
444 \docparam{pos
}{The position of the menu, starting from zero.
}
446 \docparam{enable
}{TRUE to enable the menu, FALSE to disable it.
}
450 Only use this when the menu bar has been
451 associated with a frame.
453 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
455 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
457 Finds the menu item id for a menu name/menu item string pair.
459 \wxheading{Parameters
}
461 \docparam{menuString
}{Menu title to find.
}
463 \docparam{itemString
}{Item to find.
}
465 \wxheading{Return value
}
467 The menu item identifier, or -
1 if none was found.
471 Any special menu codes are stripped out of source and target strings
474 \membersection{wxMenuBar::FindItemById
}\label{wxmenubarfinditembyid
}
476 \constfunc{wxMenuItem *
}{FindItemById
}{\param{int
}{ id
}}
478 Finds the menu item object associated with the given menu item identifier,
480 \wxheading{Parameters
}
482 \docparam{id
}{Menu item identifier.
}
484 \wxheading{Return value
}
486 The found menu item object, or NULL if one was not found.
488 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
490 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
492 Gets the help string associated with the menu item identifer.
494 \wxheading{Parameters
}
496 \docparam{id
}{The menu item identifier.
}
498 \wxheading{Return value
}
500 The help string, or the empty string if there was no help string or the menu item
505 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
507 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
509 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
511 Gets the label associated with a menu item.
513 \wxheading{Parameters
}
515 \docparam{id
}{The menu item identifier.
}
517 \wxheading{Return value
}
519 The menu item label, or the empty string if the item was not found.
523 Use only after the menubar has been associated with a frame.
525 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
527 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
529 Returns the label of a top-level menu.
531 \wxheading{Parameters
}
533 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
535 \wxheading{Return value
}
537 The menu label, or the empty string if the menu was not found.
541 Use only after the menubar has been associated with a frame.
545 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
547 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
549 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
551 Returns the menu at
{\it menuIndex
} (zero-based).
553 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
555 \constfunc{int
}{GetMenuCount
}{\void}
557 Returns the number of menus in this menubar.
559 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
561 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
563 Determines whether an item is checked.
565 \wxheading{Parameters
}
567 \docparam{id
}{The menu item identifier.
}
569 \wxheading{Return value
}
571 TRUE if the item was found and is checked, FALSE otherwise.
573 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
575 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
577 Determines whether an item is enabled.
579 \wxheading{Parameters
}
581 \docparam{id
}{The menu item identifier.
}
583 \wxheading{Return value
}
585 TRUE if the item was found and is enabled, FALSE otherwise.
587 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
589 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
591 Sets the help string associated with a menu item.
593 \wxheading{Parameters
}
595 \docparam{id
}{Menu item identifier.
}
597 \docparam{helpString
}{Help string to associate with the menu item.
}
601 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
603 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
605 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
607 Sets the label of a menu item.
609 \wxheading{Parameters
}
611 \docparam{id
}{Menu item identifier.
}
613 \docparam{label
}{Menu item label.
}
617 Use only after the menubar has been associated with a frame.
621 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
623 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
625 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
627 Sets the label of a top-level menu.
629 \wxheading{Parameters
}
631 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
633 \docparam{label
}{The menu label.
}
637 Use only after the menubar has been associated with a frame.
641 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}