1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/list.h" // for "template" list classes
18 #include "wx/dynarray.h"
20 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry
*, wxAcceleratorArray
);
23 class WXDLLEXPORT wxFrame
;
25 void wxSetShortCutKey(wxChar
* zText
);
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxMenu
: public wxMenuBase
37 wxMenu( const wxString
& rTitle
47 wxMenu(long lStyle
= 0)
56 // Implement base class virtuals
58 virtual bool DoAppend(wxMenuItem
* pItem
);
59 virtual bool DoInsert( size_t nPos
62 virtual wxMenuItem
* DoRemove(wxMenuItem
* pItem
);
63 virtual void Break(void);
64 virtual void SetTitle(const wxString
& rTitle
);
67 // Implementation only from now on
68 // -------------------------------
70 virtual void Attach(wxMenuBarBase
* pMenubar
);
72 bool OS2Command( WXUINT uParam
77 // Semi-private accessors
81 // Get the window which contains this menu
83 wxWindow
* GetWindow(void) const;
86 // Get the menu handle
88 WXHMENU
GetHMenu() const { return m_hMenu
; }
92 // Called by wxMenuBar to build its accel table from the accels of all menus
94 bool HasAccels(void) const { return m_vAccels
.IsEmpty(); }
95 size_t GetAccelCount(void) const { return m_vAccels
.GetCount(); }
96 size_t CopyAccels(wxAcceleratorEntry
* pAccels
) const;
99 // Called by wxMenuItem when its accels changes
101 void UpdateAccel(wxMenuItem
* pItem
);
104 // Helper used by wxMenu itself (returns the index in m_accels)
106 int FindAccel(int nId
) const;
107 #endif // wxUSE_ACCEL
109 // OS/2 specific Find
111 wxMenuItem
* FindItem(int id
, ULONG hItem
, wxMenu
**menu
= NULL
) const;
112 //virtual function hiding suppression
113 int FindItem(const wxString
& rsString
) const
114 { return wxMenuBase::FindItem(rsString
); }
115 wxMenuItem
* FindItem(int id
, wxMenu
**menu
= NULL
) const
116 { return wxMenuBase::FindItem(id
, menu
); }
119 // All OS/2PM Menu's have one of these
121 MENUITEM m_vMenuData
;
125 // Common part of all ctors
130 // Common part of Append/Insert (behaves as Append is pos == (size_t)-1)
132 bool DoInsertOrAppend( wxMenuItem
* pItem
133 ,size_t nPos
= (size_t)-1
137 // Terminate the current radio group, if any
139 void EndRadioGroup(void);
142 // If TRUE, insert a breal before appending the next item
147 // The menu handle of this menu
152 // The helper variable for creating unique IDs.
154 static USHORT m_nextMenuId
;
157 // The position of the first item in the current radio group or -1
159 int m_nStartRadioGroup
;
163 // The accelerators for our menu items
165 wxAcceleratorArray m_vAccels
;
166 #endif // wxUSE_ACCEL
168 DECLARE_DYNAMIC_CLASS(wxMenu
)
171 // ----------------------------------------------------------------------------
172 // Menu Bar (a la Windows)
173 // ----------------------------------------------------------------------------
175 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
183 // Default constructor
189 wxMenuBar(long lStyle
);
192 // Menubar takes ownership of the menus arrays but copies the titles
196 ,const wxString sTitles
[]
198 virtual ~wxMenuBar();
201 // Menubar construction
203 virtual bool Append( wxMenu
* pMenu
204 ,const wxString
& rTitle
206 virtual bool Insert( size_t nPos
208 ,const wxString
& rTitle
210 virtual wxMenu
* Replace( size_t nPos
212 ,const wxString
& rTitle
214 virtual wxMenu
* Remove(size_t nPos
);
215 virtual int FindMenuItem( const wxString
& rMenuString
216 ,const wxString
& rItemString
218 virtual wxMenuItem
* FindItem( int nId
219 ,wxMenu
** ppMenu
= NULL
221 virtual wxMenuItem
* FindItem( int nId
223 ,wxMenu
** ppMenu
= NULL
225 virtual void EnableTop( size_t nPos
228 virtual void SetLabelTop( size_t nPos
229 ,const wxString
& rLabel
231 virtual wxString
GetLabelTop(size_t nPos
) const;
234 // Compatibility: these functions are deprecated
236 #if WXWIN_COMPATIBILITY
237 void SetEventHandler(wxEvtHandler
* pHandler
) { m_pEventHandler
= pHandler
; }
238 wxEvtHandler
* GetEventHandler(void) { return m_pEventHandler
; }
239 bool Enabled(int nId
) const { return IsEnabled(nId
); }
240 bool Checked(int nId
) const { return IsChecked(nId
); }
241 #endif // WXWIN_COMPATIBILITY
244 // Implementation from now on
246 WXHMENU
Create(void);
247 virtual void Detach(void);
248 virtual void Attach(wxFrame
* pFrame
);
252 // Get the accel table for all the menus
254 const wxAcceleratorTable
& GetAccelTable(void) const { return m_vAccelTable
; }
257 // Update the accel table (must be called after adding/deletign a menu)
259 void RebuildAccelTable(void);
260 #endif // wxUSE_ACCEL
263 // Get the menu handle
264 WXHMENU
GetHMenu(void) const { return m_hMenu
; }
267 // If the menubar is modified, the display is not updated automatically,
268 // call this function to update it (m_menuBarFrame should be !NULL)
274 // Common part of all ctors
278 #if WXWIN_COMPATIBILITY
279 wxEvtHandler
* m_pEventHandler
;
280 #endif // WXWIN_COMPATIBILITY
282 wxArrayString m_titles
;
288 // The accelerator table for all accelerators in all our menus
290 wxAcceleratorTable m_vAccelTable
;
291 #endif // wxUSE_ACCEL
295 // Virtual function hiding suppression
297 void Refresh( bool bErase
300 { wxWindow::Refresh(bErase
, pRect
); }
302 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
305 #endif // _WX_MENU_H_