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