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