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
[]
199 virtual ~wxMenuBar();
202 // Menubar construction
204 virtual bool Append( wxMenu
* pMenu
205 ,const wxString
& rTitle
207 virtual bool Insert( size_t nPos
209 ,const wxString
& rTitle
211 virtual wxMenu
* Replace( size_t nPos
213 ,const wxString
& rTitle
215 virtual wxMenu
* Remove(size_t nPos
);
216 virtual int FindMenuItem( const wxString
& rMenuString
217 ,const wxString
& rItemString
219 virtual wxMenuItem
* FindItem( int nId
220 ,wxMenu
** ppMenu
= NULL
222 virtual wxMenuItem
* FindItem( int nId
224 ,wxMenu
** ppMenu
= NULL
226 virtual void EnableTop( size_t nPos
229 virtual void SetLabelTop( size_t nPos
230 ,const wxString
& rLabel
232 virtual wxString
GetLabelTop(size_t nPos
) const;
235 // Implementation from now on
237 WXHMENU
Create(void);
238 virtual void Detach(void);
239 virtual void Attach(wxFrame
* pFrame
);
243 // Get the accel table for all the menus
245 const wxAcceleratorTable
& GetAccelTable(void) const { return m_vAccelTable
; }
248 // Update the accel table (must be called after adding/deleting a menu)
250 void RebuildAccelTable(void);
251 #endif // wxUSE_ACCEL
254 // Get the menu handle
255 WXHMENU
GetHMenu(void) const { return m_hMenu
; }
258 // If the menubar is modified, the display is not updated automatically,
259 // call this function to update it (m_menuBarFrame should be !NULL)
265 // Common part of all ctors
269 wxArrayString m_titles
;
275 // The accelerator table for all accelerators in all our menus
277 wxAcceleratorTable m_vAccelTable
;
278 #endif // wxUSE_ACCEL
282 // Virtual function hiding suppression
284 void Refresh( bool bErase
287 { wxWindow::Refresh(bErase
, pRect
); }
289 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
292 #endif // _WX_MENU_H_