1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/dynarray.h"
19 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry
*, wxAcceleratorArray
);
22 class WXDLLEXPORT wxFrame
;
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 class WXDLLEXPORT wxMenu
: public wxMenuBase
34 wxMenu( const wxString
& rTitle
44 wxMenu(long lStyle
= 0)
53 // Implement base class virtuals
55 virtual bool DoAppend(wxMenuItem
* pItem
);
56 virtual bool DoInsert( size_t nPos
59 virtual wxMenuItem
* DoRemove(wxMenuItem
* pItem
);
60 virtual void Break(void);
61 virtual void SetTitle(const wxString
& rTitle
);
63 #if wxUSE_MENU_CALLBACK
64 wxMenu( const wxString
& rTitle
65 ,const wxFunction fnFunc
72 #endif // wxUSE_MENU_CALLBACK
77 bool ProcessCommand(wxCommandEvent
& rEvent
);
81 // Implementation only from now on
82 // -------------------------------
84 bool OS2Command( WXUINT uParam
89 // Semi-private accessors
93 // Get the window which contains this menu
95 wxWindow
* GetWindow(void) const;
98 // Get the menu handle
100 WXHMENU
GetHMenu() const { return m_hMenu
; }
103 // Attach/detach menu to/from wxMenuBar
105 void Attach(wxMenuBar
* pMenubar
);
110 // Called by wxMenuBar to build its accel table from the accels of all menus
112 bool HasAccels(void) const { return !m_vAccels
.IsEmpty(); }
113 size_t GetAccelCount(void) const { return m_vAccels
.GetCount(); }
114 size_t CopyAccels(wxAcceleratorEntry
* pAccels
) const;
117 // Called by wxMenuItem when its accels changes
119 void UpdateAccel(wxMenuItem
* pItem
);
122 // Helper used by wxMenu itself (returns the index in m_accels)
124 int FindAccel(int nId
) const;
125 #endif // wxUSE_ACCEL
128 // All OS/2PM Menu's have one of these
130 MENUITEM m_vMenuData
;
134 // Common part of all ctors
139 // Common part of Append/Insert (behaves as Append is pos == (size_t)-1)
141 bool DoInsertOrAppend( wxMenuItem
* pItem
142 ,size_t nPos
= (size_t)-1
146 // If TRUE, insert a breal before appending the next item
151 // The menu handle of this menu
157 // The accelerators for our menu items
159 wxAcceleratorArray m_vAccels
;
160 #endif // wxUSE_ACCEL
162 DECLARE_DYNAMIC_CLASS(wxMenu
)
165 // ----------------------------------------------------------------------------
166 // Menu Bar (a la Windows)
167 // ----------------------------------------------------------------------------
169 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
177 // Default constructor
183 wxMenuBar(long lStyle
);
186 // Menubar takes ownership of the menus arrays but copies the titles
190 ,const wxString sTitles
[]
192 virtual ~wxMenuBar();
195 // Menubar construction
197 virtual bool Append( wxMenu
* pMenu
198 ,const wxString
& rTitle
200 virtual bool Insert( size_t nPos
202 ,const wxString
& rTitle
204 virtual wxMenu
* Replace( size_t nPos
206 ,const wxString
& rTitle
208 virtual wxMenu
* Remove(size_t nPos
);
209 virtual int FindMenuItem( const wxString
& rMenuString
210 ,const wxString
& rItemString
212 virtual wxMenuItem
* FindItem( int nId
213 ,wxMenu
** ppMenu
= NULL
216 virtual void EnableTop( size_t nPos
219 virtual void SetLabelTop( size_t nPos
220 ,const wxString
& rLabel
222 virtual wxString
GetLabelTop(size_t nPos
) const;
225 // Compatibility: these functions are deprecated
227 #if WXWIN_COMPATIBILITY
228 void SetEventHandler(wxEvtHandler
* pHandler
) { m_pEventHandler
= pHandler
; }
229 wxEvtHandler
* GetEventHandler(void) { return m_pEventHandler
; }
230 bool Enabled(int nId
) const { return IsEnabled(nId
); }
231 bool Checked(int nId
) const { return IsChecked(nId
); }
232 #endif // WXWIN_COMPATIBILITY
235 // Implementation from now on
237 WXHMENU
Create(void);
241 // Returns TRUE if we're attached to a frame
243 bool IsAttached(void) const { return m_pMenuBarFrame
!= NULL
; }
246 // Get the frame we live in
248 wxFrame
* GetFrame(void) const { return m_pMenuBarFrame
; }
253 void Attach(wxFrame
* pFrame
);
257 // Get the accel table for all the menus
259 const wxAcceleratorTable
& GetAccelTable(void) const { return m_vAccelTable
; }
262 // Update the accel table (must be called after adding/deletign a menu)
264 void RebuildAccelTable(void);
265 #endif // wxUSE_ACCEL
268 // Get the menu handle
269 WXHMENU
GetHMenu(void) const { return m_hMenu
; }
272 // If the menubar is modified, the display is not updated automatically,
273 // call this function to update it (m_menuBarFrame should be !NULL)
279 // Common part of all ctors
283 #if WXWIN_COMPATIBILITY
284 wxEvtHandler
* m_pEventHandler
;
285 #endif // WXWIN_COMPATIBILITY
287 wxArrayString m_titles
;
289 wxFrame
* m_pMenuBarFrame
;
294 // The accelerator table for all accelerators in all our menus
296 wxAcceleratorTable m_vAccelTable
;
297 #endif // wxUSE_ACCEL
301 // Virtual function hiding suppression
303 void Refresh( bool bErase
306 { wxWindow::Refresh(bErase
, pRect
); }
308 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
311 #endif // _WX_MENU_H_