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