1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxMenu documentation
4 %% Author: wxWidgets Team
8 %% Copyright: (c) wxWidgets Team
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxMenu
}}\label{wxmenu
}
14 A menu is a popup (or pull down) list of items, one of which may be
15 selected before the menu goes away (clicking elsewhere dismisses the
16 menu). Menus may be used to construct either menu bars or popup menus.
18 A menu item has an integer ID associated with it which can be used to
19 identify the selection, or to change the menu item in some way. A menu item
20 with a special identifier $-
1$ is a separator item and doesn't have an
21 associated command but just makes a separator line appear in the menu.
23 {\bf NB:
} Please note that
{\it wxID
\_ABOUT} and
{\it wxID
\_EXIT} are
24 predefined by wxWidgets and have a special meaning since entries
25 using these IDs will be taken out of the normal menus under MacOS X
26 and will be inserted into the system menu (following the appropriate
27 MacOS X interface guideline). On PalmOS
{\it wxID
\_EXIT} is disabled according
28 to Palm OS Companion guidelines.
30 Menu items may be either normal items, check items or radio items. Normal items
31 don't have any special properties while the check items have a boolean flag
32 associated to them and they show a checkmark in the menu when the flag is set.
33 wxWidgets automatically toggles the flag value when the item is clicked and its
34 value may be retrieved using either
\helpref{IsChecked
}{wxmenuischecked
} method
35 of wxMenu or wxMenuBar itself or by using
36 \helpref{wxEvent::IsChecked
}{wxcommandeventischecked
} when you get the menu
37 notification for the item in question.
39 The radio items are similar to the check items except that all the other items
40 in the same radio group are unchecked when a radio item is checked. The radio
41 group is formed by a contiguous range of radio items, i.e. it starts at the
42 first item of this kind and ends with the first item of a different kind (or
43 the end of the menu). Notice that because the radio groups are defined in terms
44 of the item positions inserting or removing the items in the menu containing
45 the radio items risks to not work correctly. Finally note that radio items
46 are not supported under Motif.
48 \wxheading{Allocation strategy
}
50 All menus except the popup ones must be created on the heap. All menus
51 attached to a menubar or to another menu will be deleted by their parent when
52 it is deleted. As the frame menubar is deleted by the frame itself, it means
53 that normally all menus used are deleted automatically.
55 \wxheading{Derived from
}
57 \helpref{wxEvtHandler
}{wxevthandler
}\\
58 \helpref{wxObject
}{wxobject
}
60 \wxheading{Include files
}
64 \wxheading{Event handling
}
66 If the menu is part of a menubar, then
\helpref{wxMenuBar
}{wxmenubar
} event processing is used.
68 With a popup menu, there is a variety of ways to handle a menu selection event
69 (wxEVT
\_COMMAND\_MENU\_SELECTED).
71 \begin{enumerate
}\itemsep=
0pt
72 \item Derive a new class from wxMenu and define event table entries using the EVT
\_MENU macro.
73 \item Set a new event handler for wxMenu, using an object whose class has EVT
\_MENU entries.
74 \item Provide EVT
\_MENU handlers in the window which pops up the menu, or in an ancestor of
76 \item Define a callback of type wxFunction, which you pass to the wxMenu constructor.
77 The callback takes a reference to the menu, and a reference to a
78 \helpref{wxCommandEvent
}{wxcommandevent
}. This method is deprecated and should
79 not be used in the new code, it is provided for backwards compatibility only.
84 \helpref{wxMenuBar
}{wxmenubar
},
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
},
\rtfsp
85 \helpref{Event handling overview
}{eventhandlingoverview
},
\rtfsp
86 \helpref{wxFileHistory (most recently used files menu)
}{wxfilehistory
}
90 \latexignore{\rtfignore{\wxheading{Members
}}}
92 \membersection{wxMenu::wxMenu
}\label{wxmenuctor
}
94 \func{}{wxMenu
}{\param{const wxString\&
}{title = ""
},
\param{long
}{ style =
0}}
96 Constructs a wxMenu object.
98 \wxheading{Parameters
}
100 \docparam{title
}{A title for the popup menu: the empty string denotes no title.
}
102 \docparam{style
}{If set to
{\tt wxMENU
\_TEAROFF}, the menu will be detachable (wxGTK only).
}
104 \func{}{wxMenu
}{\param{long
}{ style
}}
106 Constructs a wxMenu object.
108 \wxheading{Parameters
}
110 \docparam{style
}{If set to
{\tt wxMENU
\_TEAROFF}, the menu will be detachable (wxGTK only).
}
112 \membersection{wxMenu::
\destruct{wxMenu
}}\label{wxmenudtor
}
114 \func{}{\destruct{wxMenu
}}{\void}
116 Destructor, destroying the menu.
118 Note: under Motif, a popup menu must have a valid parent (the window
119 it was last popped up on) when being destroyed. Therefore, make sure
120 you delete or re-use the popup menu
{\it before
} destroying the
121 parent window. Re-use in this context means popping up the menu on
122 a different window from last time, which causes an implicit destruction
123 and recreation of internal data structures.
125 \membersection{wxMenu::Append
}\label{wxmenuappend
}
127 \func{wxMenuItem*
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
128 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
130 Adds a string item to the end of the menu.
132 \func{wxMenuItem*
}{Append
}{\param{int
}{ id
},
\param{const wxString\&
}{ item
},
\param{wxMenu *
}{subMenu
},
\rtfsp
133 \param{const wxString\&
}{helpString = ""
}}
135 Adds a pull-right submenu to the end of the menu. Append the submenu to the parent
136 menu
{\it after
} you have added your menu items, or accelerators may not be
139 \func{wxMenuItem*
}{Append
}{\param{wxMenuItem*
}{ menuItem
}}
141 Adds a menu item object. This is the most generic variant of Append() method
142 because it may be used for both items (including separators) and submenus and
143 because you can also specify various extra properties of a menu item this way,
144 such as bitmaps and fonts.
146 \wxheading{Parameters
}
148 \docparam{id
}{The menu command identifier.
}
150 \docparam{item
}{The string to appear on the menu item.
}
152 \docparam{menu
}{Pull-right submenu.
}
154 \docparam{kind
}{May be
{\tt wxITEM
\_SEPARATOR},
{\tt wxITEM
\_NORMAL},
155 {\tt wxITEM
\_CHECK} or
{\tt wxITEM
\_RADIO}}
157 \docparam{helpString
}{An optional help string associated with the item.
158 By default, the handler for the wxEVT
\_MENU\_HIGHLIGHT event displays
159 this string in the status line.
}
161 \docparam{menuItem
}{A menuitem object. It will be owned by the wxMenu object after this function
162 is called, so do not delete it yourself.
}
166 This command can be used after the menu has been shown, as well as on initial
167 creation of a menu or menubar.
169 The
{\it item
} string for the normal menu items (not submenus or separators)
170 may include the accelerator which can be used to activate the menu item
171 from keyboard. The accelerator string follows the item label and is separated
172 from it by a
{\tt TAB
} character (
{\tt '$
\backslash$t'
}). Its general syntax is
173 any combination of
{\tt "CTRL"
},
{\tt "ALT"
} and
{\tt "SHIFT"
} strings (case
174 doesn't matter) separated by either
{\tt '-'
} or
{\tt '+'
} characters and
175 followed by the accelerator itself. The accelerator may be any alphanumeric
176 character, any function key (from
{\tt F1
} to
{\tt F12
}) or one of the special
177 characters listed in the table below (again, case doesn't matter):
179 \begin{twocollist
}\itemsep=
0pt
180 \twocolitem{{\tt DEL
} or
{\tt DELETE
}}{Delete key
}
181 \twocolitem{{\tt INS
} or
{\tt INSERT
}}{Insert key
}
182 \twocolitem{{\tt ENTER
} or
{\tt RETURN
}}{Enter key
}
183 \twocolitem{{\tt PGUP
}}{PageUp key
}
184 \twocolitem{{\tt PGDN
}}{PageDown key
}
185 \twocolitem{{\tt LEFT
}}{Left cursor arrow key
}
186 \twocolitem{{\tt RIGHT
}}{Right cursor arrow key
}
187 \twocolitem{{\tt UP
}}{Up cursor arrow key
}
188 \twocolitem{{\tt DOWN
}}{Down cursor arrow key
}
189 \twocolitem{{\tt HOME
}}{Home key
}
190 \twocolitem{{\tt END
}}{End key
}
191 \twocolitem{{\tt SPACE
}}{Space
}
192 \twocolitem{{\tt TAB
}}{Tab key
}
193 \twocolitem{{\tt ESC
} or
{\tt ESCAPE
}}{Escape key (Windows only)
}
198 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
},
\rtfsp
199 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
},
\rtfsp
200 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
},
\rtfsp
201 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
202 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
},
\helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
},
\rtfsp
203 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenuItem
}{wxmenuitem
}
205 \pythonnote{In place of a single overloaded method name, wxPython
206 implements the following methods:
208 \indented{2cm
}{\begin{twocollist
}
209 \twocolitem{{\bf Append(id, string, helpStr="", checkable=false)
}}{}
210 \twocolitem{{\bf AppendMenu(id, string, aMenu, helpStr="")
}}{}
211 \twocolitem{{\bf AppendItem(aMenuItem)
}}{}
215 \membersection{wxMenu::AppendCheckItem
}\label{wxmenuappendcheckitem
}
217 \func{wxMenuItem*
}{AppendCheckItem
}{\param{int
}{ id
},
\rtfsp
218 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
220 Adds a checkable item to the end of the menu.
224 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
225 \helpref{wxMenu::InsertCheckItem
}{wxmenuinsertcheckitem
}
227 \membersection{wxMenu::AppendRadioItem
}\label{wxmenuappendradioitem
}
229 \func{wxMenuItem*
}{AppendRadioItem
}{\param{int
}{ id
},
\rtfsp
230 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
232 Adds a radio item to the end of the menu. All consequent radio items form a
233 group and when an item in the group is checked, all the others are
234 automatically unchecked.
236 {\bf NB:
} Currently only implemented under Windows and GTK, use
237 {\tt\#if wxHAS
\_RADIO\_MENU\_ITEMS} to test for availability of this feature.
241 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
242 \helpref{wxMenu::InsertRadioItem
}{wxmenuinsertradioitem
}
244 \membersection{wxMenu::AppendSeparator
}\label{wxmenuappendseparator
}
246 \func{wxMenuItem*
}{AppendSeparator
}{\void}
248 Adds a separator to the end of the menu.
252 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
253 \helpref{wxMenu::InsertSeparator
}{wxmenuinsertseparator
}
255 \membersection{wxMenu::Break
}\label{wxmenubreak
}
257 \func{void
}{Break
}{\void}
259 Inserts a break in a menu, causing the next appended item to appear in a new column.
261 \membersection{wxMenu::Check
}\label{wxmenucheck
}
263 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
265 Checks or unchecks the menu item.
267 \wxheading{Parameters
}
269 \docparam{id
}{The menu item identifier.
}
271 \docparam{check
}{If true, the item will be checked, otherwise it will be unchecked.
}
275 \helpref{wxMenu::IsChecked
}{wxmenuischecked
}
277 \membersection{wxMenu::Delete
}\label{wxmenudelete
}
279 \func{void
}{Delete
}{\param{int
}{id
}}
281 \func{void
}{Delete
}{\param{wxMenuItem *
}{item
}}
283 Deletes the menu item from the menu. If the item is a submenu, it will
284 {\bf not
} be deleted. Use
\helpref{Destroy
}{wxmenudestroy
} if you want to
287 \wxheading{Parameters
}
289 \docparam{id
}{Id of the menu item to be deleted.
}
291 \docparam{item
}{Menu item to be deleted.
}
295 \helpref{wxMenu::FindItem
}{wxmenufinditem
},
\rtfsp
296 \helpref{wxMenu::Destroy
}{wxmenudestroy
},
\rtfsp
297 \helpref{wxMenu::Remove
}{wxmenuremove
}
299 \membersection{wxMenu::Destroy
}\label{wxmenudestroy
}
301 \func{void
}{Destroy
}{\param{int
}{id
}}
303 \func{void
}{Destroy
}{\param{wxMenuItem *
}{item
}}
305 Deletes the menu item from the menu. If the item is a submenu, it will
306 be deleted. Use
\helpref{Remove
}{wxmenuremove
} if you want to keep the submenu
307 (for example, to reuse it later).
309 \wxheading{Parameters
}
311 \docparam{id
}{Id of the menu item to be deleted.
}
313 \docparam{item
}{Menu item to be deleted.
}
317 \helpref{wxMenu::FindItem
}{wxmenufinditem
},
\rtfsp
318 \helpref{wxMenu::Deletes
}{wxmenudelete
},
\rtfsp
319 \helpref{wxMenu::Remove
}{wxmenuremove
}
321 \membersection{wxMenu::Enable
}\label{wxmenuenable
}
323 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
325 Enables or disables (greys out) a menu item.
327 \wxheading{Parameters
}
329 \docparam{id
}{The menu item identifier.
}
331 \docparam{enable
}{true to enable the menu item, false to disable it.
}
335 \helpref{wxMenu::IsEnabled
}{wxmenuisenabled
}
337 \membersection{wxMenu::FindItem
}\label{wxmenufinditem
}
339 \constfunc{int
}{FindItem
}{\param{const wxString\&
}{itemString
}}
341 Finds the menu item id for a menu item string.
343 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu **
}{menu = NULL
}}
345 Finds the menu item object associated with the given menu item identifier and,
346 optionally, the (sub)menu it belongs to.
348 \perlnote{In wxPerl this method takes just the
{\tt id
} parameter;
349 in scalar context it returns the associated
{\tt Wx::MenuItem
}, in list
350 context it returns a
2-element list
{\tt ( item, submenu )
}}
352 \wxheading{Parameters
}
354 \docparam{itemString
}{Menu item string to find.
}
356 \docparam{id
}{Menu item identifier.
}
358 \docparam{menu
}{If the pointer is not NULL, it will be filled with the item's
359 parent menu (if the item was found)
}
361 \wxheading{Return value
}
363 First form: menu item identifier, or
{\tt wxNOT
\_FOUND} if none is found.
365 Second form: returns the menu item object, or NULL if it is not found.
369 Any special menu codes are stripped out of source and target strings
372 \pythonnote{The name of this method in wxPython is
{\tt FindItemById
}
373 and it does not support the second parameter.
}
375 \membersection{wxMenu::FindItemByPosition
}\label{wxmenufinditembyposition
}
377 \constfunc{wxMenuItem*
}{FindItemByPosition
}{\param{size
\_t }{position
}}
379 Returns the wxMenuItem given a position in the menu.
381 \membersection{wxMenu::GetHelpString
}\label{wxmenugethelpstring
}
383 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
385 Returns the help string associated with a menu item.
387 \wxheading{Parameters
}
389 \docparam{id
}{The menu item identifier.
}
391 \wxheading{Return value
}
393 The help string, or the empty string if there is no help string or the
398 \helpref{wxMenu::SetHelpString
}{wxmenusethelpstring
},
\helpref{wxMenu::Append
}{wxmenuappend
}
400 \membersection{wxMenu::GetLabel
}\label{wxmenugetlabel
}
402 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
404 Returns a menu item label.
406 \wxheading{Parameters
}
408 \docparam{id
}{The menu item identifier.
}
410 \wxheading{Return value
}
412 The item label, or the empty string if the item was not found.
416 \helpref{wxMenu::SetLabel
}{wxmenusetlabel
}
418 \membersection{wxMenu::GetMenuItemCount
}\label{wxmenugetmenuitemcount
}
420 \constfunc{size
\_t}{GetMenuItemCount
}{\void}
422 Returns the number of items in the menu.
424 \membersection{wxMenu::GetMenuItems
}\label{wxmenugetmenuitems
}
426 \constfunc{wxMenuItemList\&
}{GetMenuItems
}{\void}
428 Returns the list of items in the menu. wxMenuItemList is a pseudo-template
429 list class containing wxMenuItem pointers.
431 \membersection{wxMenu::GetTitle
}\label{wxmenugettitle
}
433 \constfunc{wxString
}{GetTitle
}{\void}
435 Returns the title of the menu.
439 This is relevant only to popup menus, use
440 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
} for the menus in the
445 \helpref{wxMenu::SetTitle
}{wxmenusettitle
}
447 \membersection{wxMenu::Insert
}\label{wxmenuinsert
}
449 \func{wxMenuItem*
}{Insert
}{\param{size
\_t }{pos
},
\param{wxMenuItem *
}{item
}}
451 \func{wxMenuItem*
}{Insert
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
452 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
453 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
455 Inserts the given
{\it item
} before the position
{\it pos
}. Inserting the item
456 at position
\helpref{GetMenuItemCount
}{wxmenugetmenuitemcount
} is the same
461 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
462 \helpref{wxMenu::Prepend
}{wxmenuprepend
}
464 \membersection{wxMenu::InsertCheckItem
}\label{wxmenuinsertcheckitem
}
466 \func{wxMenuItem*
}{InsertCheckItem
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
467 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
469 Inserts a checkable item at the given position.
473 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
474 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
}
476 \membersection{wxMenu::InsertRadioItem
}\label{wxmenuinsertradioitem
}
478 \func{wxMenuItem*
}{InsertRadioItem
}{\param{size
\_t }{pos
},
\param{int
}{ id
},
\rtfsp
479 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
481 Inserts a radio item at the given position.
485 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
486 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
}
488 \membersection{wxMenu::InsertSeparator
}\label{wxmenuinsertseparator
}
490 \func{wxMenuItem*
}{InsertSeparator
}{\param{size
\_t }{pos
}}
492 Inserts a separator at the given position.
496 \helpref{wxMenu::Insert
}{wxmenuinsert
},
\rtfsp
497 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
}
499 \membersection{wxMenu::IsChecked
}\label{wxmenuischecked
}
501 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
503 Determines whether a menu item is checked.
505 \wxheading{Parameters
}
507 \docparam{id
}{The menu item identifier.
}
509 \wxheading{Return value
}
511 true if the menu item is checked, false otherwise.
515 \helpref{wxMenu::Check
}{wxmenucheck
}
517 \membersection{wxMenu::IsEnabled
}\label{wxmenuisenabled
}
519 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
521 Determines whether a menu item is enabled.
523 \wxheading{Parameters
}
525 \docparam{id
}{The menu item identifier.
}
527 \wxheading{Return value
}
529 true if the menu item is enabled, false otherwise.
533 \helpref{wxMenu::Enable
}{wxmenuenable
}
535 \membersection{wxMenu::Prepend
}\label{wxmenuprepend
}
537 \func{wxMenuItem*
}{Prepend
}{\param{wxMenuItem *
}{item
}}
539 \func{wxMenuItem*
}{Prepend
}{\param{int
}{ id
},
\rtfsp
540 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
},
\rtfsp
541 \param{wxItemKind
}{ kind = wxITEM
\_NORMAL}}
543 Inserts the given
{\it item
} at position $
0$, i.e. before all the other
548 \helpref{wxMenu::Append
}{wxmenuappend
},
\rtfsp
549 \helpref{wxMenu::Insert
}{wxmenuinsert
}
551 \membersection{wxMenu::PrependCheckItem
}\label{wxmenuprependcheckitem
}
553 \func{wxMenuItem*
}{PrependCheckItem
}{\param{int
}{ id
},
\rtfsp
554 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
556 Inserts a checkable item at position $
0$.
560 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
561 \helpref{wxMenu::AppendCheckItem
}{wxmenuappendcheckitem
}
563 \membersection{wxMenu::PrependRadioItem
}\label{wxmenuprependradioitem
}
565 \func{wxMenuItem*
}{PrependRadioItem
}{\param{int
}{ id
},
\rtfsp
566 \param{const wxString\&
}{ item
},
\param{const wxString\&
}{helpString = ""
}}
568 Inserts a radio item at position $
0$.
572 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
573 \helpref{wxMenu::AppendRadioItem
}{wxmenuappendradioitem
}
575 \membersection{wxMenu::PrependSeparator
}\label{wxmenuprependseparator
}
577 \func{wxMenuItem*
}{PrependSeparator
}{\void}
579 Inserts a separator at position $
0$.
583 \helpref{wxMenu::Prepend
}{wxmenuprepend
},
\rtfsp
584 \helpref{wxMenu::AppendSeparator
}{wxmenuappendseparator
}
586 \membersection{wxMenu::Remove
}\label{wxmenuremove
}
588 \func{wxMenuItem *
}{Remove
}{\param{int
}{id
}}
590 \func{wxMenuItem *
}{Remove
}{\param{wxMenuItem *
}{item
}}
592 Removes the menu item from the menu but doesn't delete the associated C++
593 object. This allows to reuse the same item later by adding it back to the menu
594 (especially useful with submenus).
596 \wxheading{Parameters
}
598 \docparam{id
}{The identifier of the menu item to remove.
}
600 \docparam{item
}{The menu item to remove.
}
602 \wxheading{Return value
}
604 The item which was detached from the menu.
606 \membersection{wxMenu::SetHelpString
}\label{wxmenusethelpstring
}
608 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
610 Sets an item's help string.
612 \wxheading{Parameters
}
614 \docparam{id
}{The menu item identifier.
}
616 \docparam{helpString
}{The help string to set.
}
620 \helpref{wxMenu::GetHelpString
}{wxmenugethelpstring
}
622 \membersection{wxMenu::SetLabel
}\label{wxmenusetlabel
}
624 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
626 Sets the label of a menu item.
628 \wxheading{Parameters
}
630 \docparam{id
}{The menu item identifier.
}
632 \docparam{label
}{The menu item label to set.
}
636 \helpref{wxMenu::Append
}{wxmenuappend
},
\helpref{wxMenu::GetLabel
}{wxmenugetlabel
}
638 \membersection{wxMenu::SetTitle
}\label{wxmenusettitle
}
640 \func{void
}{SetTitle
}{\param{const wxString\&
}{title
}}
642 Sets the title of the menu.
644 \wxheading{Parameters
}
646 \docparam{title
}{The title to set.
}
650 This is relevant only to popup menus, use
651 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
} for the menus in the
656 \helpref{wxMenu::GetTitle
}{wxmenugettitle
}
658 \membersection{wxMenu::UpdateUI
}\label{wxmenuupdateui
}
660 \constfunc{void
}{UpdateUI
}{\param{wxEvtHandler*
}{ source = NULL
}}
662 Sends events to
{\it source
} (or owning window if NULL) to update the
663 menu UI. This is called just before the menu is popped up with
\helpref{wxWindow::PopupMenu
}{wxwindowpopupmenu
}, but
664 the application may call it at other times if required.
668 \helpref{wxUpdateUIEvent
}{wxupdateuievent
}
670 \section{\class{wxMenuBar
}}\label{wxmenubar
}
672 A menu bar is a series of menus accessible from the top of a frame.
674 \wxheading{Derived from
}
676 \helpref{wxWindow
}{wxwindow
}\\
677 \helpref{wxEvtHandler
}{wxevthandler
}\\
678 \helpref{wxObject
}{wxobject
}
680 \wxheading{Include files
}
684 \wxheading{Event handling
}
686 To respond to a menu selection, provide a handler for EVT
\_MENU, in the frame
687 that contains the menu bar. If you have a toolbar which uses the same identifiers
688 as your EVT
\_MENU entries, events from the toolbar will also be processed by your
689 EVT
\_MENU event handlers.
691 {\bf Tip:
} under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu)
692 are not working, check any EVT
\_CHAR events you are handling in child windows.
693 If you are not calling
{\tt event.Skip()
} for events that you don't process in these event handlers,
694 menu shortcuts may cease to work.
698 \helpref{wxMenu
}{wxmenu
},
\helpref{Event handling overview
}{eventhandlingoverview
}
700 \latexignore{\rtfignore{\wxheading{Members
}}}
702 \membersection{wxMenuBar::wxMenuBar
}\label{wxmenubarctor
}
704 \func{}{wxMenuBar
}{\param{long
}{style =
0}}
708 \func{}{wxMenuBar
}{\param{size
\_t}{ n
},
\param{wxMenu*
}{ menus
[]},
\param{const wxString
}{titles
[]},
\param{long
}{style =
0}}
710 Construct a menu bar from arrays of menus and titles.
712 \wxheading{Parameters
}
714 \docparam{n
}{The number of menus.
}
716 \docparam{menus
}{An array of menus. Do not use this array again - it now belongs to the
719 \docparam{titles
}{An array of title strings. Deallocate this array after creating the menu bar.
}
721 \docparam{style
}{If
{\tt wxMB
\_DOCKABLE} the menu bar can be detached (wxGTK only).
}
723 \pythonnote{Only the default constructor is supported in wxPython.
724 Use
\helpref{wxMenuBar::Append
}{wxmenubarappend
} instead.
}
726 \perlnote{wxPerl only supports the first constructor:
727 use
\helpref{wxMenuBar::Append
}{wxmenubarappend
} instead.
}
729 \membersection{wxMenuBar::
\destruct{wxMenuBar
}}\label{wxmenubardtor
}
731 \func{void
}{\destruct{wxMenuBar
}}{\void}
733 Destructor, destroying the menu bar and removing it from the parent frame (if any).
735 \membersection{wxMenuBar::Append
}\label{wxmenubarappend
}
737 \func{bool
}{Append
}{\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
739 Adds the item to the end of the menu bar.
741 \wxheading{Parameters
}
743 \docparam{menu
}{The menu to add. Do not deallocate this menu after calling
{\bf Append
}.
}
745 \docparam{title
}{The title of the menu.
}
747 \wxheading{Return value
}
749 true on success, false if an error occurred.
753 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
}
755 \membersection{wxMenuBar::Check
}\label{wxmenubarcheck
}
757 \func{void
}{Check
}{\param{int
}{ id
},
\param{const bool
}{ check
}}
759 Checks or unchecks a menu item.
761 \wxheading{Parameters
}
763 \docparam{id
}{The menu item identifier.
}
765 \docparam{check
}{If true, checks the menu item, otherwise the item is unchecked.
}
769 Only use this when the menu bar has been associated
770 with a frame; otherwise, use the wxMenu equivalent call.
772 \membersection{wxMenuBar::Enable
}\label{wxmenubarenable
}
774 \func{void
}{Enable
}{\param{int
}{ id
},
\param{const bool
}{ enable
}}
776 Enables or disables (greys out) a menu item.
778 \wxheading{Parameters
}
780 \docparam{id
}{The menu item identifier.
}
782 \docparam{enable
}{true to enable the item, false to disable it.
}
786 Only use this when the menu bar has been
787 associated with a frame; otherwise, use the wxMenu equivalent call.
789 \membersection{wxMenuBar::EnableTop
}\label{wxmenubarenabletop
}
791 \func{void
}{EnableTop
}{\param{int
}{ pos
},
\param{const bool
}{ enable
}}
793 Enables or disables a whole menu.
795 \wxheading{Parameters
}
797 \docparam{pos
}{The position of the menu, starting from zero.
}
799 \docparam{enable
}{true to enable the menu, false to disable it.
}
803 Only use this when the menu bar has been
804 associated with a frame.
806 \membersection{wxMenuBar::FindMenu
}\label{wxmenubarfindmenu
}
808 \constfunc{int
}{FindMenu
}{\param{const wxString\&
}{title
}}
810 Returns the index of the menu with the given
{\it title
} or
{\tt wxNOT
\_FOUND} if no
811 such menu exists in this menubar. The
{\it title
} parameter may specify either
812 the menu title (with accelerator characters, i.e.
{\tt "\&File"
}) or just the
813 menu label (
{\tt "File"
}) indifferently.
815 \membersection{wxMenuBar::FindMenuItem
}\label{wxmenubarfindmenuitem
}
817 \constfunc{int
}{FindMenuItem
}{\param{const wxString\&
}{menuString
},
\param{const wxString\&
}{itemString
}}
819 Finds the menu item id for a menu name/menu item string pair.
821 \wxheading{Parameters
}
823 \docparam{menuString
}{Menu title to find.
}
825 \docparam{itemString
}{Item to find.
}
827 \wxheading{Return value
}
829 The menu item identifier, or
{\tt wxNOT
\_FOUND} if none was found.
833 Any special menu codes are stripped out of source and target strings
836 \membersection{wxMenuBar::FindItem
}\label{wxmenubarfinditem
}
838 \constfunc{wxMenuItem *
}{FindItem
}{\param{int
}{ id
},
\param{wxMenu
}{ **menu = NULL
}}
840 Finds the menu item object associated with the given menu item identifier.
842 \wxheading{Parameters
}
844 \docparam{id
}{Menu item identifier.
}
846 \docparam{menu
}{If not NULL, menu will get set to the associated menu.
}
848 \wxheading{Return value
}
850 The found menu item object, or NULL if one was not found.
852 \membersection{wxMenuBar::GetHelpString
}\label{wxmenubargethelpstring
}
854 \constfunc{wxString
}{GetHelpString
}{\param{int
}{ id
}}
856 Gets the help string associated with the menu item identifier.
858 \wxheading{Parameters
}
860 \docparam{id
}{The menu item identifier.
}
862 \wxheading{Return value
}
864 The help string, or the empty string if there was no help string or the menu item
869 \helpref{wxMenuBar::SetHelpString
}{wxmenubarsethelpstring
}
871 \membersection{wxMenuBar::GetLabel
}\label{wxmenubargetlabel
}
873 \constfunc{wxString
}{GetLabel
}{\param{int
}{ id
}}
875 Gets the label associated with a menu item.
877 \wxheading{Parameters
}
879 \docparam{id
}{The menu item identifier.
}
881 \wxheading{Return value
}
883 The menu item label, or the empty string if the item was not found.
887 Use only after the menubar has been associated with a frame.
889 \membersection{wxMenuBar::GetLabelTop
}\label{wxmenubargetlabeltop
}
891 \constfunc{wxString
}{GetLabelTop
}{\param{int
}{ pos
}}
893 Returns the label of a top-level menu. Note that the returned string does not
894 include the accelerator characters which could have been specified in the menu
895 title string during its construction.
897 \wxheading{Parameters
}
899 \docparam{pos
}{Position of the menu on the menu bar, starting from zero.
}
901 \wxheading{Return value
}
903 The menu label, or the empty string if the menu was not found.
907 Use only after the menubar has been associated with a frame.
911 \helpref{wxMenuBar::SetLabelTop
}{wxmenubarsetlabeltop
}
913 \membersection{wxMenuBar::GetMenu
}\label{wxmenubargetmenu
}
915 \constfunc{wxMenu*
}{GetMenu
}{\param{int
}{ menuIndex
}}
917 Returns the menu at
{\it menuIndex
} (zero-based).
919 \membersection{wxMenuBar::GetMenuCount
}\label{wxmenubargetmenucount
}
921 \constfunc{int
}{GetMenuCount
}{\void}
923 Returns the number of menus in this menubar.
925 \membersection{wxMenuBar::Insert
}\label{wxmenubarinsert
}
927 \func{bool
}{Insert
}{\param{size
\_t }{pos
},
\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
929 Inserts the menu at the given position into the menu bar. Inserting menu at
930 position $
0$ will insert it in the very beginning of it, inserting at position
931 \helpref{GetMenuCount()
}{wxmenubargetmenucount
} is the same as calling
932 \helpref{Append()
}{wxmenubarappend
}.
934 \wxheading{Parameters
}
936 \docparam{pos
}{The position of the new menu in the menu bar
}
938 \docparam{menu
}{The menu to add. wxMenuBar owns the menu and will free it.
}
940 \docparam{title
}{The title of the menu.
}
942 \wxheading{Return value
}
944 true on success, false if an error occurred.
948 \helpref{wxMenuBar::Append
}{wxmenubarappend
}
950 \membersection{wxMenuBar::IsChecked
}\label{wxmenubarischecked
}
952 \constfunc{bool
}{IsChecked
}{\param{int
}{ id
}}
954 Determines whether an item is checked.
956 \wxheading{Parameters
}
958 \docparam{id
}{The menu item identifier.
}
960 \wxheading{Return value
}
962 true if the item was found and is checked, false otherwise.
964 \membersection{wxMenuBar::IsEnabled
}\label{wxmenubarisenabled
}
966 \constfunc{bool
}{IsEnabled
}{\param{int
}{ id
}}
968 Determines whether an item is enabled.
970 \wxheading{Parameters
}
972 \docparam{id
}{The menu item identifier.
}
974 \wxheading{Return value
}
976 true if the item was found and is enabled, false otherwise.
978 \membersection{wxMenuBar::Refresh
}\label{wxmenubarrefresh
}
980 \func{void
}{Refresh
}{\void}
984 \membersection{wxMenuBar::Remove
}\label{wxmenubarremove
}
986 \func{wxMenu *
}{Remove
}{\param{size
\_t }{pos
}}
988 Removes the menu from the menu bar and returns the menu object - the caller is
989 responsible for deleting it. This function may be used together with
990 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
} to change the menubar
995 \helpref{wxMenuBar::Replace
}{wxmenubarreplace
}
997 \membersection{wxMenuBar::Replace
}\label{wxmenubarreplace
}
999 \func{wxMenu *
}{Replace
}{\param{size
\_t }{pos
},
\param{wxMenu *
}{menu
},
\param{const wxString\&
}{title
}}
1001 Replaces the menu at the given position with another one.
1003 \wxheading{Parameters
}
1005 \docparam{pos
}{The position of the new menu in the menu bar
}
1007 \docparam{menu
}{The menu to add.
}
1009 \docparam{title
}{The title of the menu.
}
1011 \wxheading{Return value
}
1013 The menu which was previously at position
{\it pos
}. The caller is
1014 responsible for deleting it.
1016 \wxheading{See also
}
1018 \helpref{wxMenuBar::Insert
}{wxmenubarinsert
},
\rtfsp
1019 \helpref{wxMenuBar::Remove
}{wxmenubarremove
}
1021 \membersection{wxMenuBar::SetHelpString
}\label{wxmenubarsethelpstring
}
1023 \func{void
}{SetHelpString
}{\param{int
}{ id
},
\param{const wxString\&
}{helpString
}}
1025 Sets the help string associated with a menu item.
1027 \wxheading{Parameters
}
1029 \docparam{id
}{Menu item identifier.
}
1031 \docparam{helpString
}{Help string to associate with the menu item.
}
1033 \wxheading{See also
}
1035 \helpref{wxMenuBar::GetHelpString
}{wxmenubargethelpstring
}
1037 \membersection{wxMenuBar::SetLabel
}\label{wxmenubarsetlabel
}
1039 \func{void
}{SetLabel
}{\param{int
}{ id
},
\param{const wxString\&
}{label
}}
1041 Sets the label of a menu item.
1043 \wxheading{Parameters
}
1045 \docparam{id
}{Menu item identifier.
}
1047 \docparam{label
}{Menu item label.
}
1051 Use only after the menubar has been associated with a frame.
1053 \wxheading{See also
}
1055 \helpref{wxMenuBar::GetLabel
}{wxmenubargetlabel
}
1057 \membersection{wxMenuBar::SetLabelTop
}\label{wxmenubarsetlabeltop
}
1059 \func{void
}{SetLabelTop
}{\param{int
}{ pos
},
\param{const wxString\&
}{label
}}
1061 Sets the label of a top-level menu.
1063 \wxheading{Parameters
}
1065 \docparam{pos
}{The position of a menu on the menu bar, starting from zero.
}
1067 \docparam{label
}{The menu label.
}
1071 Use only after the menubar has been associated with a frame.
1073 \wxheading{See also
}
1075 \helpref{wxMenuBar::GetLabelTop
}{wxmenubargetlabeltop
}