]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/menu.h
virtual wxListCtrl support (UNTESTED)
[wxWidgets.git] / include / wx / os2 / menu.h
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: menu.h
3// Purpose: wxMenu, wxMenuBar classes
75f11ad7 4// Author: David Webster
0e320a79 5// Modified by:
75f11ad7 6// Created: 10/10/99
0e320a79 7// RCS-ID: $Id$
75f11ad7
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_MENU_H_
13#define _WX_MENU_H_
14
75f11ad7 15#if wxUSE_ACCEL
e92f266c
DW
16 #include "wx/accel.h"
17 #include "wx/dynarray.h"
18
19 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray);
75f11ad7 20#endif // wxUSE_ACCEL
0e320a79 21
75f11ad7 22class WXDLLEXPORT wxFrame;
0e320a79 23
8c5907ce
DW
24void wxSetShortCutKey(wxChar* zText);
25
0e320a79
DW
26// ----------------------------------------------------------------------------
27// Menu
28// ----------------------------------------------------------------------------
0e320a79 29
e92f266c
DW
30class WXDLLEXPORT wxMenu : public wxMenuBase
31{
0e320a79 32public:
61243a51
DW
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 }
75f11ad7 45
61243a51
DW
46 wxMenu(long lStyle = 0)
47 : wxMenuBase(lStyle)
48 {
49 Init();
50 }
75f11ad7
DW
51
52 virtual ~wxMenu();
53
61243a51
DW
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)
e92f266c 70 {
61243a51
DW
71 Init();
72 Callback(fnFunc);
e92f266c 73 }
61243a51 74#endif // wxUSE_MENU_CALLBACK
e92f266c 75
61243a51
DW
76 //
77 // OS2-specific
78 //
79 bool ProcessCommand(wxCommandEvent& rEvent);
75f11ad7 80
75f11ad7 81
61243a51
DW
82 //
83 // Implementation only from now on
84 // -------------------------------
85 //
86 bool OS2Command( WXUINT uParam
87 ,WXWORD wId
88 );
89
90 //
91 // Semi-private accessors
92 //
93
94 //
95 // Get the window which contains this menu
96 //
97 wxWindow* GetWindow(void) const;
98
99 //
100 // Get the menu handle
101 //
e92f266c 102 WXHMENU GetHMenu() const { return m_hMenu; }
75f11ad7 103
61243a51
DW
104 //
105 // Attach/detach menu to/from wxMenuBar
106 //
107 void Attach(wxMenuBar* pMenubar);
108 void Detach(void);
75f11ad7
DW
109
110#if wxUSE_ACCEL
61243a51
DW
111 //
112 // Called by wxMenuBar to build its accel table from the accels of all menus
113 //
114 bool HasAccels(void) const { return !m_vAccels.IsEmpty(); }
115 size_t GetAccelCount(void) const { return m_vAccels.GetCount(); }
116 size_t CopyAccels(wxAcceleratorEntry* pAccels) const;
117
118 //
119 // Called by wxMenuItem when its accels changes
120 //
121 void UpdateAccel(wxMenuItem* pItem);
122
123 //
124 // Helper used by wxMenu itself (returns the index in m_accels)
125 //
126 int FindAccel(int nId) const;
e92f266c 127#endif // wxUSE_ACCEL
45bedfdd
DW
128 //
129 // OS/2 specific Find
130 //
131 wxMenuItem* FindItem(int id, ULONG hItem, wxMenu **menu = NULL) const;
132 //virtual function hiding suppression
133 int FindItem(const wxString& rsString) const
134 { return wxMenuBase::FindItem(rsString); }
135 wxMenuItem* FindItem(int id, wxMenu **menu = NULL) const
136 { return wxMenuBase::FindItem(id, menu); }
75f11ad7 137
61243a51
DW
138 //
139 // All OS/2PM Menu's have one of these
140 //
141 MENUITEM m_vMenuData;
142
75f11ad7 143private:
61243a51
DW
144 //
145 // Common part of all ctors
146 //
e92f266c
DW
147 void Init();
148
61243a51
DW
149 //
150 // Common part of Append/Insert (behaves as Append is pos == (size_t)-1)
151 //
152 bool DoInsertOrAppend( wxMenuItem* pItem
153 ,size_t nPos = (size_t)-1
154 );
155
156 //
157 // If TRUE, insert a breal before appending the next item
158 //
159 bool m_bDoBreak;
160
161 //
162 // The menu handle of this menu
163 //
164 WXHMENU m_hMenu;
75f11ad7 165
f6bcfd97
BP
166 //
167 // The helper variable for creating unique IDs.
168 //
169 static USHORT m_nextMenuId;
170
75f11ad7 171#if wxUSE_ACCEL
61243a51
DW
172 //
173 // The accelerators for our menu items
174 //
175 wxAcceleratorArray m_vAccels;
75f11ad7 176#endif // wxUSE_ACCEL
e92f266c
DW
177
178 DECLARE_DYNAMIC_CLASS(wxMenu)
61243a51 179}; // end of wxMenu
0e320a79
DW
180
181// ----------------------------------------------------------------------------
182// Menu Bar (a la Windows)
183// ----------------------------------------------------------------------------
75f11ad7 184
e92f266c 185class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
0e320a79 186{
75f11ad7 187public:
61243a51
DW
188 //
189 // Ctors & dtor
190 //
e92f266c 191
61243a51
DW
192 //
193 // Default constructor
194 //
195 wxMenuBar();
75f11ad7 196
61243a51
DW
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();
75f11ad7 209
61243a51
DW
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;
45bedfdd
DW
231 virtual wxMenuItem* FindItem( int nId
232 ,ULONG hItem
233 ,wxMenu** ppMenu = NULL
234 ) const;
61243a51
DW
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 //
e92f266c 246#if WXWIN_COMPATIBILITY
61243a51
DW
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); }
75f11ad7
DW
251#endif // WXWIN_COMPATIBILITY
252
61243a51
DW
253 //
254 // Implementation from now on
255 //
256 WXHMENU Create(void);
257 void Detach(void);
e92f266c 258
61243a51
DW
259 //
260 // Returns TRUE if we're attached to a frame
261 //
262 bool IsAttached(void) const { return m_pMenuBarFrame != NULL; }
75f11ad7 263
61243a51
DW
264 //
265 // Get the frame we live in
266 //
267 wxFrame * GetFrame(void) const { return m_pMenuBarFrame; }
e92f266c 268
61243a51
DW
269 //
270 // Attach to a frame
271 //
272 void Attach(wxFrame* pFrame);
273
274#if wxUSE_ACCEL
275 //
276 // Get the accel table for all the menus
277 //
278 const wxAcceleratorTable& GetAccelTable(void) const { return m_vAccelTable; }
279
280 //
281 // Update the accel table (must be called after adding/deletign a menu)
282 //
283 void RebuildAccelTable(void);
75f11ad7
DW
284#endif // wxUSE_ACCEL
285
61243a51
DW
286 //
287 // Get the menu handle
288 WXHMENU GetHMenu(void) const { return m_hMenu; }
75f11ad7 289
61243a51
DW
290 //
291 // If the menubar is modified, the display is not updated automatically,
75f11ad7 292 // call this function to update it (m_menuBarFrame should be !NULL)
61243a51
DW
293 //
294 void Refresh(void);
75f11ad7
DW
295
296protected:
61243a51
DW
297 //
298 // Common part of all ctors
299 //
300 void Init(void);
75f11ad7 301
e92f266c 302#if WXWIN_COMPATIBILITY
61243a51 303 wxEvtHandler* m_pEventHandler;
e92f266c
DW
304#endif // WXWIN_COMPATIBILITY
305
306 wxArrayString m_titles;
307
61243a51 308 wxFrame* m_pMenuBarFrame;
0fe536e3 309 WXHMENU m_hMenu;
75f11ad7
DW
310
311#if wxUSE_ACCEL
61243a51
DW
312 //
313 // The accelerator table for all accelerators in all our menus
314 //
315 wxAcceleratorTable m_vAccelTable;
75f11ad7 316#endif // wxUSE_ACCEL
e92f266c
DW
317
318private:
61243a51
DW
319 //
320 // Virtual function hiding suppression
321 //
322 void Refresh( bool bErase
323 ,const wxRect* pRect
324 )
325 { wxWindow::Refresh(bErase, pRect); }
326
e92f266c 327 DECLARE_DYNAMIC_CLASS(wxMenuBar)
0e320a79
DW
328};
329
330#endif // _WX_MENU_H_