1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu and wxMenuBar classes
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MENU_H_BASE_
13 #define _WX_MENU_H_BASE_
16 #pragma interface "menubase.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 #include "wx/list.h" // for wxMenuList
24 #include "wx/window.h" // base class for wxMenuBar
26 class WXDLLEXPORT wxMenu
;
27 class WXDLLEXPORT wxMenuBar
;
28 class WXDLLEXPORT wxMenuItem
;
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 // for now, it's in platform-specific file
36 WX_DECLARE_LIST(wxMenu
, wxMenuList
);
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 class WXDLLEXPORT wxMenuBarBase
: public wxWindow
48 // dtor will delete all menus we own
49 virtual ~wxMenuBarBase();
51 // menu bar construction
52 // ---------------------
54 // append a menu to the end of menubar, return TRUE if ok
55 virtual bool Append(wxMenu
*menu
, const wxString
& title
);
57 // insert a menu before the given position into the menubar, return TRUE
59 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
61 // menu bar items access
62 // ---------------------
64 // get the number of menus in the menu bar
65 size_t GetMenuCount() const { return m_menus
.GetCount(); }
67 // get the menu at given position
68 wxMenu
*GetMenu(size_t pos
) const;
70 // replace the menu at given position with another one, returns the
71 // previous menu (which should be deleted by the caller)
72 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
74 // delete the menu at given position from the menu bar, return the pointer
75 // to the menu (which should be deleted by the caller)
76 virtual wxMenu
*Remove(size_t pos
);
78 // enable or disable a submenu
79 virtual void EnableTop(size_t pos
, bool enable
) = 0;
81 // get or change the label of the menu at given position
82 virtual void SetLabelTop(size_t pos
, const wxString
& label
) = 0;
83 virtual wxString
GetLabelTop(size_t pos
) const = 0;
88 // by menu and item names, returns wxNOT_FOUND if not found or id of the
90 virtual int FindMenuItem(const wxString
& menuString
,
91 const wxString
& itemString
) const = 0;
93 // find item by id (in any menu), returns NULL if not found
95 // if menu is !NULL, it will be filled with wxMenu this item belongs to
96 virtual wxMenuItem
* FindItem(int id
, wxMenu
**menu
= NULL
) const = 0;
101 // all these functions just use FindItem() and then call an appropriate
104 // NB: under MSW, these methods can only be used after the menubar had
105 // been attached to the frame
107 void Enable(int id
, bool enable
);
108 void Check(int id
, bool check
);
109 bool IsChecked(int id
) const;
110 bool IsEnabled(int id
) const;
112 void SetLabel(int id
, const wxString
&label
);
113 wxString
GetLabel(int id
) const;
115 void SetHelpString(int id
, const wxString
& helpString
);
116 wxString
GetHelpString(int id
) const;
118 // need to override these ones to avoid virtual function hiding
119 virtual bool Enable(bool enable
= TRUE
) { return wxWindow::Enable(enable
); }
120 virtual void SetLabel(const wxString
& s
) { wxWindow::SetLabel(s
); }
121 virtual wxString
GetLabel() const { return wxWindow::GetLabel(); }
123 // compatibility only: these functions are deprecated, use the new ones
125 #ifdef WXWIN_COMPATIBILITY
126 bool Enabled(int id
) const { return IsEnabled(id
); }
127 bool Checked(int id
) const { return IsChecked(id
); }
129 wxMenuItem
* FindMenuItemById(int id
) const
130 { return FindItem(id
); }
131 wxMenuItem
* FindItemForId(int id
, wxMenu
**menu
= NULL
) const
132 { return FindItem(id
, menu
); }
133 #endif // WXWIN_COMPATIBILITY
136 // the list of all our menus
140 // ----------------------------------------------------------------------------
141 // include the real class declaration
142 // ----------------------------------------------------------------------------
144 #ifdef wxUSE_BASE_CLASSES_ONLY
145 #define wxMenuItem wxMenuItemBase
146 #else // !wxUSE_BASE_CLASSES_ONLY
147 #if defined(__WXMSW__)
148 #include "wx/msw/menu.h"
149 #elif defined(__WXMOTIF__)
150 #include "wx/motif/menu.h"
151 #elif defined(__WXGTK__)
152 #include "wx/gtk/menu.h"
153 #elif defined(__WXQT__)
154 #include "wx/qt/menu.h"
155 #elif defined(__WXMAC__)
156 #include "wx/mac/menu.h"
157 #elif defined(__WXPM__)
158 #include "wx/os2/menu.h"
159 #elif defined(__WXSTUBS__)
160 #include "wx/stubs/menu.h"
162 #endif // wxUSE_BASE_CLASSES_ONLY/!wxUSE_BASE_CLASSES_ONLY
164 // also include this one to ensure compatibility with old code which only
165 // included wx/menu.h
166 #include "wx/menuitem.h"