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 wxMenuItem
* DoAppend(wxMenuItem
* pItem
);
59 virtual wxMenuItem
* 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 // 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/deletign 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_