]>
Commit | Line | Data |
---|---|---|
9b6dbb09 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menu.h | |
3 | // Purpose: wxMenu, wxMenuBar classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_MENU_H_ | |
13 | #define _WX_MENU_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "menu.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | #include "wx/event.h" | |
94b49b93 JS |
21 | #include "wx/font.h" |
22 | #include "wx/gdicmn.h" | |
9b6dbb09 JS |
23 | |
24 | class WXDLLEXPORT wxMenuItem; | |
25 | class WXDLLEXPORT wxMenuBar; | |
26 | class WXDLLEXPORT wxMenu; | |
27 | ||
28 | WXDLLEXPORT_DATA(extern const char*) wxEmptyString; | |
29 | ||
30 | // ---------------------------------------------------------------------------- | |
31 | // Menu | |
32 | // ---------------------------------------------------------------------------- | |
33 | class WXDLLEXPORT wxMenu: public wxEvtHandler | |
34 | { | |
35 | DECLARE_DYNAMIC_CLASS(wxMenu) | |
36 | ||
37 | public: | |
38 | // ctor & dtor | |
39 | wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL); | |
40 | ~wxMenu(); | |
41 | ||
42 | // construct menu | |
43 | // append items to the menu | |
44 | // separator line | |
45 | void AppendSeparator(); | |
46 | // normal item | |
47 | void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString, | |
48 | bool checkable = FALSE); | |
49 | // a submenu | |
50 | void Append(int id, const wxString& Label, wxMenu *SubMenu, | |
51 | const wxString& helpString = wxEmptyString); | |
52 | // the most generic form (create wxMenuItem first and use it's functions) | |
53 | void Append(wxMenuItem *pItem); | |
54 | // insert a break in the menu | |
55 | void Break(); | |
56 | // delete an item | |
57 | void Delete(int id); | |
58 | ||
59 | // menu item control | |
60 | void Enable(int id, bool Flag); | |
61 | bool Enabled(int id) const; | |
62 | inline bool IsEnabled(int id) const { return Enabled(id); }; | |
63 | void Check(int id, bool Flag); | |
64 | bool Checked(int id) const; | |
65 | inline bool IsChecked(int id) const { return IsChecked(id); }; | |
66 | ||
3dd4e4e0 JS |
67 | // Client data |
68 | inline void SetClientData(void* clientData) { m_clientData = clientData; } | |
69 | inline void* GetClientData() const { return m_clientData; } | |
70 | ||
9b6dbb09 JS |
71 | // item properties |
72 | // title | |
73 | void SetTitle(const wxString& label); | |
74 | const wxString GetTitle() const; | |
75 | // label | |
76 | void SetLabel(int id, const wxString& label); | |
77 | wxString GetLabel(int id) const; | |
78 | // help string | |
79 | virtual void SetHelpString(int id, const wxString& helpString); | |
80 | virtual wxString GetHelpString(int id) const ; | |
81 | ||
82 | // find item | |
83 | // Finds the item id matching the given string, -1 if not found. | |
84 | virtual int FindItem(const wxString& itemString) const ; | |
85 | // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL. | |
86 | wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const; | |
87 | ||
88 | void ProcessCommand(wxCommandEvent& event); | |
89 | inline void Callback(const wxFunction func) { m_callback = func; } | |
90 | ||
91 | virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; } | |
92 | inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
93 | inline wxEvtHandler *GetEventHandler() { return m_eventHandler; } | |
94 | ||
95 | inline wxList& GetItems() const { return (wxList&) m_menuItems; } | |
96 | ||
97 | //// Motif-specific | |
98 | inline WXWidget GetButtonWidget() const { return m_buttonWidget; } | |
50414e24 | 99 | inline void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; } |
9b6dbb09 | 100 | inline WXWidget GetMainWidget() const { return m_menuWidget; } |
50414e24 JS |
101 | inline wxMenu* GetParent() const { return m_menuParent; } |
102 | inline int GetId() const { return m_menuId; } | |
103 | inline void SetId(int id) { m_menuId = id; } | |
104 | inline void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; } | |
105 | inline wxMenuBar* GetMenuBar() const { return m_menuBar; } | |
106 | ||
107 | void CreatePopup (WXWidget logicalParent, int x, int y); | |
108 | void DestroyPopup (void); | |
109 | void ShowPopup (int x, int y); | |
110 | void HidePopup (void); | |
111 | ||
112 | WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu, | |
113 | const wxString& title = "", bool isPulldown = FALSE); | |
114 | ||
115 | // For popups, need to destroy, then recreate menu for a different (or | |
116 | // possibly same) window, since the parent may change. | |
117 | void DestroyMenu(bool full); | |
118 | WXWidget FindMenuItem(int id, wxMenuItem **it = NULL) const; | |
119 | ||
94b49b93 JS |
120 | const wxColour& GetBackgroundColour() const { return m_backgroundColour; } |
121 | const wxColour& GetForegroundColour() const { return m_foregroundColour; } | |
122 | const wxFont& GetFont() const { return m_font; } | |
123 | ||
124 | void SetBackgroundColour(const wxColour& colour); | |
125 | void SetForegroundColour(const wxColour& colour); | |
126 | void SetFont(const wxFont& colour); | |
127 | void ChangeFont(bool keepOriginalSize = FALSE); | |
128 | ||
9b6dbb09 JS |
129 | public: |
130 | wxFunction m_callback; | |
131 | ||
132 | int m_noItems; | |
133 | wxString m_title; | |
134 | wxMenuBar * m_menuBar; | |
135 | wxList m_menuItems; | |
136 | wxEvtHandler * m_parent; | |
137 | wxEvtHandler * m_eventHandler; | |
3dd4e4e0 | 138 | void* m_clientData; |
9b6dbb09 JS |
139 | |
140 | //// Motif-specific | |
141 | int m_numColumns; | |
142 | WXWidget m_menuWidget; | |
143 | WXWidget m_popupShell; // For holding the popup shell widget | |
144 | WXWidget m_buttonWidget; // The actual string, so we can grey it etc. | |
145 | int m_menuId; | |
50414e24 | 146 | wxMenu* m_topLevelMenu ; |
9b6dbb09 JS |
147 | wxMenu* m_menuParent; |
148 | bool m_ownedByMenuBar; | |
94b49b93 JS |
149 | wxColour m_foregroundColour; |
150 | wxColour m_backgroundColour; | |
151 | wxFont m_font; | |
9b6dbb09 JS |
152 | }; |
153 | ||
154 | // ---------------------------------------------------------------------------- | |
155 | // Menu Bar (a la Windows) | |
156 | // ---------------------------------------------------------------------------- | |
157 | class WXDLLEXPORT wxFrame; | |
158 | class WXDLLEXPORT wxMenuBar: public wxEvtHandler | |
159 | { | |
160 | DECLARE_DYNAMIC_CLASS(wxMenuBar) | |
161 | ||
162 | wxMenuBar(); | |
163 | wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); | |
164 | ~wxMenuBar(); | |
165 | ||
166 | void Append(wxMenu *menu, const wxString& title); | |
167 | // Must only be used AFTER menu has been attached to frame, | |
168 | // otherwise use individual menus to enable/disable items | |
169 | void Enable(int Id, bool Flag); | |
170 | bool Enabled(int Id) const ; | |
171 | inline bool IsEnabled(int Id) const { return Enabled(Id); }; | |
172 | void EnableTop(int pos, bool Flag); | |
173 | void Check(int id, bool Flag); | |
174 | bool Checked(int id) const ; | |
175 | inline bool IsChecked(int Id) const { return Checked(Id); }; | |
176 | void SetLabel(int id, const wxString& label) ; | |
177 | wxString GetLabel(int id) const ; | |
178 | void SetLabelTop(int pos, const wxString& label) ; | |
179 | wxString GetLabelTop(int pos) const ; | |
180 | virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */ | |
181 | virtual bool OnAppend(wxMenu *menu, const char *title); | |
182 | virtual bool OnDelete(wxMenu *menu, int index); | |
183 | ||
184 | virtual void SetHelpString(int Id, const wxString& helpString); | |
185 | virtual wxString GetHelpString(int Id) const ; | |
186 | ||
187 | virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ; | |
188 | ||
189 | // Find wxMenuItem for item ID, and return item's | |
190 | // menu too if itemMenu is non-NULL. | |
191 | wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ; | |
192 | ||
193 | inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
194 | inline wxEvtHandler *GetEventHandler() { return m_eventHandler; } | |
195 | ||
196 | inline int GetMenuCount() const { return m_menuCount; } | |
197 | inline wxMenu* GetMenu(int i) const { return m_menus[i]; } | |
198 | ||
50414e24 JS |
199 | //// Motif-specific |
200 | inline wxFrame* GetMenuBarFrame() const { return m_menuBarFrame; } | |
201 | inline void SetMenuBarFrame(wxFrame* frame) { m_menuBarFrame = frame; } | |
202 | inline WXWidget GetMainWidget() const { return m_mainWidget; } | |
203 | inline void SetMainWidget(WXWidget widget) { m_mainWidget = widget; } | |
204 | ||
621793f4 JS |
205 | // Create menubar |
206 | bool CreateMenuBar(wxFrame* frame); | |
207 | ||
208 | // Destroy menubar, but keep data structures intact so we can recreate it. | |
209 | bool DestroyMenuBar(); | |
210 | ||
94b49b93 JS |
211 | const wxColour& GetBackgroundColour() const { return m_backgroundColour; } |
212 | const wxColour& GetForegroundColour() const { return m_foregroundColour; } | |
213 | const wxFont& GetFont() const { return m_font; } | |
214 | ||
215 | void SetBackgroundColour(const wxColour& colour); | |
216 | void SetForegroundColour(const wxColour& colour); | |
217 | void SetFont(const wxFont& colour); | |
218 | void ChangeFont(bool keepOriginalSize = FALSE); | |
219 | ||
9b6dbb09 JS |
220 | public: |
221 | wxEvtHandler * m_eventHandler; | |
222 | int m_menuCount; | |
223 | wxMenu ** m_menus; | |
224 | wxString * m_titles; | |
225 | wxFrame * m_menuBarFrame; | |
50414e24 JS |
226 | |
227 | //// Motif-specific | |
228 | WXWidget m_mainWidget; | |
229 | ||
94b49b93 JS |
230 | wxColour m_foregroundColour; |
231 | wxColour m_backgroundColour; | |
232 | wxFont m_font; | |
9b6dbb09 JS |
233 | }; |
234 | ||
235 | #endif // _WX_MENU_H_ |