More updates to wxWindow, wxMenu, GdiImage to get minimal to work
[wxWidgets.git] / include / wx / os2 / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/10/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MENU_H_
13 #define _WX_MENU_H_
14
15 #if wxUSE_ACCEL
16 #include "wx/accel.h"
17 #include "wx/dynarray.h"
18
19 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray);
20 #endif // wxUSE_ACCEL
21
22 class WXDLLEXPORT wxFrame;
23
24 // ----------------------------------------------------------------------------
25 // Menu
26 // ----------------------------------------------------------------------------
27
28 class WXDLLEXPORT wxMenu : public wxMenuBase
29 {
30 public:
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 }
43
44 wxMenu(long lStyle = 0)
45 : wxMenuBase(lStyle)
46 {
47 Init();
48 }
49
50 virtual ~wxMenu();
51
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)
68 {
69 Init();
70 Callback(fnFunc);
71 }
72 #endif // wxUSE_MENU_CALLBACK
73
74 //
75 // OS2-specific
76 //
77 bool ProcessCommand(wxCommandEvent& rEvent);
78
79
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 //
100 WXHMENU GetHMenu() const { return m_hMenu; }
101
102 //
103 // Attach/detach menu to/from wxMenuBar
104 //
105 void Attach(wxMenuBar* pMenubar);
106 void Detach(void);
107
108 #if wxUSE_ACCEL
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;
125 #endif // wxUSE_ACCEL
126
127 //
128 // All OS/2PM Menu's have one of these
129 //
130 MENUITEM m_vMenuData;
131
132 private:
133 //
134 // Common part of all ctors
135 //
136 void Init();
137
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;
154
155 #if wxUSE_ACCEL
156 //
157 // The accelerators for our menu items
158 //
159 wxAcceleratorArray m_vAccels;
160 #endif // wxUSE_ACCEL
161
162 DECLARE_DYNAMIC_CLASS(wxMenu)
163 }; // end of wxMenu
164
165 // ----------------------------------------------------------------------------
166 // Menu Bar (a la Windows)
167 // ----------------------------------------------------------------------------
168
169 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
170 {
171 public:
172 //
173 // Ctors & dtor
174 //
175
176 //
177 // Default constructor
178 //
179 wxMenuBar();
180
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();
193
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 //
227 #if WXWIN_COMPATIBILITY
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); }
232 #endif // WXWIN_COMPATIBILITY
233
234 //
235 // Implementation from now on
236 //
237 WXHMENU Create(void);
238 void Detach(void);
239
240 //
241 // Returns TRUE if we're attached to a frame
242 //
243 bool IsAttached(void) const { return m_pMenuBarFrame != NULL; }
244
245 //
246 // Get the frame we live in
247 //
248 wxFrame * GetFrame(void) const { return m_pMenuBarFrame; }
249
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);
265 #endif // wxUSE_ACCEL
266
267 //
268 // Get the menu handle
269 WXHMENU GetHMenu(void) const { return m_hMenu; }
270
271 //
272 // If the menubar is modified, the display is not updated automatically,
273 // call this function to update it (m_menuBarFrame should be !NULL)
274 //
275 void Refresh(void);
276
277 protected:
278 //
279 // Common part of all ctors
280 //
281 void Init(void);
282
283 #if WXWIN_COMPATIBILITY
284 wxEvtHandler* m_pEventHandler;
285 #endif // WXWIN_COMPATIBILITY
286
287 wxArrayString m_titles;
288
289 wxFrame* m_pMenuBarFrame;
290 WXHMENU m_hMenu;
291
292 #if wxUSE_ACCEL
293 //
294 // The accelerator table for all accelerators in all our menus
295 //
296 wxAcceleratorTable m_vAccelTable;
297 #endif // wxUSE_ACCEL
298
299 private:
300 //
301 // Virtual function hiding suppression
302 //
303 void Refresh( bool bErase
304 ,const wxRect* pRect
305 )
306 { wxWindow::Refresh(bErase, pRect); }
307
308 DECLARE_DYNAMIC_CLASS(wxMenuBar)
309 };
310
311 #endif // _WX_MENU_H_