]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{\class{wxMenu}}\label{wxmenu} |
2 | ||
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. | |
6 | ||
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. | |
9 | ||
10 | \wxheading{Derived from} | |
11 | ||
12 | \helpref{wxEvtHandler}{wxevthandler}\\ | |
13 | \helpref{wxObject}{wxobject} | |
14 | ||
954b8ae6 JS |
15 | \wxheading{Include files} |
16 | ||
17 | <wx/menu.h> | |
18 | ||
a660d684 KB |
19 | \wxheading{Event handling} |
20 | ||
21 | If the menu is part of a menubar, then \helpref{wxMenuBar}{wxmenubar} event processing is used. | |
22 | ||
23 | With a popup menu, there is a variety of ways to handle a menu selection event | |
24 | (wxEVT\_COMMAND\_MENU\_SELECTED). | |
25 | ||
26 | \begin{enumerate}\itemsep=0pt | |
a660d684 KB |
27 | \item Derive a new class from wxMenu and define event table entries using the EVT\_MENU macro. |
28 | \item Set a new event handler for wxMenu, using an object whose class has EVT\_MENU entries. | |
29 | \item Provide EVT\_MENU handlers in the window which pops up the menu, or in an ancestor of | |
30 | this window. | |
1aaef614 | 31 | \item Define a callback of type wxFunction, which you pass to the wxMenu constructor. |
874a1686 | 32 | The callback takes a reference to the menu, and a reference to a |
1aaef614 VZ |
33 | \helpref{wxCommandEvent}{wxcommandevent}. This method is deprecated and should |
34 | not be used in the new code, it is provided for backwards compatibility only. | |
a660d684 KB |
35 | \end{enumerate} |
36 | ||
37 | \wxheading{See also} | |
38 | ||
39 | \helpref{wxMenuBar}{wxmenubar}, \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu},\rtfsp | |
40 | \helpref{Event handling overview}{eventhandlingoverview} | |
41 | ||
42 | \latexignore{\rtfignore{\wxheading{Members}}} | |
43 | ||
44 | \membersection{wxMenu::wxMenu}\label{wxmenuconstr} | |
45 | ||
b1462dfa | 46 | \func{}{wxMenu}{\param{const wxString\& }{title = ""}, \param{long}{ style = 0}} |
a660d684 KB |
47 | |
48 | Constructs a wxMenu object. | |
49 | ||
50 | \wxheading{Parameters} | |
51 | ||
52 | \docparam{title}{A title for the popup menu: the empty string denotes no title.} | |
53 | ||
809f39fe | 54 | \docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).} |
06d20283 | 55 | |
407f3681 | 56 | \func{}{wxMenu}{\param{long}{ style}} |
4e986502 KB |
57 | |
58 | Constructs a wxMenu object. | |
59 | ||
60 | \wxheading{Parameters} | |
407f3681 | 61 | |
809f39fe | 62 | \docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).} |
4e986502 | 63 | |
a660d684 KB |
64 | \membersection{wxMenu::\destruct{wxMenu}} |
65 | ||
66 | \func{}{\destruct{wxMenu}}{\void} | |
67 | ||
68 | Destructor, destroying the menu. | |
69 | ||
b412f9be JS |
70 | Note: under Motif, a popup menu must have a valid parent (the window |
71 | it was last popped up on) when being destroyed. Therefore, make sure | |
72 | you delete or re-use the popup menu {\it before} destroying the | |
73 | parent window. Re-use in this context means popping up the menu on | |
74 | a different window from last time, which causes an implicit destruction | |
75 | and recreation of internal data structures. | |
76 | ||
a660d684 KB |
77 | \membersection{wxMenu::Append}\label{wxmenuappend} |
78 | ||
eaaa6a06 | 79 | \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp |
d65c269b | 80 | \param{wxItemKind}{ kind = wxItem\_Normal}} |
a660d684 KB |
81 | |
82 | Adds a string item to the end of the menu. | |
83 | ||
eaaa6a06 | 84 | \func{void}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{wxMenu *}{subMenu},\rtfsp |
a660d684 KB |
85 | \param{const wxString\& }{helpString = ""}} |
86 | ||
87 | Adds a pull-right submenu to the end of the menu. | |
88 | ||
89 | \func{void}{Append}{\param{wxMenuItem*}{ menuItem}} | |
90 | ||
1aaef614 VZ |
91 | Adds a menu item object. This is the most generic variant of Append() method |
92 | because it may be used for both items (including separators) and submenus and | |
93 | because you can also specify various extra properties of a menu item this way, | |
a660d684 KB |
94 | such as bitmaps and fonts. |
95 | ||
96 | \wxheading{Parameters} | |
97 | ||
98 | \docparam{id}{The menu command identifier.} | |
99 | ||
100 | \docparam{item}{The string to appear on the menu item.} | |
101 | ||
102 | \docparam{menu}{Pull-right submenu.} | |
103 | ||
d65c269b VZ |
104 | \docparam{kind}{May be {\tt wxItem\_Separator}, {\tt wxItem\_Normal}, |
105 | {\tt wxItem\_Check} or {\tt wxItem\_Radio}} | |
a660d684 KB |
106 | |
107 | \docparam{helpString}{An optional help string associated with the item. | |
108 | By default, \helpref{wxFrame::OnMenuHighlight}{wxframeonmenuhighlight} displays | |
109 | this string in the status line.} | |
110 | ||
111 | \docparam{menuItem}{A menuitem object. It will be owned by the wxMenu object after this function | |
112 | is called, so do not delete it yourself.} | |
113 | ||
114 | \wxheading{Remarks} | |
115 | ||
116 | This command can be used after the menu has been shown, as well as on initial | |
117 | creation of a menu or menubar. | |
118 | ||
119 | \wxheading{See also} | |
120 | ||
1aaef614 | 121 | \helpref{wxMenu::AppendSeparator}{wxmenuappendseparator},\rtfsp |
d65c269b VZ |
122 | \helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem},\rtfsp |
123 | \helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem},\rtfsp | |
1aaef614 VZ |
124 | \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp |
125 | \helpref{wxMenu::SetLabel}{wxmenusetlabel}, \helpref{wxMenu::GetHelpString}{wxmenugethelpstring},\rtfsp | |
a660d684 KB |
126 | \helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenuItem}{wxmenuitem} |
127 | ||
06d20283 RD |
128 | \pythonnote{In place of a single overloaded method name, wxPython |
129 | implements the following methods:\par | |
130 | \indented{2cm}{\begin{twocollist} | |
c9110876 VS |
131 | \twocolitem{{\bf Append(id, string, helpStr="", checkable=FALSE)}}{} |
132 | \twocolitem{{\bf AppendMenu(id, string, aMenu, helpStr="")}}{} | |
133 | \twocolitem{{\bf AppendItem(aMenuItem)}}{} | |
06d20283 RD |
134 | \end{twocollist}} |
135 | } | |
136 | ||
d65c269b VZ |
137 | \membersection{wxMenu::AppendCheckItem}\label{wxmenuappendcheckitem} |
138 | ||
139 | \func{void}{AppendCheckItem}{\param{int}{ id},\rtfsp | |
140 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
141 | ||
142 | Adds a checkable item to the end of the menu. | |
143 | ||
144 | \wxheading{See also} | |
145 | ||
146 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp | |
147 | \helpref{wxMenu::InsertCheckItem}{wxmenuinsertcheckitem} | |
148 | ||
149 | \membersection{wxMenu::AppendRadioItem}\label{wxmenuappendradioitem} | |
150 | ||
151 | \func{void}{AppendRadioItem}{\param{int}{ id},\rtfsp | |
152 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
153 | ||
154 | Adds a radio item to the end of the menu. All consequent radio items form a | |
155 | group and when an item in the group is checked, all the others are | |
156 | automatically unchecked. | |
157 | ||
158 | {\bf NB:} Currently only implemented under Windows and GTK, use | |
159 | {\tt #if wxHAS\_RADIO\_MENU\_ITEMS} to test for availability of this feature. | |
160 | ||
161 | \wxheading{See also} | |
162 | ||
163 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp | |
164 | \helpref{wxMenu::InsertRadioItem}{wxmenuinsertradioitem} | |
165 | ||
a660d684 KB |
166 | \membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator} |
167 | ||
168 | \func{void}{AppendSeparator}{\void} | |
169 | ||
170 | Adds a separator to the end of the menu. | |
171 | ||
172 | \wxheading{See also} | |
173 | ||
d65c269b VZ |
174 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp |
175 | \helpref{wxMenu::InsertSeparator}{wxmenuinsertseparator} | |
a660d684 KB |
176 | |
177 | \membersection{wxMenu::Break}\label{wxmenubreak} | |
178 | ||
179 | \func{void}{Break}{\void} | |
180 | ||
181 | Inserts a break in a menu, causing the next appended item to appear in a new column. | |
182 | ||
183 | \membersection{wxMenu::Check}\label{wxmenucheck} | |
184 | ||
eaaa6a06 | 185 | \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}} |
a660d684 KB |
186 | |
187 | Checks or unchecks the menu item. | |
188 | ||
189 | \wxheading{Parameters} | |
190 | ||
191 | \docparam{id}{The menu item identifier.} | |
192 | ||
193 | \docparam{check}{If TRUE, the item will be checked, otherwise it will be unchecked.} | |
194 | ||
195 | \wxheading{See also} | |
196 | ||
197 | \helpref{wxMenu::IsChecked}{wxmenuischecked} | |
198 | ||
fc9c7c09 RR |
199 | \membersection{wxMenu::Delete}\label{wxmenudelete} |
200 | ||
201 | \func{void}{Delete}{\param{int }{id}} | |
202 | ||
1aaef614 VZ |
203 | \func{void}{Delete}{\param{wxMenuItem *}{item}} |
204 | ||
874a1686 | 205 | Deletes the menu item from the menu. If the item is a submenu, it will |
1aaef614 VZ |
206 | {\bf not} be deleted. Use \helpref{Destroy}{wxmenudestroy} if you want to |
207 | delete a submenu. | |
fc9c7c09 RR |
208 | |
209 | \wxheading{Parameters} | |
210 | ||
1aaef614 | 211 | \docparam{id}{Id of the menu item to be deleted.} |
fc9c7c09 | 212 | |
1aaef614 VZ |
213 | \docparam{item}{Menu item to be deleted.} |
214 | ||
215 | \wxheading{See also} | |
216 | ||
217 | \helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp | |
218 | \helpref{wxMenu::Destroy}{wxmenudestroy},\rtfsp | |
219 | \helpref{wxMenu::Remove}{wxmenuremove} | |
220 | ||
221 | \membersection{wxMenu::Destroy}\label{wxmenudestroy} | |
222 | ||
223 | \func{void}{Destroy}{\param{int }{id}} | |
224 | ||
225 | \func{void}{Destroy}{\param{wxMenuItem *}{item}} | |
226 | ||
874a1686 | 227 | Deletes the menu item from the menu. If the item is a submenu, it will |
1aaef614 VZ |
228 | be deleted. Use \helpref{Remove}{wxmenuremove} if you want to keep the submenu |
229 | (for example, to reuse it later). | |
fc9c7c09 | 230 | |
1aaef614 VZ |
231 | \wxheading{Parameters} |
232 | ||
233 | \docparam{id}{Id of the menu item to be deleted.} | |
234 | ||
235 | \docparam{item}{Menu item to be deleted.} | |
fc9c7c09 RR |
236 | |
237 | \wxheading{See also} | |
238 | ||
1aaef614 VZ |
239 | \helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp |
240 | \helpref{wxMenu::Deletes}{wxmenudelete},\rtfsp | |
241 | \helpref{wxMenu::Remove}{wxmenuremove} | |
fc9c7c09 | 242 | |
a660d684 KB |
243 | \membersection{wxMenu::Enable}\label{wxmenuenable} |
244 | ||
eaaa6a06 | 245 | \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}} |
a660d684 KB |
246 | |
247 | Enables or disables (greys out) a menu item. | |
248 | ||
249 | \wxheading{Parameters} | |
250 | ||
251 | \docparam{id}{The menu item identifier.} | |
252 | ||
253 | \docparam{enable}{TRUE to enable the menu item, FALSE to disable it.} | |
254 | ||
255 | \wxheading{See also} | |
256 | ||
257 | \helpref{wxMenu::IsEnabled}{wxmenuisenabled} | |
258 | ||
259 | \membersection{wxMenu::FindItem}\label{wxmenufinditem} | |
260 | ||
261 | \constfunc{int}{FindItem}{\param{const wxString\& }{itemString}} | |
262 | ||
263 | Finds the menu item id for a menu item string. | |
264 | ||
1aaef614 | 265 | \constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu **}{menu = NULL}} |
407f3681 | 266 | |
1aaef614 VZ |
267 | Finds the menu item object associated with the given menu item identifier and, |
268 | optionally, the (sub)menu it belongs to. | |
a660d684 | 269 | |
5873607e VZ |
270 | \perlnote{In wxPerl this method takes just the {\tt id} parameter; |
271 | in scalar context it returns the associated {\tt Wx::MenuItem}, in list | |
9722642d | 272 | context it returns a 2-element list {\tt ( item, submenu )}} |
5873607e | 273 | |
a660d684 KB |
274 | \wxheading{Parameters} |
275 | ||
e12be2f7 JS |
276 | \docparam{itemString}{Menu item string to find.} |
277 | ||
a660d684 KB |
278 | \docparam{id}{Menu item identifier.} |
279 | ||
1aaef614 VZ |
280 | \docparam{menu}{If the pointer is not NULL, it will be filled with the items |
281 | parent menu (if the item was found)} | |
282 | ||
a660d684 KB |
283 | \wxheading{Return value} |
284 | ||
e12be2f7 | 285 | First form: menu item identifier, or wxNOT\_FOUND if none is found. |
a660d684 | 286 | |
e12be2f7 | 287 | Second form: returns the menu item object, or NULL if it is not found. |
a660d684 | 288 | |
e12be2f7 JS |
289 | \wxheading{Remarks} |
290 | ||
291 | Any special menu codes are stripped out of source and target strings | |
292 | before matching. | |
a660d684 | 293 | |
fa482912 | 294 | \pythonnote{The name of this method in wxPython is {\tt FindItemById} |
874a1686 RD |
295 | and it does not support the second parameter.} |
296 | ||
a660d684 KB |
297 | \membersection{wxMenu::GetHelpString}\label{wxmenugethelpstring} |
298 | ||
eaaa6a06 | 299 | \constfunc{wxString}{GetHelpString}{\param{int}{ id}} |
a660d684 KB |
300 | |
301 | Returns the help string associated with a menu item. | |
302 | ||
303 | \wxheading{Parameters} | |
304 | ||
305 | \docparam{id}{The menu item identifier.} | |
306 | ||
307 | \wxheading{Return value} | |
308 | ||
309 | The help string, or the empty string if there is no help string or the | |
310 | item was not found. | |
311 | ||
312 | \wxheading{See also} | |
313 | ||
314 | \helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenu::Append}{wxmenuappend} | |
315 | ||
316 | \membersection{wxMenu::GetLabel}\label{wxmenugetlabel} | |
317 | ||
eaaa6a06 | 318 | \constfunc{wxString}{GetLabel}{\param{int}{ id}} |
a660d684 KB |
319 | |
320 | Returns a menu item label. | |
321 | ||
322 | \wxheading{Parameters} | |
323 | ||
324 | \docparam{id}{The menu item identifier.} | |
325 | ||
326 | \wxheading{Return value} | |
327 | ||
328 | The item label, or the empty string if the item was not found. | |
329 | ||
330 | \wxheading{See also} | |
331 | ||
332 | \helpref{wxMenu::SetLabel}{wxmenusetlabel} | |
333 | ||
1aaef614 VZ |
334 | \membersection{wxMenu::GetMenuItemCount}\label{wxmenugetmenuitemcount} |
335 | ||
336 | \constfunc{size\_t}{GetMenuItemCount}{\void} | |
337 | ||
338 | Returns the number of items in the menu. | |
339 | ||
340 | \membersection{wxMenu::GetMenuItems}\label{wxmenugetmenuitems} | |
341 | ||
342 | \constfunc{wxMenuItemList\&}{GetMenuItems}{\void} | |
343 | ||
344 | Returns the list of items in the menu. wxMenuItemList is a pseudo-template | |
345 | list class containing wxMenuItem pointers. | |
346 | ||
a660d684 KB |
347 | \membersection{wxMenu::GetTitle}\label{wxmenugettitle} |
348 | ||
349 | \constfunc{wxString}{GetTitle}{\void} | |
350 | ||
351 | Returns the title of the menu. | |
352 | ||
353 | \wxheading{Remarks} | |
354 | ||
355 | This is relevant only to popup menus. | |
356 | ||
357 | \wxheading{See also} | |
358 | ||
359 | \helpref{wxMenu::SetTitle}{wxmenusettitle} | |
360 | ||
1aaef614 VZ |
361 | \membersection{wxMenu::Insert}\label{wxmenuinsert} |
362 | ||
363 | \func{bool}{Insert}{\param{size\_t }{pos}, \param{wxMenuItem *}{item}} | |
364 | ||
d65c269b VZ |
365 | \func{void}{Insert}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp |
366 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp | |
367 | \param{wxItemKind}{ kind = wxItem\_Normal}} | |
368 | ||
1aaef614 VZ |
369 | Inserts the given {\it item} before the position {\it pos}. Inserting the item |
370 | at the position \helpref{GetMenuItemCount}{wxmenugetmenuitemcount} is the same | |
371 | as appending it. | |
372 | ||
373 | \wxheading{See also} | |
374 | ||
d65c269b VZ |
375 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp |
376 | \helpref{wxMenu::Prepend}{wxmenuprepend} | |
377 | ||
378 | \membersection{wxMenu::InsertCheckItem}\label{wxmenuinsertcheckitem} | |
379 | ||
380 | \func{void}{InsertCheckItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp | |
381 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
382 | ||
383 | Inserts a checkable item at the given position. | |
384 | ||
385 | \wxheading{See also} | |
386 | ||
387 | \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp | |
388 | \helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem} | |
389 | ||
390 | \membersection{wxMenu::InsertRadioItem}\label{wxmenuinsertradioitem} | |
391 | ||
392 | \func{void}{InsertRadioItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp | |
393 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
394 | ||
395 | Inserts a radio item at the given position. | |
396 | ||
397 | \wxheading{See also} | |
398 | ||
399 | \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp | |
400 | \helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem} | |
401 | ||
402 | \membersection{wxMenu::InsertSeparator}\label{wxmenuinsertseparator} | |
403 | ||
404 | \func{void}{InsertSeparator}{\param{size\_t }{pos}} | |
405 | ||
406 | Inserts a separator at the given position. | |
407 | ||
408 | \wxheading{See also} | |
409 | ||
410 | \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp | |
411 | \helpref{wxMenu::AppendSeparator}{wxmenuappendseparator} | |
1aaef614 | 412 | |
a660d684 KB |
413 | \membersection{wxMenu::IsChecked}\label{wxmenuischecked} |
414 | ||
eaaa6a06 | 415 | \constfunc{bool}{IsChecked}{\param{int}{ id}} |
a660d684 KB |
416 | |
417 | Determines whether a menu item is checked. | |
418 | ||
419 | \wxheading{Parameters} | |
420 | ||
421 | \docparam{id}{The menu item identifier.} | |
422 | ||
423 | \wxheading{Return value} | |
424 | ||
425 | TRUE if the menu item is checked, FALSE otherwise. | |
426 | ||
427 | \wxheading{See also} | |
428 | ||
429 | \helpref{wxMenu::Check}{wxmenucheck} | |
430 | ||
431 | \membersection{wxMenu::IsEnabled}\label{wxmenuisenabled} | |
432 | ||
eaaa6a06 | 433 | \constfunc{bool}{IsEnabled}{\param{int}{ id}} |
a660d684 KB |
434 | |
435 | Determines whether a menu item is enabled. | |
436 | ||
437 | \wxheading{Parameters} | |
438 | ||
439 | \docparam{id}{The menu item identifier.} | |
440 | ||
441 | \wxheading{Return value} | |
442 | ||
443 | TRUE if the menu item is enabled, FALSE otherwise. | |
444 | ||
445 | \wxheading{See also} | |
446 | ||
447 | \helpref{wxMenu::Enable}{wxmenuenable} | |
448 | ||
d65c269b VZ |
449 | \membersection{wxMenu::Prepend}\label{wxmenuprepend} |
450 | ||
451 | \func{bool}{Prepend}{\param{size\_t }{pos}, \param{wxMenuItem *}{item}} | |
452 | ||
453 | \func{void}{Prepend}{\param{int}{ id},\rtfsp | |
454 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp | |
455 | \param{wxItemKind}{ kind = wxItem\_Normal}} | |
456 | ||
457 | Inserts the given {\it item} at the position $0$. | |
458 | ||
459 | \wxheading{See also} | |
460 | ||
461 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp | |
462 | \helpref{wxMenu::Inserts}{wxmenuinsert} | |
463 | ||
464 | \membersection{wxMenu::PrependCheckItem}\label{wxmenuprependcheckitem} | |
465 | ||
466 | \func{void}{PrependCheckItem}{\param{int}{ id},\rtfsp | |
467 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
468 | ||
469 | Inserts a checkable item at the position $0$. | |
470 | ||
471 | \wxheading{See also} | |
472 | ||
473 | \helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp | |
474 | \helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem} | |
475 | ||
476 | \membersection{wxMenu::PrependRadioItem}\label{wxmenuprependradioitem} | |
477 | ||
478 | \func{void}{PrependRadioItem}{\param{int}{ id},\rtfsp | |
479 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
480 | ||
481 | Inserts a radio item at the position $0$. | |
482 | ||
483 | \wxheading{See also} | |
484 | ||
485 | \helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp | |
486 | \helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem} | |
487 | ||
488 | \membersection{wxMenu::PrependSeparator}\label{wxmenuprependseparator} | |
489 | ||
490 | \func{void}{PrependSeparator}{\param{size\_t }{pos}} | |
491 | ||
492 | Inserts a separator at the position $0$. | |
493 | ||
494 | \wxheading{See also} | |
495 | ||
496 | \helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp | |
497 | \helpref{wxMenu::AppendSeparator}{wxmenuappendseparator} | |
498 | ||
1aaef614 VZ |
499 | \membersection{wxMenu::Remove}\label{wxmenuremove} |
500 | ||
501 | \func{wxMenuItem *}{Remove}{\param{int }{id}} | |
502 | ||
503 | \func{wxMenuItem *}{Remove}{\param{wxMenuItem *}{item}} | |
504 | ||
505 | Removes the menu item from the menu but doesn't delete the associated C++ | |
506 | object. This allows to reuse the same item later by adding it back to the menu | |
507 | (especially useful with submenus). | |
508 | ||
509 | \wxheading{Parameters} | |
510 | ||
511 | \docparam{id}{The identifier of the menu item to remove.} | |
512 | ||
513 | \docparam{item}{The menu item to remove.} | |
514 | ||
515 | \wxheading{Return value} | |
516 | ||
517 | The item which was detached from the menu. | |
518 | ||
a660d684 KB |
519 | \membersection{wxMenu::SetHelpString}\label{wxmenusethelpstring} |
520 | ||
eaaa6a06 | 521 | \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}} |
a660d684 KB |
522 | |
523 | Sets an item's help string. | |
524 | ||
525 | \wxheading{Parameters} | |
526 | ||
527 | \docparam{id}{The menu item identifier.} | |
528 | ||
529 | \docparam{helpString}{The help string to set.} | |
530 | ||
531 | \wxheading{See also} | |
532 | ||
533 | \helpref{wxMenu::GetHelpString}{wxmenugethelpstring} | |
534 | ||
535 | \membersection{wxMenu::SetLabel}\label{wxmenusetlabel} | |
536 | ||
eaaa6a06 | 537 | \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}} |
a660d684 KB |
538 | |
539 | Sets the label of a menu item. | |
540 | ||
541 | \wxheading{Parameters} | |
542 | ||
543 | \docparam{id}{The menu item identifier.} | |
544 | ||
545 | \docparam{label}{The menu item label to set.} | |
546 | ||
547 | \wxheading{See also} | |
548 | ||
549 | \helpref{wxMenu::Append}{wxmenuappend}, \helpref{wxMenu::GetLabel}{wxmenugetlabel} | |
550 | ||
551 | \membersection{wxMenu::SetTitle}\label{wxmenusettitle} | |
552 | ||
553 | \func{void}{SetTitle}{\param{const wxString\& }{title}} | |
554 | ||
555 | Sets the title of the menu. | |
556 | ||
557 | \wxheading{Parameters} | |
558 | ||
559 | \docparam{title}{The title to set.} | |
560 | ||
561 | \wxheading{Remarks} | |
562 | ||
563 | This is relevant only to popup menus. | |
564 | ||
565 | \wxheading{See also} | |
566 | ||
567 | \helpref{wxMenu::SetTitle}{wxmenusettitle} | |
568 | ||
631f1bfe JS |
569 | \membersection{wxMenu::UpdateUI}\label{wxmenuupdateui} |
570 | ||
571 | \constfunc{void}{UpdateUI}{\param{wxEvtHandler*}{ source = NULL}} | |
572 | ||
573 | Sends events to {\it source} (or owning window if NULL) to update the | |
574 | menu UI. This is called just before the menu is popped up with \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu}, but | |
575 | the application may call it at other times if required. | |
576 | ||
577 | \wxheading{See also} | |
578 | ||
579 | \helpref{wxUpdateUIEvent}{wxupdateuievent} | |
580 | ||
a660d684 KB |
581 | \section{\class{wxMenuBar}}\label{wxmenubar} |
582 | ||
583 | A menu bar is a series of menus accessible from the top of a frame. | |
584 | ||
585 | \wxheading{Derived from} | |
586 | ||
587 | \helpref{wxEvtHandler}{wxevthandler}\\ | |
588 | \helpref{wxObject}{wxobject} | |
589 | ||
954b8ae6 JS |
590 | \wxheading{Include files} |
591 | ||
592 | <wx/menu.h> | |
593 | ||
a660d684 KB |
594 | \wxheading{Event handling} |
595 | ||
596 | To respond to a menu selection, provide a handler for EVT\_MENU, in the frame | |
e702ff0f JS |
597 | that contains the menu bar. If you have a toolbar which uses the same identifiers |
598 | as your EVT\_MENU entries, events from the toolbar will also be processed by your | |
599 | EVT\_MENU event handlers. | |
600 | ||
601 | Note that menu commands (and UI update events for menus) are first sent to | |
602 | the focus window within the frame. If no window within the frame has the focus, | |
603 | then the events are sent directly to the frame. This allows command and UI update | |
604 | handling to be processed by specific windows and controls, and not necessarily | |
605 | by the application frame. | |
a660d684 | 606 | |
0ddef74d JS |
607 | {\bf Tip:} under Windows, if you discover that menu shortcuts (for example, Alt-F to show the file menu) |
608 | are not working, check any EVT\_CHAR events you are handling in child windows. | |
609 | If you are not calling {\tt event.Skip()} for events that you don't process in these event handlers, | |
610 | menu shortcuts may cease to work. | |
611 | ||
a660d684 KB |
612 | \wxheading{See also} |
613 | ||
614 | \helpref{wxMenu}{wxmenu}, \helpref{Event handling overview}{eventhandlingoverview} | |
615 | ||
616 | \latexignore{\rtfignore{\wxheading{Members}}} | |
617 | ||
618 | \membersection{wxMenuBar::wxMenuBar}\label{wxmenubarconstr} | |
619 | ||
17e79918 | 620 | \func{void}{wxMenuBar}{\param{long }{style = 0}} |
a660d684 KB |
621 | |
622 | Default constructor. | |
623 | ||
eaaa6a06 | 624 | \func{void}{wxMenuBar}{\param{int}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}} |
a660d684 KB |
625 | |
626 | Construct a menu bar from arrays of menus and titles. | |
627 | ||
628 | \wxheading{Parameters} | |
629 | ||
630 | \docparam{n}{The number of menus.} | |
631 | ||
632 | \docparam{menus}{An array of menus. Do not use this array again - it now belongs to the | |
633 | menu bar.} | |
634 | ||
635 | \docparam{titles}{An array of title strings. Deallocate this array after creating the menu bar.} | |
636 | ||
d17f05af | 637 | \docparam{style}{If {\tt wxMB\_DOCKABLE} the menu bar can be detached (wxGTK only).} |
17e79918 | 638 | |
06d20283 RD |
639 | \pythonnote{Only the default constructor is supported in wxPython. |
640 | Use wxMenuBar.Append instead.} | |
641 | ||
5873607e VZ |
642 | \perlnote{wxPerl only supports the first contructor: |
643 | use {\tt Append} instead.} | |
644 | ||
a660d684 KB |
645 | \membersection{wxMenuBar::\destruct{wxMenuBar}} |
646 | ||
647 | \func{void}{\destruct{wxMenuBar}}{\void} | |
648 | ||
649 | Destructor, destroying the menu bar and removing it from the parent frame (if any). | |
650 | ||
651 | \membersection{wxMenuBar::Append}\label{wxmenubarappend} | |
652 | ||
1aaef614 | 653 | \func{bool}{Append}{\param{wxMenu *}{menu}, \param{const wxString\& }{title}} |
a660d684 KB |
654 | |
655 | Adds the item to the end of the menu bar. | |
656 | ||
657 | \wxheading{Parameters} | |
658 | ||
659 | \docparam{menu}{The menu to add. Do not deallocate this menu after calling {\bf Append}.} | |
660 | ||
661 | \docparam{title}{The title of the menu.} | |
662 | ||
1aaef614 VZ |
663 | \wxheading{Return value} |
664 | ||
f6bcfd97 | 665 | TRUE on success, FALSE if an error occurred. |
1aaef614 VZ |
666 | |
667 | \wxheading{See also} | |
668 | ||
669 | \helpref{wxMenuBar::Insert}{wxmenubarinsert} | |
670 | ||
a660d684 KB |
671 | \membersection{wxMenuBar::Check}\label{wxmenubarcheck} |
672 | ||
eaaa6a06 | 673 | \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}} |
a660d684 KB |
674 | |
675 | Checks or unchecks a menu item. | |
676 | ||
677 | \wxheading{Parameters} | |
678 | ||
679 | \docparam{id}{The menu item identifier.} | |
680 | ||
681 | \docparam{check}{If TRUE, checks the menu item, otherwise the item is unchecked.} | |
682 | ||
683 | \wxheading{Remarks} | |
684 | ||
685 | Only use this when the menu bar has been associated | |
686 | with a frame; otherwise, use the wxMenu equivalent call. | |
687 | ||
688 | \membersection{wxMenuBar::Enable}\label{wxmenubarenable} | |
689 | ||
eaaa6a06 | 690 | \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}} |
a660d684 KB |
691 | |
692 | Enables or disables (greys out) a menu item. | |
693 | ||
694 | \wxheading{Parameters} | |
695 | ||
696 | \docparam{id}{The menu item identifier.} | |
697 | ||
698 | \docparam{enable}{TRUE to enable the item, FALSE to disable it.} | |
699 | ||
700 | \wxheading{Remarks} | |
701 | ||
702 | Only use this when the menu bar has been | |
703 | associated with a frame; otherwise, use the wxMenu equivalent call. | |
704 | ||
705 | \membersection{wxMenuBar::EnableTop}\label{wxmenubarenabletop} | |
706 | ||
eaaa6a06 | 707 | \func{void}{EnableTop}{\param{int}{ pos}, \param{const bool}{ enable}} |
a660d684 KB |
708 | |
709 | Enables or disables a whole menu. | |
710 | ||
711 | \wxheading{Parameters} | |
712 | ||
713 | \docparam{pos}{The position of the menu, starting from zero.} | |
714 | ||
715 | \docparam{enable}{TRUE to enable the menu, FALSE to disable it.} | |
716 | ||
717 | \wxheading{Remarks} | |
718 | ||
719 | Only use this when the menu bar has been | |
720 | associated with a frame. | |
721 | ||
270e8b6a VZ |
722 | \membersection{wxMenuBar::FindMenu}\label{wxmenubarfindmenu} |
723 | ||
724 | \constfunc{int}{FindMenu}{\param{const wxString\& }{title}} | |
725 | ||
726 | Returns the index of the menu with the given {\it title} or wxNOT\_FOUND if no | |
727 | such menu exists in this menubar. The {\it title} parameter may specify either | |
728 | the menu title (with accelerator characters, i.e. {\tt "\&File"}) or just the | |
729 | menu label ({\tt "File"}) indifferently. | |
730 | ||
a660d684 KB |
731 | \membersection{wxMenuBar::FindMenuItem}\label{wxmenubarfindmenuitem} |
732 | ||
733 | \constfunc{int}{FindMenuItem}{\param{const wxString\& }{menuString}, \param{const wxString\& }{itemString}} | |
734 | ||
735 | Finds the menu item id for a menu name/menu item string pair. | |
736 | ||
737 | \wxheading{Parameters} | |
738 | ||
739 | \docparam{menuString}{Menu title to find.} | |
740 | ||
741 | \docparam{itemString}{Item to find.} | |
742 | ||
743 | \wxheading{Return value} | |
744 | ||
1aaef614 | 745 | The menu item identifier, or wxNOT\_FOUND if none was found. |
a660d684 KB |
746 | |
747 | \wxheading{Remarks} | |
748 | ||
749 | Any special menu codes are stripped out of source and target strings | |
750 | before matching. | |
751 | ||
fc9c7c09 | 752 | \membersection{wxMenuBar::FindItem}\label{wxmenubarfinditem} |
a660d684 | 753 | |
407f3681 | 754 | \constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu}{ **menu = NULL}} |
a660d684 | 755 | |
fc9c7c09 | 756 | Finds the menu item object associated with the given menu item identifier. |
a660d684 KB |
757 | |
758 | \wxheading{Parameters} | |
759 | ||
760 | \docparam{id}{Menu item identifier.} | |
407f3681 | 761 | |
fc9c7c09 | 762 | \docparam{menu}{If not NULL, menu will get set to the associated menu.} |
a660d684 KB |
763 | |
764 | \wxheading{Return value} | |
765 | ||
766 | The found menu item object, or NULL if one was not found. | |
767 | ||
768 | \membersection{wxMenuBar::GetHelpString}\label{wxmenubargethelpstring} | |
769 | ||
eaaa6a06 | 770 | \constfunc{wxString}{GetHelpString}{\param{int}{ id}} |
a660d684 KB |
771 | |
772 | Gets the help string associated with the menu item identifer. | |
773 | ||
774 | \wxheading{Parameters} | |
775 | ||
776 | \docparam{id}{The menu item identifier.} | |
777 | ||
778 | \wxheading{Return value} | |
779 | ||
780 | The help string, or the empty string if there was no help string or the menu item | |
781 | was not found. | |
782 | ||
783 | \wxheading{See also} | |
784 | ||
785 | \helpref{wxMenuBar::SetHelpString}{wxmenubarsethelpstring} | |
786 | ||
787 | \membersection{wxMenuBar::GetLabel}\label{wxmenubargetlabel} | |
788 | ||
eaaa6a06 | 789 | \constfunc{wxString}{GetLabel}{\param{int}{ id}} |
a660d684 KB |
790 | |
791 | Gets the label associated with a menu item. | |
792 | ||
793 | \wxheading{Parameters} | |
794 | ||
795 | \docparam{id}{The menu item identifier.} | |
796 | ||
797 | \wxheading{Return value} | |
798 | ||
799 | The menu item label, or the empty string if the item was not found. | |
800 | ||
801 | \wxheading{Remarks} | |
802 | ||
803 | Use only after the menubar has been associated with a frame. | |
804 | ||
805 | \membersection{wxMenuBar::GetLabelTop}\label{wxmenubargetlabeltop} | |
806 | ||
eaaa6a06 | 807 | \constfunc{wxString}{GetLabelTop}{\param{int}{ pos}} |
a660d684 KB |
808 | |
809 | Returns the label of a top-level menu. | |
810 | ||
811 | \wxheading{Parameters} | |
812 | ||
813 | \docparam{pos}{Position of the menu on the menu bar, starting from zero.} | |
814 | ||
815 | \wxheading{Return value} | |
816 | ||
817 | The menu label, or the empty string if the menu was not found. | |
818 | ||
819 | \wxheading{Remarks} | |
820 | ||
821 | Use only after the menubar has been associated with a frame. | |
822 | ||
823 | \wxheading{See also} | |
824 | ||
825 | \helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop} | |
826 | ||
7f555861 JS |
827 | \membersection{wxMenuBar::GetMenu}\label{wxmenubargetmenu} |
828 | ||
829 | \constfunc{wxMenu*}{GetMenu}{\param{int}{ menuIndex}} | |
830 | ||
831 | Returns the menu at {\it menuIndex} (zero-based). | |
832 | ||
833 | \membersection{wxMenuBar::GetMenuCount}\label{wxmenubargetmenucount} | |
834 | ||
835 | \constfunc{int}{GetMenuCount}{\void} | |
836 | ||
837 | Returns the number of menus in this menubar. | |
838 | ||
e12be2f7 | 839 | \membersection{wxMenuBar::Insert}\label{wxmenubarinsert} |
1aaef614 VZ |
840 | |
841 | \func{bool}{Insert}{\param{size\_t }{pos}, \param{wxMenu *}{menu}, \param{const wxString\& }{title}} | |
842 | ||
843 | Inserts the menu at the given position into the menu bar. Inserting menu at | |
fa482912 JS |
844 | position $0$ will insert it in the very beginning of it, inserting at position |
845 | \helpref{GetMenuCount()}{wxmenubargetmenucount} is the same as calling | |
1aaef614 VZ |
846 | \helpref{Append()}{wxmenubarappend}. |
847 | ||
848 | \wxheading{Parameters} | |
849 | ||
850 | \docparam{pos}{The position of the new menu in the menu bar} | |
851 | ||
852 | \docparam{menu}{The menu to add. wxMenuBar owns the menu and will free it.} | |
853 | ||
854 | \docparam{title}{The title of the menu.} | |
855 | ||
856 | \wxheading{Return value} | |
857 | ||
f6bcfd97 | 858 | TRUE on success, FALSE if an error occurred. |
1aaef614 VZ |
859 | |
860 | \wxheading{See also} | |
861 | ||
862 | \helpref{wxMenuBar::Append}{wxmenubarappend} | |
863 | ||
a660d684 KB |
864 | \membersection{wxMenuBar::IsChecked}\label{wxmenubarischecked} |
865 | ||
eaaa6a06 | 866 | \constfunc{bool}{IsChecked}{\param{int}{ id}} |
a660d684 KB |
867 | |
868 | Determines whether an item is checked. | |
869 | ||
870 | \wxheading{Parameters} | |
871 | ||
872 | \docparam{id}{The menu item identifier.} | |
873 | ||
874 | \wxheading{Return value} | |
875 | ||
876 | TRUE if the item was found and is checked, FALSE otherwise. | |
877 | ||
878 | \membersection{wxMenuBar::IsEnabled}\label{wxmenubarisenabled} | |
879 | ||
eaaa6a06 | 880 | \constfunc{bool}{IsEnabled}{\param{int}{ id}} |
a660d684 KB |
881 | |
882 | Determines whether an item is enabled. | |
883 | ||
884 | \wxheading{Parameters} | |
885 | ||
886 | \docparam{id}{The menu item identifier.} | |
887 | ||
888 | \wxheading{Return value} | |
889 | ||
890 | TRUE if the item was found and is enabled, FALSE otherwise. | |
891 | ||
63dcfc15 PA |
892 | \membersection{wxMenuBar::Refresh}\label{wxmenubarrefresh} |
893 | ||
894 | \func{void}{Refresh}{\void} | |
895 | ||
896 | Redraw the menu bar | |
897 | ||
1aaef614 VZ |
898 | \membersection{wxMenuBar::Remove}\label{wxmenubarremove} |
899 | ||
900 | \func{wxMenu *}{Remove}{\param{size\_t }{pos}} | |
901 | ||
902 | Removes the menu from the menu bar and returns the menu object - the caller is | |
d7d17624 | 903 | responsible for deleting it. This function may be used together with |
1aaef614 VZ |
904 | \helpref{wxMenuBar::Insert}{wxmenubarinsert} to change the menubar |
905 | dynamically. | |
906 | ||
907 | \wxheading{See also} | |
908 | ||
2182e26f | 909 | \helpref{wxMenuBar::Replace}{wxmenubarreplace} |
1aaef614 VZ |
910 | |
911 | \membersection{wxMenuBar::Replace}\label{wxmenubarreplace} | |
912 | ||
913 | \func{wxMenu *}{Replace}{\param{size\_t }{pos}, \param{wxMenu *}{menu}, \param{const wxString\& }{title}} | |
914 | ||
fa482912 | 915 | Replaces the menu at the given position with another one. |
1aaef614 VZ |
916 | |
917 | \wxheading{Parameters} | |
918 | ||
919 | \docparam{pos}{The position of the new menu in the menu bar} | |
920 | ||
921 | \docparam{menu}{The menu to add.} | |
922 | ||
923 | \docparam{title}{The title of the menu.} | |
924 | ||
925 | \wxheading{Return value} | |
926 | ||
927 | The menu which was previously at the position {\it pos}. The caller is | |
928 | responsible for deleting it. | |
929 | ||
930 | \wxheading{See also} | |
931 | ||
932 | \helpref{wxMenuBar::Insert}{wxmenubarinsert},\rtfsp | |
933 | \helpref{wxMenuBar::Remove}{wxmenubarremove} | |
934 | ||
a660d684 KB |
935 | \membersection{wxMenuBar::SetHelpString}\label{wxmenubarsethelpstring} |
936 | ||
eaaa6a06 | 937 | \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}} |
a660d684 KB |
938 | |
939 | Sets the help string associated with a menu item. | |
940 | ||
941 | \wxheading{Parameters} | |
942 | ||
943 | \docparam{id}{Menu item identifier.} | |
944 | ||
945 | \docparam{helpString}{Help string to associate with the menu item.} | |
946 | ||
947 | \wxheading{See also} | |
948 | ||
949 | \helpref{wxMenuBar::GetHelpString}{wxmenubargethelpstring} | |
950 | ||
951 | \membersection{wxMenuBar::SetLabel}\label{wxmenubarsetlabel} | |
952 | ||
eaaa6a06 | 953 | \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}} |
a660d684 KB |
954 | |
955 | Sets the label of a menu item. | |
956 | ||
957 | \wxheading{Parameters} | |
958 | ||
959 | \docparam{id}{Menu item identifier.} | |
960 | ||
961 | \docparam{label}{Menu item label.} | |
962 | ||
963 | \wxheading{Remarks} | |
964 | ||
965 | Use only after the menubar has been associated with a frame. | |
966 | ||
967 | \wxheading{See also} | |
968 | ||
969 | \helpref{wxMenuBar::GetLabel}{wxmenubargetlabel} | |
970 | ||
971 | \membersection{wxMenuBar::SetLabelTop}\label{wxmenubarsetlabeltop} | |
972 | ||
eaaa6a06 | 973 | \func{void}{SetLabelTop}{\param{int}{ pos}, \param{const wxString\& }{label}} |
a660d684 KB |
974 | |
975 | Sets the label of a top-level menu. | |
976 | ||
977 | \wxheading{Parameters} | |
978 | ||
979 | \docparam{pos}{The position of a menu on the menu bar, starting from zero.} | |
980 | ||
981 | \docparam{label}{The menu label.} | |
982 | ||
983 | \wxheading{Remarks} | |
984 | ||
985 | Use only after the menubar has been associated with a frame. | |
986 | ||
987 | \wxheading{See also} | |
988 | ||
989 | \helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop} | |
990 |