]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/menu.h
Make storing non-trivial data in wxThreadSpecificInfo possible.
[wxWidgets.git] / include / wx / os2 / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/10/99
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_MENU_H_
12 #define _WX_MENU_H_
13
14 #if wxUSE_ACCEL
15 #include "wx/accel.h"
16 #include "wx/list.h" // for "template" list classes
17 #include "wx/dynarray.h"
18
19 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray);
20 #endif // wxUSE_ACCEL
21
22 class WXDLLIMPEXP_FWD_CORE wxFrame;
23
24 void wxSetShortCutKey(wxChar* zText);
25
26 // ----------------------------------------------------------------------------
27 // Menu
28 // ----------------------------------------------------------------------------
29
30 class WXDLLIMPEXP_CORE 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 wxMenuItem* DoAppend(wxMenuItem* pItem);
58 virtual wxMenuItem* 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 //
66 // Implementation only from now on
67 // -------------------------------
68 //
69 virtual void Attach(wxMenuBarBase* pMenubar);
70
71 bool OS2Command( WXUINT uParam
72 ,WXWORD wId
73 );
74
75 //
76 // Semi-private accessors
77 //
78
79 //
80 // Get the window which contains this menu
81 //
82 wxWindow* GetWindow(void) const;
83
84 //
85 // Get the menu handle
86 //
87 WXHMENU GetHMenu() const { return m_hMenu; }
88
89 #if wxUSE_ACCEL
90 //
91 // Called by wxMenuBar to build its accel table from the accels of all menus
92 //
93 bool HasAccels(void) const { return m_vAccels.IsEmpty(); }
94 size_t GetAccelCount(void) const { return m_vAccels.GetCount(); }
95 size_t CopyAccels(wxAcceleratorEntry* pAccels) const;
96
97 //
98 // Called by wxMenuItem when its accels changes
99 //
100 void UpdateAccel(wxMenuItem* pItem);
101
102 //
103 // Helper used by wxMenu itself (returns the index in m_accels)
104 //
105 int FindAccel(int nId) const;
106 #endif // wxUSE_ACCEL
107 //
108 // OS/2 specific Find
109 //
110 wxMenuItem* FindItem(int id, ULONG hItem, wxMenu **menu = NULL) const;
111 //virtual function hiding suppression
112 int FindItem(const wxString& rsString) const
113 { return wxMenuBase::FindItem(rsString); }
114 wxMenuItem* FindItem(int id, wxMenu **menu = NULL) const
115 { return wxMenuBase::FindItem(id, menu); }
116
117 //
118 // All OS/2PM Menu's have one of these
119 //
120 MENUITEM m_vMenuData;
121
122 private:
123 //
124 // Common part of all ctors
125 //
126 void Init();
127
128 //
129 // Common part of Append/Insert (behaves as Append is pos == (size_t)-1)
130 //
131 bool DoInsertOrAppend( wxMenuItem* pItem
132 ,size_t nPos = (size_t)-1
133 );
134
135 //
136 // Terminate the current radio group, if any
137 //
138 void EndRadioGroup(void);
139
140 //
141 // If true, insert a breal before appending the next item
142 //
143 bool m_bDoBreak;
144
145 //
146 // The menu handle of this menu
147 //
148 WXHMENU m_hMenu;
149
150 //
151 // The helper variable for creating unique IDs.
152 //
153 static USHORT m_nextMenuId;
154
155 //
156 // The position of the first item in the current radio group or -1
157 //
158 int m_nStartRadioGroup;
159
160 #if wxUSE_ACCEL
161 //
162 // The accelerators for our menu items
163 //
164 wxAcceleratorArray m_vAccels;
165 #endif // wxUSE_ACCEL
166
167 DECLARE_DYNAMIC_CLASS(wxMenu)
168 }; // end of wxMenu
169
170 // ----------------------------------------------------------------------------
171 // Menu Bar (a la Windows)
172 // ----------------------------------------------------------------------------
173
174 class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase
175 {
176 public:
177 //
178 // Ctors & dtor
179 //
180
181 //
182 // Default constructor
183 //
184 wxMenuBar();
185
186 //
187 // Unused under OS2
188 wxMenuBar(long lStyle);
189
190 //
191 // Menubar takes ownership of the menus arrays but copies the titles
192 //
193 wxMenuBar( int n
194 ,wxMenu* vMenus[]
195 ,const wxString sTitles[]
196 ,long lStyle = 0
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 SetMenuLabel( size_t nPos
229 ,const wxString& rLabel
230 );
231 virtual wxString GetMenuLabel(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/deleting 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_