]>
Commit | Line | Data |
---|---|---|
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. 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. | |
11 | ||
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). | |
17 | ||
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. | |
26 | ||
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 radio items | |
34 | are not supported under Motif. | |
35 | ||
36 | \wxheading{Allocation strategy} | |
37 | ||
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. | |
42 | ||
43 | \wxheading{Derived from} | |
44 | ||
45 | \helpref{wxEvtHandler}{wxevthandler}\\ | |
46 | \helpref{wxObject}{wxobject} | |
47 | ||
48 | \wxheading{Include files} | |
49 | ||
50 | <wx/menu.h> | |
51 | ||
52 | \wxheading{Event handling} | |
53 | ||
54 | If the menu is part of a menubar, then \helpref{wxMenuBar}{wxmenubar} event processing is used. | |
55 | ||
56 | With a popup menu, there is a variety of ways to handle a menu selection event | |
57 | (wxEVT\_COMMAND\_MENU\_SELECTED). | |
58 | ||
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 | |
63 | this window. | |
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. | |
68 | \end{enumerate} | |
69 | ||
70 | \wxheading{See also} | |
71 | ||
72 | \helpref{wxMenuBar}{wxmenubar}, \helpref{wxWindow::PopupMenu}{wxwindowpopupmenu},\rtfsp | |
73 | \helpref{Event handling overview}{eventhandlingoverview} | |
74 | ||
75 | \latexignore{\rtfignore{\wxheading{Members}}} | |
76 | ||
77 | \membersection{wxMenu::wxMenu}\label{wxmenuctor} | |
78 | ||
79 | \func{}{wxMenu}{\param{const wxString\& }{title = ""}, \param{long}{ style = 0}} | |
80 | ||
81 | Constructs a wxMenu object. | |
82 | ||
83 | \wxheading{Parameters} | |
84 | ||
85 | \docparam{title}{A title for the popup menu: the empty string denotes no title.} | |
86 | ||
87 | \docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).} | |
88 | ||
89 | \func{}{wxMenu}{\param{long}{ style}} | |
90 | ||
91 | Constructs a wxMenu object. | |
92 | ||
93 | \wxheading{Parameters} | |
94 | ||
95 | \docparam{style}{If set to {\tt wxMENU\_TEAROFF}, the menu will be detachable (wxGTK only).} | |
96 | ||
97 | \membersection{wxMenu::\destruct{wxMenu}}\label{wxmenudtor} | |
98 | ||
99 | \func{}{\destruct{wxMenu}}{\void} | |
100 | ||
101 | Destructor, destroying the menu. | |
102 | ||
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. | |
109 | ||
110 | \membersection{wxMenu::Append}\label{wxmenuappend} | |
111 | ||
112 | \func{wxMenuItem*}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp | |
113 | \param{wxItemKind}{ kind = wxITEM\_NORMAL}} | |
114 | ||
115 | Adds a string item to the end of the menu. | |
116 | ||
117 | \func{wxMenuItem*}{Append}{\param{int}{ id}, \param{const wxString\& }{ item}, \param{wxMenu *}{subMenu},\rtfsp | |
118 | \param{const wxString\& }{helpString = ""}} | |
119 | ||
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 | |
122 | registered properly. | |
123 | ||
124 | \func{wxMenuItem*}{Append}{\param{wxMenuItem*}{ menuItem}} | |
125 | ||
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. | |
130 | ||
131 | \wxheading{Parameters} | |
132 | ||
133 | \docparam{id}{The menu command identifier.} | |
134 | ||
135 | \docparam{item}{The string to appear on the menu item.} | |
136 | ||
137 | \docparam{menu}{Pull-right submenu.} | |
138 | ||
139 | \docparam{kind}{May be {\tt wxITEM\_SEPARATOR}, {\tt wxITEM\_NORMAL}, | |
140 | {\tt wxITEM\_CHECK} or {\tt wxITEM\_RADIO}} | |
141 | ||
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.} | |
145 | ||
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.} | |
148 | ||
149 | \wxheading{Remarks} | |
150 | ||
151 | This command can be used after the menu has been shown, as well as on initial | |
152 | creation of a menu or menubar. | |
153 | ||
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): | |
163 | ||
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)} | |
179 | \end{twocollist} | |
180 | ||
181 | \wxheading{See also} | |
182 | ||
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} | |
189 | ||
190 | \pythonnote{In place of a single overloaded method name, wxPython | |
191 | implements the following methods: | |
192 | ||
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)}}{} | |
197 | \end{twocollist}} | |
198 | } | |
199 | ||
200 | \membersection{wxMenu::AppendCheckItem}\label{wxmenuappendcheckitem} | |
201 | ||
202 | \func{wxMenuItem*}{AppendCheckItem}{\param{int}{ id},\rtfsp | |
203 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
204 | ||
205 | Adds a checkable item to the end of the menu. | |
206 | ||
207 | \wxheading{See also} | |
208 | ||
209 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp | |
210 | \helpref{wxMenu::InsertCheckItem}{wxmenuinsertcheckitem} | |
211 | ||
212 | \membersection{wxMenu::AppendRadioItem}\label{wxmenuappendradioitem} | |
213 | ||
214 | \func{wxMenuItem*}{AppendRadioItem}{\param{int}{ id},\rtfsp | |
215 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
216 | ||
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. | |
220 | ||
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. | |
223 | ||
224 | \wxheading{See also} | |
225 | ||
226 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp | |
227 | \helpref{wxMenu::InsertRadioItem}{wxmenuinsertradioitem} | |
228 | ||
229 | \membersection{wxMenu::AppendSeparator}\label{wxmenuappendseparator} | |
230 | ||
231 | \func{wxMenuItem*}{AppendSeparator}{\void} | |
232 | ||
233 | Adds a separator to the end of the menu. | |
234 | ||
235 | \wxheading{See also} | |
236 | ||
237 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp | |
238 | \helpref{wxMenu::InsertSeparator}{wxmenuinsertseparator} | |
239 | ||
240 | \membersection{wxMenu::Break}\label{wxmenubreak} | |
241 | ||
242 | \func{void}{Break}{\void} | |
243 | ||
244 | Inserts a break in a menu, causing the next appended item to appear in a new column. | |
245 | ||
246 | \membersection{wxMenu::Check}\label{wxmenucheck} | |
247 | ||
248 | \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}} | |
249 | ||
250 | Checks or unchecks the menu item. | |
251 | ||
252 | \wxheading{Parameters} | |
253 | ||
254 | \docparam{id}{The menu item identifier.} | |
255 | ||
256 | \docparam{check}{If true, the item will be checked, otherwise it will be unchecked.} | |
257 | ||
258 | \wxheading{See also} | |
259 | ||
260 | \helpref{wxMenu::IsChecked}{wxmenuischecked} | |
261 | ||
262 | \membersection{wxMenu::Delete}\label{wxmenudelete} | |
263 | ||
264 | \func{void}{Delete}{\param{int }{id}} | |
265 | ||
266 | \func{void}{Delete}{\param{wxMenuItem *}{item}} | |
267 | ||
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 | |
270 | delete a submenu. | |
271 | ||
272 | \wxheading{Parameters} | |
273 | ||
274 | \docparam{id}{Id of the menu item to be deleted.} | |
275 | ||
276 | \docparam{item}{Menu item to be deleted.} | |
277 | ||
278 | \wxheading{See also} | |
279 | ||
280 | \helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp | |
281 | \helpref{wxMenu::Destroy}{wxmenudestroy},\rtfsp | |
282 | \helpref{wxMenu::Remove}{wxmenuremove} | |
283 | ||
284 | \membersection{wxMenu::Destroy}\label{wxmenudestroy} | |
285 | ||
286 | \func{void}{Destroy}{\param{int }{id}} | |
287 | ||
288 | \func{void}{Destroy}{\param{wxMenuItem *}{item}} | |
289 | ||
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). | |
293 | ||
294 | \wxheading{Parameters} | |
295 | ||
296 | \docparam{id}{Id of the menu item to be deleted.} | |
297 | ||
298 | \docparam{item}{Menu item to be deleted.} | |
299 | ||
300 | \wxheading{See also} | |
301 | ||
302 | \helpref{wxMenu::FindItem}{wxmenufinditem},\rtfsp | |
303 | \helpref{wxMenu::Deletes}{wxmenudelete},\rtfsp | |
304 | \helpref{wxMenu::Remove}{wxmenuremove} | |
305 | ||
306 | \membersection{wxMenu::Enable}\label{wxmenuenable} | |
307 | ||
308 | \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}} | |
309 | ||
310 | Enables or disables (greys out) a menu item. | |
311 | ||
312 | \wxheading{Parameters} | |
313 | ||
314 | \docparam{id}{The menu item identifier.} | |
315 | ||
316 | \docparam{enable}{true to enable the menu item, false to disable it.} | |
317 | ||
318 | \wxheading{See also} | |
319 | ||
320 | \helpref{wxMenu::IsEnabled}{wxmenuisenabled} | |
321 | ||
322 | \membersection{wxMenu::FindItem}\label{wxmenufinditem} | |
323 | ||
324 | \constfunc{int}{FindItem}{\param{const wxString\& }{itemString}} | |
325 | ||
326 | Finds the menu item id for a menu item string. | |
327 | ||
328 | \constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu **}{menu = NULL}} | |
329 | ||
330 | Finds the menu item object associated with the given menu item identifier and, | |
331 | optionally, the (sub)menu it belongs to. | |
332 | ||
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 )}} | |
336 | ||
337 | \wxheading{Parameters} | |
338 | ||
339 | \docparam{itemString}{Menu item string to find.} | |
340 | ||
341 | \docparam{id}{Menu item identifier.} | |
342 | ||
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)} | |
345 | ||
346 | \wxheading{Return value} | |
347 | ||
348 | First form: menu item identifier, or {\tt wxNOT\_FOUND} if none is found. | |
349 | ||
350 | Second form: returns the menu item object, or NULL if it is not found. | |
351 | ||
352 | \wxheading{Remarks} | |
353 | ||
354 | Any special menu codes are stripped out of source and target strings | |
355 | before matching. | |
356 | ||
357 | \pythonnote{The name of this method in wxPython is {\tt FindItemById} | |
358 | and it does not support the second parameter.} | |
359 | ||
360 | \membersection{wxMenu::FindItemByPosition}\label{wxmenufinditembyposition} | |
361 | ||
362 | \constfunc{wxMenuItem*}{FindItemByPosition}{\param{size\_t }{position}} | |
363 | ||
364 | Returns the wxMenuItem given a position in the menu. | |
365 | ||
366 | \membersection{wxMenu::GetHelpString}\label{wxmenugethelpstring} | |
367 | ||
368 | \constfunc{wxString}{GetHelpString}{\param{int}{ id}} | |
369 | ||
370 | Returns the help string associated with a menu item. | |
371 | ||
372 | \wxheading{Parameters} | |
373 | ||
374 | \docparam{id}{The menu item identifier.} | |
375 | ||
376 | \wxheading{Return value} | |
377 | ||
378 | The help string, or the empty string if there is no help string or the | |
379 | item was not found. | |
380 | ||
381 | \wxheading{See also} | |
382 | ||
383 | \helpref{wxMenu::SetHelpString}{wxmenusethelpstring}, \helpref{wxMenu::Append}{wxmenuappend} | |
384 | ||
385 | \membersection{wxMenu::GetLabel}\label{wxmenugetlabel} | |
386 | ||
387 | \constfunc{wxString}{GetLabel}{\param{int}{ id}} | |
388 | ||
389 | Returns a menu item label. | |
390 | ||
391 | \wxheading{Parameters} | |
392 | ||
393 | \docparam{id}{The menu item identifier.} | |
394 | ||
395 | \wxheading{Return value} | |
396 | ||
397 | The item label, or the empty string if the item was not found. | |
398 | ||
399 | \wxheading{See also} | |
400 | ||
401 | \helpref{wxMenu::SetLabel}{wxmenusetlabel} | |
402 | ||
403 | \membersection{wxMenu::GetMenuItemCount}\label{wxmenugetmenuitemcount} | |
404 | ||
405 | \constfunc{size\_t}{GetMenuItemCount}{\void} | |
406 | ||
407 | Returns the number of items in the menu. | |
408 | ||
409 | \membersection{wxMenu::GetMenuItems}\label{wxmenugetmenuitems} | |
410 | ||
411 | \constfunc{wxMenuItemList\&}{GetMenuItems}{\void} | |
412 | ||
413 | Returns the list of items in the menu. wxMenuItemList is a pseudo-template | |
414 | list class containing wxMenuItem pointers. | |
415 | ||
416 | \membersection{wxMenu::GetTitle}\label{wxmenugettitle} | |
417 | ||
418 | \constfunc{wxString}{GetTitle}{\void} | |
419 | ||
420 | Returns the title of the menu. | |
421 | ||
422 | \wxheading{Remarks} | |
423 | ||
424 | This is relevant only to popup menus, use | |
425 | \helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop} for the menus in the | |
426 | menubar. | |
427 | ||
428 | \wxheading{See also} | |
429 | ||
430 | \helpref{wxMenu::SetTitle}{wxmenusettitle} | |
431 | ||
432 | \membersection{wxMenu::Insert}\label{wxmenuinsert} | |
433 | ||
434 | \func{wxMenuItem*}{Insert}{\param{size\_t }{pos}, \param{wxMenuItem *}{item}} | |
435 | ||
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}} | |
439 | ||
440 | Inserts the given {\it item} before the position {\it pos}. Inserting the item | |
441 | at position \helpref{GetMenuItemCount}{wxmenugetmenuitemcount} is the same | |
442 | as appending it. | |
443 | ||
444 | \wxheading{See also} | |
445 | ||
446 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp | |
447 | \helpref{wxMenu::Prepend}{wxmenuprepend} | |
448 | ||
449 | \membersection{wxMenu::InsertCheckItem}\label{wxmenuinsertcheckitem} | |
450 | ||
451 | \func{wxMenuItem*}{InsertCheckItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp | |
452 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
453 | ||
454 | Inserts a checkable item at the given position. | |
455 | ||
456 | \wxheading{See also} | |
457 | ||
458 | \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp | |
459 | \helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem} | |
460 | ||
461 | \membersection{wxMenu::InsertRadioItem}\label{wxmenuinsertradioitem} | |
462 | ||
463 | \func{wxMenuItem*}{InsertRadioItem}{\param{size\_t }{pos}, \param{int}{ id},\rtfsp | |
464 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
465 | ||
466 | Inserts a radio item at the given position. | |
467 | ||
468 | \wxheading{See also} | |
469 | ||
470 | \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp | |
471 | \helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem} | |
472 | ||
473 | \membersection{wxMenu::InsertSeparator}\label{wxmenuinsertseparator} | |
474 | ||
475 | \func{wxMenuItem*}{InsertSeparator}{\param{size\_t }{pos}} | |
476 | ||
477 | Inserts a separator at the given position. | |
478 | ||
479 | \wxheading{See also} | |
480 | ||
481 | \helpref{wxMenu::Insert}{wxmenuinsert},\rtfsp | |
482 | \helpref{wxMenu::AppendSeparator}{wxmenuappendseparator} | |
483 | ||
484 | \membersection{wxMenu::IsChecked}\label{wxmenuischecked} | |
485 | ||
486 | \constfunc{bool}{IsChecked}{\param{int}{ id}} | |
487 | ||
488 | Determines whether a menu item is checked. | |
489 | ||
490 | \wxheading{Parameters} | |
491 | ||
492 | \docparam{id}{The menu item identifier.} | |
493 | ||
494 | \wxheading{Return value} | |
495 | ||
496 | true if the menu item is checked, false otherwise. | |
497 | ||
498 | \wxheading{See also} | |
499 | ||
500 | \helpref{wxMenu::Check}{wxmenucheck} | |
501 | ||
502 | \membersection{wxMenu::IsEnabled}\label{wxmenuisenabled} | |
503 | ||
504 | \constfunc{bool}{IsEnabled}{\param{int}{ id}} | |
505 | ||
506 | Determines whether a menu item is enabled. | |
507 | ||
508 | \wxheading{Parameters} | |
509 | ||
510 | \docparam{id}{The menu item identifier.} | |
511 | ||
512 | \wxheading{Return value} | |
513 | ||
514 | true if the menu item is enabled, false otherwise. | |
515 | ||
516 | \wxheading{See also} | |
517 | ||
518 | \helpref{wxMenu::Enable}{wxmenuenable} | |
519 | ||
520 | \membersection{wxMenu::Prepend}\label{wxmenuprepend} | |
521 | ||
522 | \func{wxMenuItem*}{Prepend}{\param{wxMenuItem *}{item}} | |
523 | ||
524 | \func{wxMenuItem*}{Prepend}{\param{int}{ id},\rtfsp | |
525 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""},\rtfsp | |
526 | \param{wxItemKind}{ kind = wxITEM\_NORMAL}} | |
527 | ||
528 | Inserts the given {\it item} at position $0$, i.e. before all the other | |
529 | existing items. | |
530 | ||
531 | \wxheading{See also} | |
532 | ||
533 | \helpref{wxMenu::Append}{wxmenuappend},\rtfsp | |
534 | \helpref{wxMenu::Insert}{wxmenuinsert} | |
535 | ||
536 | \membersection{wxMenu::PrependCheckItem}\label{wxmenuprependcheckitem} | |
537 | ||
538 | \func{wxMenuItem*}{PrependCheckItem}{\param{int}{ id},\rtfsp | |
539 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
540 | ||
541 | Inserts a checkable item at position $0$. | |
542 | ||
543 | \wxheading{See also} | |
544 | ||
545 | \helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp | |
546 | \helpref{wxMenu::AppendCheckItem}{wxmenuappendcheckitem} | |
547 | ||
548 | \membersection{wxMenu::PrependRadioItem}\label{wxmenuprependradioitem} | |
549 | ||
550 | \func{wxMenuItem*}{PrependRadioItem}{\param{int}{ id},\rtfsp | |
551 | \param{const wxString\& }{ item}, \param{const wxString\& }{helpString = ""}} | |
552 | ||
553 | Inserts a radio item at position $0$. | |
554 | ||
555 | \wxheading{See also} | |
556 | ||
557 | \helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp | |
558 | \helpref{wxMenu::AppendRadioItem}{wxmenuappendradioitem} | |
559 | ||
560 | \membersection{wxMenu::PrependSeparator}\label{wxmenuprependseparator} | |
561 | ||
562 | \func{wxMenuItem*}{PrependSeparator}{\void} | |
563 | ||
564 | Inserts a separator at position $0$. | |
565 | ||
566 | \wxheading{See also} | |
567 | ||
568 | \helpref{wxMenu::Prepend}{wxmenuprepend},\rtfsp | |
569 | \helpref{wxMenu::AppendSeparator}{wxmenuappendseparator} | |
570 | ||
571 | \membersection{wxMenu::Remove}\label{wxmenuremove} | |
572 | ||
573 | \func{wxMenuItem *}{Remove}{\param{int }{id}} | |
574 | ||
575 | \func{wxMenuItem *}{Remove}{\param{wxMenuItem *}{item}} | |
576 | ||
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). | |
580 | ||
581 | \wxheading{Parameters} | |
582 | ||
583 | \docparam{id}{The identifier of the menu item to remove.} | |
584 | ||
585 | \docparam{item}{The menu item to remove.} | |
586 | ||
587 | \wxheading{Return value} | |
588 | ||
589 | The item which was detached from the menu. | |
590 | ||
591 | \membersection{wxMenu::SetHelpString}\label{wxmenusethelpstring} | |
592 | ||
593 | \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}} | |
594 | ||
595 | Sets an item's help string. | |
596 | ||
597 | \wxheading{Parameters} | |
598 | ||
599 | \docparam{id}{The menu item identifier.} | |
600 | ||
601 | \docparam{helpString}{The help string to set.} | |
602 | ||
603 | \wxheading{See also} | |
604 | ||
605 | \helpref{wxMenu::GetHelpString}{wxmenugethelpstring} | |
606 | ||
607 | \membersection{wxMenu::SetLabel}\label{wxmenusetlabel} | |
608 | ||
609 | \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}} | |
610 | ||
611 | Sets the label of a menu item. | |
612 | ||
613 | \wxheading{Parameters} | |
614 | ||
615 | \docparam{id}{The menu item identifier.} | |
616 | ||
617 | \docparam{label}{The menu item label to set.} | |
618 | ||
619 | \wxheading{See also} | |
620 | ||
621 | \helpref{wxMenu::Append}{wxmenuappend}, \helpref{wxMenu::GetLabel}{wxmenugetlabel} | |
622 | ||
623 | \membersection{wxMenu::SetTitle}\label{wxmenusettitle} | |
624 | ||
625 | \func{void}{SetTitle}{\param{const wxString\& }{title}} | |
626 | ||
627 | Sets the title of the menu. | |
628 | ||
629 | \wxheading{Parameters} | |
630 | ||
631 | \docparam{title}{The title to set.} | |
632 | ||
633 | \wxheading{Remarks} | |
634 | ||
635 | This is relevant only to popup menus, use | |
636 | \helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop} for the menus in the | |
637 | menubar. | |
638 | ||
639 | \wxheading{See also} | |
640 | ||
641 | \helpref{wxMenu::GetTitle}{wxmenugettitle} | |
642 | ||
643 | \membersection{wxMenu::UpdateUI}\label{wxmenuupdateui} | |
644 | ||
645 | \constfunc{void}{UpdateUI}{\param{wxEvtHandler*}{ source = NULL}} | |
646 | ||
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. | |
650 | ||
651 | \wxheading{See also} | |
652 | ||
653 | \helpref{wxUpdateUIEvent}{wxupdateuievent} | |
654 | ||
655 | \section{\class{wxMenuBar}}\label{wxmenubar} | |
656 | ||
657 | A menu bar is a series of menus accessible from the top of a frame. | |
658 | ||
659 | \wxheading{Derived from} | |
660 | ||
661 | \helpref{wxWindow}{wxwindow}\\ | |
662 | \helpref{wxEvtHandler}{wxevthandler}\\ | |
663 | \helpref{wxObject}{wxobject} | |
664 | ||
665 | \wxheading{Include files} | |
666 | ||
667 | <wx/menu.h> | |
668 | ||
669 | \wxheading{Event handling} | |
670 | ||
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. | |
675 | ||
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. | |
680 | ||
681 | \wxheading{See also} | |
682 | ||
683 | \helpref{wxMenu}{wxmenu}, \helpref{Event handling overview}{eventhandlingoverview} | |
684 | ||
685 | \latexignore{\rtfignore{\wxheading{Members}}} | |
686 | ||
687 | \membersection{wxMenuBar::wxMenuBar}\label{wxmenubarctor} | |
688 | ||
689 | \func{}{wxMenuBar}{\param{long }{style = 0}} | |
690 | ||
691 | Default constructor. | |
692 | ||
693 | \func{}{wxMenuBar}{\param{int}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}} | |
694 | ||
695 | Construct a menu bar from arrays of menus and titles. | |
696 | ||
697 | \wxheading{Parameters} | |
698 | ||
699 | \docparam{n}{The number of menus.} | |
700 | ||
701 | \docparam{menus}{An array of menus. Do not use this array again - it now belongs to the | |
702 | menu bar.} | |
703 | ||
704 | \docparam{titles}{An array of title strings. Deallocate this array after creating the menu bar.} | |
705 | ||
706 | \docparam{style}{If {\tt wxMB\_DOCKABLE} the menu bar can be detached (wxGTK only).} | |
707 | ||
708 | \pythonnote{Only the default constructor is supported in wxPython. | |
709 | Use wxMenuBar.Append instead.} | |
710 | ||
711 | \perlnote{wxPerl only supports the first constructor: | |
712 | use {\tt Append} instead.} | |
713 | ||
714 | \membersection{wxMenuBar::\destruct{wxMenuBar}}\label{wxmenubardtor} | |
715 | ||
716 | \func{void}{\destruct{wxMenuBar}}{\void} | |
717 | ||
718 | Destructor, destroying the menu bar and removing it from the parent frame (if any). | |
719 | ||
720 | \membersection{wxMenuBar::Append}\label{wxmenubarappend} | |
721 | ||
722 | \func{bool}{Append}{\param{wxMenu *}{menu}, \param{const wxString\& }{title}} | |
723 | ||
724 | Adds the item to the end of the menu bar. | |
725 | ||
726 | \wxheading{Parameters} | |
727 | ||
728 | \docparam{menu}{The menu to add. Do not deallocate this menu after calling {\bf Append}.} | |
729 | ||
730 | \docparam{title}{The title of the menu.} | |
731 | ||
732 | \wxheading{Return value} | |
733 | ||
734 | true on success, false if an error occurred. | |
735 | ||
736 | \wxheading{See also} | |
737 | ||
738 | \helpref{wxMenuBar::Insert}{wxmenubarinsert} | |
739 | ||
740 | \membersection{wxMenuBar::Check}\label{wxmenubarcheck} | |
741 | ||
742 | \func{void}{Check}{\param{int}{ id}, \param{const bool}{ check}} | |
743 | ||
744 | Checks or unchecks a menu item. | |
745 | ||
746 | \wxheading{Parameters} | |
747 | ||
748 | \docparam{id}{The menu item identifier.} | |
749 | ||
750 | \docparam{check}{If true, checks the menu item, otherwise the item is unchecked.} | |
751 | ||
752 | \wxheading{Remarks} | |
753 | ||
754 | Only use this when the menu bar has been associated | |
755 | with a frame; otherwise, use the wxMenu equivalent call. | |
756 | ||
757 | \membersection{wxMenuBar::Enable}\label{wxmenubarenable} | |
758 | ||
759 | \func{void}{Enable}{\param{int}{ id}, \param{const bool}{ enable}} | |
760 | ||
761 | Enables or disables (greys out) a menu item. | |
762 | ||
763 | \wxheading{Parameters} | |
764 | ||
765 | \docparam{id}{The menu item identifier.} | |
766 | ||
767 | \docparam{enable}{true to enable the item, false to disable it.} | |
768 | ||
769 | \wxheading{Remarks} | |
770 | ||
771 | Only use this when the menu bar has been | |
772 | associated with a frame; otherwise, use the wxMenu equivalent call. | |
773 | ||
774 | \membersection{wxMenuBar::EnableTop}\label{wxmenubarenabletop} | |
775 | ||
776 | \func{void}{EnableTop}{\param{int}{ pos}, \param{const bool}{ enable}} | |
777 | ||
778 | Enables or disables a whole menu. | |
779 | ||
780 | \wxheading{Parameters} | |
781 | ||
782 | \docparam{pos}{The position of the menu, starting from zero.} | |
783 | ||
784 | \docparam{enable}{true to enable the menu, false to disable it.} | |
785 | ||
786 | \wxheading{Remarks} | |
787 | ||
788 | Only use this when the menu bar has been | |
789 | associated with a frame. | |
790 | ||
791 | \membersection{wxMenuBar::FindMenu}\label{wxmenubarfindmenu} | |
792 | ||
793 | \constfunc{int}{FindMenu}{\param{const wxString\& }{title}} | |
794 | ||
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. | |
799 | ||
800 | \membersection{wxMenuBar::FindMenuItem}\label{wxmenubarfindmenuitem} | |
801 | ||
802 | \constfunc{int}{FindMenuItem}{\param{const wxString\& }{menuString}, \param{const wxString\& }{itemString}} | |
803 | ||
804 | Finds the menu item id for a menu name/menu item string pair. | |
805 | ||
806 | \wxheading{Parameters} | |
807 | ||
808 | \docparam{menuString}{Menu title to find.} | |
809 | ||
810 | \docparam{itemString}{Item to find.} | |
811 | ||
812 | \wxheading{Return value} | |
813 | ||
814 | The menu item identifier, or {\tt wxNOT\_FOUND} if none was found. | |
815 | ||
816 | \wxheading{Remarks} | |
817 | ||
818 | Any special menu codes are stripped out of source and target strings | |
819 | before matching. | |
820 | ||
821 | \membersection{wxMenuBar::FindItem}\label{wxmenubarfinditem} | |
822 | ||
823 | \constfunc{wxMenuItem *}{FindItem}{\param{int}{ id}, \param{wxMenu}{ **menu = NULL}} | |
824 | ||
825 | Finds the menu item object associated with the given menu item identifier. | |
826 | ||
827 | \wxheading{Parameters} | |
828 | ||
829 | \docparam{id}{Menu item identifier.} | |
830 | ||
831 | \docparam{menu}{If not NULL, menu will get set to the associated menu.} | |
832 | ||
833 | \wxheading{Return value} | |
834 | ||
835 | The found menu item object, or NULL if one was not found. | |
836 | ||
837 | \membersection{wxMenuBar::GetHelpString}\label{wxmenubargethelpstring} | |
838 | ||
839 | \constfunc{wxString}{GetHelpString}{\param{int}{ id}} | |
840 | ||
841 | Gets the help string associated with the menu item identifier. | |
842 | ||
843 | \wxheading{Parameters} | |
844 | ||
845 | \docparam{id}{The menu item identifier.} | |
846 | ||
847 | \wxheading{Return value} | |
848 | ||
849 | The help string, or the empty string if there was no help string or the menu item | |
850 | was not found. | |
851 | ||
852 | \wxheading{See also} | |
853 | ||
854 | \helpref{wxMenuBar::SetHelpString}{wxmenubarsethelpstring} | |
855 | ||
856 | \membersection{wxMenuBar::GetLabel}\label{wxmenubargetlabel} | |
857 | ||
858 | \constfunc{wxString}{GetLabel}{\param{int}{ id}} | |
859 | ||
860 | Gets the label associated with a menu item. | |
861 | ||
862 | \wxheading{Parameters} | |
863 | ||
864 | \docparam{id}{The menu item identifier.} | |
865 | ||
866 | \wxheading{Return value} | |
867 | ||
868 | The menu item label, or the empty string if the item was not found. | |
869 | ||
870 | \wxheading{Remarks} | |
871 | ||
872 | Use only after the menubar has been associated with a frame. | |
873 | ||
874 | \membersection{wxMenuBar::GetLabelTop}\label{wxmenubargetlabeltop} | |
875 | ||
876 | \constfunc{wxString}{GetLabelTop}{\param{int}{ pos}} | |
877 | ||
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. | |
881 | ||
882 | \wxheading{Parameters} | |
883 | ||
884 | \docparam{pos}{Position of the menu on the menu bar, starting from zero.} | |
885 | ||
886 | \wxheading{Return value} | |
887 | ||
888 | The menu label, or the empty string if the menu was not found. | |
889 | ||
890 | \wxheading{Remarks} | |
891 | ||
892 | Use only after the menubar has been associated with a frame. | |
893 | ||
894 | \wxheading{See also} | |
895 | ||
896 | \helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop} | |
897 | ||
898 | \membersection{wxMenuBar::GetMenu}\label{wxmenubargetmenu} | |
899 | ||
900 | \constfunc{wxMenu*}{GetMenu}{\param{int}{ menuIndex}} | |
901 | ||
902 | Returns the menu at {\it menuIndex} (zero-based). | |
903 | ||
904 | \membersection{wxMenuBar::GetMenuCount}\label{wxmenubargetmenucount} | |
905 | ||
906 | \constfunc{int}{GetMenuCount}{\void} | |
907 | ||
908 | Returns the number of menus in this menubar. | |
909 | ||
910 | \membersection{wxMenuBar::Insert}\label{wxmenubarinsert} | |
911 | ||
912 | \func{bool}{Insert}{\param{size\_t }{pos}, \param{wxMenu *}{menu}, \param{const wxString\& }{title}} | |
913 | ||
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}. | |
918 | ||
919 | \wxheading{Parameters} | |
920 | ||
921 | \docparam{pos}{The position of the new menu in the menu bar} | |
922 | ||
923 | \docparam{menu}{The menu to add. wxMenuBar owns the menu and will free it.} | |
924 | ||
925 | \docparam{title}{The title of the menu.} | |
926 | ||
927 | \wxheading{Return value} | |
928 | ||
929 | true on success, false if an error occurred. | |
930 | ||
931 | \wxheading{See also} | |
932 | ||
933 | \helpref{wxMenuBar::Append}{wxmenubarappend} | |
934 | ||
935 | \membersection{wxMenuBar::IsChecked}\label{wxmenubarischecked} | |
936 | ||
937 | \constfunc{bool}{IsChecked}{\param{int}{ id}} | |
938 | ||
939 | Determines whether an item is checked. | |
940 | ||
941 | \wxheading{Parameters} | |
942 | ||
943 | \docparam{id}{The menu item identifier.} | |
944 | ||
945 | \wxheading{Return value} | |
946 | ||
947 | true if the item was found and is checked, false otherwise. | |
948 | ||
949 | \membersection{wxMenuBar::IsEnabled}\label{wxmenubarisenabled} | |
950 | ||
951 | \constfunc{bool}{IsEnabled}{\param{int}{ id}} | |
952 | ||
953 | Determines whether an item is enabled. | |
954 | ||
955 | \wxheading{Parameters} | |
956 | ||
957 | \docparam{id}{The menu item identifier.} | |
958 | ||
959 | \wxheading{Return value} | |
960 | ||
961 | true if the item was found and is enabled, false otherwise. | |
962 | ||
963 | \membersection{wxMenuBar::Refresh}\label{wxmenubarrefresh} | |
964 | ||
965 | \func{void}{Refresh}{\void} | |
966 | ||
967 | Redraw the menu bar | |
968 | ||
969 | \membersection{wxMenuBar::Remove}\label{wxmenubarremove} | |
970 | ||
971 | \func{wxMenu *}{Remove}{\param{size\_t }{pos}} | |
972 | ||
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 | |
976 | dynamically. | |
977 | ||
978 | \wxheading{See also} | |
979 | ||
980 | \helpref{wxMenuBar::Replace}{wxmenubarreplace} | |
981 | ||
982 | \membersection{wxMenuBar::Replace}\label{wxmenubarreplace} | |
983 | ||
984 | \func{wxMenu *}{Replace}{\param{size\_t }{pos}, \param{wxMenu *}{menu}, \param{const wxString\& }{title}} | |
985 | ||
986 | Replaces the menu at the given position with another one. | |
987 | ||
988 | \wxheading{Parameters} | |
989 | ||
990 | \docparam{pos}{The position of the new menu in the menu bar} | |
991 | ||
992 | \docparam{menu}{The menu to add.} | |
993 | ||
994 | \docparam{title}{The title of the menu.} | |
995 | ||
996 | \wxheading{Return value} | |
997 | ||
998 | The menu which was previously at position {\it pos}. The caller is | |
999 | responsible for deleting it. | |
1000 | ||
1001 | \wxheading{See also} | |
1002 | ||
1003 | \helpref{wxMenuBar::Insert}{wxmenubarinsert},\rtfsp | |
1004 | \helpref{wxMenuBar::Remove}{wxmenubarremove} | |
1005 | ||
1006 | \membersection{wxMenuBar::SetHelpString}\label{wxmenubarsethelpstring} | |
1007 | ||
1008 | \func{void}{SetHelpString}{\param{int}{ id}, \param{const wxString\& }{helpString}} | |
1009 | ||
1010 | Sets the help string associated with a menu item. | |
1011 | ||
1012 | \wxheading{Parameters} | |
1013 | ||
1014 | \docparam{id}{Menu item identifier.} | |
1015 | ||
1016 | \docparam{helpString}{Help string to associate with the menu item.} | |
1017 | ||
1018 | \wxheading{See also} | |
1019 | ||
1020 | \helpref{wxMenuBar::GetHelpString}{wxmenubargethelpstring} | |
1021 | ||
1022 | \membersection{wxMenuBar::SetLabel}\label{wxmenubarsetlabel} | |
1023 | ||
1024 | \func{void}{SetLabel}{\param{int}{ id}, \param{const wxString\& }{label}} | |
1025 | ||
1026 | Sets the label of a menu item. | |
1027 | ||
1028 | \wxheading{Parameters} | |
1029 | ||
1030 | \docparam{id}{Menu item identifier.} | |
1031 | ||
1032 | \docparam{label}{Menu item label.} | |
1033 | ||
1034 | \wxheading{Remarks} | |
1035 | ||
1036 | Use only after the menubar has been associated with a frame. | |
1037 | ||
1038 | \wxheading{See also} | |
1039 | ||
1040 | \helpref{wxMenuBar::GetLabel}{wxmenubargetlabel} | |
1041 | ||
1042 | \membersection{wxMenuBar::SetLabelTop}\label{wxmenubarsetlabeltop} | |
1043 | ||
1044 | \func{void}{SetLabelTop}{\param{int}{ pos}, \param{const wxString\& }{label}} | |
1045 | ||
1046 | Sets the label of a top-level menu. | |
1047 | ||
1048 | \wxheading{Parameters} | |
1049 | ||
1050 | \docparam{pos}{The position of a menu on the menu bar, starting from zero.} | |
1051 | ||
1052 | \docparam{label}{The menu label.} | |
1053 | ||
1054 | \wxheading{Remarks} | |
1055 | ||
1056 | Use only after the menubar has been associated with a frame. | |
1057 | ||
1058 | \wxheading{See also} | |
1059 | ||
1060 | \helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop} | |
1061 |