1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin (wxMenuItem is now in separate file)
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "menu.h"
21 #include "wx/dynarray.h"
23 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry
*, wxAcceleratorArray
);
26 class WXDLLEXPORT wxFrame
;
28 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
29 class WXDLLEXPORT wxToolBar
;
33 // Not using a combined wxToolBar/wxMenuBar? then use
34 // a commandbar in WinCE .NET to implement the
35 // menubar, since there is no ::SetMenu function.
36 #if defined(__WXWINCE__)
37 # if ((_WIN32_WCE >= 400) && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)) || \
38 defined(__HANDHELDPC__)
39 # define WINCE_WITH_COMMANDBAR
41 # define WINCE_WITHOUT_COMMANDBAR
46 #include "wx/arrstr.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 class WXDLLEXPORT wxMenu
: public wxMenuBase
56 wxMenu(const wxString
& title
, long style
= 0)
57 : wxMenuBase(title
, style
) { Init(); }
59 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
63 // implement base class virtuals
64 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
65 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
66 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
70 virtual void SetTitle(const wxString
& title
);
72 // implementation only from now on
73 // -------------------------------
75 virtual void Attach(wxMenuBarBase
*menubar
);
77 bool MSWCommand(WXUINT param
, WXWORD id
);
79 // semi-private accessors
80 // get the window which contains this menu
81 wxWindow
*GetWindow() const;
82 // get the menu handle
83 WXHMENU
GetHMenu() const { return m_hMenu
; }
86 // called by wxMenuBar to build its accel table from the accels of all menus
87 bool HasAccels() const { return !m_accels
.IsEmpty(); }
88 size_t GetAccelCount() const { return m_accels
.GetCount(); }
89 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
91 // called by wxMenuItem when its accels changes
92 void UpdateAccel(wxMenuItem
*item
);
94 // helper used by wxMenu itself (returns the index in m_accels)
95 int FindAccel(int id
) const;
99 // common part of all ctors
102 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
103 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
105 // terminate the current radio group, if any
106 void EndRadioGroup();
108 // if true, insert a breal before appending the next item
111 // the position of the first item in the current radio group or -1
112 int m_startRadioGroup
;
114 // the menu handle of this menu
118 // the accelerators for our menu items
119 wxAcceleratorArray m_accels
;
120 #endif // wxUSE_ACCEL
122 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu
)
125 // ----------------------------------------------------------------------------
126 // Menu Bar (a la Windows)
127 // ----------------------------------------------------------------------------
129 class WXDLLEXPORT wxMenuInfo
: public wxObject
132 wxMenuInfo() { m_menu
= NULL
; }
133 virtual ~wxMenuInfo() { }
135 void Create( wxMenu
*menu
, const wxString
&title
)
136 { m_menu
= menu
; m_title
= title
; }
137 wxMenu
* GetMenu() const { return m_menu
; }
138 wxString
GetTitle() const { return m_title
; }
143 DECLARE_DYNAMIC_CLASS(wxMenuInfo
)
146 WX_DECLARE_EXPORTED_LIST(wxMenuInfo
, wxMenuInfoList
);
148 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
152 // default constructor
155 wxMenuBar(long style
);
156 // menubar takes ownership of the menus arrays but copies the titles
157 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
158 virtual ~wxMenuBar();
160 // menubar construction
161 bool Append( wxMenuInfo
*info
) { return Append( info
->GetMenu() , info
->GetTitle() ); }
162 const wxMenuInfoList
& GetMenuInfos() const;
164 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
165 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
166 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
167 virtual wxMenu
*Remove(size_t pos
);
169 virtual void EnableTop( size_t pos
, bool flag
);
170 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
171 virtual wxString
GetLabelTop( size_t pos
) const;
173 // implementation from now on
175 virtual void Detach();
176 virtual void Attach(wxFrame
*frame
);
178 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
179 // Under WinCE, a menubar is owned by the frame's toolbar
180 void SetToolBar(wxToolBar
* toolBar
) { m_toolBar
= toolBar
; }
181 wxToolBar
* GetToolBar() const { return m_toolBar
; }
184 #ifdef WINCE_WITH_COMMANDBAR
185 WXHWND
GetCommandBar() const { return m_commandBar
; }
186 bool AddAdornments(long style
);
190 // get the accel table for all the menus
191 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
193 // update the accel table (must be called after adding/deleting a menu)
194 void RebuildAccelTable();
195 #endif // wxUSE_ACCEL
197 // get the menu handle
198 WXHMENU
GetHMenu() const { return m_hMenu
; }
200 // if the menubar is modified, the display is not updated automatically,
201 // call this function to update it (m_menuBarFrame should be !NULL)
204 // To avoid compile warning
205 void Refresh( bool eraseBackground
,
206 const wxRect
*rect
= (const wxRect
*) NULL
) { wxWindow::Refresh(eraseBackground
, rect
); }
209 // common part of all ctors
212 wxArrayString m_titles
;
213 wxMenuInfoList m_menuInfos
;
217 // Return the MSW position for a wxMenu which is sometimes different from
218 // the wxWidgets position.
219 int MSWPositionForWxMenu(wxMenu
*menu
, int wxpos
);
221 // the accelerator table for all accelerators in all our menus
222 wxAcceleratorTable m_accelTable
;
223 #endif // wxUSE_ACCEL
225 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
226 wxToolBar
* m_toolBar
;
229 #ifdef WINCE_WITH_COMMANDBAR
231 bool m_adornmentsAdded
;
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar
)
238 #endif // _WX_MENU_H_