]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menu.h | |
3 | // Purpose: wxMenu, wxMenuBar classes | |
75f11ad7 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
75f11ad7 | 6 | // Created: 10/10/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
75f11ad7 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_MENU_H_ | |
13 | #define _WX_MENU_H_ | |
14 | ||
75f11ad7 | 15 | #if wxUSE_ACCEL |
e92f266c DW |
16 | #include "wx/accel.h" |
17 | #include "wx/dynarray.h" | |
18 | ||
19 | WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray); | |
75f11ad7 | 20 | #endif // wxUSE_ACCEL |
0e320a79 | 21 | |
75f11ad7 | 22 | class WXDLLEXPORT wxFrame; |
0e320a79 | 23 | |
0e320a79 DW |
24 | // ---------------------------------------------------------------------------- |
25 | // Menu | |
26 | // ---------------------------------------------------------------------------- | |
0e320a79 | 27 | |
e92f266c DW |
28 | class WXDLLEXPORT wxMenu : public wxMenuBase |
29 | { | |
0e320a79 | 30 | public: |
61243a51 DW |
31 | // |
32 | // Ctors & dtor | |
33 | // | |
34 | wxMenu( const wxString& rTitle | |
35 | ,long lStyle = 0 | |
36 | ) | |
37 | : wxMenuBase( rTitle | |
38 | ,lStyle | |
39 | ) | |
40 | { | |
41 | Init(); | |
42 | } | |
75f11ad7 | 43 | |
61243a51 DW |
44 | wxMenu(long lStyle = 0) |
45 | : wxMenuBase(lStyle) | |
46 | { | |
47 | Init(); | |
48 | } | |
75f11ad7 DW |
49 | |
50 | virtual ~wxMenu(); | |
51 | ||
61243a51 DW |
52 | // |
53 | // Implement base class virtuals | |
54 | // | |
55 | virtual bool DoAppend(wxMenuItem* pItem); | |
56 | virtual bool DoInsert( size_t nPos | |
57 | ,wxMenuItem* pItem | |
58 | ); | |
59 | virtual wxMenuItem* DoRemove(wxMenuItem* pItem); | |
60 | virtual void Break(void); | |
61 | virtual void SetTitle(const wxString& rTitle); | |
62 | ||
63 | #if wxUSE_MENU_CALLBACK | |
64 | wxMenu( const wxString& rTitle | |
65 | ,const wxFunction fnFunc | |
66 | ) | |
67 | : wxMenuBase(rTitle) | |
e92f266c | 68 | { |
61243a51 DW |
69 | Init(); |
70 | Callback(fnFunc); | |
e92f266c | 71 | } |
61243a51 | 72 | #endif // wxUSE_MENU_CALLBACK |
e92f266c | 73 | |
61243a51 DW |
74 | // |
75 | // OS2-specific | |
76 | // | |
77 | bool ProcessCommand(wxCommandEvent& rEvent); | |
75f11ad7 | 78 | |
75f11ad7 | 79 | |
61243a51 DW |
80 | // |
81 | // Implementation only from now on | |
82 | // ------------------------------- | |
83 | // | |
84 | bool OS2Command( WXUINT uParam | |
85 | ,WXWORD wId | |
86 | ); | |
87 | ||
88 | // | |
89 | // Semi-private accessors | |
90 | // | |
91 | ||
92 | // | |
93 | // Get the window which contains this menu | |
94 | // | |
95 | wxWindow* GetWindow(void) const; | |
96 | ||
97 | // | |
98 | // Get the menu handle | |
99 | // | |
e92f266c | 100 | WXHMENU GetHMenu() const { return m_hMenu; } |
75f11ad7 | 101 | |
61243a51 DW |
102 | // |
103 | // Attach/detach menu to/from wxMenuBar | |
104 | // | |
105 | void Attach(wxMenuBar* pMenubar); | |
106 | void Detach(void); | |
75f11ad7 DW |
107 | |
108 | #if wxUSE_ACCEL | |
61243a51 DW |
109 | // |
110 | // Called by wxMenuBar to build its accel table from the accels of all menus | |
111 | // | |
112 | bool HasAccels(void) const { return !m_vAccels.IsEmpty(); } | |
113 | size_t GetAccelCount(void) const { return m_vAccels.GetCount(); } | |
114 | size_t CopyAccels(wxAcceleratorEntry* pAccels) const; | |
115 | ||
116 | // | |
117 | // Called by wxMenuItem when its accels changes | |
118 | // | |
119 | void UpdateAccel(wxMenuItem* pItem); | |
120 | ||
121 | // | |
122 | // Helper used by wxMenu itself (returns the index in m_accels) | |
123 | // | |
124 | int FindAccel(int nId) const; | |
e92f266c | 125 | #endif // wxUSE_ACCEL |
75f11ad7 | 126 | |
61243a51 DW |
127 | // |
128 | // All OS/2PM Menu's have one of these | |
129 | // | |
130 | MENUITEM m_vMenuData; | |
131 | ||
75f11ad7 | 132 | private: |
61243a51 DW |
133 | // |
134 | // Common part of all ctors | |
135 | // | |
e92f266c DW |
136 | void Init(); |
137 | ||
61243a51 DW |
138 | // |
139 | // Common part of Append/Insert (behaves as Append is pos == (size_t)-1) | |
140 | // | |
141 | bool DoInsertOrAppend( wxMenuItem* pItem | |
142 | ,size_t nPos = (size_t)-1 | |
143 | ); | |
144 | ||
145 | // | |
146 | // If TRUE, insert a breal before appending the next item | |
147 | // | |
148 | bool m_bDoBreak; | |
149 | ||
150 | // | |
151 | // The menu handle of this menu | |
152 | // | |
153 | WXHMENU m_hMenu; | |
75f11ad7 DW |
154 | |
155 | #if wxUSE_ACCEL | |
61243a51 DW |
156 | // |
157 | // The accelerators for our menu items | |
158 | // | |
159 | wxAcceleratorArray m_vAccels; | |
75f11ad7 | 160 | #endif // wxUSE_ACCEL |
e92f266c DW |
161 | |
162 | DECLARE_DYNAMIC_CLASS(wxMenu) | |
61243a51 | 163 | }; // end of wxMenu |
0e320a79 DW |
164 | |
165 | // ---------------------------------------------------------------------------- | |
166 | // Menu Bar (a la Windows) | |
167 | // ---------------------------------------------------------------------------- | |
75f11ad7 | 168 | |
e92f266c | 169 | class WXDLLEXPORT wxMenuBar : public wxMenuBarBase |
0e320a79 | 170 | { |
75f11ad7 | 171 | public: |
61243a51 DW |
172 | // |
173 | // Ctors & dtor | |
174 | // | |
e92f266c | 175 | |
61243a51 DW |
176 | // |
177 | // Default constructor | |
178 | // | |
179 | wxMenuBar(); | |
75f11ad7 | 180 | |
61243a51 DW |
181 | // |
182 | // Unused under OS2 | |
183 | wxMenuBar(long lStyle); | |
184 | ||
185 | // | |
186 | // Menubar takes ownership of the menus arrays but copies the titles | |
187 | // | |
188 | wxMenuBar( int n | |
189 | ,wxMenu* vMenus[] | |
190 | ,const wxString sTitles[] | |
191 | ); | |
192 | virtual ~wxMenuBar(); | |
75f11ad7 | 193 | |
61243a51 DW |
194 | // |
195 | // Menubar construction | |
196 | // | |
197 | virtual bool Append( wxMenu* pMenu | |
198 | ,const wxString& rTitle | |
199 | ); | |
200 | virtual bool Insert( size_t nPos | |
201 | ,wxMenu* pMenu | |
202 | ,const wxString& rTitle | |
203 | ); | |
204 | virtual wxMenu* Replace( size_t nPos | |
205 | ,wxMenu* pMenu | |
206 | ,const wxString& rTitle | |
207 | ); | |
208 | virtual wxMenu* Remove(size_t nPos); | |
209 | virtual int FindMenuItem( const wxString& rMenuString | |
210 | ,const wxString& rItemString | |
211 | ) const; | |
212 | virtual wxMenuItem* FindItem( int nId | |
213 | ,wxMenu** ppMenu = NULL | |
214 | ) const; | |
215 | ||
216 | virtual void EnableTop( size_t nPos | |
217 | ,bool bFlag | |
218 | ); | |
219 | virtual void SetLabelTop( size_t nPos | |
220 | ,const wxString& rLabel | |
221 | ); | |
222 | virtual wxString GetLabelTop(size_t nPos) const; | |
223 | ||
224 | // | |
225 | // Compatibility: these functions are deprecated | |
226 | // | |
e92f266c | 227 | #if WXWIN_COMPATIBILITY |
61243a51 DW |
228 | void SetEventHandler(wxEvtHandler* pHandler) { m_pEventHandler = pHandler; } |
229 | wxEvtHandler* GetEventHandler(void) { return m_pEventHandler; } | |
230 | bool Enabled(int nId) const { return IsEnabled(nId); } | |
231 | bool Checked(int nId) const { return IsChecked(nId); } | |
75f11ad7 DW |
232 | #endif // WXWIN_COMPATIBILITY |
233 | ||
61243a51 DW |
234 | // |
235 | // Implementation from now on | |
236 | // | |
237 | WXHMENU Create(void); | |
238 | void Detach(void); | |
e92f266c | 239 | |
61243a51 DW |
240 | // |
241 | // Returns TRUE if we're attached to a frame | |
242 | // | |
243 | bool IsAttached(void) const { return m_pMenuBarFrame != NULL; } | |
75f11ad7 | 244 | |
61243a51 DW |
245 | // |
246 | // Get the frame we live in | |
247 | // | |
248 | wxFrame * GetFrame(void) const { return m_pMenuBarFrame; } | |
e92f266c | 249 | |
61243a51 DW |
250 | // |
251 | // Attach to a frame | |
252 | // | |
253 | void Attach(wxFrame* pFrame); | |
254 | ||
255 | #if wxUSE_ACCEL | |
256 | // | |
257 | // Get the accel table for all the menus | |
258 | // | |
259 | const wxAcceleratorTable& GetAccelTable(void) const { return m_vAccelTable; } | |
260 | ||
261 | // | |
262 | // Update the accel table (must be called after adding/deletign a menu) | |
263 | // | |
264 | void RebuildAccelTable(void); | |
75f11ad7 DW |
265 | #endif // wxUSE_ACCEL |
266 | ||
61243a51 DW |
267 | // |
268 | // Get the menu handle | |
269 | WXHMENU GetHMenu(void) const { return m_hMenu; } | |
75f11ad7 | 270 | |
61243a51 DW |
271 | // |
272 | // If the menubar is modified, the display is not updated automatically, | |
75f11ad7 | 273 | // call this function to update it (m_menuBarFrame should be !NULL) |
61243a51 DW |
274 | // |
275 | void Refresh(void); | |
75f11ad7 DW |
276 | |
277 | protected: | |
61243a51 DW |
278 | // |
279 | // Common part of all ctors | |
280 | // | |
281 | void Init(void); | |
75f11ad7 | 282 | |
e92f266c | 283 | #if WXWIN_COMPATIBILITY |
61243a51 | 284 | wxEvtHandler* m_pEventHandler; |
e92f266c DW |
285 | #endif // WXWIN_COMPATIBILITY |
286 | ||
287 | wxArrayString m_titles; | |
288 | ||
61243a51 | 289 | wxFrame* m_pMenuBarFrame; |
0fe536e3 | 290 | WXHMENU m_hMenu; |
75f11ad7 DW |
291 | |
292 | #if wxUSE_ACCEL | |
61243a51 DW |
293 | // |
294 | // The accelerator table for all accelerators in all our menus | |
295 | // | |
296 | wxAcceleratorTable m_vAccelTable; | |
75f11ad7 | 297 | #endif // wxUSE_ACCEL |
e92f266c DW |
298 | |
299 | private: | |
61243a51 DW |
300 | // |
301 | // Virtual function hiding suppression | |
302 | // | |
303 | void Refresh( bool bErase | |
304 | ,const wxRect* pRect | |
305 | ) | |
306 | { wxWindow::Refresh(bErase, pRect); } | |
307 | ||
e92f266c | 308 | DECLARE_DYNAMIC_CLASS(wxMenuBar) |
0e320a79 DW |
309 | }; |
310 | ||
311 | #endif // _WX_MENU_H_ |