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 // semi-private accessors
71 // get the window which contains this menu
72 wxWindow
*GetWindow() const;
73 // get the menu handle
74 WXHMENU
GetHMenu() const { return m_hMenu
; }
77 // called by wxMenuBar to build its accel table from the accels of all menus
78 bool HasAccels() const { return !m_accels
.empty(); }
79 size_t GetAccelCount() const { return m_accels
.size(); }
80 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
82 // called by wxMenuItem when its accels changes
83 void UpdateAccel(wxMenuItem
*item
);
85 // helper used by wxMenu itself (returns the index in m_accels)
86 int FindAccel(int id
) const;
88 // used only by wxMDIParentFrame currently but could be useful elsewhere:
89 // returns a new accelerator table with accelerators for just this menu
90 // (shouldn't be called if we don't have any accelerators)
91 wxAcceleratorTable
*CreateAccelTable() const;
95 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
96 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
97 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
100 // common part of all ctors
103 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
104 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
106 // terminate the current radio group, if any
107 void EndRadioGroup();
109 // if true, insert a breal before appending the next item
112 // the position of the first item in the current radio group or -1
113 int m_startRadioGroup
;
115 // the menu handle of this menu
119 // the accelerators for our menu items
120 wxAcceleratorArray m_accels
;
121 #endif // wxUSE_ACCEL
123 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu
)
126 // ----------------------------------------------------------------------------
127 // Menu Bar (a la Windows)
128 // ----------------------------------------------------------------------------
130 class WXDLLIMPEXP_CORE wxMenuInfo
: public wxObject
133 wxMenuInfo() { m_menu
= NULL
; }
134 virtual ~wxMenuInfo() { }
136 void Create( wxMenu
*menu
, const wxString
&title
)
137 { m_menu
= menu
; m_title
= title
; }
138 wxMenu
* GetMenu() const { return m_menu
; }
139 wxString
GetTitle() const { return m_title
; }
144 DECLARE_DYNAMIC_CLASS(wxMenuInfo
)
147 WX_DECLARE_EXPORTED_LIST(wxMenuInfo
, wxMenuInfoList
);
149 class WXDLLIMPEXP_CORE wxMenuBar
: public wxMenuBarBase
153 // default constructor
156 wxMenuBar(long style
);
157 // menubar takes ownership of the menus arrays but copies the titles
158 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
159 virtual ~wxMenuBar();
161 // menubar construction
162 bool Append( wxMenuInfo
*info
) { return Append( info
->GetMenu() , info
->GetTitle() ); }
163 const wxMenuInfoList
& GetMenuInfos() const;
165 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
166 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
167 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
168 virtual wxMenu
*Remove(size_t pos
);
170 virtual void EnableTop( size_t pos
, bool flag
);
171 virtual void SetMenuLabel( size_t pos
, const wxString
& label
);
172 virtual wxString
GetMenuLabel( size_t pos
) const;
174 // implementation from now on
176 virtual void Detach();
177 virtual void Attach(wxFrame
*frame
);
179 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
180 // Under WinCE, a menubar is owned by the frame's toolbar
181 void SetToolBar(wxToolBar
* toolBar
) { m_toolBar
= toolBar
; }
182 wxToolBar
* GetToolBar() const { return m_toolBar
; }
185 #ifdef WINCE_WITH_COMMANDBAR
186 WXHWND
GetCommandBar() const { return m_commandBar
; }
187 bool AddAdornments(long style
);
191 // update the accel table (must be called after adding/deleting a menu)
192 void RebuildAccelTable();
193 #endif // wxUSE_ACCEL
195 // get the menu handle
196 WXHMENU
GetHMenu() const { return m_hMenu
; }
198 // if the menubar is modified, the display is not updated automatically,
199 // call this function to update it (m_menuBarFrame should be !NULL)
202 // To avoid compile warning
203 void Refresh( bool eraseBackground
,
204 const wxRect
*rect
= (const wxRect
*) NULL
) { wxWindow::Refresh(eraseBackground
, rect
); }
207 // common part of all ctors
210 wxArrayString m_titles
;
211 wxMenuInfoList m_menuInfos
;
215 // Return the MSW position for a wxMenu which is sometimes different from
216 // the wxWidgets position.
217 int MSWPositionForWxMenu(wxMenu
*menu
, int wxpos
);
219 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
220 wxToolBar
* m_toolBar
;
223 #ifdef WINCE_WITH_COMMANDBAR
225 bool m_adornmentsAdded
;
229 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar
)
232 #endif // _WX_MENU_H_