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