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
79 bool ProcessCommand(wxCommandEvent
& rEvent
);
83 // Implementation only from now on
84 // -------------------------------
86 bool OS2Command( WXUINT uParam
91 // Semi-private accessors
95 // Get the window which contains this menu
97 wxWindow
* GetWindow(void) const;
100 // Get the menu handle
102 WXHMENU
GetHMenu() const { return m_hMenu
; }
105 // Attach/detach menu to/from wxMenuBar
107 void Attach(wxMenuBar
* pMenubar
);
112 // Called by wxMenuBar to build its accel table from the accels of all menus
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;
119 // Called by wxMenuItem when its accels changes
121 void UpdateAccel(wxMenuItem
* pItem
);
124 // Helper used by wxMenu itself (returns the index in m_accels)
126 int FindAccel(int nId
) const;
127 #endif // wxUSE_ACCEL
129 // OS/2 specific Find
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
); }
139 // All OS/2PM Menu's have one of these
141 MENUITEM m_vMenuData
;
145 // Common part of all ctors
150 // Common part of Append/Insert (behaves as Append is pos == (size_t)-1)
152 bool DoInsertOrAppend( wxMenuItem
* pItem
153 ,size_t nPos
= (size_t)-1
157 // If TRUE, insert a breal before appending the next item
162 // The menu handle of this menu
167 // The helper variable for creating unique IDs.
169 static USHORT m_nextMenuId
;
173 // The accelerators for our menu items
175 wxAcceleratorArray m_vAccels
;
176 #endif // wxUSE_ACCEL
178 DECLARE_DYNAMIC_CLASS(wxMenu
)
181 // ----------------------------------------------------------------------------
182 // Menu Bar (a la Windows)
183 // ----------------------------------------------------------------------------
185 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
193 // Default constructor
199 wxMenuBar(long lStyle
);
202 // Menubar takes ownership of the menus arrays but copies the titles
206 ,const wxString sTitles
[]
208 virtual ~wxMenuBar();
211 // Menubar construction
213 virtual bool Append( wxMenu
* pMenu
214 ,const wxString
& rTitle
216 virtual bool Insert( size_t nPos
218 ,const wxString
& rTitle
220 virtual wxMenu
* Replace( size_t nPos
222 ,const wxString
& rTitle
224 virtual wxMenu
* Remove(size_t nPos
);
225 virtual int FindMenuItem( const wxString
& rMenuString
226 ,const wxString
& rItemString
228 virtual wxMenuItem
* FindItem( int nId
229 ,wxMenu
** ppMenu
= NULL
231 virtual wxMenuItem
* FindItem( int nId
233 ,wxMenu
** ppMenu
= NULL
235 virtual void EnableTop( size_t nPos
238 virtual void SetLabelTop( size_t nPos
239 ,const wxString
& rLabel
241 virtual wxString
GetLabelTop(size_t nPos
) const;
244 // Compatibility: these functions are deprecated
246 #if WXWIN_COMPATIBILITY
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
); }
251 #endif // WXWIN_COMPATIBILITY
254 // Implementation from now on
256 WXHMENU
Create(void);
260 // Returns TRUE if we're attached to a frame
262 bool IsAttached(void) const { return m_pMenuBarFrame
!= NULL
; }
265 // Get the frame we live in
267 wxFrame
* GetFrame(void) const { return m_pMenuBarFrame
; }
272 void Attach(wxFrame
* pFrame
);
276 // Get the accel table for all the menus
278 const wxAcceleratorTable
& GetAccelTable(void) const { return m_vAccelTable
; }
281 // Update the accel table (must be called after adding/deletign a menu)
283 void RebuildAccelTable(void);
284 #endif // wxUSE_ACCEL
287 // Get the menu handle
288 WXHMENU
GetHMenu(void) const { return m_hMenu
; }
291 // If the menubar is modified, the display is not updated automatically,
292 // call this function to update it (m_menuBarFrame should be !NULL)
298 // Common part of all ctors
302 #if WXWIN_COMPATIBILITY
303 wxEvtHandler
* m_pEventHandler
;
304 #endif // WXWIN_COMPATIBILITY
306 wxArrayString m_titles
;
308 wxFrame
* m_pMenuBarFrame
;
313 // The accelerator table for all accelerators in all our menus
315 wxAcceleratorTable m_vAccelTable
;
316 #endif // wxUSE_ACCEL
320 // Virtual function hiding suppression
322 void Refresh( bool bErase
325 { wxWindow::Refresh(bErase
, pRect
); }
327 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
330 #endif // _WX_MENU_H_