]>
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 JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_MENU_H_ |
13 | #define _WX_MENU_H_ | |
2bda0e17 | 14 | |
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
c626a8b7 | 16 | #pragma interface "menu.h" |
2bda0e17 KB |
17 | #endif |
18 | ||
3f3cec48 | 19 | #if wxUSE_ACCEL |
974e8d94 | 20 | #include "wx/accel.h" |
717a57c2 VZ |
21 | #include "wx/dynarray.h" |
22 | ||
d5d29b8a | 23 | WX_DEFINE_EXPORTED_ARRAY_PTR(wxAcceleratorEntry *, wxAcceleratorArray); |
3f3cec48 | 24 | #endif // wxUSE_ACCEL |
2bda0e17 | 25 | |
c626a8b7 | 26 | class WXDLLEXPORT wxFrame; |
2bda0e17 | 27 | |
39d2f9a7 JS |
28 | #if defined(__WXWINCE__) && wxUSE_TOOLBAR |
29 | class WXDLLEXPORT wxToolBar; | |
30 | #endif | |
31 | ||
a381fd1c MB |
32 | #include "wx/arrstr.h" |
33 | ||
2bda0e17 KB |
34 | // ---------------------------------------------------------------------------- |
35 | // Menu | |
36 | // ---------------------------------------------------------------------------- | |
c626a8b7 | 37 | |
717a57c2 | 38 | class WXDLLEXPORT wxMenu : public wxMenuBase |
2bda0e17 | 39 | { |
2bda0e17 | 40 | public: |
b908d224 | 41 | // ctors & dtor |
717a57c2 VZ |
42 | wxMenu(const wxString& title, long style = 0) |
43 | : wxMenuBase(title, style) { Init(); } | |
33961d59 | 44 | |
717a57c2 | 45 | wxMenu(long style = 0) : wxMenuBase(style) { Init(); } |
b908d224 | 46 | |
c626a8b7 VZ |
47 | virtual ~wxMenu(); |
48 | ||
717a57c2 VZ |
49 | // implement base class virtuals |
50 | virtual bool DoAppend(wxMenuItem *item); | |
51 | virtual bool DoInsert(size_t pos, wxMenuItem *item); | |
52 | virtual wxMenuItem *DoRemove(wxMenuItem *item); | |
53 | ||
54 | virtual void Break(); | |
55 | ||
56 | virtual void SetTitle(const wxString& title); | |
c626a8b7 | 57 | |
39428534 JS |
58 | // deprecated functions |
59 | #if wxUSE_MENU_CALLBACK | |
60 | wxMenu(const wxString& title, const wxFunction func) | |
61 | : wxMenuBase(title) | |
62 | { | |
63 | Init(); | |
64 | ||
65 | Callback(func); | |
66 | } | |
67 | #endif // wxUSE_MENU_CALLBACK | |
68 | ||
717a57c2 VZ |
69 | // implementation only from now on |
70 | // ------------------------------- | |
c626a8b7 | 71 | |
0472ece7 VZ |
72 | virtual void Attach(wxMenuBarBase *menubar); |
73 | ||
717a57c2 | 74 | bool MSWCommand(WXUINT param, WXWORD id); |
c626a8b7 VZ |
75 | |
76 | // semi-private accessors | |
77 | // get the window which contains this menu | |
78 | wxWindow *GetWindow() const; | |
79 | // get the menu handle | |
717a57c2 | 80 | WXHMENU GetHMenu() const { return m_hMenu; } |
2bda0e17 | 81 | |
d427503c | 82 | #if wxUSE_ACCEL |
717a57c2 VZ |
83 | // called by wxMenuBar to build its accel table from the accels of all menus |
84 | bool HasAccels() const { return !m_accels.IsEmpty(); } | |
974e8d94 | 85 | size_t GetAccelCount() const { return m_accels.GetCount(); } |
42e69d6b VZ |
86 | size_t CopyAccels(wxAcceleratorEntry *accels) const; |
87 | ||
717a57c2 VZ |
88 | // called by wxMenuItem when its accels changes |
89 | void UpdateAccel(wxMenuItem *item); | |
42e69d6b | 90 | |
717a57c2 VZ |
91 | // helper used by wxMenu itself (returns the index in m_accels) |
92 | int FindAccel(int id) const; | |
93 | #endif // wxUSE_ACCEL | |
42e69d6b | 94 | |
2bda0e17 | 95 | private: |
b908d224 | 96 | // common part of all ctors |
717a57c2 VZ |
97 | void Init(); |
98 | ||
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); | |
101 | ||
0472ece7 VZ |
102 | // terminate the current radio group, if any |
103 | void EndRadioGroup(); | |
104 | ||
717a57c2 VZ |
105 | // if TRUE, insert a breal before appending the next item |
106 | bool m_doBreak; | |
107 | ||
0472ece7 VZ |
108 | // the position of the first item in the current radio group or -1 |
109 | int m_startRadioGroup; | |
110 | ||
717a57c2 VZ |
111 | // the menu handle of this menu |
112 | WXHMENU m_hMenu; | |
42e69d6b | 113 | |
d427503c | 114 | #if wxUSE_ACCEL |
974e8d94 VZ |
115 | // the accelerators for our menu items |
116 | wxAcceleratorArray m_accels; | |
d427503c | 117 | #endif // wxUSE_ACCEL |
717a57c2 | 118 | |
fc7a2a60 | 119 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenu) |
2bda0e17 KB |
120 | }; |
121 | ||
122 | // ---------------------------------------------------------------------------- | |
123 | // Menu Bar (a la Windows) | |
124 | // ---------------------------------------------------------------------------- | |
c626a8b7 | 125 | |
6c7a1f82 SC |
126 | class WXDLLEXPORT wxMenuInfo : public wxObject |
127 | { | |
128 | public : | |
129 | wxMenuInfo() { m_menu = NULL ; } | |
130 | virtual ~wxMenuInfo() { } | |
131 | ||
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 ; } | |
136 | private : | |
137 | wxMenu *m_menu ; | |
138 | wxString m_title ; | |
139 | ||
140 | DECLARE_DYNAMIC_CLASS(wxMenuInfo) ; | |
141 | } ; | |
142 | ||
143 | WX_DECLARE_EXPORTED_LIST(wxMenuInfo, wxMenuInfoList ); | |
144 | ||
a8cfd0cb | 145 | class WXDLLEXPORT wxMenuBar : public wxMenuBarBase |
2bda0e17 | 146 | { |
c626a8b7 | 147 | public: |
6c7a1f82 | 148 | // ctors & dtor |
c2dcfdef | 149 | // default constructor |
c626a8b7 | 150 | wxMenuBar(); |
c2dcfdef | 151 | // unused under MSW |
c626a8b7 | 152 | wxMenuBar(long style); |
c2dcfdef | 153 | // menubar takes ownership of the menus arrays but copies the titles |
c626a8b7 VZ |
154 | wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); |
155 | virtual ~wxMenuBar(); | |
156 | ||
157 | // menubar construction | |
6c7a1f82 SC |
158 | bool Append( wxMenuInfo *info ) { return Append( info->GetMenu() , info->GetTitle() ) ; } |
159 | const wxMenuInfoList& GetMenuInfos() const ; | |
160 | ||
a8cfd0cb VZ |
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); | |
c626a8b7 | 165 | |
a8cfd0cb VZ |
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; | |
c626a8b7 | 169 | |
a8cfd0cb VZ |
170 | // implementation from now on |
171 | WXHMENU Create(); | |
1e6feb95 VZ |
172 | virtual void Detach(); |
173 | virtual void Attach(wxFrame *frame); | |
c2dcfdef | 174 | |
a96b4743 | 175 | #if wxUSE_TOOLBAR && defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI) |
39d2f9a7 JS |
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; } | |
179 | #endif | |
180 | ||
d427503c | 181 | #if wxUSE_ACCEL |
717a57c2 | 182 | // get the accel table for all the menus |
42e69d6b | 183 | const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; } |
717a57c2 VZ |
184 | |
185 | // update the accel table (must be called after adding/deletign a menu) | |
186 | void RebuildAccelTable(); | |
d427503c VZ |
187 | #endif // wxUSE_ACCEL |
188 | ||
c2dcfdef VZ |
189 | // get the menu handle |
190 | WXHMENU GetHMenu() const { return m_hMenu; } | |
191 | ||
c2dcfdef VZ |
192 | // if the menubar is modified, the display is not updated automatically, |
193 | // call this function to update it (m_menuBarFrame should be !NULL) | |
194 | void Refresh(); | |
195 | ||
b85b77ae | 196 | // To avoid compile warning |
39428534 | 197 | void Refresh( bool eraseBackground, |
b85b77ae JS |
198 | const wxRect *rect = (const wxRect *) NULL ) { wxWindow::Refresh(eraseBackground, rect); } |
199 | ||
fbb90f7f PA |
200 | protected: |
201 | // common part of all ctors | |
202 | void Init(); | |
203 | ||
6c7a1f82 SC |
204 | wxArrayString m_titles ; |
205 | wxMenuInfoList m_menuInfos; | |
a8cfd0cb | 206 | |
c2dcfdef | 207 | WXHMENU m_hMenu; |
42e69d6b | 208 | |
b2c5f143 DE |
209 | // Return the MSW position for a wxMenu which is sometimes different from |
210 | // the wxWindows position. | |
211 | int MSWPositionForWxMenu(wxMenu *menu, int wxpos); | |
d427503c | 212 | #if wxUSE_ACCEL |
42e69d6b VZ |
213 | // the accelerator table for all accelerators in all our menus |
214 | wxAcceleratorTable m_accelTable; | |
d427503c | 215 | #endif // wxUSE_ACCEL |
a8cfd0cb | 216 | |
39d2f9a7 JS |
217 | #if defined(__WXWINCE__) && wxUSE_TOOLBAR |
218 | wxToolBar* m_toolBar; | |
219 | #endif | |
a96b4743 JS |
220 | // Not using a combined wxToolBar/wxMenuBar? then use |
221 | // a commandbar in WinCE .NET to implement the | |
222 | // menubar, since there is no ::SetMenu function. | |
223 | #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !wxUSE_POCKETPC_UI) | |
224 | WXHWND m_commandBar; | |
225 | #endif | |
39d2f9a7 | 226 | |
a8cfd0cb | 227 | private: |
fc7a2a60 | 228 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar) |
2bda0e17 KB |
229 | }; |
230 | ||
bbcdf8bc | 231 | #endif // _WX_MENU_H_ |