]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/menu.h
Applied patch [ 670782 ] Combobox uses popup window width
[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_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray);
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 virtual void Attach(wxMenuBarBase* pMenubar);
82
83 bool OS2Command( WXUINT uParam
84 ,WXWORD wId
85 );
86
87 //
88 // Semi-private accessors
89 //
90
91 //
92 // Get the window which contains this menu
93 //
94 wxWindow* GetWindow(void) const;
95
96 //
97 // Get the menu handle
98 //
99 WXHMENU GetHMenu() const { return m_hMenu; }
100
101 #if wxUSE_ACCEL
102 //
103 // Called by wxMenuBar to build its accel table from the accels of all menus
104 //
105 bool HasAccels(void) const { return m_vAccels.IsEmpty(); }
106 size_t GetAccelCount(void) const { return m_vAccels.GetCount(); }
107 size_t CopyAccels(wxAcceleratorEntry* pAccels) const;
108
109 //
110 // Called by wxMenuItem when its accels changes
111 //
112 void UpdateAccel(wxMenuItem* pItem);
113
114 //
115 // Helper used by wxMenu itself (returns the index in m_accels)
116 //
117 int FindAccel(int nId) const;
118 #endif // wxUSE_ACCEL
119 //
120 // OS/2 specific Find
121 //
122 wxMenuItem* FindItem(int id, ULONG hItem, wxMenu **menu = NULL) const;
123 //virtual function hiding suppression
124 int FindItem(const wxString& rsString) const
125 { return wxMenuBase::FindItem(rsString); }
126 wxMenuItem* FindItem(int id, wxMenu **menu = NULL) const
127 { return wxMenuBase::FindItem(id, menu); }
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 // Terminate the current radio group, if any
149 //
150 void EndRadioGroup(void);
151
152 //
153 // If TRUE, insert a breal before appending the next item
154 //
155 bool m_bDoBreak;
156
157 //
158 // The menu handle of this menu
159 //
160 WXHMENU m_hMenu;
161
162 //
163 // The helper variable for creating unique IDs.
164 //
165 static USHORT m_nextMenuId;
166
167 //
168 // The position of the first item in the current radio group or -1
169 //
170 int m_nStartRadioGroup;
171
172 #if wxUSE_ACCEL
173 //
174 // The accelerators for our menu items
175 //
176 wxAcceleratorArray m_vAccels;
177 #endif // wxUSE_ACCEL
178
179 DECLARE_DYNAMIC_CLASS(wxMenu)
180 }; // end of wxMenu
181
182 // ----------------------------------------------------------------------------
183 // Menu Bar (a la Windows)
184 // ----------------------------------------------------------------------------
185
186 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
187 {
188 public:
189 //
190 // Ctors & dtor
191 //
192
193 //
194 // Default constructor
195 //
196 wxMenuBar();
197
198 //
199 // Unused under OS2
200 wxMenuBar(long lStyle);
201
202 //
203 // Menubar takes ownership of the menus arrays but copies the titles
204 //
205 wxMenuBar( int n
206 ,wxMenu* vMenus[]
207 ,const wxString sTitles[]
208 );
209 virtual ~wxMenuBar();
210
211 //
212 // Menubar construction
213 //
214 virtual bool Append( wxMenu* pMenu
215 ,const wxString& rTitle
216 );
217 virtual bool Insert( size_t nPos
218 ,wxMenu* pMenu
219 ,const wxString& rTitle
220 );
221 virtual wxMenu* Replace( size_t nPos
222 ,wxMenu* pMenu
223 ,const wxString& rTitle
224 );
225 virtual wxMenu* Remove(size_t nPos);
226 virtual int FindMenuItem( const wxString& rMenuString
227 ,const wxString& rItemString
228 ) const;
229 virtual wxMenuItem* FindItem( int nId
230 ,wxMenu** ppMenu = NULL
231 ) const;
232 virtual wxMenuItem* FindItem( int nId
233 ,ULONG hItem
234 ,wxMenu** ppMenu = NULL
235 ) const;
236 virtual void EnableTop( size_t nPos
237 ,bool bFlag
238 );
239 virtual void SetLabelTop( size_t nPos
240 ,const wxString& rLabel
241 );
242 virtual wxString GetLabelTop(size_t nPos) const;
243
244 //
245 // Compatibility: these functions are deprecated
246 //
247 #if WXWIN_COMPATIBILITY
248 void SetEventHandler(wxEvtHandler* pHandler) { m_pEventHandler = pHandler; }
249 wxEvtHandler* GetEventHandler(void) { return m_pEventHandler; }
250 bool Enabled(int nId) const { return IsEnabled(nId); }
251 bool Checked(int nId) const { return IsChecked(nId); }
252 #endif // WXWIN_COMPATIBILITY
253
254 //
255 // Implementation from now on
256 //
257 WXHMENU Create(void);
258 virtual void Detach(void);
259 virtual void Attach(wxFrame* pFrame);
260
261 #if wxUSE_ACCEL
262 //
263 // Get the accel table for all the menus
264 //
265 const wxAcceleratorTable& GetAccelTable(void) const { return m_vAccelTable; }
266
267 //
268 // Update the accel table (must be called after adding/deletign a menu)
269 //
270 void RebuildAccelTable(void);
271 #endif // wxUSE_ACCEL
272
273 //
274 // Get the menu handle
275 WXHMENU GetHMenu(void) const { return m_hMenu; }
276
277 //
278 // If the menubar is modified, the display is not updated automatically,
279 // call this function to update it (m_menuBarFrame should be !NULL)
280 //
281 void Refresh(void);
282
283 protected:
284 //
285 // Common part of all ctors
286 //
287 void Init(void);
288
289 #if WXWIN_COMPATIBILITY
290 wxEvtHandler* m_pEventHandler;
291 #endif // WXWIN_COMPATIBILITY
292
293 wxArrayString m_titles;
294
295 WXHMENU m_hMenu;
296
297 #if wxUSE_ACCEL
298 //
299 // The accelerator table for all accelerators in all our menus
300 //
301 wxAcceleratorTable m_vAccelTable;
302 #endif // wxUSE_ACCEL
303
304 private:
305 //
306 // Virtual function hiding suppression
307 //
308 void Refresh( bool bErase
309 ,const wxRect* pRect
310 )
311 { wxWindow::Refresh(bErase, pRect); }
312
313 DECLARE_DYNAMIC_CLASS(wxMenuBar)
314 };
315
316 #endif // _WX_MENU_H_