]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/msw/menu.h | |
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$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_MENU_H_ | |
13 | #define _WX_MENU_H_ | |
14 | ||
15 | #if wxUSE_ACCEL | |
16 | #include "wx/accel.h" | |
17 | #include "wx/dynarray.h" | |
18 | ||
19 | WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray); | |
20 | #endif // wxUSE_ACCEL | |
21 | ||
22 | class WXDLLIMPEXP_FWD_CORE wxFrame; | |
23 | ||
24 | #if defined(__WXWINCE__) && wxUSE_TOOLBAR | |
25 | class WXDLLIMPEXP_FWD_CORE wxToolBar; | |
26 | #endif | |
27 | ||
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 | ||
42 | #include "wx/arrstr.h" | |
43 | ||
44 | // ---------------------------------------------------------------------------- | |
45 | // Menu | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | class WXDLLIMPEXP_CORE wxMenu : public wxMenuBase | |
49 | { | |
50 | public: | |
51 | // ctors & dtor | |
52 | wxMenu(const wxString& title, long style = 0) | |
53 | : wxMenuBase(title, style) { Init(); } | |
54 | ||
55 | wxMenu(long style = 0) : wxMenuBase(style) { Init(); } | |
56 | ||
57 | virtual ~wxMenu(); | |
58 | ||
59 | virtual void Break(); | |
60 | ||
61 | virtual void SetTitle(const wxString& title); | |
62 | ||
63 | // implementation only from now on | |
64 | // ------------------------------- | |
65 | ||
66 | virtual void Attach(wxMenuBarBase *menubar); | |
67 | ||
68 | bool MSWCommand(WXUINT param, WXWORD id); | |
69 | ||
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; } | |
75 | ||
76 | #if wxUSE_ACCEL | |
77 | // called by wxMenuBar to build its accel table from the accels of all menus | |
78 | bool HasAccels() const { return !m_accels.IsEmpty(); } | |
79 | size_t GetAccelCount() const { return m_accels.GetCount(); } | |
80 | size_t CopyAccels(wxAcceleratorEntry *accels) const; | |
81 | ||
82 | // called by wxMenuItem when its accels changes | |
83 | void UpdateAccel(wxMenuItem *item); | |
84 | ||
85 | // helper used by wxMenu itself (returns the index in m_accels) | |
86 | int FindAccel(int id) const; | |
87 | #endif // wxUSE_ACCEL | |
88 | ||
89 | protected: | |
90 | virtual wxMenuItem* DoAppend(wxMenuItem *item); | |
91 | virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item); | |
92 | virtual wxMenuItem* DoRemove(wxMenuItem *item); | |
93 | ||
94 | private: | |
95 | // common part of all ctors | |
96 | void Init(); | |
97 | ||
98 | // common part of Append/Insert (behaves as Append is pos == (size_t)-1) | |
99 | bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1); | |
100 | ||
101 | // terminate the current radio group, if any | |
102 | void EndRadioGroup(); | |
103 | ||
104 | // if true, insert a breal before appending the next item | |
105 | bool m_doBreak; | |
106 | ||
107 | // the position of the first item in the current radio group or -1 | |
108 | int m_startRadioGroup; | |
109 | ||
110 | // the menu handle of this menu | |
111 | WXHMENU m_hMenu; | |
112 | ||
113 | #if wxUSE_ACCEL | |
114 | // the accelerators for our menu items | |
115 | wxAcceleratorArray m_accels; | |
116 | #endif // wxUSE_ACCEL | |
117 | ||
118 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu) | |
119 | }; | |
120 | ||
121 | // ---------------------------------------------------------------------------- | |
122 | // Menu Bar (a la Windows) | |
123 | // ---------------------------------------------------------------------------- | |
124 | ||
125 | class WXDLLIMPEXP_CORE wxMenuInfo : public wxObject | |
126 | { | |
127 | public : | |
128 | wxMenuInfo() { m_menu = NULL; } | |
129 | virtual ~wxMenuInfo() { } | |
130 | ||
131 | void Create( wxMenu *menu , const wxString &title ) | |
132 | { m_menu = menu; m_title = title; } | |
133 | wxMenu* GetMenu() const { return m_menu; } | |
134 | wxString GetTitle() const { return m_title; } | |
135 | private : | |
136 | wxMenu *m_menu; | |
137 | wxString m_title; | |
138 | ||
139 | DECLARE_DYNAMIC_CLASS(wxMenuInfo) | |
140 | }; | |
141 | ||
142 | WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList ); | |
143 | ||
144 | class WXDLLIMPEXP_CORE wxMenuBar : public wxMenuBarBase | |
145 | { | |
146 | public: | |
147 | // ctors & dtor | |
148 | // default constructor | |
149 | wxMenuBar(); | |
150 | // unused under MSW | |
151 | wxMenuBar(long style); | |
152 | // menubar takes ownership of the menus arrays but copies the titles | |
153 | wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); | |
154 | virtual ~wxMenuBar(); | |
155 | ||
156 | // menubar construction | |
157 | bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ); } | |
158 | const wxMenuInfoList& GetMenuInfos() const; | |
159 | ||
160 | virtual bool Append( wxMenu *menu, const wxString &title ); | |
161 | virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); | |
162 | virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); | |
163 | virtual wxMenu *Remove(size_t pos); | |
164 | ||
165 | virtual void EnableTop( size_t pos, bool flag ); | |
166 | virtual void SetMenuLabel( size_t pos, const wxString& label ); | |
167 | virtual wxString GetMenuLabel( size_t pos ) const; | |
168 | ||
169 | // implementation from now on | |
170 | WXHMENU Create(); | |
171 | virtual void Detach(); | |
172 | virtual void Attach(wxFrame *frame); | |
173 | ||
174 | #if defined(__WXWINCE__) && wxUSE_TOOLBAR | |
175 | // Under WinCE, a menubar is owned by the frame's toolbar | |
176 | void SetToolBar(wxToolBar* toolBar) { m_toolBar = toolBar; } | |
177 | wxToolBar* GetToolBar() const { return m_toolBar; } | |
178 | #endif | |
179 | ||
180 | #ifdef WINCE_WITH_COMMANDBAR | |
181 | WXHWND GetCommandBar() const { return m_commandBar; } | |
182 | bool AddAdornments(long style); | |
183 | #endif | |
184 | ||
185 | #if wxUSE_ACCEL | |
186 | // get the accel table for all the menus | |
187 | const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; } | |
188 | ||
189 | // update the accel table (must be called after adding/deleting a menu) | |
190 | void RebuildAccelTable(); | |
191 | #endif // wxUSE_ACCEL | |
192 | ||
193 | // get the menu handle | |
194 | WXHMENU GetHMenu() const { return m_hMenu; } | |
195 | ||
196 | // if the menubar is modified, the display is not updated automatically, | |
197 | // call this function to update it (m_menuBarFrame should be !NULL) | |
198 | void Refresh(); | |
199 | ||
200 | // To avoid compile warning | |
201 | void Refresh( bool eraseBackground, | |
202 | const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); } | |
203 | ||
204 | protected: | |
205 | // common part of all ctors | |
206 | void Init(); | |
207 | ||
208 | wxArrayString m_titles; | |
209 | wxMenuInfoList m_menuInfos; | |
210 | ||
211 | WXHMENU m_hMenu; | |
212 | ||
213 | // Return the MSW position for a wxMenu which is sometimes different from | |
214 | // the wxWidgets position. | |
215 | int MSWPositionForWxMenu(wxMenu *menu, int wxpos); | |
216 | #if wxUSE_ACCEL | |
217 | // the accelerator table for all accelerators in all our menus | |
218 | wxAcceleratorTable m_accelTable; | |
219 | #endif // wxUSE_ACCEL | |
220 | ||
221 | #if defined(__WXWINCE__) && wxUSE_TOOLBAR | |
222 | wxToolBar* m_toolBar; | |
223 | #endif | |
224 | ||
225 | #ifdef WINCE_WITH_COMMANDBAR | |
226 | WXHWND m_commandBar; | |
227 | bool m_adornmentsAdded; | |
228 | #endif | |
229 | ||
230 | private: | |
231 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar) | |
232 | }; | |
233 | ||
234 | #endif // _WX_MENU_H_ |