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
;
32 #include "wx/arrstr.h"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxMenu
: public wxMenuBase
42 wxMenu(const wxString
& title
, long style
= 0)
43 : wxMenuBase(title
, style
) { Init(); }
45 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
49 // implement base class virtuals
50 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
51 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
52 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
56 virtual void SetTitle(const wxString
& title
);
58 // deprecated functions
59 #if wxUSE_MENU_CALLBACK
60 wxMenu(const wxString
& title
, const wxFunction func
)
67 #endif // wxUSE_MENU_CALLBACK
69 // implementation only from now on
70 // -------------------------------
72 virtual void Attach(wxMenuBarBase
*menubar
);
74 bool MSWCommand(WXUINT param
, WXWORD id
);
76 // semi-private accessors
77 // get the window which contains this menu
78 wxWindow
*GetWindow() const;
79 // get the menu handle
80 WXHMENU
GetHMenu() const { return m_hMenu
; }
83 // called by wxMenuBar to build its accel table from the accels of all menus
84 bool HasAccels() const { return !m_accels
.IsEmpty(); }
85 size_t GetAccelCount() const { return m_accels
.GetCount(); }
86 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
88 // called by wxMenuItem when its accels changes
89 void UpdateAccel(wxMenuItem
*item
);
91 // helper used by wxMenu itself (returns the index in m_accels)
92 int FindAccel(int id
) const;
96 // common part of all ctors
99 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
100 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
102 // terminate the current radio group, if any
103 void EndRadioGroup();
105 // if TRUE, insert a breal before appending the next item
108 // the position of the first item in the current radio group or -1
109 int m_startRadioGroup
;
111 // the menu handle of this menu
115 // the accelerators for our menu items
116 wxAcceleratorArray m_accels
;
117 #endif // wxUSE_ACCEL
119 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu
)
122 // ----------------------------------------------------------------------------
123 // Menu Bar (a la Windows)
124 // ----------------------------------------------------------------------------
126 class WXDLLEXPORT wxMenuInfo
: public wxObject
129 wxMenuInfo() { m_menu
= NULL
; }
130 virtual ~wxMenuInfo() { }
132 void Create( wxMenu
*menu
, const wxString
&title
)
133 { m_menu
= menu
; m_title
= title
; }
134 wxMenu
* GetMenu() const { return m_menu
; }
135 wxString
GetTitle() const { return m_title
; }
140 DECLARE_DYNAMIC_CLASS(wxMenuInfo
) ;
143 WX_DECLARE_EXPORTED_LIST(wxMenuInfo
, wxMenuInfoList
);
145 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
149 // default constructor
152 wxMenuBar(long style
);
153 // menubar takes ownership of the menus arrays but copies the titles
154 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
155 virtual ~wxMenuBar();
157 // menubar construction
158 bool Append( wxMenuInfo
*info
) { return Append( info
->GetMenu() , info
->GetTitle() ) ; }
159 const wxMenuInfoList
& GetMenuInfos() const ;
161 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
162 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
163 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
164 virtual wxMenu
*Remove(size_t pos
);
166 virtual void EnableTop( size_t pos
, bool flag
);
167 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
168 virtual wxString
GetLabelTop( size_t pos
) const;
170 // implementation from now on
172 virtual void Detach();
173 virtual void Attach(wxFrame
*frame
);
175 #if wxUSE_TOOLBAR && defined(__WXWINCE__) && (_WIN32_WCE < 400 || defined(__POCKETPC__) || defined(__SMARTPHONE__))
176 // Under WinCE, a menubar is owned by the frame's toolbar
177 void SetToolBar(wxToolBar
* toolBar
) { m_toolBar
= toolBar
; }
178 wxToolBar
* GetToolBar() const { return m_toolBar
; }
181 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
182 WXHWND
GetCommandBar() const { return m_commandBar
; }
183 bool AddAdornments(long style
);
187 // get the accel table for all the menus
188 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
190 // update the accel table (must be called after adding/deletign a menu)
191 void RebuildAccelTable();
192 #endif // wxUSE_ACCEL
194 // get the menu handle
195 WXHMENU
GetHMenu() const { return m_hMenu
; }
197 // if the menubar is modified, the display is not updated automatically,
198 // call this function to update it (m_menuBarFrame should be !NULL)
201 // To avoid compile warning
202 void Refresh( bool eraseBackground
,
203 const wxRect
*rect
= (const wxRect
*) NULL
) { wxWindow::Refresh(eraseBackground
, rect
); }
206 // common part of all ctors
209 wxArrayString m_titles
;
210 wxMenuInfoList m_menuInfos
;
214 // Return the MSW position for a wxMenu which is sometimes different from
215 // the wxWidgets position.
216 int MSWPositionForWxMenu(wxMenu
*menu
, int wxpos
);
218 // the accelerator table for all accelerators in all our menus
219 wxAcceleratorTable m_accelTable
;
220 #endif // wxUSE_ACCEL
222 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
223 wxToolBar
* m_toolBar
;
225 // Not using a combined wxToolBar/wxMenuBar? then use
226 // a commandbar in WinCE .NET to implement the
227 // menubar, since there is no ::SetMenu function.
228 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
230 bool m_adornmentsAdded
;
234 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar
)
237 #endif // _WX_MENU_H_