]>
Commit | Line | Data |
---|---|---|
3dfac970 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/menu.h | |
3 | // Purpose: wxMenu and wxMenuBar classes | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 26.10.99 | |
77ffb593 | 7 | // Copyright: (c) wxWidgets team |
65571936 | 8 | // Licence: wxWindows licence |
3dfac970 VZ |
9 | /////////////////////////////////////////////////////////////////////////////// |
10 | ||
34138703 JS |
11 | #ifndef _WX_MENU_H_BASE_ |
12 | #define _WX_MENU_H_BASE_ | |
c801d85f | 13 | |
997176a3 VZ |
14 | #include "wx/defs.h" |
15 | ||
1e6feb95 VZ |
16 | #if wxUSE_MENUS |
17 | ||
3dfac970 VZ |
18 | // ---------------------------------------------------------------------------- |
19 | // headers | |
20 | // ---------------------------------------------------------------------------- | |
21 | ||
717a57c2 | 22 | #include "wx/list.h" // for "template" list classes |
3dfac970 VZ |
23 | #include "wx/window.h" // base class for wxMenuBar |
24 | ||
717a57c2 VZ |
25 | // also include this one to ensure compatibility with old code which only |
26 | // included wx/menu.h | |
27 | #include "wx/menuitem.h" | |
28 | ||
7118e711 | 29 | class WXDLLIMPEXP_FWD_CORE wxFrame; |
b5dbe15d VS |
30 | class WXDLLIMPEXP_FWD_CORE wxMenu; |
31 | class WXDLLIMPEXP_FWD_CORE wxMenuBarBase; | |
32 | class WXDLLIMPEXP_FWD_CORE wxMenuBar; | |
33 | class WXDLLIMPEXP_FWD_CORE wxMenuItem; | |
3dfac970 | 34 | |
717a57c2 | 35 | // pseudo template list classes |
f6bcfd97 BP |
36 | WX_DECLARE_EXPORTED_LIST(wxMenu, wxMenuList); |
37 | WX_DECLARE_EXPORTED_LIST(wxMenuItem, wxMenuItemList); | |
717a57c2 | 38 | |
3dfac970 VZ |
39 | // ---------------------------------------------------------------------------- |
40 | // wxMenu | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
53a2db12 | 43 | class WXDLLIMPEXP_CORE wxMenuBase : public wxEvtHandler |
717a57c2 VZ |
44 | { |
45 | public: | |
46 | // create a menu | |
47 | static wxMenu *New(const wxString& title = wxEmptyString, long style = 0); | |
48 | ||
49 | // ctors | |
50 | wxMenuBase(const wxString& title, long style = 0) : m_title(title) | |
51 | { Init(style); } | |
52 | wxMenuBase(long style = 0) | |
53 | { Init(style); } | |
54 | ||
55 | // dtor deletes all the menu items we own | |
56 | virtual ~wxMenuBase(); | |
57 | ||
58 | // menu construction | |
59 | // ----------------- | |
60 | ||
d65c269b | 61 | // append any kind of item (normal/check/radio/separator) |
9add9367 | 62 | wxMenuItem* Append(int itemid, |
ee0a94cf | 63 | const wxString& text = wxEmptyString, |
9add9367 RD |
64 | const wxString& help = wxEmptyString, |
65 | wxItemKind kind = wxITEM_NORMAL) | |
717a57c2 | 66 | { |
9add9367 | 67 | return DoAppend(wxMenuItem::New((wxMenu *)this, itemid, text, help, kind)); |
717a57c2 VZ |
68 | } |
69 | ||
0e528b99 | 70 | // append a separator to the menu |
fa7134b0 | 71 | wxMenuItem* AppendSeparator() { return Append(wxID_SEPARATOR); } |
0e528b99 | 72 | |
d65c269b | 73 | // append a check item |
9add9367 RD |
74 | wxMenuItem* AppendCheckItem(int itemid, |
75 | const wxString& text, | |
76 | const wxString& help = wxEmptyString) | |
d65c269b | 77 | { |
9add9367 | 78 | return Append(itemid, text, help, wxITEM_CHECK); |
d65c269b VZ |
79 | } |
80 | ||
81 | // append a radio item | |
9add9367 RD |
82 | wxMenuItem* AppendRadioItem(int itemid, |
83 | const wxString& text, | |
84 | const wxString& help = wxEmptyString) | |
d65c269b | 85 | { |
9add9367 | 86 | return Append(itemid, text, help, wxITEM_RADIO); |
d65c269b VZ |
87 | } |
88 | ||
717a57c2 | 89 | // append a submenu |
3786c8b5 VZ |
90 | wxMenuItem* AppendSubMenu(wxMenu *submenu, |
91 | const wxString& text, | |
92 | const wxString& help = wxEmptyString) | |
717a57c2 | 93 | { |
3786c8b5 | 94 | return DoAppend(wxMenuItem::New((wxMenu *)this, wxID_ANY, text, help, |
9add9367 | 95 | wxITEM_NORMAL, submenu)); |
717a57c2 VZ |
96 | } |
97 | ||
98 | // the most generic form of Append() - append anything | |
9add9367 | 99 | wxMenuItem* Append(wxMenuItem *item) { return DoAppend(item); } |
717a57c2 VZ |
100 | |
101 | // insert a break in the menu (only works when appending the items, not | |
102 | // inserting them) | |
103 | virtual void Break() { } | |
104 | ||
105 | // insert an item before given position | |
9add9367 | 106 | wxMenuItem* Insert(size_t pos, wxMenuItem *item); |
d65c269b VZ |
107 | |
108 | // insert an item before given position | |
9add9367 RD |
109 | wxMenuItem* Insert(size_t pos, |
110 | int itemid, | |
ee0a94cf | 111 | const wxString& text = wxEmptyString, |
9add9367 RD |
112 | const wxString& help = wxEmptyString, |
113 | wxItemKind kind = wxITEM_NORMAL) | |
f6bcfd97 | 114 | { |
9add9367 | 115 | return Insert(pos, wxMenuItem::New((wxMenu *)this, itemid, text, help, kind)); |
f6bcfd97 BP |
116 | } |
117 | ||
118 | // insert a separator | |
9add9367 | 119 | wxMenuItem* InsertSeparator(size_t pos) |
f6bcfd97 | 120 | { |
9add9367 | 121 | return Insert(pos, wxMenuItem::New((wxMenu *)this, wxID_SEPARATOR)); |
f6bcfd97 BP |
122 | } |
123 | ||
d65c269b | 124 | // insert a check item |
9add9367 RD |
125 | wxMenuItem* InsertCheckItem(size_t pos, |
126 | int itemid, | |
127 | const wxString& text, | |
128 | const wxString& help = wxEmptyString) | |
d65c269b | 129 | { |
9add9367 | 130 | return Insert(pos, itemid, text, help, wxITEM_CHECK); |
d65c269b VZ |
131 | } |
132 | ||
133 | // insert a radio item | |
9add9367 RD |
134 | wxMenuItem* InsertRadioItem(size_t pos, |
135 | int itemid, | |
136 | const wxString& text, | |
137 | const wxString& help = wxEmptyString) | |
d65c269b | 138 | { |
9add9367 | 139 | return Insert(pos, itemid, text, help, wxITEM_RADIO); |
d65c269b VZ |
140 | } |
141 | ||
f6bcfd97 | 142 | // insert a submenu |
9add9367 RD |
143 | wxMenuItem* Insert(size_t pos, |
144 | int itemid, | |
145 | const wxString& text, | |
146 | wxMenu *submenu, | |
147 | const wxString& help = wxEmptyString) | |
f6bcfd97 | 148 | { |
9add9367 RD |
149 | return Insert(pos, wxMenuItem::New((wxMenu *)this, itemid, text, help, |
150 | wxITEM_NORMAL, submenu)); | |
f6bcfd97 BP |
151 | } |
152 | ||
153 | // prepend an item to the menu | |
9add9367 | 154 | wxMenuItem* Prepend(wxMenuItem *item) |
f6bcfd97 | 155 | { |
9add9367 | 156 | return Insert(0u, item); |
f6bcfd97 BP |
157 | } |
158 | ||
d65c269b | 159 | // prepend any item to the menu |
9add9367 | 160 | wxMenuItem* Prepend(int itemid, |
ee0a94cf | 161 | const wxString& text = wxEmptyString, |
9add9367 RD |
162 | const wxString& help = wxEmptyString, |
163 | wxItemKind kind = wxITEM_NORMAL) | |
f6bcfd97 | 164 | { |
9add9367 | 165 | return Insert(0u, itemid, text, help, kind); |
f6bcfd97 BP |
166 | } |
167 | ||
d65c269b | 168 | // prepend a separator |
9add9367 | 169 | wxMenuItem* PrependSeparator() |
f6bcfd97 | 170 | { |
9add9367 | 171 | return InsertSeparator(0u); |
f6bcfd97 BP |
172 | } |
173 | ||
d65c269b | 174 | // prepend a check item |
9add9367 RD |
175 | wxMenuItem* PrependCheckItem(int itemid, |
176 | const wxString& text, | |
177 | const wxString& help = wxEmptyString) | |
d65c269b | 178 | { |
9add9367 | 179 | return InsertCheckItem(0u, itemid, text, help); |
d65c269b VZ |
180 | } |
181 | ||
182 | // prepend a radio item | |
9add9367 RD |
183 | wxMenuItem* PrependRadioItem(int itemid, |
184 | const wxString& text, | |
185 | const wxString& help = wxEmptyString) | |
d65c269b | 186 | { |
9add9367 | 187 | return InsertRadioItem(0u, itemid, text, help); |
d65c269b VZ |
188 | } |
189 | ||
190 | // prepend a submenu | |
9add9367 RD |
191 | wxMenuItem* Prepend(int itemid, |
192 | const wxString& text, | |
193 | wxMenu *submenu, | |
194 | const wxString& help = wxEmptyString) | |
f6bcfd97 | 195 | { |
9add9367 | 196 | return Insert(0u, itemid, text, submenu, help); |
f6bcfd97 | 197 | } |
717a57c2 VZ |
198 | |
199 | // detach an item from the menu, but don't delete it so that it can be | |
200 | // added back later (but if it's not, the caller is responsible for | |
201 | // deleting it!) | |
d9e2e4c2 | 202 | wxMenuItem *Remove(int itemid) { return Remove(FindChildItem(itemid)); } |
717a57c2 VZ |
203 | wxMenuItem *Remove(wxMenuItem *item); |
204 | ||
205 | // delete an item from the menu (submenus are not destroyed by this | |
206 | // function, see Destroy) | |
d9e2e4c2 | 207 | bool Delete(int itemid) { return Delete(FindChildItem(itemid)); } |
717a57c2 VZ |
208 | bool Delete(wxMenuItem *item); |
209 | ||
210 | // delete the item from menu and destroy it (if it's a submenu) | |
d9e2e4c2 | 211 | bool Destroy(int itemid) { return Destroy(FindChildItem(itemid)); } |
717a57c2 VZ |
212 | bool Destroy(wxMenuItem *item); |
213 | ||
214 | // menu items access | |
215 | // ----------------- | |
216 | ||
217 | // get the items | |
218 | size_t GetMenuItemCount() const { return m_items.GetCount(); } | |
219 | ||
220 | const wxMenuItemList& GetMenuItems() const { return m_items; } | |
221 | wxMenuItemList& GetMenuItems() { return m_items; } | |
222 | ||
223 | // search | |
1e6feb95 | 224 | virtual int FindItem(const wxString& item) const; |
d9e2e4c2 | 225 | wxMenuItem* FindItem(int itemid, wxMenu **menu = NULL) const; |
717a57c2 | 226 | |
bd582574 JS |
227 | // find by position |
228 | wxMenuItem* FindItemByPosition(size_t position) const; | |
229 | ||
717a57c2 | 230 | // get/set items attributes |
d9e2e4c2 DE |
231 | void Enable(int itemid, bool enable); |
232 | bool IsEnabled(int itemid) const; | |
3dfac970 | 233 | |
d9e2e4c2 DE |
234 | void Check(int itemid, bool check); |
235 | bool IsChecked(int itemid) const; | |
717a57c2 | 236 | |
d9e2e4c2 DE |
237 | void SetLabel(int itemid, const wxString& label); |
238 | wxString GetLabel(int itemid) const; | |
717a57c2 | 239 | |
52af3158 JS |
240 | // Returns the stripped label |
241 | wxString GetLabelText(int itemid) const { return wxMenuItem::GetLabelText(GetLabel(itemid)); } | |
242 | ||
d9e2e4c2 DE |
243 | virtual void SetHelpString(int itemid, const wxString& helpString); |
244 | virtual wxString GetHelpString(int itemid) const; | |
717a57c2 VZ |
245 | |
246 | // misc accessors | |
247 | // -------------- | |
248 | ||
249 | // the title | |
250 | virtual void SetTitle(const wxString& title) { m_title = title; } | |
56454c15 | 251 | const wxString& GetTitle() const { return m_title; } |
717a57c2 | 252 | |
717a57c2 VZ |
253 | // event handler |
254 | void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
255 | wxEvtHandler *GetEventHandler() const { return m_eventHandler; } | |
256 | ||
e3f5caa2 | 257 | // Invoking window: this is set by wxWindow::PopupMenu() before showing a |
394cfde3 VZ |
258 | // popup menu and reset after it's hidden. Notice that you probably want to |
259 | // use GetWindow() below instead of GetInvokingWindow() as the latter only | |
260 | // returns non-NULL for the top level menus | |
c59aa14a VZ |
261 | // |
262 | // NB: avoid calling SetInvokingWindow() directly if possible, use | |
263 | // wxMenuInvokingWindowSetter class below instead | |
e3f5caa2 | 264 | void SetInvokingWindow(wxWindow *win); |
394cfde3 | 265 | wxWindow *GetInvokingWindow() const { return m_invokingWindow; } |
717a57c2 | 266 | |
7118e711 VZ |
267 | // the window associated with this menu: this is the invoking window for |
268 | // popup menus or the top level window to which the menu bar is attached | |
269 | // for menus which are part of a menu bar | |
270 | wxWindow *GetWindow() const; | |
271 | ||
717a57c2 VZ |
272 | // style |
273 | long GetStyle() const { return m_style; } | |
274 | ||
275 | // implementation helpers | |
276 | // ---------------------- | |
277 | ||
278 | // Updates the UI for a menu and all submenus recursively. source is the | |
279 | // object that has the update event handlers defined for it. If NULL, the | |
280 | // menu or associated window will be used. | |
d3b9f782 | 281 | void UpdateUI(wxEvtHandler* source = NULL); |
717a57c2 | 282 | |
1e6feb95 | 283 | // get the menu bar this menu is attached to (may be NULL, always NULL for |
dbdf9a17 DE |
284 | // popup menus). Traverse up the menu hierarchy to find it. |
285 | wxMenuBar *GetMenuBar() const; | |
1e6feb95 VZ |
286 | |
287 | // called when the menu is attached/detached to/from a menu bar | |
288 | virtual void Attach(wxMenuBarBase *menubar); | |
289 | virtual void Detach(); | |
290 | ||
717a57c2 | 291 | // is the menu attached to a menu bar (or is it a popup one)? |
dbdf9a17 | 292 | bool IsAttached() const { return GetMenuBar() != NULL; } |
717a57c2 VZ |
293 | |
294 | // set/get the parent of this menu | |
295 | void SetParent(wxMenu *parent) { m_menuParent = parent; } | |
296 | wxMenu *GetParent() const { return m_menuParent; } | |
297 | ||
d65c269b VZ |
298 | // implementation only from now on |
299 | // ------------------------------- | |
300 | ||
301 | // unlike FindItem(), this function doesn't recurse but only looks through | |
302 | // our direct children and also may return the index of the found child if | |
303 | // pos != NULL | |
d9e2e4c2 | 304 | wxMenuItem *FindChildItem(int itemid, size_t *pos = NULL) const; |
d65c269b | 305 | |
4e32eea1 WS |
306 | // called to generate a wxCommandEvent, return true if it was processed, |
307 | // false otherwise | |
d65c269b VZ |
308 | // |
309 | // the checked parameter may have boolean value or -1 for uncheckable items | |
d9e2e4c2 | 310 | bool SendEvent(int itemid, int checked = -1); |
d65c269b | 311 | |
717a57c2 | 312 | // compatibility: these functions are deprecated, use the new ones instead |
d65c269b VZ |
313 | // ----------------------------------------------------------------------- |
314 | ||
315 | // use the versions taking wxItem_XXX now instead, they're more readable | |
316 | // and allow adding the radio items as well | |
d9e2e4c2 | 317 | void Append(int itemid, |
d65c269b VZ |
318 | const wxString& text, |
319 | const wxString& help, | |
320 | bool isCheckable) | |
321 | { | |
d9e2e4c2 | 322 | Append(itemid, text, help, isCheckable ? wxITEM_CHECK : wxITEM_NORMAL); |
d65c269b VZ |
323 | } |
324 | ||
3786c8b5 VZ |
325 | // use more readable and not requiring unused itemid AppendSubMenu() instead |
326 | wxMenuItem* Append(int itemid, | |
327 | const wxString& text, | |
328 | wxMenu *submenu, | |
329 | const wxString& help = wxEmptyString) | |
330 | { | |
331 | return DoAppend(wxMenuItem::New((wxMenu *)this, itemid, text, help, | |
332 | wxITEM_NORMAL, submenu)); | |
333 | } | |
334 | ||
d65c269b | 335 | void Insert(size_t pos, |
d9e2e4c2 | 336 | int itemid, |
d65c269b VZ |
337 | const wxString& text, |
338 | const wxString& help, | |
339 | bool isCheckable) | |
340 | { | |
d9e2e4c2 | 341 | Insert(pos, itemid, text, help, isCheckable ? wxITEM_CHECK : wxITEM_NORMAL); |
d65c269b VZ |
342 | } |
343 | ||
d9e2e4c2 | 344 | void Prepend(int itemid, |
d65c269b VZ |
345 | const wxString& text, |
346 | const wxString& help, | |
347 | bool isCheckable) | |
348 | { | |
d9e2e4c2 | 349 | Insert(0u, itemid, text, help, isCheckable); |
d65c269b VZ |
350 | } |
351 | ||
6d971354 RR |
352 | static void LockAccels(bool locked) |
353 | { | |
354 | ms_locked = locked; | |
355 | } | |
4e32eea1 | 356 | |
717a57c2 VZ |
357 | protected: |
358 | // virtuals to override in derived classes | |
359 | // --------------------------------------- | |
360 | ||
9add9367 RD |
361 | virtual wxMenuItem* DoAppend(wxMenuItem *item); |
362 | virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item); | |
717a57c2 VZ |
363 | |
364 | virtual wxMenuItem *DoRemove(wxMenuItem *item); | |
365 | virtual bool DoDelete(wxMenuItem *item); | |
366 | virtual bool DoDestroy(wxMenuItem *item); | |
367 | ||
368 | // helpers | |
369 | // ------- | |
370 | ||
371 | // common part of all ctors | |
372 | void Init(long style); | |
373 | ||
1e6feb95 VZ |
374 | // associate the submenu with this menu |
375 | void AddSubMenu(wxMenu *submenu); | |
376 | ||
717a57c2 VZ |
377 | wxMenuBar *m_menuBar; // menubar we belong to or NULL |
378 | wxMenu *m_menuParent; // parent menu or NULL | |
379 | ||
380 | wxString m_title; // the menu title or label | |
381 | wxMenuItemList m_items; // the list of menu items | |
382 | ||
383 | wxWindow *m_invokingWindow; // for popup menus | |
717a57c2 VZ |
384 | |
385 | long m_style; // combination of wxMENU_XXX flags | |
386 | ||
387 | wxEvtHandler *m_eventHandler; // a pluggable in event handler | |
22f3361e | 388 | |
6d971354 | 389 | static bool ms_locked; |
4e32eea1 | 390 | |
c0c133e1 | 391 | wxDECLARE_NO_COPY_CLASS(wxMenuBase); |
717a57c2 | 392 | }; |
3dfac970 | 393 | |
28953245 SC |
394 | #if wxUSE_EXTENDED_RTTI |
395 | ||
396 | // ---------------------------------------------------------------------------- | |
397 | // XTI accessor | |
398 | // ---------------------------------------------------------------------------- | |
399 | ||
54912101 | 400 | class WXDLLEXPORT wxMenuInfoHelper : public wxObject |
28953245 SC |
401 | { |
402 | public: | |
54912101 SC |
403 | wxMenuInfoHelper() { m_menu = NULL; } |
404 | virtual ~wxMenuInfoHelper() { } | |
28953245 SC |
405 | |
406 | bool Create( wxMenu *menu, const wxString &title ) | |
407 | { | |
408 | m_menu = menu; | |
409 | m_title = title; | |
410 | return true; | |
411 | } | |
412 | ||
413 | wxMenu* GetMenu() const { return m_menu; } | |
414 | wxString GetTitle() const { return m_title; } | |
415 | ||
416 | private: | |
417 | wxMenu *m_menu; | |
418 | wxString m_title; | |
419 | ||
54912101 | 420 | DECLARE_DYNAMIC_CLASS(wxMenuInfoHelper) |
28953245 SC |
421 | }; |
422 | ||
54912101 | 423 | WX_DECLARE_EXPORTED_LIST(wxMenuInfoHelper, wxMenuInfoHelperList ); |
28953245 SC |
424 | |
425 | #endif | |
426 | ||
3dfac970 VZ |
427 | // ---------------------------------------------------------------------------- |
428 | // wxMenuBar | |
429 | // ---------------------------------------------------------------------------- | |
430 | ||
53a2db12 | 431 | class WXDLLIMPEXP_CORE wxMenuBarBase : public wxWindow |
3dfac970 VZ |
432 | { |
433 | public: | |
434 | // default ctor | |
435 | wxMenuBarBase(); | |
436 | ||
437 | // dtor will delete all menus we own | |
438 | virtual ~wxMenuBarBase(); | |
439 | ||
440 | // menu bar construction | |
441 | // --------------------- | |
442 | ||
4e32eea1 | 443 | // append a menu to the end of menubar, return true if ok |
3dfac970 VZ |
444 | virtual bool Append(wxMenu *menu, const wxString& title); |
445 | ||
4e32eea1 | 446 | // insert a menu before the given position into the menubar, return true |
3dfac970 VZ |
447 | // if inserted ok |
448 | virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); | |
449 | ||
450 | // menu bar items access | |
451 | // --------------------- | |
452 | ||
453 | // get the number of menus in the menu bar | |
454 | size_t GetMenuCount() const { return m_menus.GetCount(); } | |
455 | ||
456 | // get the menu at given position | |
457 | wxMenu *GetMenu(size_t pos) const; | |
458 | ||
459 | // replace the menu at given position with another one, returns the | |
460 | // previous menu (which should be deleted by the caller) | |
461 | virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); | |
462 | ||
463 | // delete the menu at given position from the menu bar, return the pointer | |
464 | // to the menu (which should be deleted by the caller) | |
465 | virtual wxMenu *Remove(size_t pos); | |
466 | ||
467 | // enable or disable a submenu | |
468 | virtual void EnableTop(size_t pos, bool enable) = 0; | |
469 | ||
1e6feb95 | 470 | // is the menu enabled? |
4e32eea1 | 471 | virtual bool IsEnabledTop(size_t WXUNUSED(pos)) const { return true; } |
1e6feb95 | 472 | |
3dfac970 | 473 | // get or change the label of the menu at given position |
52af3158 JS |
474 | virtual void SetMenuLabel(size_t pos, const wxString& label) = 0; |
475 | virtual wxString GetMenuLabel(size_t pos) const = 0; | |
476 | ||
477 | // get the stripped label of the menu at given position | |
478 | virtual wxString GetMenuLabelText(size_t pos) const { return wxMenuItem::GetLabelText(GetMenuLabel(pos)); } | |
3dfac970 VZ |
479 | |
480 | // item search | |
481 | // ----------- | |
482 | ||
483 | // by menu and item names, returns wxNOT_FOUND if not found or id of the | |
484 | // found item | |
1e6feb95 | 485 | virtual int FindMenuItem(const wxString& menu, const wxString& item) const; |
3dfac970 VZ |
486 | |
487 | // find item by id (in any menu), returns NULL if not found | |
488 | // | |
489 | // if menu is !NULL, it will be filled with wxMenu this item belongs to | |
d9e2e4c2 | 490 | virtual wxMenuItem* FindItem(int itemid, wxMenu **menu = NULL) const; |
3dfac970 | 491 | |
52130557 | 492 | // find menu by its caption, return wxNOT_FOUND on failure |
270e8b6a | 493 | int FindMenu(const wxString& title) const; |
52130557 | 494 | |
3dfac970 VZ |
495 | // item access |
496 | // ----------- | |
497 | ||
498 | // all these functions just use FindItem() and then call an appropriate | |
499 | // method on it | |
500 | // | |
501 | // NB: under MSW, these methods can only be used after the menubar had | |
502 | // been attached to the frame | |
503 | ||
d9e2e4c2 DE |
504 | void Enable(int itemid, bool enable); |
505 | void Check(int itemid, bool check); | |
506 | bool IsChecked(int itemid) const; | |
507 | bool IsEnabled(int itemid) const; | |
b1c741f8 | 508 | virtual bool IsEnabled() const { return wxWindow::IsEnabled(); } |
3dfac970 | 509 | |
d9e2e4c2 DE |
510 | void SetLabel(int itemid, const wxString &label); |
511 | wxString GetLabel(int itemid) const; | |
3dfac970 | 512 | |
d9e2e4c2 DE |
513 | void SetHelpString(int itemid, const wxString& helpString); |
514 | wxString GetHelpString(int itemid) const; | |
3dfac970 | 515 | |
1e6feb95 VZ |
516 | // implementation helpers |
517 | ||
518 | // get the frame we are attached to (may return NULL) | |
519 | wxFrame *GetFrame() const { return m_menuBarFrame; } | |
520 | ||
4e32eea1 | 521 | // returns true if we're attached to a frame |
1e6feb95 VZ |
522 | bool IsAttached() const { return GetFrame() != NULL; } |
523 | ||
524 | // associate the menubar with the frame | |
525 | virtual void Attach(wxFrame *frame); | |
526 | ||
527 | // called before deleting the menubar normally | |
528 | virtual void Detach(); | |
529 | ||
9874b4ee | 530 | // need to override these ones to avoid virtual function hiding |
4e32eea1 | 531 | virtual bool Enable(bool enable = true) { return wxWindow::Enable(enable); } |
9874b4ee | 532 | virtual void SetLabel(const wxString& s) { wxWindow::SetLabel(s); } |
3dfac970 VZ |
533 | virtual wxString GetLabel() const { return wxWindow::GetLabel(); } |
534 | ||
1e6feb95 | 535 | // don't want menu bars to accept the focus by tabbing to them |
4e32eea1 | 536 | virtual bool AcceptsFocusFromKeyboard() const { return false; } |
1e6feb95 | 537 | |
4d538595 DS |
538 | // update all menu item states in all menus |
539 | virtual void UpdateMenus(); | |
540 | ||
c04c7a3d VS |
541 | virtual bool CanBeOutsideClientArea() const { return true; } |
542 | ||
28953245 SC |
543 | #if wxUSE_EXTENDED_RTTI |
544 | // XTI helpers: | |
54912101 | 545 | bool AppendMenuInfo( const wxMenuInfoHelper *info ) |
28953245 | 546 | { return Append( info->GetMenu(), info->GetTitle() ); } |
54912101 | 547 | const wxMenuInfoHelperList& GetMenuInfos() const; |
28953245 SC |
548 | #endif |
549 | ||
52af3158 JS |
550 | #if WXWIN_COMPATIBILITY_2_8 |
551 | // get or change the label of the menu at given position | |
0253bbba | 552 | // Deprecated in favour of SetMenuLabel |
03647350 | 553 | wxDEPRECATED( void SetLabelTop(size_t pos, const wxString& label) ); |
0253bbba | 554 | // Deprecated in favour of GetMenuLabelText |
52af3158 JS |
555 | wxDEPRECATED( wxString GetLabelTop(size_t pos) const ); |
556 | #endif | |
557 | ||
3dfac970 VZ |
558 | protected: |
559 | // the list of all our menus | |
560 | wxMenuList m_menus; | |
1e6feb95 | 561 | |
28953245 SC |
562 | #if wxUSE_EXTENDED_RTTI |
563 | // used by XTI | |
54912101 | 564 | wxMenuInfoHelperList m_menuInfos; |
28953245 SC |
565 | #endif |
566 | ||
1e6feb95 VZ |
567 | // the frame we are attached to (may be NULL) |
568 | wxFrame *m_menuBarFrame; | |
22f3361e | 569 | |
c0c133e1 | 570 | wxDECLARE_NO_COPY_CLASS(wxMenuBarBase); |
3dfac970 VZ |
571 | }; |
572 | ||
573 | // ---------------------------------------------------------------------------- | |
574 | // include the real class declaration | |
575 | // ---------------------------------------------------------------------------- | |
576 | ||
577 | #ifdef wxUSE_BASE_CLASSES_ONLY | |
578 | #define wxMenuItem wxMenuItemBase | |
579 | #else // !wxUSE_BASE_CLASSES_ONLY | |
1e6feb95 VZ |
580 | #if defined(__WXUNIVERSAL__) |
581 | #include "wx/univ/menu.h" | |
582 | #elif defined(__WXMSW__) | |
3dfac970 | 583 | #include "wx/msw/menu.h" |
2049ba38 | 584 | #elif defined(__WXMOTIF__) |
3dfac970 | 585 | #include "wx/motif/menu.h" |
1be7a35c | 586 | #elif defined(__WXGTK20__) |
3dfac970 | 587 | #include "wx/gtk/menu.h" |
1be7a35c MR |
588 | #elif defined(__WXGTK__) |
589 | #include "wx/gtk1/menu.h" | |
34138703 | 590 | #elif defined(__WXMAC__) |
ef0e9220 | 591 | #include "wx/osx/menu.h" |
e64df9bc DE |
592 | #elif defined(__WXCOCOA__) |
593 | #include "wx/cocoa/menu.h" | |
1777b9bb | 594 | #elif defined(__WXPM__) |
3dfac970 | 595 | #include "wx/os2/menu.h" |
c801d85f | 596 | #endif |
3dfac970 VZ |
597 | #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY |
598 | ||
c59aa14a VZ |
599 | // ---------------------------------------------------------------------------- |
600 | // Helper class used in the implementation only: sets the invoking window of | |
601 | // the given menu in its ctor and resets it in dtor. | |
602 | // ---------------------------------------------------------------------------- | |
603 | ||
604 | class wxMenuInvokingWindowSetter | |
605 | { | |
606 | public: | |
607 | // Ctor sets the invoking window for the given menu. | |
608 | // | |
609 | // The menu lifetime must be greater than that of this class. | |
610 | wxMenuInvokingWindowSetter(wxMenu& menu, wxWindow *win) | |
611 | : m_menu(menu) | |
612 | { | |
613 | menu.SetInvokingWindow(win); | |
614 | } | |
615 | ||
616 | // Dtor resets the invoking window. | |
617 | ~wxMenuInvokingWindowSetter() | |
618 | { | |
619 | m_menu.SetInvokingWindow(NULL); | |
620 | } | |
621 | ||
622 | private: | |
623 | wxMenu& m_menu; | |
624 | ||
625 | wxDECLARE_NO_COPY_CLASS(wxMenuInvokingWindowSetter); | |
626 | }; | |
627 | ||
1e6feb95 VZ |
628 | #endif // wxUSE_MENUS |
629 | ||
c59aa14a | 630 | #endif // _WX_MENU_H_BASE_ |