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