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