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
);
66 #if wxUSE_MENU_CALLBACK
67 wxMenu( const wxString
& rTitle
68 ,const wxFunction fnFunc
75 #endif // wxUSE_MENU_CALLBACK
78 // Implementation only from now on
79 // -------------------------------
81 virtual void Attach(wxMenuBarBase
* pMenubar
);
83 bool OS2Command( WXUINT uParam
88 // Semi-private accessors
92 // Get the window which contains this menu
94 wxWindow
* GetWindow(void) const;
97 // Get the menu handle
99 WXHMENU
GetHMenu() const { return m_hMenu
; }
103 // Called by wxMenuBar to build its accel table from the accels of all menus
105 bool HasAccels(void) const { return m_vAccels
.IsEmpty(); }
106 size_t GetAccelCount(void) const { return m_vAccels
.GetCount(); }
107 size_t CopyAccels(wxAcceleratorEntry
* pAccels
) const;
110 // Called by wxMenuItem when its accels changes
112 void UpdateAccel(wxMenuItem
* pItem
);
115 // Helper used by wxMenu itself (returns the index in m_accels)
117 int FindAccel(int nId
) const;
118 #endif // wxUSE_ACCEL
120 // OS/2 specific Find
122 wxMenuItem
* FindItem(int id
, ULONG hItem
, wxMenu
**menu
= NULL
) const;
123 //virtual function hiding suppression
124 int FindItem(const wxString
& rsString
) const
125 { return wxMenuBase::FindItem(rsString
); }
126 wxMenuItem
* FindItem(int id
, wxMenu
**menu
= NULL
) const
127 { return wxMenuBase::FindItem(id
, menu
); }
130 // All OS/2PM Menu's have one of these
132 MENUITEM m_vMenuData
;
136 // Common part of all ctors
141 // Common part of Append/Insert (behaves as Append is pos == (size_t)-1)
143 bool DoInsertOrAppend( wxMenuItem
* pItem
144 ,size_t nPos
= (size_t)-1
148 // Terminate the current radio group, if any
150 void EndRadioGroup(void);
153 // If TRUE, insert a breal before appending the next item
158 // The menu handle of this menu
163 // The helper variable for creating unique IDs.
165 static USHORT m_nextMenuId
;
168 // The position of the first item in the current radio group or -1
170 int m_nStartRadioGroup
;
174 // The accelerators for our menu items
176 wxAcceleratorArray m_vAccels
;
177 #endif // wxUSE_ACCEL
179 DECLARE_DYNAMIC_CLASS(wxMenu
)
182 // ----------------------------------------------------------------------------
183 // Menu Bar (a la Windows)
184 // ----------------------------------------------------------------------------
186 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
194 // Default constructor
200 wxMenuBar(long lStyle
);
203 // Menubar takes ownership of the menus arrays but copies the titles
207 ,const wxString sTitles
[]
209 virtual ~wxMenuBar();
212 // Menubar construction
214 virtual bool Append( wxMenu
* pMenu
215 ,const wxString
& rTitle
217 virtual bool Insert( size_t nPos
219 ,const wxString
& rTitle
221 virtual wxMenu
* Replace( size_t nPos
223 ,const wxString
& rTitle
225 virtual wxMenu
* Remove(size_t nPos
);
226 virtual int FindMenuItem( const wxString
& rMenuString
227 ,const wxString
& rItemString
229 virtual wxMenuItem
* FindItem( int nId
230 ,wxMenu
** ppMenu
= NULL
232 virtual wxMenuItem
* FindItem( int nId
234 ,wxMenu
** ppMenu
= NULL
236 virtual void EnableTop( size_t nPos
239 virtual void SetLabelTop( size_t nPos
240 ,const wxString
& rLabel
242 virtual wxString
GetLabelTop(size_t nPos
) const;
245 // Compatibility: these functions are deprecated
247 #if WXWIN_COMPATIBILITY
248 void SetEventHandler(wxEvtHandler
* pHandler
) { m_pEventHandler
= pHandler
; }
249 wxEvtHandler
* GetEventHandler(void) { return m_pEventHandler
; }
250 bool Enabled(int nId
) const { return IsEnabled(nId
); }
251 bool Checked(int nId
) const { return IsChecked(nId
); }
252 #endif // WXWIN_COMPATIBILITY
255 // Implementation from now on
257 WXHMENU
Create(void);
258 virtual void Detach(void);
259 virtual void Attach(wxFrame
* pFrame
);
263 // Get the accel table for all the menus
265 const wxAcceleratorTable
& GetAccelTable(void) const { return m_vAccelTable
; }
268 // Update the accel table (must be called after adding/deletign a menu)
270 void RebuildAccelTable(void);
271 #endif // wxUSE_ACCEL
274 // Get the menu handle
275 WXHMENU
GetHMenu(void) const { return m_hMenu
; }
278 // If the menubar is modified, the display is not updated automatically,
279 // call this function to update it (m_menuBarFrame should be !NULL)
285 // Common part of all ctors
289 #if WXWIN_COMPATIBILITY
290 wxEvtHandler
* m_pEventHandler
;
291 #endif // WXWIN_COMPATIBILITY
293 wxArrayString m_titles
;
299 // The accelerator table for all accelerators in all our menus
301 wxAcceleratorTable m_vAccelTable
;
302 #endif // wxUSE_ACCEL
306 // Virtual function hiding suppression
308 void Refresh( bool bErase
311 { wxWindow::Refresh(bErase
, pRect
); }
313 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
316 #endif // _WX_MENU_H_