]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
0472ece7 | 2 | // Name: wx/msw/menu.h |
2bda0e17 KB |
3 | // Purpose: wxMenu, wxMenuBar classes |
4 | // Author: Julian Smart | |
5 | // Modified by: Vadim Zeitlin (wxMenuItem is now in separate file) | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
371a5b4e | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_MENU_H_ |
13 | #define _WX_MENU_H_ | |
2bda0e17 | 14 | |
3f3cec48 | 15 | #if wxUSE_ACCEL |
974e8d94 | 16 | #include "wx/accel.h" |
717a57c2 VZ |
17 | #include "wx/dynarray.h" |
18 | ||
d5d29b8a | 19 | WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray); |
3f3cec48 | 20 | #endif // wxUSE_ACCEL |
2bda0e17 | 21 | |
b5dbe15d | 22 | class WXDLLIMPEXP_FWD_CORE wxFrame; |
2bda0e17 | 23 | |
39d2f9a7 | 24 | #if defined(__WXWINCE__) && wxUSE_TOOLBAR |
b5dbe15d | 25 | class WXDLLIMPEXP_FWD_CORE wxToolBar; |
39d2f9a7 JS |
26 | #endif |
27 | ||
b3900fb5 RR |
28 | |
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 | |
36 | # else | |
37 | # define WINCE_WITHOUT_COMMANDBAR | |
38 | # endif | |
39 | #endif | |
40 | ||
41 | ||
a381fd1c MB |
42 | #include "wx/arrstr.h" |
43 | ||
2bda0e17 KB |
44 | // ---------------------------------------------------------------------------- |
45 | // Menu | |
46 | // ---------------------------------------------------------------------------- | |
c626a8b7 | 47 | |
53a2db12 | 48 | class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase |
2bda0e17 | 49 | { |
2bda0e17 | 50 | public: |
b908d224 | 51 | // ctors & dtor |
717a57c2 VZ |
52 | wxMenu(const wxString& title, long style = 0) |
53 | : wxMenuBase(title, style) { Init(); } | |
33961d59 | 54 | |
717a57c2 | 55 | wxMenu(long style = 0) : wxMenuBase(style) { Init(); } |
b908d224 | 56 | |
c626a8b7 VZ |
57 | virtual ~wxMenu(); |
58 | ||
717a57c2 VZ |
59 | virtual void Break(); |
60 | ||
61 | virtual void SetTitle(const wxString& title); | |
c626a8b7 | 62 | |
717a57c2 VZ |
63 | // implementation only from now on |
64 | // ------------------------------- | |
c626a8b7 | 65 | |
0472ece7 VZ |
66 | virtual void Attach(wxMenuBarBase *menubar); |
67 | ||
717a57c2 | 68 | bool MSWCommand(WXUINT param, WXWORD id); |
c626a8b7 | 69 | |
7118e711 | 70 | // get the native menu handle |
717a57c2 | 71 | WXHMENU GetHMenu() const { return m_hMenu; } |
2bda0e17 | 72 | |
d427503c | 73 | #if wxUSE_ACCEL |
717a57c2 | 74 | // called by wxMenuBar to build its accel table from the accels of all menus |
67fdb6f9 VZ |
75 | bool HasAccels() const { return !m_accels.empty(); } |
76 | size_t GetAccelCount() const { return m_accels.size(); } | |
42e69d6b VZ |
77 | size_t CopyAccels(wxAcceleratorEntry *accels) const; |
78 | ||
717a57c2 VZ |
79 | // called by wxMenuItem when its accels changes |
80 | void UpdateAccel(wxMenuItem *item); | |
42e69d6b | 81 | |
717a57c2 VZ |
82 | // helper used by wxMenu itself (returns the index in m_accels) |
83 | int FindAccel(int id) const; | |
67fdb6f9 VZ |
84 | |
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; | |
717a57c2 | 89 | #endif // wxUSE_ACCEL |
42e69d6b | 90 | |
9c32ed26 VZ |
91 | #if wxUSE_OWNER_DRAWN |
92 | ||
93 | int GetMaxAccelWidth() | |
94 | { | |
95 | if (m_maxAccelWidth == -1) | |
96 | CalculateMaxAccelWidth(); | |
97 | return m_maxAccelWidth; | |
98 | } | |
99 | ||
100 | void ResetMaxAccelWidth() | |
101 | { | |
102 | m_maxAccelWidth = -1; | |
103 | } | |
104 | ||
105 | private: | |
106 | void CalculateMaxAccelWidth(); | |
107 | ||
108 | #endif // wxUSE_OWNER_DRAWN | |
109 | ||
6f02a879 VZ |
110 | protected: |
111 | virtual wxMenuItem* DoAppend(wxMenuItem *item); | |
112 | virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item); | |
113 | virtual wxMenuItem* DoRemove(wxMenuItem *item); | |
114 | ||
2bda0e17 | 115 | private: |
b908d224 | 116 | // common part of all ctors |
717a57c2 VZ |
117 | void Init(); |
118 | ||
119 | // common part of Append/Insert (behaves as Append is pos == (size_t)-1) | |
120 | bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1); | |
121 | ||
0472ece7 VZ |
122 | // terminate the current radio group, if any |
123 | void EndRadioGroup(); | |
124 | ||
598ddd96 | 125 | // if true, insert a breal before appending the next item |
717a57c2 VZ |
126 | bool m_doBreak; |
127 | ||
0472ece7 VZ |
128 | // the position of the first item in the current radio group or -1 |
129 | int m_startRadioGroup; | |
130 | ||
717a57c2 VZ |
131 | // the menu handle of this menu |
132 | WXHMENU m_hMenu; | |
42e69d6b | 133 | |
d427503c | 134 | #if wxUSE_ACCEL |
974e8d94 VZ |
135 | // the accelerators for our menu items |
136 | wxAcceleratorArray m_accels; | |
d427503c | 137 | #endif // wxUSE_ACCEL |
717a57c2 | 138 | |
d08504df VZ |
139 | #if wxUSE_OWNER_DRAWN |
140 | // true if the menu has any ownerdrawn items | |
141 | bool m_ownerDrawn; | |
142 | ||
143 | // the max width of menu items bitmaps | |
144 | int m_maxBitmapWidth; | |
9c32ed26 VZ |
145 | |
146 | // the max width of menu items accels | |
147 | int m_maxAccelWidth; | |
d08504df VZ |
148 | #endif // wxUSE_OWNER_DRAWN |
149 | ||
fc7a2a60 | 150 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu) |
2bda0e17 KB |
151 | }; |
152 | ||
153 | // ---------------------------------------------------------------------------- | |
154 | // Menu Bar (a la Windows) | |
155 | // ---------------------------------------------------------------------------- | |
c626a8b7 | 156 | |
53a2db12 | 157 | class WXDLLIMPEXP_CORE wxMenuInfo : public wxObject |
6c7a1f82 SC |
158 | { |
159 | public : | |
3839f37e | 160 | wxMenuInfo() { m_menu = NULL; } |
6c7a1f82 SC |
161 | virtual ~wxMenuInfo() { } |
162 | ||
598ddd96 | 163 | void Create( wxMenu *menu , const wxString &title ) |
3839f37e VZ |
164 | { m_menu = menu; m_title = title; } |
165 | wxMenu* GetMenu() const { return m_menu; } | |
166 | wxString GetTitle() const { return m_title; } | |
6c7a1f82 | 167 | private : |
3839f37e VZ |
168 | wxMenu *m_menu; |
169 | wxString m_title; | |
6c7a1f82 | 170 | |
3839f37e VZ |
171 | DECLARE_DYNAMIC_CLASS(wxMenuInfo) |
172 | }; | |
6c7a1f82 SC |
173 | |
174 | WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList ); | |
175 | ||
53a2db12 | 176 | class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase |
2bda0e17 | 177 | { |
c626a8b7 | 178 | public: |
598ddd96 | 179 | // ctors & dtor |
c2dcfdef | 180 | // default constructor |
c626a8b7 | 181 | wxMenuBar(); |
c2dcfdef | 182 | // unused under MSW |
c626a8b7 | 183 | wxMenuBar(long style); |
c2dcfdef | 184 | // menubar takes ownership of the menus arrays but copies the titles |
294ea16d | 185 | wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); |
c626a8b7 VZ |
186 | virtual ~wxMenuBar(); |
187 | ||
188 | // menubar construction | |
3839f37e VZ |
189 | bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ); } |
190 | const wxMenuInfoList& GetMenuInfos() const; | |
6c7a1f82 | 191 | |
a8cfd0cb VZ |
192 | virtual bool Append( wxMenu *menu, const wxString &title ); |
193 | virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); | |
194 | virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); | |
195 | virtual wxMenu *Remove(size_t pos); | |
c626a8b7 | 196 | |
a8cfd0cb | 197 | virtual void EnableTop( size_t pos, bool flag ); |
52af3158 JS |
198 | virtual void SetMenuLabel( size_t pos, const wxString& label ); |
199 | virtual wxString GetMenuLabel( size_t pos ) const; | |
c626a8b7 | 200 | |
a8cfd0cb VZ |
201 | // implementation from now on |
202 | WXHMENU Create(); | |
1e6feb95 VZ |
203 | virtual void Detach(); |
204 | virtual void Attach(wxFrame *frame); | |
c2dcfdef | 205 | |
b3900fb5 | 206 | #if defined(__WXWINCE__) && wxUSE_TOOLBAR |
39d2f9a7 JS |
207 | // Under WinCE, a menubar is owned by the frame's toolbar |
208 | void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; } | |
209 | wxToolBar* GetToolBar() const { return m_toolBar; } | |
210 | #endif | |
211 | ||
b3900fb5 | 212 | #ifdef WINCE_WITH_COMMANDBAR |
45f27284 | 213 | WXHWND GetCommandBar() const { return m_commandBar; } |
a9928e9d | 214 | bool AddAdornments(long style); |
45f27284 JS |
215 | #endif |
216 | ||
d427503c | 217 | #if wxUSE_ACCEL |
3103e8a9 | 218 | // update the accel table (must be called after adding/deleting a menu) |
717a57c2 | 219 | void RebuildAccelTable(); |
d427503c VZ |
220 | #endif // wxUSE_ACCEL |
221 | ||
c2dcfdef VZ |
222 | // get the menu handle |
223 | WXHMENU GetHMenu() const { return m_hMenu; } | |
224 | ||
c2dcfdef VZ |
225 | // if the menubar is modified, the display is not updated automatically, |
226 | // call this function to update it (m_menuBarFrame should be !NULL) | |
227 | void Refresh(); | |
228 | ||
b85b77ae | 229 | // To avoid compile warning |
39428534 | 230 | void Refresh( bool eraseBackground, |
b85b77ae JS |
231 | const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); } |
232 | ||
fbb90f7f PA |
233 | protected: |
234 | // common part of all ctors | |
235 | void Init(); | |
236 | ||
3839f37e | 237 | wxArrayString m_titles; |
6c7a1f82 | 238 | wxMenuInfoList m_menuInfos; |
a8cfd0cb | 239 | |
c2dcfdef | 240 | WXHMENU m_hMenu; |
42e69d6b | 241 | |
b2c5f143 | 242 | // Return the MSW position for a wxMenu which is sometimes different from |
77ffb593 | 243 | // the wxWidgets position. |
b2c5f143 | 244 | int MSWPositionForWxMenu(wxMenu *menu, int wxpos); |
a8cfd0cb | 245 | |
39d2f9a7 JS |
246 | #if defined(__WXWINCE__) && wxUSE_TOOLBAR |
247 | wxToolBar* m_toolBar; | |
248 | #endif | |
b3900fb5 RR |
249 | |
250 | #ifdef WINCE_WITH_COMMANDBAR | |
a96b4743 | 251 | WXHWND m_commandBar; |
a9928e9d | 252 | bool m_adornmentsAdded; |
a96b4743 | 253 | #endif |
39d2f9a7 | 254 | |
a8cfd0cb | 255 | private: |
fc7a2a60 | 256 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar) |
2bda0e17 KB |
257 | }; |
258 | ||
bbcdf8bc | 259 | #endif // _WX_MENU_H_ |