1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/list.h" // for "template" list classes
17 #include "wx/dynarray.h"
19 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry
*, wxAcceleratorArray
);
22 class WXDLLIMPEXP_FWD_CORE wxFrame
;
24 void wxSetShortCutKey(wxChar
* zText
);
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class WXDLLIMPEXP_CORE wxMenu
: public wxMenuBase
36 wxMenu( const wxString
& rTitle
46 wxMenu(long lStyle
= 0)
55 // Implement base class virtuals
57 virtual wxMenuItem
* DoAppend(wxMenuItem
* pItem
);
58 virtual wxMenuItem
* DoInsert( size_t nPos
61 virtual wxMenuItem
* DoRemove(wxMenuItem
* pItem
);
62 virtual void Break(void);
63 virtual void SetTitle(const wxString
& rTitle
);
66 // Implementation only from now on
67 // -------------------------------
69 virtual void Attach(wxMenuBarBase
* pMenubar
);
71 bool OS2Command( WXUINT uParam
76 // Semi-private accessors
80 // Get the window which contains this menu
82 wxWindow
* GetWindow(void) const;
85 // Get the menu handle
87 WXHMENU
GetHMenu() const { return m_hMenu
; }
91 // Called by wxMenuBar to build its accel table from the accels of all menus
93 bool HasAccels(void) const { return m_vAccels
.IsEmpty(); }
94 size_t GetAccelCount(void) const { return m_vAccels
.GetCount(); }
95 size_t CopyAccels(wxAcceleratorEntry
* pAccels
) const;
98 // Called by wxMenuItem when its accels changes
100 void UpdateAccel(wxMenuItem
* pItem
);
103 // Helper used by wxMenu itself (returns the index in m_accels)
105 int FindAccel(int nId
) const;
106 #endif // wxUSE_ACCEL
108 // OS/2 specific Find
110 wxMenuItem
* FindItem(int id
, ULONG hItem
, wxMenu
**menu
= NULL
) const;
111 //virtual function hiding suppression
112 int FindItem(const wxString
& rsString
) const
113 { return wxMenuBase::FindItem(rsString
); }
114 wxMenuItem
* FindItem(int id
, wxMenu
**menu
= NULL
) const
115 { return wxMenuBase::FindItem(id
, menu
); }
118 // All OS/2PM Menu's have one of these
120 MENUITEM m_vMenuData
;
124 // Common part of all ctors
129 // Common part of Append/Insert (behaves as Append is pos == (size_t)-1)
131 bool DoInsertOrAppend( wxMenuItem
* pItem
132 ,size_t nPos
= (size_t)-1
136 // Terminate the current radio group, if any
138 void EndRadioGroup(void);
141 // If true, insert a breal before appending the next item
146 // The menu handle of this menu
151 // The helper variable for creating unique IDs.
153 static USHORT m_nextMenuId
;
156 // The position of the first item in the current radio group or -1
158 int m_nStartRadioGroup
;
162 // The accelerators for our menu items
164 wxAcceleratorArray m_vAccels
;
165 #endif // wxUSE_ACCEL
167 DECLARE_DYNAMIC_CLASS(wxMenu
)
170 // ----------------------------------------------------------------------------
171 // Menu Bar (a la Windows)
172 // ----------------------------------------------------------------------------
174 class WXDLLIMPEXP_CORE wxMenuBar
: public wxMenuBarBase
182 // Default constructor
188 wxMenuBar(long lStyle
);
191 // Menubar takes ownership of the menus arrays but copies the titles
195 ,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 SetMenuLabel( size_t nPos
229 ,const wxString
& rLabel
231 virtual wxString
GetMenuLabel(size_t nPos
) const;
234 // Implementation from now on
236 WXHMENU
Create(void);
237 virtual void Detach(void);
238 virtual void Attach(wxFrame
* pFrame
);
242 // Get the accel table for all the menus
244 const wxAcceleratorTable
& GetAccelTable(void) const { return m_vAccelTable
; }
247 // Update the accel table (must be called after adding/deleting a menu)
249 void RebuildAccelTable(void);
250 #endif // wxUSE_ACCEL
253 // Get the menu handle
254 WXHMENU
GetHMenu(void) const { return m_hMenu
; }
257 // If the menubar is modified, the display is not updated automatically,
258 // call this function to update it (m_menuBarFrame should be !NULL)
264 // Common part of all ctors
268 wxArrayString m_titles
;
274 // The accelerator table for all accelerators in all our menus
276 wxAcceleratorTable m_vAccelTable
;
277 #endif // wxUSE_ACCEL
281 // Virtual function hiding suppression
283 void Refresh( bool bErase
286 { wxWindow::Refresh(bErase
, pRect
); }
288 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
291 #endif // _WX_MENU_H_