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 \membersection{wxMenu::Append
}\label{wxmenuappend
}
58 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
59 \param{const bool
}{ checkable = FALSE
}}
61 Adds a string item to the end of the menu.
63 \func{void
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
64 \param{const wxString\&
}{helpString = ""
}}
66 Adds a pull-right submenu to the end of the menu.
68 \func{void
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
70 Adds a menu item object. You can specify various extra properties of a menu item this way,
71 such as bitmaps and fonts.
73 \wxheading{Parameters
}
75 \docparam{id
}{The menu command identifier.
}
77 \docparam{item
}{The string to appear on the menu item.
}
79 \docparam{menu
}{Pull-right submenu.
}
81 \docparam{checkable
}{If TRUE, this item is checkable.
}
83 \docparam{helpString
}{An optional help string associated with the item.
84 By default,
\helpref{wxFrame::OnMenuHighlight
}{wxframeonmenuhighlight
} displays
85 this string in the status line.
}
87 \docparam{menuItem
}{A menuitem object. It will be owned by the wxMenu object after this function
88 is called, so do not delete it yourself.
}
92 This command can be used after the menu has been shown, as well as on initial
93 creation of a menu or menubar.
97 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
},
\helpref{wxMenu::SetLabel
}{wxmenusetlabel
},
\helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
},
\rtfsp
98 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenuItem
}{wxmenuitem
}
100 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
102 \func{void
}{AppendSeparator
}{\void}
104 Adds a separator to the end of the menu.
108 \helpref{wxMenu::Append
}{wxmenuappend
}
110 \membersection{wxMenu::Break
}\label{wxmenubreak
}
112 \func{void
}{Break
}{\void}
114 Inserts a break in a menu, causing the next appended item to appear in a new column.
116 \membersection{wxMenu::Check
}\label{wxmenucheck
}
118 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
120 Checks or unchecks the menu item.
122 \wxheading{Parameters
}
124 \docparam{id
}{The menu item identifier.
}
126 \docparam{check
}{If TRUE, the item will be checked, otherwise it will be unchecked.
}
130 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
132 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
134 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
136 Enables or disables (greys out) a menu item.
138 \wxheading{Parameters
}
140 \docparam{id
}{The menu item identifier.
}
142 \docparam{enable
}{TRUE to enable the menu item, FALSE to disable it.
}
146 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
148 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
150 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
152 Finds the menu item id for a menu item string.
154 \wxheading{Parameters
}
156 \docparam{itemString
}{Menu item string to find.
}
158 \wxheading{Return value
}
160 Menu item identifier, or -
1 if none is found.
164 Any special menu codes are stripped out of source and target strings
169 \helpref{wxMenu::FindItemForId
}{wxmenufinditemforid
}
171 \membersection{wxMenu::FindItemForId
}\label{wxmenufinditemforid
}
173 \constfunc{wxMenuItem*
}{FindItemForId
}{\param{int
}{ id
}}
175 Finds the menu item object associated with the given menu item identifier.
177 \wxheading{Parameters
}
179 \docparam{id
}{Menu item identifier.
}
181 \wxheading{Return value
}
183 Returns the menu item object, or NULL if it is not found.
187 \helpref{wxMenu::FindItem
}{wxmenufinditem
}
189 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
191 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
193 Returns the help string associated with a menu item.
195 \wxheading{Parameters
}
197 \docparam{id
}{The menu item identifier.
}
199 \wxheading{Return value
}
201 The help string, or the empty string if there is no help string or the
206 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
208 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
210 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
212 Returns a menu item label.
214 \wxheading{Parameters
}
216 \docparam{id
}{The menu item identifier.
}
218 \wxheading{Return value
}
220 The item label, or the empty string if the item was not found.
224 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
226 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
228 \constfunc{wxString
}{GetTitle
}{\void}
230 Returns the title of the menu.
234 This is relevant only to popup menus.
238 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
240 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
242 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
244 Determines whether a menu item is checked.
246 \wxheading{Parameters
}
248 \docparam{id
}{The menu item identifier.
}
250 \wxheading{Return value
}
252 TRUE if the menu item is checked, FALSE otherwise.
256 \helpref{wxMenu::Check
}{wxmenucheck
}
258 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
260 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
262 Determines whether a menu item is enabled.
264 \wxheading{Parameters
}
266 \docparam{id
}{The menu item identifier.
}
268 \wxheading{Return value
}
270 TRUE if the menu item is enabled, FALSE otherwise.
274 \helpref{wxMenu::Enable
}{wxmenuenable
}
276 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
278 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
280 Sets an item's help string.
282 \wxheading{Parameters
}
284 \docparam{id
}{The menu item identifier.
}
286 \docparam{helpString
}{The help string to set.
}
290 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
292 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
294 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
296 Sets the label of a menu item.
298 \wxheading{Parameters
}
300 \docparam{id
}{The menu item identifier.
}
302 \docparam{label
}{The menu item label to set.
}
306 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
308 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
310 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
312 Sets the title of the menu.
314 \wxheading{Parameters
}
316 \docparam{title
}{The title to set.
}
320 This is relevant only to popup menus.
324 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
326 \section{\class{wxMenuBar
}}\label{wxmenubar
}
328 A menu bar is a series of menus accessible from the top of a frame.
330 \wxheading{Derived from
}
332 \helpref{wxEvtHandler
}{wxevthandler
}\\
333 \helpref{wxObject
}{wxobject
}
335 \wxheading{Event handling
}
337 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
338 that contains the menu bar.
342 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
344 \latexignore{\rtfignore{\wxheading{Members
}}}
346 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarconstr
}
348 \func{void
}{wxMenuBar
}{\void}
352 \func{void
}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
354 Construct a menu bar from arrays of menus and titles.
356 \wxheading{Parameters
}
358 \docparam{n
}{The number of menus.
}
360 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
363 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
365 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}
367 \func{void
}{\destruct{wxMenuBar
}}{\void}
369 Destructor, destroying the menu bar and removing it from the parent frame (if any).
371 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
373 \func{void
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
375 Adds the item to the end of the menu bar.
377 \wxheading{Parameters
}
379 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
381 \docparam{title
}{The title of the menu.
}
383 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
385 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
387 Checks or unchecks a menu item.
389 \wxheading{Parameters
}
391 \docparam{id
}{The menu item identifier.
}
393 \docparam{check
}{If TRUE, checks the menu item, otherwise the item is unchecked.
}
397 Only use this when the menu bar has been associated
398 with a frame; otherwise, use the wxMenu equivalent call.
400 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
402 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
404 Enables or disables (greys out) a menu item.
406 \wxheading{Parameters
}
408 \docparam{id
}{The menu item identifier.
}
410 \docparam{enable
}{TRUE to enable the item, FALSE to disable it.
}
414 Only use this when the menu bar has been
415 associated with a frame; otherwise, use the wxMenu equivalent call.
417 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
419 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
421 Enables or disables a whole menu.
423 \wxheading{Parameters
}
425 \docparam{pos
}{The position of the menu, starting from zero.
}
427 \docparam{enable
}{TRUE to enable the menu, FALSE to disable it.
}
431 Only use this when the menu bar has been
432 associated with a frame.
434 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
436 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
438 Finds the menu item id for a menu name/menu item string pair.
440 \wxheading{Parameters
}
442 \docparam{menuString
}{Menu title to find.
}
444 \docparam{itemString
}{Item to find.
}
446 \wxheading{Return value
}
448 The menu item identifier, or -
1 if none was found.
452 Any special menu codes are stripped out of source and target strings
455 \membersection{wxMenuBar::FindItemById
}\label{wxmenubarfinditembyid
}
457 \constfunc{wxMenuItem *
}{FindItemById
}{\param{int
}{ id
}}
459 Finds the menu item object associated with the given menu item identifier,
461 \wxheading{Parameters
}
463 \docparam{id
}{Menu item identifier.
}
465 \wxheading{Return value
}
467 The found menu item object, or NULL if one was not found.
469 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
471 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
473 Gets the help string associated with the menu item identifer.
475 \wxheading{Parameters
}
477 \docparam{id
}{The menu item identifier.
}
479 \wxheading{Return value
}
481 The help string, or the empty string if there was no help string or the menu item
486 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
488 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
490 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
492 Gets the label associated with a menu item.
494 \wxheading{Parameters
}
496 \docparam{id
}{The menu item identifier.
}
498 \wxheading{Return value
}
500 The menu item label, or the empty string if the item was not found.
504 Use only after the menubar has been associated with a frame.
506 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
508 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
510 Returns the label of a top-level menu.
512 \wxheading{Parameters
}
514 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
516 \wxheading{Return value
}
518 The menu label, or the empty string if the menu was not found.
522 Use only after the menubar has been associated with a frame.
526 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
528 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
530 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
532 Returns the menu at
{\it menuIndex
} (zero-based).
534 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
536 \constfunc{int
}{GetMenuCount
}{\void}
538 Returns the number of menus in this menubar.
540 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
542 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
544 Determines whether an item is checked.
546 \wxheading{Parameters
}
548 \docparam{id
}{The menu item identifier.
}
550 \wxheading{Return value
}
552 TRUE if the item was found and is checked, FALSE otherwise.
554 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
556 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
558 Determines whether an item is enabled.
560 \wxheading{Parameters
}
562 \docparam{id
}{The menu item identifier.
}
564 \wxheading{Return value
}
566 TRUE if the item was found and is enabled, FALSE otherwise.
568 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
570 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
572 Sets the help string associated with a menu item.
574 \wxheading{Parameters
}
576 \docparam{id
}{Menu item identifier.
}
578 \docparam{helpString
}{Help string to associate with the menu item.
}
582 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
584 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
586 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
588 Sets the label of a menu item.
590 \wxheading{Parameters
}
592 \docparam{id
}{Menu item identifier.
}
594 \docparam{label
}{Menu item label.
}
598 Use only after the menubar has been associated with a frame.
602 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
604 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
606 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
608 Sets the label of a top-level menu.
610 \wxheading{Parameters
}
612 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
614 \docparam{label
}{The menu label.
}
618 Use only after the menubar has been associated with a frame.
622 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}