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 // deprecated functions
73 #if wxUSE_MENU_CALLBACK
74 wxMenu(const wxString
& title
, const wxFunction func
)
81 #endif // wxUSE_MENU_CALLBACK
83 // implementation only from now on
84 // -------------------------------
86 virtual void Attach(wxMenuBarBase
*menubar
);
88 bool MSWCommand(WXUINT param
, WXWORD id
);
90 // semi-private accessors
91 // get the window which contains this menu
92 wxWindow
*GetWindow() const;
93 // get the menu handle
94 WXHMENU
GetHMenu() const { return m_hMenu
; }
97 // called by wxMenuBar to build its accel table from the accels of all menus
98 bool HasAccels() const { return !m_accels
.IsEmpty(); }
99 size_t GetAccelCount() const { return m_accels
.GetCount(); }
100 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
102 // called by wxMenuItem when its accels changes
103 void UpdateAccel(wxMenuItem
*item
);
105 // helper used by wxMenu itself (returns the index in m_accels)
106 int FindAccel(int id
) const;
107 #endif // wxUSE_ACCEL
110 // common part of all ctors
113 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
114 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
116 // terminate the current radio group, if any
117 void EndRadioGroup();
119 // if true, insert a breal before appending the next item
122 // the position of the first item in the current radio group or -1
123 int m_startRadioGroup
;
125 // the menu handle of this menu
129 // the accelerators for our menu items
130 wxAcceleratorArray m_accels
;
131 #endif // wxUSE_ACCEL
133 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu
)
136 // ----------------------------------------------------------------------------
137 // Menu Bar (a la Windows)
138 // ----------------------------------------------------------------------------
140 class WXDLLEXPORT wxMenuInfo
: public wxObject
143 wxMenuInfo() { m_menu
= NULL
; }
144 virtual ~wxMenuInfo() { }
146 void Create( wxMenu
*menu
, const wxString
&title
)
147 { m_menu
= menu
; m_title
= title
; }
148 wxMenu
* GetMenu() const { return m_menu
; }
149 wxString
GetTitle() const { return m_title
; }
154 DECLARE_DYNAMIC_CLASS(wxMenuInfo
)
157 WX_DECLARE_EXPORTED_LIST(wxMenuInfo
, wxMenuInfoList
);
159 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
163 // default constructor
166 wxMenuBar(long style
);
167 // menubar takes ownership of the menus arrays but copies the titles
168 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
169 virtual ~wxMenuBar();
171 // menubar construction
172 bool Append( wxMenuInfo
*info
) { return Append( info
->GetMenu() , info
->GetTitle() ); }
173 const wxMenuInfoList
& GetMenuInfos() const;
175 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
176 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
177 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
178 virtual wxMenu
*Remove(size_t pos
);
180 virtual void EnableTop( size_t pos
, bool flag
);
181 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
182 virtual wxString
GetLabelTop( size_t pos
) const;
184 // implementation from now on
186 virtual void Detach();
187 virtual void Attach(wxFrame
*frame
);
189 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
190 // Under WinCE, a menubar is owned by the frame's toolbar
191 void SetToolBar(wxToolBar
* toolBar
) { m_toolBar
= toolBar
; }
192 wxToolBar
* GetToolBar() const { return m_toolBar
; }
195 #ifdef WINCE_WITH_COMMANDBAR
196 WXHWND
GetCommandBar() const { return m_commandBar
; }
197 bool AddAdornments(long style
);
201 // get the accel table for all the menus
202 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
204 // update the accel table (must be called after adding/deleting a menu)
205 void RebuildAccelTable();
206 #endif // wxUSE_ACCEL
208 // get the menu handle
209 WXHMENU
GetHMenu() const { return m_hMenu
; }
211 // if the menubar is modified, the display is not updated automatically,
212 // call this function to update it (m_menuBarFrame should be !NULL)
215 // To avoid compile warning
216 void Refresh( bool eraseBackground
,
217 const wxRect
*rect
= (const wxRect
*) NULL
) { wxWindow::Refresh(eraseBackground
, rect
); }
220 // common part of all ctors
223 wxArrayString m_titles
;
224 wxMenuInfoList m_menuInfos
;
228 // Return the MSW position for a wxMenu which is sometimes different from
229 // the wxWidgets position.
230 int MSWPositionForWxMenu(wxMenu
*menu
, int wxpos
);
232 // the accelerator table for all accelerators in all our menus
233 wxAcceleratorTable m_accelTable
;
234 #endif // wxUSE_ACCEL
236 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
237 wxToolBar
* m_toolBar
;
240 #ifdef WINCE_WITH_COMMANDBAR
242 bool m_adornmentsAdded
;
246 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar
)
249 #endif // _WX_MENU_H_