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 void wxSetShortCutKey(wxChar
* zText
);
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class WXDLLEXPORT wxMenu
: public wxMenuBase
36 wxMenu( const wxString
& rTitle
46 wxMenu(long lStyle
= 0)
55 // Implement base class virtuals
57 virtual bool DoAppend(wxMenuItem
* pItem
);
58 virtual bool DoInsert( size_t nPos
61 virtual wxMenuItem
* DoRemove(wxMenuItem
* pItem
);
62 virtual void Break(void);
63 virtual void SetTitle(const wxString
& rTitle
);
65 #if wxUSE_MENU_CALLBACK
66 wxMenu( const wxString
& rTitle
67 ,const wxFunction fnFunc
74 #endif // wxUSE_MENU_CALLBACK
77 // Implementation only from now on
78 // -------------------------------
80 bool OS2Command( WXUINT uParam
85 // Semi-private accessors
89 // Get the window which contains this menu
91 wxWindow
* GetWindow(void) const;
94 // Get the menu handle
96 WXHMENU
GetHMenu() const { return m_hMenu
; }
100 // Called by wxMenuBar to build its accel table from the accels of all menus
102 bool HasAccels(void) const { return !m_vAccels
.IsEmpty(); }
103 size_t GetAccelCount(void) const { return m_vAccels
.GetCount(); }
104 size_t CopyAccels(wxAcceleratorEntry
* pAccels
) const;
107 // Called by wxMenuItem when its accels changes
109 void UpdateAccel(wxMenuItem
* pItem
);
112 // Helper used by wxMenu itself (returns the index in m_accels)
114 int FindAccel(int nId
) const;
115 #endif // wxUSE_ACCEL
117 // OS/2 specific Find
119 wxMenuItem
* FindItem(int id
, ULONG hItem
, wxMenu
**menu
= NULL
) const;
120 //virtual function hiding suppression
121 int FindItem(const wxString
& rsString
) const
122 { return wxMenuBase::FindItem(rsString
); }
123 wxMenuItem
* FindItem(int id
, wxMenu
**menu
= NULL
) const
124 { return wxMenuBase::FindItem(id
, menu
); }
127 // All OS/2PM Menu's have one of these
129 MENUITEM m_vMenuData
;
133 // Common part of all ctors
138 // Common part of Append/Insert (behaves as Append is pos == (size_t)-1)
140 bool DoInsertOrAppend( wxMenuItem
* pItem
141 ,size_t nPos
= (size_t)-1
145 // If TRUE, insert a breal before appending the next item
150 // The menu handle of this menu
155 // The helper variable for creating unique IDs.
157 static USHORT m_nextMenuId
;
161 // The accelerators for our menu items
163 wxAcceleratorArray m_vAccels
;
164 #endif // wxUSE_ACCEL
166 DECLARE_DYNAMIC_CLASS(wxMenu
)
169 // ----------------------------------------------------------------------------
170 // Menu Bar (a la Windows)
171 // ----------------------------------------------------------------------------
173 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
181 // Default constructor
187 wxMenuBar(long lStyle
);
190 // Menubar takes ownership of the menus arrays but copies the titles
194 ,const wxString sTitles
[]
196 virtual ~wxMenuBar();
199 // Menubar construction
201 virtual bool Append( wxMenu
* pMenu
202 ,const wxString
& rTitle
204 virtual bool Insert( size_t nPos
206 ,const wxString
& rTitle
208 virtual wxMenu
* Replace( size_t nPos
210 ,const wxString
& rTitle
212 virtual wxMenu
* Remove(size_t nPos
);
213 virtual int FindMenuItem( const wxString
& rMenuString
214 ,const wxString
& rItemString
216 virtual wxMenuItem
* FindItem( int nId
217 ,wxMenu
** ppMenu
= NULL
219 virtual wxMenuItem
* FindItem( int nId
221 ,wxMenu
** ppMenu
= NULL
223 virtual void EnableTop( size_t nPos
226 virtual void SetLabelTop( size_t nPos
227 ,const wxString
& rLabel
229 virtual wxString
GetLabelTop(size_t nPos
) const;
232 // Compatibility: these functions are deprecated
234 #if WXWIN_COMPATIBILITY
235 void SetEventHandler(wxEvtHandler
* pHandler
) { m_pEventHandler
= pHandler
; }
236 wxEvtHandler
* GetEventHandler(void) { return m_pEventHandler
; }
237 bool Enabled(int nId
) const { return IsEnabled(nId
); }
238 bool Checked(int nId
) const { return IsChecked(nId
); }
239 #endif // WXWIN_COMPATIBILITY
242 // Implementation from now on
244 WXHMENU
Create(void);
245 virtual void Detach(void);
246 virtual void Attach(wxFrame
* pFrame
);
250 // Get the accel table for all the menus
252 const wxAcceleratorTable
& GetAccelTable(void) const { return m_vAccelTable
; }
255 // Update the accel table (must be called after adding/deletign a menu)
257 void RebuildAccelTable(void);
258 #endif // wxUSE_ACCEL
261 // Get the menu handle
262 WXHMENU
GetHMenu(void) const { return m_hMenu
; }
265 // If the menubar is modified, the display is not updated automatically,
266 // call this function to update it (m_menuBarFrame should be !NULL)
272 // Common part of all ctors
276 #if WXWIN_COMPATIBILITY
277 wxEvtHandler
* m_pEventHandler
;
278 #endif // WXWIN_COMPATIBILITY
280 wxArrayString m_titles
;
286 // The accelerator table for all accelerators in all our menus
288 wxAcceleratorTable m_vAccelTable
;
289 #endif // wxUSE_ACCEL
293 // Virtual function hiding suppression
295 void Refresh( bool bErase
298 { wxWindow::Refresh(bErase
, pRect
); }
300 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
303 #endif // _WX_MENU_H_