]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menu.h | |
e54c96f1 | 3 | // Purpose: interface of wxMenuBar |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
9 | /** | |
10 | @class wxMenuBar | |
7c913512 | 11 | |
23324ae1 | 12 | A menu bar is a series of menus accessible from the top of a frame. |
7c913512 | 13 | |
ba1d7a6c FM |
14 | @remarks |
15 | To respond to a menu selection, provide a handler for EVT_MENU, in the frame | |
16 | that contains the menu bar. | |
17 | ||
18 | If you have a toolbar which uses the same identifiers as your EVT_MENU entries, | |
19 | events from the toolbar will also be processed by your EVT_MENU event handlers. | |
20 | ||
21 | Tip: under Windows, if you discover that menu shortcuts (for example, Alt-F | |
22 | to show the file menu) are not working, check any EVT_CHAR events you are | |
23 | handling in child windows. | |
24 | If you are not calling event.Skip() for events that you don't process in | |
25 | these event handlers, menu shortcuts may cease to work. | |
26 | ||
23324ae1 FM |
27 | @library{wxcore} |
28 | @category{menus} | |
7c913512 | 29 | |
3e083d65 | 30 | @see wxMenu, @ref overview_events |
23324ae1 FM |
31 | */ |
32 | class wxMenuBar : public wxWindow | |
33 | { | |
34 | public: | |
ff58644a | 35 | /** |
ba1d7a6c | 36 | Construct an empty menu bar. |
ff58644a RR |
37 | |
38 | @param style | |
39 | If wxMB_DOCKABLE the menu bar can be detached (wxGTK only). | |
40 | */ | |
41 | wxMenuBar(long style = 0); | |
ba1d7a6c | 42 | |
23324ae1 FM |
43 | /** |
44 | Construct a menu bar from arrays of menus and titles. | |
3c4f71cc | 45 | |
7c913512 | 46 | @param n |
4cc4bfaf | 47 | The number of menus. |
7c913512 | 48 | @param menus |
ff58644a RR |
49 | An array of menus. Do not use this array again - it now belongs to |
50 | the menu bar. | |
7c913512 | 51 | @param titles |
ff58644a RR |
52 | An array of title strings. Deallocate this array after creating |
53 | the menu bar. | |
7c913512 | 54 | @param style |
4cc4bfaf | 55 | If wxMB_DOCKABLE the menu bar can be detached (wxGTK only). |
1058f652 MB |
56 | |
57 | @beginWxPerlOnly | |
58 | Not supported by wxPerl. | |
59 | @endWxPerlOnly | |
23324ae1 | 60 | */ |
7c913512 FM |
61 | wxMenuBar(size_t n, wxMenu* menus[], const wxString titles[], |
62 | long style = 0); | |
23324ae1 FM |
63 | |
64 | /** | |
ba1d7a6c FM |
65 | Destructor, destroying the menu bar and removing it from the parent |
66 | frame (if any). | |
23324ae1 | 67 | */ |
adaaa686 | 68 | virtual ~wxMenuBar(); |
23324ae1 FM |
69 | |
70 | /** | |
71 | Adds the item to the end of the menu bar. | |
3c4f71cc | 72 | |
7c913512 | 73 | @param menu |
ba1d7a6c | 74 | The menu to add. Do not deallocate this menu after calling Append(). |
7c913512 | 75 | @param title |
b871bb95 | 76 | The title of the menu, must be non-empty. |
3c4f71cc | 77 | |
d29a9a8a | 78 | @return @true on success, @false if an error occurred. |
3c4f71cc | 79 | |
4cc4bfaf | 80 | @see Insert() |
23324ae1 | 81 | */ |
adaaa686 | 82 | virtual bool Append(wxMenu* menu, const wxString& title); |
23324ae1 FM |
83 | |
84 | /** | |
85 | Checks or unchecks a menu item. | |
3c4f71cc | 86 | |
7c913512 | 87 | @param id |
4cc4bfaf | 88 | The menu item identifier. |
7c913512 | 89 | @param check |
4cc4bfaf | 90 | If @true, checks the menu item, otherwise the item is unchecked. |
3c4f71cc | 91 | |
23324ae1 | 92 | @remarks Only use this when the menu bar has been associated with a |
4cc4bfaf | 93 | frame; otherwise, use the wxMenu equivalent call. |
23324ae1 | 94 | */ |
43c48e1e | 95 | void Check(int id, bool check); |
23324ae1 FM |
96 | |
97 | /** | |
98 | Enables or disables (greys out) a menu item. | |
3c4f71cc | 99 | |
7c913512 | 100 | @param id |
4cc4bfaf | 101 | The menu item identifier. |
7c913512 | 102 | @param enable |
4cc4bfaf | 103 | @true to enable the item, @false to disable it. |
3c4f71cc | 104 | |
23324ae1 | 105 | @remarks Only use this when the menu bar has been associated with a |
4cc4bfaf | 106 | frame; otherwise, use the wxMenu equivalent call. |
23324ae1 | 107 | */ |
0a98423e | 108 | void Enable(int id, bool enable); |
23324ae1 FM |
109 | |
110 | /** | |
111 | Enables or disables a whole menu. | |
3c4f71cc | 112 | |
7c913512 | 113 | @param pos |
4cc4bfaf | 114 | The position of the menu, starting from zero. |
7c913512 | 115 | @param enable |
4cc4bfaf | 116 | @true to enable the menu, @false to disable it. |
3c4f71cc | 117 | |
23324ae1 FM |
118 | @remarks Only use this when the menu bar has been associated with a frame. |
119 | */ | |
43c48e1e | 120 | virtual void EnableTop(size_t pos, bool enable); |
23324ae1 FM |
121 | |
122 | /** | |
123 | Finds the menu item object associated with the given menu item identifier. | |
3c4f71cc | 124 | |
7c913512 | 125 | @param id |
4cc4bfaf | 126 | Menu item identifier. |
7c913512 | 127 | @param menu |
4cc4bfaf | 128 | If not @NULL, menu will get set to the associated menu. |
3c4f71cc | 129 | |
d29a9a8a | 130 | @return The found menu item object, or @NULL if one was not found. |
1058f652 MB |
131 | |
132 | @beginWxPerlOnly | |
133 | In wxPerl this method takes just the @a id parameter; | |
134 | in scalar context it returns the associated @c Wx::MenuItem, in list | |
135 | context it returns a 2-element list (item, submenu). | |
136 | @endWxPerlOnly | |
23324ae1 | 137 | */ |
86381d42 | 138 | virtual wxMenuItem* FindItem(int id, wxMenu** menu = NULL) const; |
23324ae1 FM |
139 | |
140 | /** | |
4cc4bfaf | 141 | Returns the index of the menu with the given @a title or @c wxNOT_FOUND if no |
ba1d7a6c FM |
142 | such menu exists in this menubar. |
143 | ||
144 | The @a title parameter may specify either the menu title | |
145 | (with accelerator characters, i.e. @c "&File") or just the | |
23324ae1 FM |
146 | menu label (@c "File") indifferently. |
147 | */ | |
328f5751 | 148 | int FindMenu(const wxString& title) const; |
23324ae1 FM |
149 | |
150 | /** | |
151 | Finds the menu item id for a menu name/menu item string pair. | |
3c4f71cc | 152 | |
7c913512 | 153 | @param menuString |
4cc4bfaf | 154 | Menu title to find. |
7c913512 | 155 | @param itemString |
4cc4bfaf | 156 | Item to find. |
3c4f71cc | 157 | |
d29a9a8a | 158 | @return The menu item identifier, or wxNOT_FOUND if none was found. |
3c4f71cc | 159 | |
23324ae1 | 160 | @remarks Any special menu codes are stripped out of source and target |
4cc4bfaf | 161 | strings before matching. |
23324ae1 | 162 | */ |
fadc2df6 FM |
163 | virtual int FindMenuItem(const wxString& menuString, |
164 | const wxString& itemString) const; | |
23324ae1 FM |
165 | |
166 | /** | |
167 | Gets the help string associated with the menu item identifier. | |
3c4f71cc | 168 | |
7c913512 | 169 | @param id |
4cc4bfaf | 170 | The menu item identifier. |
3c4f71cc | 171 | |
d29a9a8a BP |
172 | @return The help string, or the empty string if there was no help string |
173 | or the menu item was not found. | |
3c4f71cc | 174 | |
4cc4bfaf | 175 | @see SetHelpString() |
23324ae1 | 176 | */ |
328f5751 | 177 | wxString GetHelpString(int id) const; |
23324ae1 FM |
178 | |
179 | /** | |
180 | Gets the label associated with a menu item. | |
3c4f71cc | 181 | |
7c913512 | 182 | @param id |
4cc4bfaf | 183 | The menu item identifier. |
3c4f71cc | 184 | |
d29a9a8a BP |
185 | @return The menu item label, or the empty string if the item was not |
186 | found. | |
3c4f71cc | 187 | |
23324ae1 FM |
188 | @remarks Use only after the menubar has been associated with a frame. |
189 | */ | |
328f5751 | 190 | wxString GetLabel(int id) const; |
23324ae1 FM |
191 | |
192 | /** | |
193 | Returns the label of a top-level menu. Note that the returned string does not | |
194 | include the accelerator characters which could have been specified in the menu | |
195 | title string during its construction. | |
3c4f71cc | 196 | |
7c913512 | 197 | @param pos |
4cc4bfaf | 198 | Position of the menu on the menu bar, starting from zero. |
3c4f71cc | 199 | |
d29a9a8a | 200 | @return The menu label, or the empty string if the menu was not found. |
3c4f71cc | 201 | |
23324ae1 | 202 | @remarks Use only after the menubar has been associated with a frame. |
3c4f71cc | 203 | |
ba1d7a6c FM |
204 | @deprecated |
205 | This function is deprecated in favour of GetMenuLabel() and GetMenuLabelText(). | |
206 | ||
4cc4bfaf | 207 | @see SetLabelTop() |
23324ae1 | 208 | */ |
43c48e1e | 209 | wxString GetLabelTop(size_t pos) const; |
23324ae1 FM |
210 | |
211 | /** | |
4cc4bfaf | 212 | Returns the menu at @a menuIndex (zero-based). |
23324ae1 | 213 | */ |
43c48e1e | 214 | wxMenu* GetMenu(size_t menuIndex) const; |
23324ae1 FM |
215 | |
216 | /** | |
217 | Returns the number of menus in this menubar. | |
218 | */ | |
328f5751 | 219 | size_t GetMenuCount() const; |
23324ae1 FM |
220 | |
221 | /** | |
222 | Returns the label of a top-level menu. Note that the returned string | |
223 | includes the accelerator characters that have been specified in the menu | |
224 | title string during its construction. | |
3c4f71cc | 225 | |
7c913512 | 226 | @param pos |
4cc4bfaf | 227 | Position of the menu on the menu bar, starting from zero. |
3c4f71cc | 228 | |
d29a9a8a | 229 | @return The menu label, or the empty string if the menu was not found. |
3c4f71cc | 230 | |
23324ae1 | 231 | @remarks Use only after the menubar has been associated with a frame. |
3c4f71cc | 232 | |
4cc4bfaf | 233 | @see GetMenuLabelText(), SetMenuLabel() |
23324ae1 | 234 | */ |
43c48e1e | 235 | virtual wxString GetMenuLabel(size_t pos) const; |
23324ae1 FM |
236 | |
237 | /** | |
238 | Returns the label of a top-level menu. Note that the returned string does not | |
239 | include any accelerator characters that may have been specified in the menu | |
240 | title string during its construction. | |
3c4f71cc | 241 | |
7c913512 | 242 | @param pos |
4cc4bfaf | 243 | Position of the menu on the menu bar, starting from zero. |
3c4f71cc | 244 | |
d29a9a8a | 245 | @return The menu label, or the empty string if the menu was not found. |
3c4f71cc | 246 | |
23324ae1 | 247 | @remarks Use only after the menubar has been associated with a frame. |
3c4f71cc | 248 | |
4cc4bfaf | 249 | @see GetMenuLabel(), SetMenuLabel() |
23324ae1 | 250 | */ |
43c48e1e | 251 | virtual wxString GetMenuLabelText(size_t pos) const; |
23324ae1 FM |
252 | |
253 | /** | |
254 | Inserts the menu at the given position into the menu bar. Inserting menu at | |
7c913512 | 255 | position 0 will insert it in the very beginning of it, inserting at position |
ba1d7a6c | 256 | GetMenuCount() is the same as calling Append(). |
3c4f71cc | 257 | |
7c913512 | 258 | @param pos |
4cc4bfaf | 259 | The position of the new menu in the menu bar |
7c913512 | 260 | @param menu |
4cc4bfaf | 261 | The menu to add. wxMenuBar owns the menu and will free it. |
7c913512 | 262 | @param title |
4cc4bfaf | 263 | The title of the menu. |
3c4f71cc | 264 | |
d29a9a8a | 265 | @return @true on success, @false if an error occurred. |
3c4f71cc | 266 | |
4cc4bfaf | 267 | @see Append() |
23324ae1 | 268 | */ |
adaaa686 | 269 | virtual bool Insert(size_t pos, wxMenu* menu, const wxString& title); |
23324ae1 FM |
270 | |
271 | /** | |
272 | Determines whether an item is checked. | |
3c4f71cc | 273 | |
7c913512 | 274 | @param id |
4cc4bfaf | 275 | The menu item identifier. |
3c4f71cc | 276 | |
d29a9a8a | 277 | @return @true if the item was found and is checked, @false otherwise. |
23324ae1 | 278 | */ |
328f5751 | 279 | bool IsChecked(int id) const; |
23324ae1 FM |
280 | |
281 | /** | |
282 | Determines whether an item is enabled. | |
3c4f71cc | 283 | |
7c913512 | 284 | @param id |
4cc4bfaf | 285 | The menu item identifier. |
3c4f71cc | 286 | |
d29a9a8a | 287 | @return @true if the item was found and is enabled, @false otherwise. |
23324ae1 | 288 | */ |
328f5751 | 289 | bool IsEnabled(int id) const; |
23324ae1 FM |
290 | |
291 | /** | |
292 | Redraw the menu bar | |
293 | */ | |
43c48e1e | 294 | virtual void Refresh(bool eraseBackground = true, const wxRect* rect = NULL); |
23324ae1 FM |
295 | |
296 | /** | |
ba1d7a6c FM |
297 | Removes the menu from the menu bar and returns the menu object - the caller |
298 | is responsible for deleting it. This function may be used together with | |
299 | Insert() to change the menubar dynamically. | |
3c4f71cc | 300 | |
4cc4bfaf | 301 | @see Replace() |
23324ae1 | 302 | */ |
adaaa686 | 303 | virtual wxMenu* Remove(size_t pos); |
23324ae1 FM |
304 | |
305 | /** | |
306 | Replaces the menu at the given position with another one. | |
3c4f71cc | 307 | |
7c913512 | 308 | @param pos |
4cc4bfaf | 309 | The position of the new menu in the menu bar |
7c913512 | 310 | @param menu |
4cc4bfaf | 311 | The menu to add. |
7c913512 | 312 | @param title |
4cc4bfaf | 313 | The title of the menu. |
3c4f71cc | 314 | |
ba1d7a6c FM |
315 | @return The menu which was previously at position pos. |
316 | The caller is responsible for deleting it. | |
3c4f71cc | 317 | |
4cc4bfaf | 318 | @see Insert(), Remove() |
23324ae1 | 319 | */ |
adaaa686 | 320 | virtual wxMenu* Replace(size_t pos, wxMenu* menu, const wxString& title); |
23324ae1 FM |
321 | |
322 | /** | |
323 | Sets the help string associated with a menu item. | |
3c4f71cc | 324 | |
7c913512 | 325 | @param id |
4cc4bfaf | 326 | Menu item identifier. |
7c913512 | 327 | @param helpString |
4cc4bfaf | 328 | Help string to associate with the menu item. |
3c4f71cc | 329 | |
4cc4bfaf | 330 | @see GetHelpString() |
23324ae1 FM |
331 | */ |
332 | void SetHelpString(int id, const wxString& helpString); | |
333 | ||
334 | /** | |
335 | Sets the label of a menu item. | |
3c4f71cc | 336 | |
7c913512 | 337 | @param id |
4cc4bfaf | 338 | Menu item identifier. |
7c913512 | 339 | @param label |
4cc4bfaf | 340 | Menu item label. |
3c4f71cc | 341 | |
23324ae1 | 342 | @remarks Use only after the menubar has been associated with a frame. |
3c4f71cc | 343 | |
4cc4bfaf | 344 | @see GetLabel() |
23324ae1 FM |
345 | */ |
346 | void SetLabel(int id, const wxString& label); | |
347 | ||
348 | /** | |
349 | Sets the label of a top-level menu. | |
3c4f71cc | 350 | |
7c913512 | 351 | @param pos |
4cc4bfaf | 352 | The position of a menu on the menu bar, starting from zero. |
7c913512 | 353 | @param label |
4cc4bfaf | 354 | The menu label. |
3c4f71cc | 355 | |
23324ae1 | 356 | @remarks Use only after the menubar has been associated with a frame. |
3c4f71cc | 357 | |
ba1d7a6c FM |
358 | @deprecated |
359 | This function has been deprecated in favour of SetMenuLabel(). | |
360 | ||
4cc4bfaf | 361 | @see GetLabelTop() |
23324ae1 | 362 | */ |
43c48e1e | 363 | void SetLabelTop(size_t pos, const wxString& label); |
23324ae1 FM |
364 | |
365 | /** | |
366 | Sets the label of a top-level menu. | |
3c4f71cc | 367 | |
7c913512 | 368 | @param pos |
4cc4bfaf | 369 | The position of a menu on the menu bar, starting from zero. |
7c913512 | 370 | @param label |
4cc4bfaf | 371 | The menu label. |
3c4f71cc | 372 | |
23324ae1 FM |
373 | @remarks Use only after the menubar has been associated with a frame. |
374 | */ | |
43c48e1e | 375 | virtual void SetMenuLabel(size_t pos, const wxString& label); |
e9321277 RD |
376 | |
377 | /** | |
378 | Enables you to set the global menubar on Mac, that is, the menubar displayed | |
379 | when the app is running without any frames open. | |
380 | ||
381 | @param menubar | |
382 | The menubar to set. | |
383 | ||
384 | @remarks Only exists on Mac, other platforms do not have this method. | |
385 | */ | |
386 | static void MacSetCommonMenuBar(wxMenuBar* menubar); | |
387 | ||
388 | /** | |
389 | Enables you to get the global menubar on Mac, that is, the menubar displayed | |
390 | when the app is running without any frames open. | |
391 | ||
392 | @return The global menubar. | |
393 | ||
394 | @remarks Only exists on Mac, other platforms do not have this method. | |
395 | */ | |
396 | static wxMenuBar* MacGetCommonMenuBar(); | |
397 | ||
23324ae1 FM |
398 | }; |
399 | ||
400 | ||
e54c96f1 | 401 | |
23324ae1 FM |
402 | /** |
403 | @class wxMenu | |
7c913512 | 404 | |
23324ae1 FM |
405 | A menu is a popup (or pull down) list of items, one of which may be |
406 | selected before the menu goes away (clicking elsewhere dismisses the | |
407 | menu). Menus may be used to construct either menu bars or popup menus. | |
7c913512 | 408 | |
23324ae1 FM |
409 | A menu item has an integer ID associated with it which can be used to |
410 | identify the selection, or to change the menu item in some way. A menu item | |
0c466250 VZ |
411 | with a special identifier @e wxID_SEPARATOR is a separator item and doesn't |
412 | have an associated command but just makes a separator line appear in the | |
413 | menu. | |
7c913512 | 414 | |
ba1d7a6c FM |
415 | @note |
416 | Please note that @e wxID_ABOUT and @e wxID_EXIT are predefined by wxWidgets | |
417 | and have a special meaning since entries using these IDs will be taken out | |
418 | of the normal menus under MacOS X and will be inserted into the system menu | |
419 | (following the appropriate MacOS X interface guideline). | |
420 | On PalmOS @e wxID_EXIT is disabled according to Palm OS Companion guidelines. | |
421 | ||
c7e52709 | 422 | Menu items may be either @e normal items, @e check items or @e radio items. |
ba1d7a6c FM |
423 | Normal items don't have any special properties while the check items have a |
424 | boolean flag associated to them and they show a checkmark in the menu when | |
425 | the flag is set. | |
23324ae1 | 426 | wxWidgets automatically toggles the flag value when the item is clicked and its |
ba1d7a6c FM |
427 | value may be retrieved using either wxMenu::IsChecked method of wxMenu or |
428 | wxMenuBar itself or by using wxEvent::IsChecked when you get the menu | |
23324ae1 | 429 | notification for the item in question. |
7c913512 | 430 | |
23324ae1 FM |
431 | The radio items are similar to the check items except that all the other items |
432 | in the same radio group are unchecked when a radio item is checked. The radio | |
433 | group is formed by a contiguous range of radio items, i.e. it starts at the | |
434 | first item of this kind and ends with the first item of a different kind (or | |
435 | the end of the menu). Notice that because the radio groups are defined in terms | |
436 | of the item positions inserting or removing the items in the menu containing | |
c7e52709 | 437 | the radio items risks to not work correctly. |
7c913512 | 438 | |
ba1d7a6c FM |
439 | |
440 | @section menu_allocation Allocation strategy | |
441 | ||
d16ba464 VZ |
442 | All menus must be created on the @b heap because all menus attached to a |
443 | menubar or to another menu will be deleted by their parent when it is | |
444 | deleted. The only exception to this rule are the popup menus (i.e. menus | |
445 | used with wxWindow::PopupMenu()) as wxWidgets does not destroy them to | |
446 | allow reusing the same menu more than once. But the exception applies only | |
447 | to the menus themselves and not to any submenus of popup menus which are | |
448 | still destroyed by wxWidgets as usual and so must be heap-allocated. | |
c7e52709 | 449 | |
ba1d7a6c FM |
450 | As the frame menubar is deleted by the frame itself, it means that normally |
451 | all menus used are deleted automatically. | |
452 | ||
453 | ||
454 | @section menu_eventhandling Event handling | |
455 | ||
456 | If the menu is part of a menubar, then wxMenuBar event processing is used. | |
ba1d7a6c | 457 | |
c7e52709 FM |
458 | With a popup menu (see wxWindow::PopupMenu), there is a variety of ways to |
459 | handle a menu selection event (@c wxEVT_COMMAND_MENU_SELECTED): | |
460 | - Provide @c EVT_MENU handlers in the window which pops up the menu, or in an | |
461 | ancestor of that window (the simplest method); | |
462 | - Derive a new class from wxMenu and define event table entries using the @c EVT_MENU macro; | |
463 | - Set a new event handler for wxMenu, through wxEvtHandler::SetNextHandler, | |
464 | specifying an object whose class has @c EVT_MENU entries; | |
465 | ||
466 | Note that instead of static @c EVT_MENU macros you can also use dynamic | |
8d2d37d2 | 467 | connection; see @ref overview_events_bind. |
ba1d7a6c | 468 | |
23324ae1 FM |
469 | @library{wxcore} |
470 | @category{menus} | |
7c913512 | 471 | |
3e083d65 | 472 | @see wxMenuBar, wxWindow::PopupMenu, @ref overview_events, |
ba1d7a6c | 473 | @ref wxFileHistory "wxFileHistory (most recently used files menu)" |
23324ae1 FM |
474 | */ |
475 | class wxMenu : public wxEvtHandler | |
476 | { | |
477 | public: | |
8ff9b17d RD |
478 | |
479 | /** | |
480 | Constructs a wxMenu object. | |
481 | */ | |
482 | wxMenu(); | |
483 | ||
23324ae1 FM |
484 | /** |
485 | Constructs a wxMenu object. | |
3c4f71cc | 486 | |
7c913512 | 487 | @param style |
4cc4bfaf | 488 | If set to wxMENU_TEAROFF, the menu will be detachable (wxGTK only). |
23324ae1 | 489 | */ |
7c913512 | 490 | wxMenu(long style); |
23324ae1 | 491 | |
ff58644a | 492 | /** |
ba1d7a6c | 493 | Constructs a wxMenu object with a title. |
ff58644a RR |
494 | |
495 | @param title | |
496 | Title at the top of the menu (not always supported). | |
497 | @param style | |
498 | If set to wxMENU_TEAROFF, the menu will be detachable (wxGTK only). | |
499 | */ | |
0a98423e | 500 | wxMenu(const wxString& title, long style = 0); |
ba1d7a6c | 501 | |
23324ae1 FM |
502 | /** |
503 | Destructor, destroying the menu. | |
ba1d7a6c FM |
504 | |
505 | @note | |
506 | Under Motif, a popup menu must have a valid parent (the window | |
507 | it was last popped up on) when being destroyed. Therefore, make sure | |
508 | you delete or re-use the popup menu @e before destroying the parent | |
509 | window. Re-use in this context means popping up the menu on a different | |
510 | window from last time, which causes an implicit destruction and | |
511 | recreation of internal data structures. | |
23324ae1 | 512 | */ |
adaaa686 | 513 | virtual ~wxMenu(); |
23324ae1 | 514 | |
23324ae1 | 515 | /** |
ba1d7a6c | 516 | Adds a menu item. |
3c4f71cc | 517 | |
7c913512 | 518 | @param id |
4cc4bfaf | 519 | The menu command identifier. |
7c913512 | 520 | @param item |
4cc4bfaf | 521 | The string to appear on the menu item. |
7145bcfc | 522 | See wxMenuItem::SetItemLabel() for more details. |
7c913512 | 523 | @param helpString |
4cc4bfaf | 524 | An optional help string associated with the item. |
7145bcfc | 525 | By default, the handler for the @c wxEVT_MENU_HIGHLIGHT event displays |
4cc4bfaf | 526 | this string in the status line. |
54c49fab | 527 | @param kind |
7145bcfc | 528 | May be @c wxITEM_SEPARATOR, @c wxITEM_NORMAL, @c wxITEM_CHECK or @c wxITEM_RADIO. |
b871bb95 | 529 | |
7145bcfc FM |
530 | Example: |
531 | @code | |
532 | m_pFileMenu->Append(ID_NEW_FILE, "&New file\tCTRL+N", "Creates a new XYZ document"); | |
533 | @endcode | |
534 | or even better for stock menu items (see wxMenuItem::wxMenuItem): | |
535 | @code | |
536 | m_pFileMenu->Append(wxID_NEW, "", "Creates a new XYZ document"); | |
537 | @endcode | |
ba1d7a6c FM |
538 | |
539 | @remarks | |
540 | This command can be used after the menu has been shown, as well as on | |
541 | initial creation of a menu or menubar. | |
542 | ||
4cc4bfaf | 543 | @see AppendSeparator(), AppendCheckItem(), AppendRadioItem(), |
ba1d7a6c FM |
544 | AppendSubMenu(), Insert(), SetLabel(), GetHelpString(), |
545 | SetHelpString(), wxMenuItem | |
23324ae1 | 546 | */ |
54c49fab VZ |
547 | wxMenuItem* Append(int id, const wxString& item = wxEmptyString, |
548 | const wxString& helpString = wxEmptyString, | |
23324ae1 | 549 | wxItemKind kind = wxITEM_NORMAL); |
ba1d7a6c | 550 | |
ff58644a RR |
551 | /** |
552 | Adds a submenu. | |
553 | ||
5dfae0ad | 554 | @deprecated This function is deprecated, use AppendSubMenu() instead. |
54c49fab | 555 | |
ff58644a RR |
556 | @param id |
557 | The menu command identifier. | |
558 | @param item | |
559 | The string to appear on the menu item. | |
54c49fab | 560 | @param subMenu |
ff58644a RR |
561 | Pull-right submenu. |
562 | @param helpString | |
563 | An optional help string associated with the item. | |
3a194bda | 564 | By default, the handler for the @c wxEVT_MENU_HIGHLIGHT event displays |
ff58644a RR |
565 | this string in the status line. |
566 | ||
567 | @see AppendSeparator(), AppendCheckItem(), AppendRadioItem(), | |
ba1d7a6c FM |
568 | AppendSubMenu(), Insert(), SetLabel(), GetHelpString(), |
569 | SetHelpString(), wxMenuItem | |
ff58644a | 570 | */ |
adaaa686 | 571 | wxMenuItem* Append(int id, const wxString& item, wxMenu* subMenu, |
54c49fab | 572 | const wxString& helpString = wxEmptyString); |
ba1d7a6c | 573 | |
ff58644a | 574 | /** |
ba1d7a6c FM |
575 | Adds a menu item object. |
576 | ||
577 | This is the most generic variant of Append() method because it may be | |
578 | used for both items (including separators) and submenus and because | |
579 | you can also specify various extra properties of a menu item this way, | |
ff58644a RR |
580 | such as bitmaps and fonts. |
581 | ||
582 | @param menuItem | |
ba1d7a6c FM |
583 | A menuitem object. It will be owned by the wxMenu object after this |
584 | function is called, so do not delete it yourself. | |
585 | ||
586 | @remarks | |
587 | See the remarks for the other Append() overloads. | |
ff58644a RR |
588 | |
589 | @see AppendSeparator(), AppendCheckItem(), AppendRadioItem(), | |
ba1d7a6c FM |
590 | AppendSubMenu(), Insert(), SetLabel(), GetHelpString(), |
591 | SetHelpString(), wxMenuItem | |
ff58644a | 592 | */ |
7c913512 | 593 | wxMenuItem* Append(wxMenuItem* menuItem); |
23324ae1 FM |
594 | |
595 | /** | |
596 | Adds a checkable item to the end of the menu. | |
3c4f71cc | 597 | |
4cc4bfaf | 598 | @see Append(), InsertCheckItem() |
23324ae1 FM |
599 | */ |
600 | wxMenuItem* AppendCheckItem(int id, const wxString& item, | |
43c48e1e | 601 | const wxString& help = wxEmptyString); |
23324ae1 FM |
602 | |
603 | /** | |
ba1d7a6c FM |
604 | Adds a radio item to the end of the menu. |
605 | All consequent radio items form a group and when an item in the group is | |
606 | checked, all the others are automatically unchecked. | |
3c4f71cc | 607 | |
c7e52709 FM |
608 | @note Radio items are not supported under wxMotif. |
609 | ||
4cc4bfaf | 610 | @see Append(), InsertRadioItem() |
23324ae1 FM |
611 | */ |
612 | wxMenuItem* AppendRadioItem(int id, const wxString& item, | |
43c48e1e | 613 | const wxString& help = wxEmptyString); |
23324ae1 FM |
614 | |
615 | /** | |
616 | Adds a separator to the end of the menu. | |
3c4f71cc | 617 | |
4cc4bfaf | 618 | @see Append(), InsertSeparator() |
23324ae1 FM |
619 | */ |
620 | wxMenuItem* AppendSeparator(); | |
621 | ||
622 | /** | |
4cc4bfaf FM |
623 | Adds the given @a submenu to this menu. @a text is the text shown in the |
624 | menu for it and @a help is the help string shown in the status bar when the | |
23324ae1 FM |
625 | submenu item is selected. |
626 | */ | |
4cc4bfaf FM |
627 | wxMenuItem* AppendSubMenu(wxMenu* submenu, const wxString& text, |
628 | const wxString& help = wxEmptyString); | |
23324ae1 FM |
629 | |
630 | /** | |
ba1d7a6c FM |
631 | Inserts a break in a menu, causing the next appended item to appear in |
632 | a new column. | |
23324ae1 | 633 | */ |
adaaa686 | 634 | virtual void Break(); |
23324ae1 FM |
635 | |
636 | /** | |
637 | Checks or unchecks the menu item. | |
3c4f71cc | 638 | |
7c913512 | 639 | @param id |
4cc4bfaf | 640 | The menu item identifier. |
7c913512 | 641 | @param check |
4cc4bfaf | 642 | If @true, the item will be checked, otherwise it will be unchecked. |
3c4f71cc | 643 | |
4cc4bfaf | 644 | @see IsChecked() |
23324ae1 | 645 | */ |
43c48e1e | 646 | void Check(int id, bool check); |
23324ae1 | 647 | |
23324ae1 FM |
648 | /** |
649 | Deletes the menu item from the menu. If the item is a submenu, it will | |
ff58644a | 650 | @b not be deleted. Use Destroy() if you want to delete a submenu. |
3c4f71cc | 651 | |
7c913512 | 652 | @param id |
4cc4bfaf | 653 | Id of the menu item to be deleted. |
ff58644a RR |
654 | |
655 | @see FindItem(), Destroy(), Remove() | |
656 | */ | |
0a98423e | 657 | bool Delete(int id); |
ff58644a RR |
658 | |
659 | /** | |
660 | Deletes the menu item from the menu. If the item is a submenu, it will | |
661 | @b not be deleted. Use Destroy() if you want to delete a submenu. | |
662 | ||
7c913512 | 663 | @param item |
4cc4bfaf | 664 | Menu item to be deleted. |
3c4f71cc | 665 | |
4cc4bfaf | 666 | @see FindItem(), Destroy(), Remove() |
23324ae1 | 667 | */ |
0a98423e | 668 | bool Delete(wxMenuItem* item); |
23324ae1 | 669 | |
23324ae1 FM |
670 | /** |
671 | Deletes the menu item from the menu. If the item is a submenu, it will | |
ff58644a RR |
672 | be deleted. Use Remove() if you want to keep the submenu (for example, |
673 | to reuse it later). | |
3c4f71cc | 674 | |
7c913512 | 675 | @param id |
4cc4bfaf | 676 | Id of the menu item to be deleted. |
ff58644a | 677 | |
0c466250 | 678 | @see FindItem(), Delete(), Remove() |
ff58644a | 679 | */ |
0a98423e | 680 | bool Destroy(int id); |
ff58644a RR |
681 | |
682 | /** | |
683 | Deletes the menu item from the menu. If the item is a submenu, it will | |
684 | be deleted. Use Remove() if you want to keep the submenu (for example, | |
685 | to reuse it later). | |
686 | ||
7c913512 | 687 | @param item |
4cc4bfaf | 688 | Menu item to be deleted. |
3c4f71cc | 689 | |
0c466250 | 690 | @see FindItem(), Delete(), Remove() |
23324ae1 | 691 | */ |
0a98423e | 692 | bool Destroy(wxMenuItem* item); |
23324ae1 FM |
693 | |
694 | /** | |
695 | Enables or disables (greys out) a menu item. | |
3c4f71cc | 696 | |
7c913512 | 697 | @param id |
4cc4bfaf | 698 | The menu item identifier. |
7c913512 | 699 | @param enable |
4cc4bfaf | 700 | @true to enable the menu item, @false to disable it. |
3c4f71cc | 701 | |
4cc4bfaf | 702 | @see IsEnabled() |
23324ae1 | 703 | */ |
43c48e1e | 704 | void Enable(int id, bool enable); |
23324ae1 | 705 | |
7b2e024e VZ |
706 | /** |
707 | Finds the menu item object associated with the given menu item identifier | |
708 | and, optionally, the position of the item in the menu. | |
709 | ||
710 | Unlike FindItem(), this function doesn't recurse but only looks at the | |
711 | direct children of this menu. | |
712 | ||
713 | @param id | |
714 | The identifier of the menu item to find. | |
715 | @param pos | |
716 | If the pointer is not @NULL, it is filled with the item's position if | |
717 | it was found or @c (size_t)wxNOT_FOUND otherwise. | |
718 | @return | |
719 | Menu item object or @NULL if not found. | |
720 | */ | |
721 | wxMenuItem *FindChildItem(int id, size_t *pos = NULL) const; | |
722 | ||
23324ae1 | 723 | /** |
ff58644a | 724 | Finds the menu id for a menu item string. |
3c4f71cc | 725 | |
7c913512 | 726 | @param itemString |
4cc4bfaf | 727 | Menu item string to find. |
ff58644a | 728 | |
d29a9a8a | 729 | @return Menu item identifier, or wxNOT_FOUND if none is found. |
ff58644a RR |
730 | |
731 | @remarks Any special menu codes are stripped out of source and target | |
732 | strings before matching. | |
733 | */ | |
adaaa686 | 734 | virtual int FindItem(const wxString& itemString) const; |
ff58644a RR |
735 | |
736 | /** | |
737 | Finds the menu item object associated with the given menu item identifier and, | |
738 | optionally, the (sub)menu it belongs to. | |
739 | ||
7c913512 | 740 | @param id |
4cc4bfaf | 741 | Menu item identifier. |
7c913512 | 742 | @param menu |
4cc4bfaf FM |
743 | If the pointer is not @NULL, it will be filled with the item's |
744 | parent menu (if the item was found) | |
3c4f71cc | 745 | |
d29a9a8a | 746 | @return Menu item object or NULL if none is found. |
23324ae1 | 747 | */ |
0a98423e | 748 | wxMenuItem* FindItem(int id, wxMenu** menu = NULL) const; |
23324ae1 FM |
749 | |
750 | /** | |
751 | Returns the wxMenuItem given a position in the menu. | |
752 | */ | |
328f5751 | 753 | wxMenuItem* FindItemByPosition(size_t position) const; |
23324ae1 FM |
754 | |
755 | /** | |
756 | Returns the help string associated with a menu item. | |
3c4f71cc | 757 | |
7c913512 | 758 | @param id |
4cc4bfaf | 759 | The menu item identifier. |
3c4f71cc | 760 | |
d29a9a8a BP |
761 | @return The help string, or the empty string if there is no help string |
762 | or the item was not found. | |
3c4f71cc | 763 | |
4cc4bfaf | 764 | @see SetHelpString(), Append() |
23324ae1 | 765 | */ |
adaaa686 | 766 | virtual wxString GetHelpString(int id) const; |
23324ae1 FM |
767 | |
768 | /** | |
769 | Returns a menu item label. | |
3c4f71cc | 770 | |
7c913512 | 771 | @param id |
4cc4bfaf | 772 | The menu item identifier. |
3c4f71cc | 773 | |
d29a9a8a | 774 | @return The item label, or the empty string if the item was not found. |
3c4f71cc | 775 | |
4cc4bfaf | 776 | @see GetLabelText(), SetLabel() |
23324ae1 | 777 | */ |
328f5751 | 778 | wxString GetLabel(int id) const; |
23324ae1 FM |
779 | |
780 | /** | |
781 | Returns a menu item label, without any of the original mnemonics and | |
782 | accelerators. | |
3c4f71cc | 783 | |
7c913512 | 784 | @param id |
4cc4bfaf | 785 | The menu item identifier. |
3c4f71cc | 786 | |
d29a9a8a | 787 | @return The item label, or the empty string if the item was not found. |
3c4f71cc | 788 | |
4cc4bfaf | 789 | @see GetLabel(), SetLabel() |
23324ae1 | 790 | */ |
328f5751 | 791 | wxString GetLabelText(int id) const; |
23324ae1 FM |
792 | |
793 | /** | |
794 | Returns the number of items in the menu. | |
795 | */ | |
328f5751 | 796 | size_t GetMenuItemCount() const; |
23324ae1 | 797 | |
0a98423e | 798 | //@{ |
23324ae1 | 799 | /** |
ba1d7a6c FM |
800 | Returns the list of items in the menu. |
801 | ||
802 | wxMenuItemList is a pseudo-template list class containing wxMenuItem | |
803 | pointers, see wxList. | |
23324ae1 | 804 | */ |
0a98423e FM |
805 | wxMenuItemList& GetMenuItems() const; |
806 | const wxMenuItemList& GetMenuItems() const; | |
807 | //@} | |
23324ae1 FM |
808 | |
809 | /** | |
810 | Returns the title of the menu. | |
3c4f71cc | 811 | |
4cc4bfaf | 812 | @see SetTitle() |
23324ae1 | 813 | */ |
43c48e1e | 814 | const wxString& GetTitle() const; |
23324ae1 | 815 | |
23324ae1 | 816 | /** |
ba1d7a6c FM |
817 | Inserts the given @a item before the position @a pos. |
818 | ||
819 | Inserting the item at position GetMenuItemCount() is the same | |
23324ae1 | 820 | as appending it. |
3c4f71cc | 821 | |
4cc4bfaf | 822 | @see Append(), Prepend() |
23324ae1 | 823 | */ |
e9321277 | 824 | wxMenuItem* Insert(size_t pos, wxMenuItem* menuItem); |
ba1d7a6c | 825 | |
ff58644a | 826 | /** |
ba1d7a6c FM |
827 | Inserts the given @a item before the position @a pos. |
828 | ||
829 | Inserting the item at position GetMenuItemCount() is the same | |
ff58644a RR |
830 | as appending it. |
831 | ||
832 | @see Append(), Prepend() | |
833 | */ | |
7c913512 | 834 | wxMenuItem* Insert(size_t pos, int id, |
0a98423e FM |
835 | const wxString& item = wxEmptyString, |
836 | const wxString& helpString = wxEmptyString, | |
7c913512 | 837 | wxItemKind kind = wxITEM_NORMAL); |
23324ae1 FM |
838 | |
839 | /** | |
840 | Inserts a checkable item at the given position. | |
3c4f71cc | 841 | |
4cc4bfaf | 842 | @see Insert(), AppendCheckItem() |
23324ae1 | 843 | */ |
43c48e1e FM |
844 | wxMenuItem* InsertCheckItem(size_t pos, int id, const wxString& item, |
845 | const wxString& helpString = wxEmptyString); | |
23324ae1 FM |
846 | |
847 | /** | |
848 | Inserts a radio item at the given position. | |
3c4f71cc | 849 | |
4cc4bfaf | 850 | @see Insert(), AppendRadioItem() |
23324ae1 | 851 | */ |
43c48e1e FM |
852 | wxMenuItem* InsertRadioItem(size_t pos, int id, const wxString& item, |
853 | const wxString& helpString = wxEmptyString); | |
23324ae1 FM |
854 | |
855 | /** | |
856 | Inserts a separator at the given position. | |
3c4f71cc | 857 | |
4cc4bfaf | 858 | @see Insert(), AppendSeparator() |
23324ae1 FM |
859 | */ |
860 | wxMenuItem* InsertSeparator(size_t pos); | |
861 | ||
862 | /** | |
863 | Determines whether a menu item is checked. | |
3c4f71cc | 864 | |
7c913512 | 865 | @param id |
4cc4bfaf | 866 | The menu item identifier. |
3c4f71cc | 867 | |
d29a9a8a | 868 | @return @true if the menu item is checked, @false otherwise. |
3c4f71cc | 869 | |
4cc4bfaf | 870 | @see Check() |
23324ae1 | 871 | */ |
328f5751 | 872 | bool IsChecked(int id) const; |
23324ae1 FM |
873 | |
874 | /** | |
875 | Determines whether a menu item is enabled. | |
3c4f71cc | 876 | |
7c913512 | 877 | @param id |
4cc4bfaf | 878 | The menu item identifier. |
3c4f71cc | 879 | |
d29a9a8a | 880 | @return @true if the menu item is enabled, @false otherwise. |
3c4f71cc | 881 | |
4cc4bfaf | 882 | @see Enable() |
23324ae1 | 883 | */ |
328f5751 | 884 | bool IsEnabled(int id) const; |
23324ae1 | 885 | |
23324ae1 | 886 | /** |
4cc4bfaf | 887 | Inserts the given @a item at position 0, i.e. before all the other |
23324ae1 | 888 | existing items. |
3c4f71cc | 889 | |
4cc4bfaf | 890 | @see Append(), Insert() |
23324ae1 | 891 | */ |
4cc4bfaf | 892 | wxMenuItem* Prepend(wxMenuItem* item); |
ff58644a RR |
893 | |
894 | /** | |
895 | Inserts the given @a item at position 0, i.e. before all the other | |
896 | existing items. | |
897 | ||
898 | @see Append(), Insert() | |
899 | */ | |
0a98423e FM |
900 | wxMenuItem* Prepend(int id, const wxString& item = wxEmptyString, |
901 | const wxString& helpString = wxEmptyString, | |
7c913512 | 902 | wxItemKind kind = wxITEM_NORMAL); |
23324ae1 FM |
903 | |
904 | /** | |
905 | Inserts a checkable item at position 0. | |
3c4f71cc | 906 | |
4cc4bfaf | 907 | @see Prepend(), AppendCheckItem() |
23324ae1 FM |
908 | */ |
909 | wxMenuItem* PrependCheckItem(int id, const wxString& item, | |
43c48e1e | 910 | const wxString& helpString = wxEmptyString); |
23324ae1 FM |
911 | |
912 | /** | |
913 | Inserts a radio item at position 0. | |
3c4f71cc | 914 | |
4cc4bfaf | 915 | @see Prepend(), AppendRadioItem() |
23324ae1 FM |
916 | */ |
917 | wxMenuItem* PrependRadioItem(int id, const wxString& item, | |
43c48e1e | 918 | const wxString& helpString = wxEmptyString); |
23324ae1 FM |
919 | |
920 | /** | |
921 | Inserts a separator at position 0. | |
3c4f71cc | 922 | |
4cc4bfaf | 923 | @see Prepend(), AppendSeparator() |
23324ae1 FM |
924 | */ |
925 | wxMenuItem* PrependSeparator(); | |
926 | ||
23324ae1 FM |
927 | /** |
928 | Removes the menu item from the menu but doesn't delete the associated C++ | |
ba1d7a6c FM |
929 | object. This allows you to reuse the same item later by adding it back to |
930 | the menu (especially useful with submenus). | |
3c4f71cc | 931 | |
7c913512 | 932 | @param id |
4cc4bfaf | 933 | The identifier of the menu item to remove. |
ff58644a | 934 | |
5dfae0ad | 935 | @return A pointer to the item which was detached from the menu. |
ff58644a RR |
936 | */ |
937 | wxMenuItem* Remove(int id); | |
ba1d7a6c | 938 | |
ff58644a RR |
939 | /** |
940 | Removes the menu item from the menu but doesn't delete the associated C++ | |
ba1d7a6c FM |
941 | object. This allows you to reuse the same item later by adding it back to |
942 | the menu (especially useful with submenus). | |
ff58644a | 943 | |
7c913512 | 944 | @param item |
4cc4bfaf | 945 | The menu item to remove. |
3c4f71cc | 946 | |
5dfae0ad | 947 | @return A pointer to the item which was detached from the menu. |
23324ae1 | 948 | */ |
4cc4bfaf | 949 | wxMenuItem* Remove(wxMenuItem* item); |
23324ae1 FM |
950 | |
951 | /** | |
952 | Sets an item's help string. | |
3c4f71cc | 953 | |
7c913512 | 954 | @param id |
4cc4bfaf | 955 | The menu item identifier. |
7c913512 | 956 | @param helpString |
4cc4bfaf | 957 | The help string to set. |
3c4f71cc | 958 | |
4cc4bfaf | 959 | @see GetHelpString() |
23324ae1 | 960 | */ |
adaaa686 | 961 | virtual void SetHelpString(int id, const wxString& helpString); |
23324ae1 FM |
962 | |
963 | /** | |
964 | Sets the label of a menu item. | |
3c4f71cc | 965 | |
7c913512 | 966 | @param id |
4cc4bfaf | 967 | The menu item identifier. |
7c913512 | 968 | @param label |
4cc4bfaf | 969 | The menu item label to set. |
3c4f71cc | 970 | |
4cc4bfaf | 971 | @see Append(), GetLabel() |
23324ae1 FM |
972 | */ |
973 | void SetLabel(int id, const wxString& label); | |
974 | ||
975 | /** | |
976 | Sets the title of the menu. | |
3c4f71cc | 977 | |
7c913512 | 978 | @param title |
4cc4bfaf | 979 | The title to set. |
3c4f71cc | 980 | |
a302a5ca VZ |
981 | @remarks Notice that you can only call this method directly for the |
982 | popup menus, to change the title of a menu that is part of a menu | |
983 | bar you need to use wxMenuBar::SetLabelTop(). | |
3c4f71cc | 984 | |
4cc4bfaf | 985 | @see GetTitle() |
23324ae1 | 986 | */ |
adaaa686 | 987 | virtual void SetTitle(const wxString& title); |
23324ae1 FM |
988 | |
989 | /** | |
4cc4bfaf | 990 | Sends events to @a source (or owning window if @NULL) to update the |
ba1d7a6c FM |
991 | menu UI. |
992 | ||
993 | This is called just before the menu is popped up with wxWindow::PopupMenu, | |
994 | but the application may call it at other times if required. | |
23324ae1 | 995 | */ |
adaaa686 | 996 | void UpdateUI(wxEvtHandler* source = NULL); |
23324ae1 | 997 | }; |
e54c96f1 | 998 |