1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 // #include "wx/accel.h"
17 // #include "wx/list.h" // for "template" list classes
18 // #include "wx/dynarray.h"
20 // WX_DECLARE_EXPORTED_LIST(wxAcceleratorEntry, wxAcceleratorList);
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 bool OS2Command( WXUINT uParam
86 // Semi-private accessors
90 // Get the window which contains this menu
92 wxWindow
* GetWindow(void) const;
95 // Get the menu handle
97 WXHMENU
GetHMenu() const { return m_hMenu
; }
101 // Called by wxMenuBar to build its accel table from the accels of all menus
103 bool HasAccels(void) const { return m_vAccels
[0] != NULL
; }
104 size_t GetAccelCount(void) const { return (size_t)m_nNextAccel
; }
105 size_t CopyAccels(wxAcceleratorEntry
* pAccels
) const;
108 // Called by wxMenuItem when its accels changes
110 void UpdateAccel(wxMenuItem
* pItem
);
113 // Helper used by wxMenu itself (returns the index in m_accels)
115 int FindAccel(int nId
) const;
116 #endif // wxUSE_ACCEL
118 // OS/2 specific Find
120 wxMenuItem
* FindItem(int id
, ULONG hItem
, wxMenu
**menu
= NULL
) const;
121 //virtual function hiding suppression
122 int FindItem(const wxString
& rsString
) const
123 { return wxMenuBase::FindItem(rsString
); }
124 wxMenuItem
* FindItem(int id
, wxMenu
**menu
= NULL
) const
125 { return wxMenuBase::FindItem(id
, menu
); }
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 // Terminate the current radio group, if any
148 void EndRadioGroup(void);
151 // If TRUE, insert a breal before appending the next item
156 // The menu handle of this menu
161 // The helper variable for creating unique IDs.
163 static USHORT m_nextMenuId
;
166 // The position of the first item in the current radio group or -1
168 int m_nStartRadioGroup
;
172 // The accelerators for our menu items
174 wxAcceleratorEntry
* m_vAccels
[128];
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);
257 virtual void Detach(void);
258 virtual void Attach(wxFrame
* pFrame
);
262 // Get the accel table for all the menus
264 const wxAcceleratorTable
& GetAccelTable(void) const { return m_vAccelTable
; }
267 // Update the accel table (must be called after adding/deletign a menu)
269 void RebuildAccelTable(void);
270 #endif // wxUSE_ACCEL
273 // Get the menu handle
274 WXHMENU
GetHMenu(void) const { return m_hMenu
; }
277 // If the menubar is modified, the display is not updated automatically,
278 // call this function to update it (m_menuBarFrame should be !NULL)
284 // Common part of all ctors
288 #if WXWIN_COMPATIBILITY
289 wxEvtHandler
* m_pEventHandler
;
290 #endif // WXWIN_COMPATIBILITY
292 wxArrayString m_titles
;
298 // The accelerator table for all accelerators in all our menus
300 wxAcceleratorTable m_vAccelTable
;
301 #endif // wxUSE_ACCEL
305 // Virtual function hiding suppression
307 void Refresh( bool bErase
310 { wxWindow::Refresh(bErase
, pRect
); }
312 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
315 #endif // _WX_MENU_H_