]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/menu.h
update from gtk/changes.txt to changes.txt (sic...)
[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 // 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 //
96 WXHMENU GetHMenu() const { return m_hMenu; }
97
98 #if wxUSE_ACCEL
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;
115 #endif // wxUSE_ACCEL
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); }
125
126 //
127 // All OS/2PM Menu's have one of these
128 //
129 MENUITEM m_vMenuData;
130
131 private:
132 //
133 // Common part of all ctors
134 //
135 void Init();
136
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 // Terminate the current radio group, if any
146 //
147 void EndRadioGroup(void);
148
149 //
150 // If TRUE, insert a breal before appending the next item
151 //
152 bool m_bDoBreak;
153
154 //
155 // The menu handle of this menu
156 //
157 WXHMENU m_hMenu;
158
159 //
160 // The helper variable for creating unique IDs.
161 //
162 static USHORT m_nextMenuId;
163
164 //
165 // The position of the first item in the current radio group or -1
166 //
167 int m_nStartRadioGroup;
168
169 #if wxUSE_ACCEL
170 //
171 // The accelerators for our menu items
172 //
173 wxAcceleratorArray m_vAccels;
174 #endif // wxUSE_ACCEL
175
176 DECLARE_DYNAMIC_CLASS(wxMenu)
177 }; // end of wxMenu
178
179 // ----------------------------------------------------------------------------
180 // Menu Bar (a la Windows)
181 // ----------------------------------------------------------------------------
182
183 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
184 {
185 public:
186 //
187 // Ctors & dtor
188 //
189
190 //
191 // Default constructor
192 //
193 wxMenuBar();
194
195 //
196 // Unused under OS2
197 wxMenuBar(long lStyle);
198
199 //
200 // Menubar takes ownership of the menus arrays but copies the titles
201 //
202 wxMenuBar( int n
203 ,wxMenu* vMenus[]
204 ,const wxString sTitles[]
205 );
206 virtual ~wxMenuBar();
207
208 //
209 // Menubar construction
210 //
211 virtual bool Append( wxMenu* pMenu
212 ,const wxString& rTitle
213 );
214 virtual bool Insert( size_t nPos
215 ,wxMenu* pMenu
216 ,const wxString& rTitle
217 );
218 virtual wxMenu* Replace( size_t nPos
219 ,wxMenu* pMenu
220 ,const wxString& rTitle
221 );
222 virtual wxMenu* Remove(size_t nPos);
223 virtual int FindMenuItem( const wxString& rMenuString
224 ,const wxString& rItemString
225 ) const;
226 virtual wxMenuItem* FindItem( int nId
227 ,wxMenu** ppMenu = NULL
228 ) const;
229 virtual wxMenuItem* FindItem( int nId
230 ,ULONG hItem
231 ,wxMenu** ppMenu = NULL
232 ) const;
233 virtual void EnableTop( size_t nPos
234 ,bool bFlag
235 );
236 virtual void SetLabelTop( size_t nPos
237 ,const wxString& rLabel
238 );
239 virtual wxString GetLabelTop(size_t nPos) const;
240
241 //
242 // Compatibility: these functions are deprecated
243 //
244 #if WXWIN_COMPATIBILITY
245 void SetEventHandler(wxEvtHandler* pHandler) { m_pEventHandler = pHandler; }
246 wxEvtHandler* GetEventHandler(void) { return m_pEventHandler; }
247 bool Enabled(int nId) const { return IsEnabled(nId); }
248 bool Checked(int nId) const { return IsChecked(nId); }
249 #endif // WXWIN_COMPATIBILITY
250
251 //
252 // Implementation from now on
253 //
254 WXHMENU Create(void);
255 virtual void Detach(void);
256 virtual void Attach(wxFrame* pFrame);
257
258 #if wxUSE_ACCEL
259 //
260 // Get the accel table for all the menus
261 //
262 const wxAcceleratorTable& GetAccelTable(void) const { return m_vAccelTable; }
263
264 //
265 // Update the accel table (must be called after adding/deletign a menu)
266 //
267 void RebuildAccelTable(void);
268 #endif // wxUSE_ACCEL
269
270 //
271 // Get the menu handle
272 WXHMENU GetHMenu(void) const { return m_hMenu; }
273
274 //
275 // If the menubar is modified, the display is not updated automatically,
276 // call this function to update it (m_menuBarFrame should be !NULL)
277 //
278 void Refresh(void);
279
280 protected:
281 //
282 // Common part of all ctors
283 //
284 void Init(void);
285
286 #if WXWIN_COMPATIBILITY
287 wxEvtHandler* m_pEventHandler;
288 #endif // WXWIN_COMPATIBILITY
289
290 wxArrayString m_titles;
291
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_