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. A menu item
9 with a special identifier $-
1$ is a separator item and doesn't have an
10 associated command but just makes a separator line appear in the menu.
12 {\bf NB:
} Please note that
{\it wxID
\_ABOUT} and
{\it wxID
\_EXIT} are
13 predefined by wxWidgets and have a special meaning since entries
14 using these IDs will be taken out of the normal menus under MacOS X
15 and will be inserted into the system menu (following the appropriate
16 MacOS X interface guideline).
18 Menu items may be either normal items, check items or radio items. Normal items
19 don't have any special properties while the check items have a boolean flag
20 associated to them and they show a checkmark in the menu when the flag is set.
21 wxWidgets automatically toggles the flag value when the item is clicked and its
22 value may be retrieved using either
\helpref{IsChecked
}{wxmenuischecked
} method
23 of wxMenu or wxMenuBar itself or by using
24 \helpref{wxEvent::IsChecked
}{wxcommandeventischecked
} when you get the menu
25 notification for the item in question.
27 The radio items are similar to the check items except that all the other items
28 in the same radio group are unchecked when a radio item is checked. The radio
29 group is formed by a contiguous range of radio items, i.e. it starts at the
30 first item of this kind and ends with the first item of a different kind (or
31 the end of the menu). Notice that because the radio groups are defined in terms
32 of the item positions inserting or removing the items in the menu containing
33 the radio items risks to not work correctly. Finally note that the radio items
34 are only supported under Windows and GTK+ currently.
36 \wxheading{Allocation strategy
}
38 All menus except the popup ones must be created on the heap. All menus
39 attached to a menubar or to another menu will be deleted by their parent when
40 it is deleted. As the frame menubar is deleted by the frame itself, it means
41 that normally all menus used are deleted automatically.
43 \wxheading{Derived from
}
45 \helpref{wxEvtHandler
}{wxevthandler
}\\
46 \helpref{wxObject
}{wxobject
}
48 \wxheading{Include files
}
52 \wxheading{Event handling
}
54 If the menu is part of a menubar, then
\helpref{wxMenuBar
}{wxmenubar
} event processing is used.
56 With a popup menu, there is a variety of ways to handle a menu selection event
57 (wxEVT
\_COMMAND\_MENU\_SELECTED).
59 \begin{enumerate
}\itemsep=
0pt
60 \item Derive a new class from wxMenu and define event table entries using the EVT
\_MENU macro.
61 \item Set a new event handler for wxMenu, using an object whose class has EVT
\_MENU entries.
62 \item Provide EVT
\_MENU handlers in the window which pops up the menu, or in an ancestor of
64 \item Define a callback of type wxFunction, which you pass to the wxMenu constructor.
65 The callback takes a reference to the menu, and a reference to a
66 \helpref{wxCommandEvent
}{wxcommandevent
}. This method is deprecated and should
67 not be used in the new code, it is provided for backwards compatibility only.
72 \helpref{wxMenuBar
}{wxmenubar
},
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
},
\rtfsp
73 \helpref{Event handling overview
}{eventhandlingoverview
}
75 \latexignore{\rtfignore{\wxheading{Members
}}}
77 \membersection{wxMenu::wxMenu
}\label{wxmenuctor
}
79 \func{}{wxMenu
}{\param{const wxString\&
}{title = ""
},
\param{long
}{ style =
0}}
81 Constructs a wxMenu object.
83 \wxheading{Parameters
}
85 \docparam{title
}{A title for the popup menu: the empty string denotes no title.
}
87 \docparam{style
}{If set to
{\tt wxMENU
\_TEAROFF}, the menu will be detachable (wxGTK only).
}
89 \func{}{wxMenu
}{\param{long
}{ style
}}
91 Constructs a wxMenu object.
93 \wxheading{Parameters
}
95 \docparam{style
}{If set to
{\tt wxMENU
\_TEAROFF}, the menu will be detachable (wxGTK only).
}
97 \membersection{wxMenu::
\destruct{wxMenu
}}\label{wxmenudtor
}
99 \func{}{\destruct{wxMenu
}}{\void}
101 Destructor, destroying the menu.
103 Note: under Motif, a popup menu must have a valid parent (the window
104 it was last popped up on) when being destroyed. Therefore, make sure
105 you delete or re-use the popup menu
{\it before
} destroying the
106 parent window. Re-use in this context means popping up the menu on
107 a different window from last time, which causes an implicit destruction
108 and recreation of internal data structures.
110 \membersection{wxMenu::Append
}\label{wxmenuappend
}
112 \func{wxMenuItem*
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
113 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
115 Adds a string item to the end of the menu.
117 \func{wxMenuItem*
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
118 \param{const wxString\&
}{helpString = ""
}}
120 Adds a pull-right submenu to the end of the menu. Append the submenu to the parent
121 menu
{\it after
} you have added your menu items, or accelerators may not be
124 \func{wxMenuItem*
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
126 Adds a menu item object. This is the most generic variant of Append() method
127 because it may be used for both items (including separators) and submenus and
128 because you can also specify various extra properties of a menu item this way,
129 such as bitmaps and fonts.
131 \wxheading{Parameters
}
133 \docparam{id
}{The menu command identifier.
}
135 \docparam{item
}{The string to appear on the menu item.
}
137 \docparam{menu
}{Pull-right submenu.
}
139 \docparam{kind
}{May be
{\tt wxITEM
\_SEPARATOR},
{\tt wxITEM
\_NORMAL},
140 {\tt wxITEM
\_CHECK} or
{\tt wxITEM
\_RADIO}}
142 \docparam{helpString
}{An optional help string associated with the item.
143 By default, the handler for the wxEVT
\_MENU\_HIGHLIGHT event displays
144 this string in the status line.
}
146 \docparam{menuItem
}{A menuitem object. It will be owned by the wxMenu object after this function
147 is called, so do not delete it yourself.
}
151 This command can be used after the menu has been shown, as well as on initial
152 creation of a menu or menubar.
154 The
{\it item
} string for the normal menu items (not submenus or separators)
155 may include the accelerator which can be used to activate the menu item
156 from keyboard. The accelerator string follows the item label and is separated
157 from it by a
{\tt TAB
} character (
{\tt '$
\backslash$t'
}). Its general syntax is
158 any combination of
{\tt "CTRL"
},
{\tt "ALT"
} and
{\tt "SHIFT"
} strings (case
159 doesn't matter) separated by either
{\tt '-'
} or
{\tt '+'
} characters and
160 followed by the accelerator itself. The accelerator may be any alphanumeric
161 character, any function key (from
{\tt F1
} to
{\tt F12
}) or one of the special
162 characters listed in the table below (again, case doesn't matter):
164 \begin{twocollist
}\itemsep=
0pt
165 \twocolitem{{\tt DEL
} or
{\tt DELETE
}}{Delete key
}
166 \twocolitem{{\tt INS
} or
{\tt INSERT
}}{Insert key
}
167 \twocolitem{{\tt ENTER
} or
{\tt RETURN
}}{Enter key
}
168 \twocolitem{{\tt PGUP
}}{PageUp key
}
169 \twocolitem{{\tt PGDN
}}{PageDown key
}
170 \twocolitem{{\tt LEFT
}}{Left cursor arrow key
}
171 \twocolitem{{\tt RIGHT
}}{Right cursor arrow key
}
172 \twocolitem{{\tt UP
}}{Up cursor arrow key
}
173 \twocolitem{{\tt DOWN
}}{Down cursor arrow key
}
174 \twocolitem{{\tt HOME
}}{Home key
}
175 \twocolitem{{\tt END
}}{End key
}
176 \twocolitem{{\tt SPACE
}}{Space
}
177 \twocolitem{{\tt TAB
}}{Tab key
}
178 \twocolitem{{\tt ESC
} or
{\tt ESCAPE
}}{Escape key (Windows only)
}
183 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
},
\rtfsp
184 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
},
\rtfsp
185 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
},
\rtfsp
186 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
187 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
},
\helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
},
\rtfsp
188 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenuItem
}{wxmenuitem
}
190 \pythonnote{In place of a single overloaded method name, wxPython
191 implements the following methods:
193 \indented{2cm
}{\begin{twocollist
}
194 \twocolitem{{\bf Append(id, string, helpStr="", checkable=false)
}}{}
195 \twocolitem{{\bf AppendMenu(id, string, aMenu, helpStr="")
}}{}
196 \twocolitem{{\bf AppendItem(aMenuItem)
}}{}
200 \membersection{wxMenu::AppendCheckItem
}\label{wxmenuappendcheckitem
}
202 \func{wxMenuItem*
}{AppendCheckItem
}{\param{int
}{ id
},
\rtfsp
203 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
205 Adds a checkable item to the end of the menu.
209 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
210 \helpref{wxMenu::InsertCheckItem
}{wxmenuinsertcheckitem
}
212 \membersection{wxMenu::AppendRadioItem
}\label{wxmenuappendradioitem
}
214 \func{wxMenuItem*
}{AppendRadioItem
}{\param{int
}{ id
},
\rtfsp
215 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
217 Adds a radio item to the end of the menu. All consequent radio items form a
218 group and when an item in the group is checked, all the others are
219 automatically unchecked.
221 {\bf NB:
} Currently only implemented under Windows and GTK, use
222 {\tt\#if wxHAS
\_RADIO\_MENU\_ITEMS} to test for availability of this feature.
226 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
227 \helpref{wxMenu::InsertRadioItem
}{wxmenuinsertradioitem
}
229 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
231 \func{wxMenuItem*
}{AppendSeparator
}{\void}
233 Adds a separator to the end of the menu.
237 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
238 \helpref{wxMenu::InsertSeparator
}{wxmenuinsertseparator
}
240 \membersection{wxMenu::Break
}\label{wxmenubreak
}
242 \func{void
}{Break
}{\void}
244 Inserts a break in a menu, causing the next appended item to appear in a new column.
246 \membersection{wxMenu::Check
}\label{wxmenucheck
}
248 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
250 Checks or unchecks the menu item.
252 \wxheading{Parameters
}
254 \docparam{id
}{The menu item identifier.
}
256 \docparam{check
}{If true, the item will be checked, otherwise it will be unchecked.
}
260 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
262 \membersection{wxMenu::Delete
}\label{wxmenudelete
}
264 \func{void
}{Delete
}{\param{int
}{id
}}
266 \func{void
}{Delete
}{\param{wxMenuItem *
}{item
}}
268 Deletes the menu item from the menu. If the item is a submenu, it will
269 {\bf not
} be deleted. Use
\helpref{Destroy
}{wxmenudestroy
} if you want to
272 \wxheading{Parameters
}
274 \docparam{id
}{Id of the menu item to be deleted.
}
276 \docparam{item
}{Menu item to be deleted.
}
280 \helpref{wxMenu::FindItem
}{wxmenufinditem
},
\rtfsp
281 \helpref{wxMenu::Destroy
}{wxmenudestroy
},
\rtfsp
282 \helpref{wxMenu::Remove
}{wxmenuremove
}
284 \membersection{wxMenu::Destroy
}\label{wxmenudestroy
}
286 \func{void
}{Destroy
}{\param{int
}{id
}}
288 \func{void
}{Destroy
}{\param{wxMenuItem *
}{item
}}
290 Deletes the menu item from the menu. If the item is a submenu, it will
291 be deleted. Use
\helpref{Remove
}{wxmenuremove
} if you want to keep the submenu
292 (for example, to reuse it later).
294 \wxheading{Parameters
}
296 \docparam{id
}{Id of the menu item to be deleted.
}
298 \docparam{item
}{Menu item to be deleted.
}
302 \helpref{wxMenu::FindItem
}{wxmenufinditem
},
\rtfsp
303 \helpref{wxMenu::Deletes
}{wxmenudelete
},
\rtfsp
304 \helpref{wxMenu::Remove
}{wxmenuremove
}
306 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
308 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
310 Enables or disables (greys out) a menu item.
312 \wxheading{Parameters
}
314 \docparam{id
}{The menu item identifier.
}
316 \docparam{enable
}{true to enable the menu item, false to disable it.
}
320 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
322 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
324 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
326 Finds the menu item id for a menu item string.
328 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu **
}{menu = NULL
}}
330 Finds the menu item object associated with the given menu item identifier and,
331 optionally, the (sub)menu it belongs to.
333 \perlnote{In wxPerl this method takes just the
{\tt id
} parameter;
334 in scalar context it returns the associated
{\tt Wx::MenuItem
}, in list
335 context it returns a
2-element list
{\tt ( item, submenu )
}}
337 \wxheading{Parameters
}
339 \docparam{itemString
}{Menu item string to find.
}
341 \docparam{id
}{Menu item identifier.
}
343 \docparam{menu
}{If the pointer is not NULL, it will be filled with the item's
344 parent menu (if the item was found)
}
346 \wxheading{Return value
}
348 First form: menu item identifier, or
{\tt wxNOT
\_FOUND} if none is found.
350 Second form: returns the menu item object, or NULL if it is not found.
354 Any special menu codes are stripped out of source and target strings
357 \pythonnote{The name of this method in wxPython is
{\tt FindItemById
}
358 and it does not support the second parameter.
}
360 \membersection{wxMenu::FindItemByPosition
}\label{wxmenufinditembyposition
}
362 \constfunc{wxMenuItem*
}{FindItemByPosition
}{\param{size
\_t }{position
}}
364 Returns the wxMenuItem given a position in the menu.
366 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
368 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
370 Returns the help string associated with a menu item.
372 \wxheading{Parameters
}
374 \docparam{id
}{The menu item identifier.
}
376 \wxheading{Return value
}
378 The help string, or the empty string if there is no help string or the
383 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
385 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
387 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
389 Returns a menu item label.
391 \wxheading{Parameters
}
393 \docparam{id
}{The menu item identifier.
}
395 \wxheading{Return value
}
397 The item label, or the empty string if the item was not found.
401 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
403 \membersection{wxMenu::GetMenuItemCount
}\label{wxmenugetmenuitemcount
}
405 \constfunc{size
\_t}{GetMenuItemCount
}{\void}
407 Returns the number of items in the menu.
409 \membersection{wxMenu::GetMenuItems
}\label{wxmenugetmenuitems
}
411 \constfunc{wxMenuItemList\&
}{GetMenuItems
}{\void}
413 Returns the list of items in the menu. wxMenuItemList is a pseudo-template
414 list class containing wxMenuItem pointers.
416 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
418 \constfunc{wxString
}{GetTitle
}{\void}
420 Returns the title of the menu.
424 This is relevant only to popup menus, use
425 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
} for the menus in the
430 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
432 \membersection{wxMenu::Insert
}\label{wxmenuinsert
}
434 \func{wxMenuItem*
}{Insert
}{\param{size
\_t }{pos
},
\param{wxMenuItem *
}{item
}}
436 \func{wxMenuItem*
}{Insert
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
437 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
438 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
440 Inserts the given
{\it item
} before the position
{\it pos
}. Inserting the item
441 at position
\helpref{GetMenuItemCount
}{wxmenugetmenuitemcount
} is the same
446 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
447 \helpref{wxMenu::Prepend
}{wxmenuprepend
}
449 \membersection{wxMenu::InsertCheckItem
}\label{wxmenuinsertcheckitem
}
451 \func{wxMenuItem*
}{InsertCheckItem
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
452 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
454 Inserts a checkable item at the given position.
458 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
459 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
}
461 \membersection{wxMenu::InsertRadioItem
}\label{wxmenuinsertradioitem
}
463 \func{wxMenuItem*
}{InsertRadioItem
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
464 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
466 Inserts a radio item at the given position.
470 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
471 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
}
473 \membersection{wxMenu::InsertSeparator
}\label{wxmenuinsertseparator
}
475 \func{wxMenuItem*
}{InsertSeparator
}{\param{size
\_t }{pos
}}
477 Inserts a separator at the given position.
481 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
482 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
}
484 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
486 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
488 Determines whether a menu item is checked.
490 \wxheading{Parameters
}
492 \docparam{id
}{The menu item identifier.
}
494 \wxheading{Return value
}
496 true if the menu item is checked, false otherwise.
500 \helpref{wxMenu::Check
}{wxmenucheck
}
502 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
504 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
506 Determines whether a menu item is enabled.
508 \wxheading{Parameters
}
510 \docparam{id
}{The menu item identifier.
}
512 \wxheading{Return value
}
514 true if the menu item is enabled, false otherwise.
518 \helpref{wxMenu::Enable
}{wxmenuenable
}
520 \membersection{wxMenu::Prepend
}\label{wxmenuprepend
}
522 \func{wxMenuItem*
}{Prepend
}{\param{wxMenuItem *
}{item
}}
524 \func{wxMenuItem*
}{Prepend
}{\param{int
}{ id
},
\rtfsp
525 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
526 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
528 Inserts the given
{\it item
} at position $
0$, i.e. before all the other
533 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
534 \helpref{wxMenu::Insert
}{wxmenuinsert
}
536 \membersection{wxMenu::PrependCheckItem
}\label{wxmenuprependcheckitem
}
538 \func{wxMenuItem*
}{PrependCheckItem
}{\param{int
}{ id
},
\rtfsp
539 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
541 Inserts a checkable item at position $
0$.
545 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
546 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
}
548 \membersection{wxMenu::PrependRadioItem
}\label{wxmenuprependradioitem
}
550 \func{wxMenuItem*
}{PrependRadioItem
}{\param{int
}{ id
},
\rtfsp
551 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
553 Inserts a radio item at position $
0$.
557 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
558 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
}
560 \membersection{wxMenu::PrependSeparator
}\label{wxmenuprependseparator
}
562 \func{wxMenuItem*
}{PrependSeparator
}{\void}
564 Inserts a separator at position $
0$.
568 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
569 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
}
571 \membersection{wxMenu::Remove
}\label{wxmenuremove
}
573 \func{wxMenuItem *
}{Remove
}{\param{int
}{id
}}
575 \func{wxMenuItem *
}{Remove
}{\param{wxMenuItem *
}{item
}}
577 Removes the menu item from the menu but doesn't delete the associated C++
578 object. This allows to reuse the same item later by adding it back to the menu
579 (especially useful with submenus).
581 \wxheading{Parameters
}
583 \docparam{id
}{The identifier of the menu item to remove.
}
585 \docparam{item
}{The menu item to remove.
}
587 \wxheading{Return value
}
589 The item which was detached from the menu.
591 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
593 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
595 Sets an item's help string.
597 \wxheading{Parameters
}
599 \docparam{id
}{The menu item identifier.
}
601 \docparam{helpString
}{The help string to set.
}
605 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
607 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
609 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
611 Sets the label of a menu item.
613 \wxheading{Parameters
}
615 \docparam{id
}{The menu item identifier.
}
617 \docparam{label
}{The menu item label to set.
}
621 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
623 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
625 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
627 Sets the title of the menu.
629 \wxheading{Parameters
}
631 \docparam{title
}{The title to set.
}
635 This is relevant only to popup menus, use
636 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
} for the menus in the
641 \helpref{wxMenu::GetTitle
}{wxmenugettitle
}
643 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
645 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
647 Sends events to
{\it source
} (or owning window if NULL) to update the
648 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
649 the application may call it at other times if required.
653 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
655 \section{\class{wxMenuBar
}}\label{wxmenubar
}
657 A menu bar is a series of menus accessible from the top of a frame.
659 \wxheading{Derived from
}
661 \helpref{wxWindow
}{wxwindow
}\\
662 \helpref{wxEvtHandler
}{wxevthandler
}\\
663 \helpref{wxObject
}{wxobject
}
665 \wxheading{Include files
}
669 \wxheading{Event handling
}
671 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
672 that contains the menu bar. If you have a toolbar which uses the same identifiers
673 as your EVT
\_MENU entries, events from the toolbar will also be processed by your
674 EVT
\_MENU event handlers.
676 {\bf Tip:
} under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu)
677 are not working, check any EVT
\_CHAR events you are handling in child windows.
678 If you are not calling
{\tt event.Skip()
} for events that you don't process in these event handlers,
679 menu shortcuts may cease to work.
683 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
685 \latexignore{\rtfignore{\wxheading{Members
}}}
687 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarctor
}
689 \func{}{wxMenuBar
}{\param{long
}{style =
0}}
693 \func{}{wxMenuBar
}{\param{int
}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]}}
695 Construct a menu bar from arrays of menus and titles.
697 \wxheading{Parameters
}
699 \docparam{n
}{The number of menus.
}
701 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
704 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
706 \docparam{style
}{If
{\tt wxMB
\_DOCKABLE} the menu bar can be detached (wxGTK only).
}
708 \pythonnote{Only the default constructor is supported in wxPython.
709 Use wxMenuBar.Append instead.
}
711 \perlnote{wxPerl only supports the first constructor:
712 use
{\tt Append
} instead.
}
714 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}\label{wxmenubardtor
}
716 \func{void
}{\destruct{wxMenuBar
}}{\void}
718 Destructor, destroying the menu bar and removing it from the parent frame (if any).
720 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
722 \func{bool
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
724 Adds the item to the end of the menu bar.
726 \wxheading{Parameters
}
728 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
730 \docparam{title
}{The title of the menu.
}
732 \wxheading{Return value
}
734 true on success, false if an error occurred.
738 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
}
740 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
742 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
744 Checks or unchecks a menu item.
746 \wxheading{Parameters
}
748 \docparam{id
}{The menu item identifier.
}
750 \docparam{check
}{If true, checks the menu item, otherwise the item is unchecked.
}
754 Only use this when the menu bar has been associated
755 with a frame; otherwise, use the wxMenu equivalent call.
757 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
759 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
761 Enables or disables (greys out) a menu item.
763 \wxheading{Parameters
}
765 \docparam{id
}{The menu item identifier.
}
767 \docparam{enable
}{true to enable the item, false to disable it.
}
771 Only use this when the menu bar has been
772 associated with a frame; otherwise, use the wxMenu equivalent call.
774 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
776 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
778 Enables or disables a whole menu.
780 \wxheading{Parameters
}
782 \docparam{pos
}{The position of the menu, starting from zero.
}
784 \docparam{enable
}{true to enable the menu, false to disable it.
}
788 Only use this when the menu bar has been
789 associated with a frame.
791 \membersection{wxMenuBar::FindMenu
}\label{wxmenubarfindmenu
}
793 \constfunc{int
}{FindMenu
}{\param{const wxString\&
}{title
}}
795 Returns the index of the menu with the given
{\it title
} or
{\tt wxNOT
\_FOUND} if no
796 such menu exists in this menubar. The
{\it title
} parameter may specify either
797 the menu title (with accelerator characters, i.e.
{\tt "\&File"
}) or just the
798 menu label (
{\tt "File"
}) indifferently.
800 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
802 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
804 Finds the menu item id for a menu name/menu item string pair.
806 \wxheading{Parameters
}
808 \docparam{menuString
}{Menu title to find.
}
810 \docparam{itemString
}{Item to find.
}
812 \wxheading{Return value
}
814 The menu item identifier, or
{\tt wxNOT
\_FOUND} if none was found.
818 Any special menu codes are stripped out of source and target strings
821 \membersection{wxMenuBar::FindItem
}\label{wxmenubarfinditem
}
823 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu
}{ **menu = NULL
}}
825 Finds the menu item object associated with the given menu item identifier.
827 \wxheading{Parameters
}
829 \docparam{id
}{Menu item identifier.
}
831 \docparam{menu
}{If not NULL, menu will get set to the associated menu.
}
833 \wxheading{Return value
}
835 The found menu item object, or NULL if one was not found.
837 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
839 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
841 Gets the help string associated with the menu item identifier.
843 \wxheading{Parameters
}
845 \docparam{id
}{The menu item identifier.
}
847 \wxheading{Return value
}
849 The help string, or the empty string if there was no help string or the menu item
854 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
856 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
858 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
860 Gets the label associated with a menu item.
862 \wxheading{Parameters
}
864 \docparam{id
}{The menu item identifier.
}
866 \wxheading{Return value
}
868 The menu item label, or the empty string if the item was not found.
872 Use only after the menubar has been associated with a frame.
874 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
876 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
878 Returns the label of a top-level menu. Note that the returned string does not
879 include the accelerator characters which could have been specified in the menu
880 title string during its construction.
882 \wxheading{Parameters
}
884 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
886 \wxheading{Return value
}
888 The menu label, or the empty string if the menu was not found.
892 Use only after the menubar has been associated with a frame.
896 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
898 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
900 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
902 Returns the menu at
{\it menuIndex
} (zero-based).
904 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
906 \constfunc{int
}{GetMenuCount
}{\void}
908 Returns the number of menus in this menubar.
910 \membersection{wxMenuBar::Insert
}\label{wxmenubarinsert
}
912 \func{bool
}{Insert
}{\param{size
\_t }{pos
},
\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
914 Inserts the menu at the given position into the menu bar. Inserting menu at
915 position $
0$ will insert it in the very beginning of it, inserting at position
916 \helpref{GetMenuCount()
}{wxmenubargetmenucount
} is the same as calling
917 \helpref{Append()
}{wxmenubarappend
}.
919 \wxheading{Parameters
}
921 \docparam{pos
}{The position of the new menu in the menu bar
}
923 \docparam{menu
}{The menu to add. wxMenuBar owns the menu and will free it.
}
925 \docparam{title
}{The title of the menu.
}
927 \wxheading{Return value
}
929 true on success, false if an error occurred.
933 \helpref{wxMenuBar::Append
}{wxmenubarappend
}
935 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
937 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
939 Determines whether an item is checked.
941 \wxheading{Parameters
}
943 \docparam{id
}{The menu item identifier.
}
945 \wxheading{Return value
}
947 true if the item was found and is checked, false otherwise.
949 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
951 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
953 Determines whether an item is enabled.
955 \wxheading{Parameters
}
957 \docparam{id
}{The menu item identifier.
}
959 \wxheading{Return value
}
961 true if the item was found and is enabled, false otherwise.
963 \membersection{wxMenuBar::Refresh
}\label{wxmenubarrefresh
}
965 \func{void
}{Refresh
}{\void}
969 \membersection{wxMenuBar::Remove
}\label{wxmenubarremove
}
971 \func{wxMenu *
}{Remove
}{\param{size
\_t }{pos
}}
973 Removes the menu from the menu bar and returns the menu object - the caller is
974 responsible for deleting it. This function may be used together with
975 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
} to change the menubar
980 \helpref{wxMenuBar::Replace
}{wxmenubarreplace
}
982 \membersection{wxMenuBar::Replace
}\label{wxmenubarreplace
}
984 \func{wxMenu *
}{Replace
}{\param{size
\_t }{pos
},
\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
986 Replaces the menu at the given position with another one.
988 \wxheading{Parameters
}
990 \docparam{pos
}{The position of the new menu in the menu bar
}
992 \docparam{menu
}{The menu to add.
}
994 \docparam{title
}{The title of the menu.
}
996 \wxheading{Return value
}
998 The menu which was previously at position
{\it pos
}. The caller is
999 responsible for deleting it.
1001 \wxheading{See also
}
1003 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
},
\rtfsp
1004 \helpref{wxMenuBar::Remove
}{wxmenubarremove
}
1006 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
1008 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
1010 Sets the help string associated with a menu item.
1012 \wxheading{Parameters
}
1014 \docparam{id
}{Menu item identifier.
}
1016 \docparam{helpString
}{Help string to associate with the menu item.
}
1018 \wxheading{See also
}
1020 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
1022 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
1024 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
1026 Sets the label of a menu item.
1028 \wxheading{Parameters
}
1030 \docparam{id
}{Menu item identifier.
}
1032 \docparam{label
}{Menu item label.
}
1036 Use only after the menubar has been associated with a frame.
1038 \wxheading{See also
}
1040 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
1042 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
1044 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
1046 Sets the label of a top-level menu.
1048 \wxheading{Parameters
}
1050 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
1052 \docparam{label
}{The menu label.
}
1056 Use only after the menubar has been associated with a frame.
1058 \wxheading{See also
}
1060 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}