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 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/dynarray.h"
19 WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry
*, wxAcceleratorArray
);
22 class WXDLLIMPEXP_FWD_CORE wxFrame
;
24 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
25 class WXDLLIMPEXP_FWD_CORE wxToolBar
;
29 // Not using a combined wxToolBar/wxMenuBar? then use
30 // a commandbar in WinCE .NET to implement the
31 // menubar, since there is no ::SetMenu function.
32 #if defined(__WXWINCE__)
33 # if ((_WIN32_WCE >= 400) && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)) || \
34 defined(__HANDHELDPC__)
35 # define WINCE_WITH_COMMANDBAR
37 # define WINCE_WITHOUT_COMMANDBAR
42 #include "wx/arrstr.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 class WXDLLIMPEXP_CORE wxMenu
: public wxMenuBase
52 wxMenu(const wxString
& title
, long style
= 0)
53 : wxMenuBase(title
, style
) { Init(); }
55 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
61 virtual void SetTitle(const wxString
& title
);
63 // implementation only from now on
64 // -------------------------------
66 virtual void Attach(wxMenuBarBase
*menubar
);
68 bool MSWCommand(WXUINT param
, WXWORD id
);
70 // get the native menu handle
71 WXHMENU
GetHMenu() const { return m_hMenu
; }
74 // called by wxMenuBar to build its accel table from the accels of all menus
75 bool HasAccels() const { return !m_accels
.empty(); }
76 size_t GetAccelCount() const { return m_accels
.size(); }
77 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
79 // called by wxMenuItem when its accels changes
80 void UpdateAccel(wxMenuItem
*item
);
82 // helper used by wxMenu itself (returns the index in m_accels)
83 int FindAccel(int id
) const;
85 // used only by wxMDIParentFrame currently but could be useful elsewhere:
86 // returns a new accelerator table with accelerators for just this menu
87 // (shouldn't be called if we don't have any accelerators)
88 wxAcceleratorTable
*CreateAccelTable() const;
93 int GetMaxAccelWidth()
95 if (m_maxAccelWidth
== -1)
96 CalculateMaxAccelWidth();
97 return m_maxAccelWidth
;
100 void ResetMaxAccelWidth()
102 m_maxAccelWidth
= -1;
105 // get the menu with given handle (recursively)
106 wxMenu
* MSWGetMenu(WXHMENU hMenu
);
109 void CalculateMaxAccelWidth();
111 #endif // wxUSE_OWNER_DRAWN
114 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
115 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
116 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
119 // common part of all ctors
122 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
123 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
125 // terminate the current radio group, if any
126 void EndRadioGroup();
128 // if true, insert a breal before appending the next item
131 // the position of the first item in the current radio group or -1
132 int m_startRadioGroup
;
134 // the menu handle of this menu
138 // the accelerators for our menu items
139 wxAcceleratorArray m_accels
;
140 #endif // wxUSE_ACCEL
142 #if wxUSE_OWNER_DRAWN
143 // true if the menu has any ownerdrawn items
146 // the max width of menu items bitmaps
147 int m_maxBitmapWidth
;
149 // the max width of menu items accels
151 #endif // wxUSE_OWNER_DRAWN
153 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu
)
156 // ----------------------------------------------------------------------------
157 // Menu Bar (a la Windows)
158 // ----------------------------------------------------------------------------
160 class WXDLLIMPEXP_CORE wxMenuBar
: public wxMenuBarBase
164 // default constructor
167 wxMenuBar(long style
);
168 // menubar takes ownership of the menus arrays but copies the titles
169 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
170 virtual ~wxMenuBar();
172 // menubar construction
173 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
174 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
175 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
176 virtual wxMenu
*Remove(size_t pos
);
178 virtual void EnableTop( size_t pos
, bool flag
);
179 virtual void SetMenuLabel( size_t pos
, const wxString
& label
);
180 virtual wxString
GetMenuLabel( size_t pos
) const;
182 // implementation from now on
184 virtual void Detach();
185 virtual void Attach(wxFrame
*frame
);
187 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
188 // Under WinCE, a menubar is owned by the frame's toolbar
189 void SetToolBar(wxToolBar
* toolBar
) { m_toolBar
= toolBar
; }
190 wxToolBar
* GetToolBar() const { return m_toolBar
; }
193 #ifdef WINCE_WITH_COMMANDBAR
194 WXHWND
GetCommandBar() const { return m_commandBar
; }
195 bool AddAdornments(long style
);
199 // update the accel table (must be called after adding/deleting a menu)
200 void RebuildAccelTable();
201 #endif // wxUSE_ACCEL
203 // get the menu handle
204 WXHMENU
GetHMenu() const { return m_hMenu
; }
206 // if the menubar is modified, the display is not updated automatically,
207 // call this function to update it (m_menuBarFrame should be !NULL)
210 // To avoid compile warning
211 void Refresh( bool eraseBackground
,
212 const wxRect
*rect
= (const wxRect
*) NULL
) { wxWindow::Refresh(eraseBackground
, rect
); }
214 // get the menu with given handle (recursively)
215 wxMenu
* MSWGetMenu(WXHMENU hMenu
);
218 // common part of all ctors
223 // Return the MSW position for a wxMenu which is sometimes different from
224 // the wxWidgets position.
225 int MSWPositionForWxMenu(wxMenu
*menu
, int wxpos
);
227 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
228 wxToolBar
* m_toolBar
;
231 #ifdef WINCE_WITH_COMMANDBAR
233 bool m_adornmentsAdded
;
237 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar
)
240 #endif // _WX_MENU_H_