]>
Commit | Line | Data |
---|---|---|
9c7f49f5 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/renderer.h | |
3 | // Purpose: wxRendererNative class declaration | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 20.07.2003 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> |
65571936 | 9 | // Licence: wxWindows licence |
9c7f49f5 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | /* | |
77ffb593 | 13 | Renderers are used in wxWidgets for two similar but different things: |
9c7f49f5 VZ |
14 | (a) wxUniversal uses them to draw everything, i.e. all the control |
15 | (b) all the native ports use them to draw generic controls only | |
16 | ||
17 | wxUniversal needs more functionality than what is included in the base class | |
18 | as it needs to draw stuff like scrollbars which are never going to be | |
19 | generic. So we put the bare minimum needed by the native ports here and the | |
20 | full wxRenderer class is declared in wx/univ/renderer.h and is only used by | |
21 | wxUniveral (although note that native ports can load wxRenderer objects from | |
22 | theme DLLs and use them as wxRendererNative ones, of course). | |
23 | */ | |
24 | ||
25 | #ifndef _WX_RENDERER_H_ | |
26 | #define _WX_RENDERER_H_ | |
27 | ||
38c4cb6a | 28 | class WXDLLEXPORT wxDC; |
38c4cb6a VZ |
29 | class WXDLLEXPORT wxWindow; |
30 | ||
7df07b10 | 31 | #include "wx/gdicmn.h" // for wxPoint |
0856300f WS |
32 | #include "wx/colour.h" |
33 | #include "wx/font.h" | |
34 | #include "wx/bitmap.h" | |
35 | #include "wx/string.h" | |
7df07b10 | 36 | |
f0244295 | 37 | // some platforms have their own renderers, others use the generic one |
82ef81ed | 38 | #if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXGTK__) |
f0244295 VZ |
39 | #define wxHAS_NATIVE_RENDERER |
40 | #else | |
41 | #undef wxHAS_NATIVE_RENDERER | |
42 | #endif | |
43 | ||
9c7f49f5 VZ |
44 | // ---------------------------------------------------------------------------- |
45 | // constants | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | // control state flags used in wxRenderer and wxColourScheme | |
49 | enum | |
50 | { | |
51 | wxCONTROL_DISABLED = 0x00000001, // control is disabled | |
52 | wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus | |
53 | wxCONTROL_PRESSED = 0x00000004, // (button) is pressed | |
fb61f58a VZ |
54 | wxCONTROL_SPECIAL = 0x00000008, // control-specific bit: |
55 | wxCONTROL_ISDEFAULT = wxCONTROL_SPECIAL, // only for the buttons | |
56 | wxCONTROL_ISSUBMENU = wxCONTROL_SPECIAL, // only for the menu items | |
57 | wxCONTROL_EXPANDED = wxCONTROL_SPECIAL, // only for the tree items | |
58 | wxCONTROL_SIZEGRIP = wxCONTROL_SPECIAL, // only for the status bar panes | |
9c7f49f5 VZ |
59 | wxCONTROL_CURRENT = 0x00000010, // mouse is currently over the control |
60 | wxCONTROL_SELECTED = 0x00000020, // selected item in e.g. listbox | |
61 | wxCONTROL_CHECKED = 0x00000040, // (check/radio button) is checked | |
62 | wxCONTROL_CHECKABLE = 0x00000080, // (menu) item can be checked | |
415a0ff1 | 63 | wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state |
9c7f49f5 | 64 | |
80752b57 | 65 | wxCONTROL_FLAGS_MASK = 0x000000ff, |
9c7f49f5 VZ |
66 | |
67 | // this is a pseudo flag not used directly by wxRenderer but rather by some | |
68 | // controls internally | |
69 | wxCONTROL_DIRTY = 0x80000000 | |
70 | }; | |
71 | ||
af99040c VZ |
72 | // ---------------------------------------------------------------------------- |
73 | // helper structs | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | // wxSplitterWindow parameters | |
77 | struct WXDLLEXPORT wxSplitterRenderParams | |
78 | { | |
79 | // the only way to initialize this struct is by using this ctor | |
80 | wxSplitterRenderParams(wxCoord widthSash_, wxCoord border_, bool isSens_) | |
81 | : widthSash(widthSash_), border(border_), isHotSensitive(isSens_) | |
82 | { | |
83 | } | |
84 | ||
85 | // the width of the splitter sash | |
86 | const wxCoord widthSash; | |
87 | ||
88 | // the width of the border of the splitter window | |
89 | const wxCoord border; | |
90 | ||
91 | // true if the splitter changes its appearance when the mouse is over it | |
92 | const bool isHotSensitive; | |
93 | }; | |
94 | ||
4b94ddc4 RD |
95 | |
96 | // extra optional parameters for DrawHeaderButton | |
97 | struct WXDLLEXPORT wxHeaderButtonParams | |
98 | { | |
99 | wxHeaderButtonParams() | |
100 | : m_labelAlignment(wxALIGN_LEFT) | |
101 | { } | |
0856300f | 102 | |
4b94ddc4 RD |
103 | wxColour m_arrowColour; |
104 | wxColour m_selectionColour; | |
105 | wxString m_labelText; | |
106 | wxFont m_labelFont; | |
107 | wxColour m_labelColour; | |
108 | wxBitmap m_labelBitmap; | |
109 | int m_labelAlignment; | |
110 | }; | |
111 | ||
80752b57 RD |
112 | enum wxHeaderSortIconType { |
113 | wxHDR_SORT_ICON_NONE, // Header button has no sort arrow | |
114 | wxHDR_SORT_ICON_UP, // Header button an an up sort arrow icon | |
115 | wxHDR_SORT_ICON_DOWN // Header button an a down sort arrow icon | |
116 | }; | |
117 | ||
4b94ddc4 | 118 | |
04857cb7 VZ |
119 | // wxRendererNative interface version |
120 | struct WXDLLEXPORT wxRendererVersion | |
121 | { | |
122 | wxRendererVersion(int version_, int age_) : version(version_), age(age_) { } | |
123 | ||
124 | // default copy ctor, assignment operator and dtor are ok | |
125 | ||
126 | // the current version and age of wxRendererNative interface: different | |
127 | // versions are incompatible (in both ways) while the ages inside the same | |
128 | // version are upwards compatible, i.e. the version of the renderer must | |
129 | // match the version of the main program exactly while the age may be | |
130 | // highergreater or equal to it | |
131 | // | |
132 | // NB: don't forget to increment age after adding any new virtual function! | |
133 | enum | |
134 | { | |
135 | Current_Version = 1, | |
136 | Current_Age = 5 | |
137 | }; | |
138 | ||
139 | ||
140 | // check if the given version is compatible with the current one | |
141 | static bool IsCompatible(const wxRendererVersion& ver) | |
142 | { | |
143 | return ver.version == Current_Version && ver.age >= Current_Age; | |
144 | } | |
145 | ||
146 | const int version; | |
147 | const int age; | |
148 | }; | |
149 | ||
9c7f49f5 VZ |
150 | // ---------------------------------------------------------------------------- |
151 | // wxRendererNative: abstracts drawing methods needed by the native controls | |
152 | // ---------------------------------------------------------------------------- | |
153 | ||
154 | class WXDLLEXPORT wxRendererNative | |
155 | { | |
156 | public: | |
157 | // drawing functions | |
158 | // ----------------- | |
159 | ||
c97c9952 RD |
160 | // draw the header control button (used by wxListCtrl) Returns optimal |
161 | // width for the label contents. | |
162 | virtual int DrawHeaderButton(wxWindow *win, | |
9c7f49f5 VZ |
163 | wxDC& dc, |
164 | const wxRect& rect, | |
4b94ddc4 | 165 | int flags = 0, |
80752b57 | 166 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 RD |
167 | wxHeaderButtonParams* params=NULL) = 0; |
168 | ||
169 | ||
170 | // Draw the contents of a header control button (label, sort arrows, etc.) | |
171 | // Normally only called by DrawHeaderButton. | |
c97c9952 | 172 | virtual int DrawHeaderButtonContents(wxWindow *win, |
4b94ddc4 RD |
173 | wxDC& dc, |
174 | const wxRect& rect, | |
175 | int flags = 0, | |
80752b57 | 176 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 RD |
177 | wxHeaderButtonParams* params=NULL) = 0; |
178 | ||
179 | // Returns the default height of a header button, either a fixed platform | |
180 | // height if available, or a generic height based on the window's font. | |
181 | virtual int GetHeaderButtonHeight(wxWindow *win) = 0; | |
182 | ||
9c7f49f5 VZ |
183 | |
184 | // draw the expanded/collapsed icon for a tree control item | |
185 | virtual void DrawTreeItemButton(wxWindow *win, | |
186 | wxDC& dc, | |
187 | const wxRect& rect, | |
188 | int flags = 0) = 0; | |
189 | ||
b3208e11 VZ |
190 | // draw the border for sash window: this border must be such that the sash |
191 | // drawn by DrawSash() blends into it well | |
192 | virtual void DrawSplitterBorder(wxWindow *win, | |
193 | wxDC& dc, | |
af99040c VZ |
194 | const wxRect& rect, |
195 | int flags = 0) = 0; | |
b3208e11 VZ |
196 | |
197 | // draw a (vertical) sash | |
198 | virtual void DrawSplitterSash(wxWindow *win, | |
199 | wxDC& dc, | |
200 | const wxSize& size, | |
62dc9cb4 | 201 | wxCoord position, |
af99040c VZ |
202 | wxOrientation orient, |
203 | int flags = 0) = 0; | |
b3208e11 | 204 | |
f33cef9f VZ |
205 | // draw a combobox dropdown button |
206 | // | |
4c85ab75 | 207 | // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT |
f33cef9f VZ |
208 | virtual void DrawComboBoxDropButton(wxWindow *win, |
209 | wxDC& dc, | |
210 | const wxRect& rect, | |
211 | int flags = 0) = 0; | |
212 | ||
4c85ab75 VZ |
213 | // draw a dropdown arrow |
214 | // | |
215 | // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT | |
216 | virtual void DrawDropArrow(wxWindow *win, | |
217 | wxDC& dc, | |
218 | const wxRect& rect, | |
219 | int flags = 0) = 0; | |
b3208e11 | 220 | |
862d8041 RR |
221 | // draw check button |
222 | // | |
223 | // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT | |
90b903c2 WS |
224 | virtual void DrawCheckBox(wxWindow *win, |
225 | wxDC& dc, | |
226 | const wxRect& rect, | |
227 | int flags = 0) = 0; | |
2209baae RR |
228 | |
229 | // draw blank button | |
230 | // | |
231 | // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT | |
232 | virtual void DrawPushButton(wxWindow *win, | |
233 | wxDC& dc, | |
234 | const wxRect& rect, | |
235 | int flags = 0) = 0; | |
236 | ||
daebb44c RR |
237 | // draw rectangle indicating that an item in e.g. a list control |
238 | // has been selected or focused | |
239 | // | |
0856300f | 240 | // flags may use |
daebb44c RR |
241 | // wxCONTROL_SELECTED (item is selected, e.g. draw background) |
242 | // wxCONTROL_CURRENT (item is the current item, e.g. dotted border) | |
243 | // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise) | |
244 | virtual void DrawItemSelectionRect(wxWindow *win, | |
245 | wxDC& dc, | |
246 | const wxRect& rect, | |
247 | int flags = 0) = 0; | |
248 | ||
b3208e11 VZ |
249 | // geometry functions |
250 | // ------------------ | |
251 | ||
252 | // get the splitter parameters: the x field of the returned point is the | |
253 | // sash width and the y field is the border width | |
af99040c | 254 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0; |
b3208e11 | 255 | |
9c7f49f5 VZ |
256 | |
257 | // pseudo constructors | |
258 | // ------------------- | |
259 | ||
260 | // return the currently used renderer | |
261 | static wxRendererNative& Get(); | |
262 | ||
263 | // return the generic implementation of the renderer | |
264 | static wxRendererNative& GetGeneric(); | |
f0244295 VZ |
265 | |
266 | // return the default (native) implementation for this platform | |
267 | static wxRendererNative& GetDefault(); | |
9f2be125 VZ |
268 | |
269 | ||
270 | // changing the global renderer | |
271 | // ---------------------------- | |
272 | ||
273 | #if wxUSE_DYNLIB_CLASS | |
274 | // load the renderer from the specified DLL, the returned pointer must be | |
275 | // deleted by caller if not NULL when it is not used any more | |
276 | static wxRendererNative *Load(const wxString& name); | |
277 | #endif // wxUSE_DYNLIB_CLASS | |
278 | ||
279 | // set the renderer to use, passing NULL reverts to using the default | |
280 | // renderer | |
281 | // | |
282 | // return the previous renderer used with Set() or NULL if none | |
283 | static wxRendererNative *Set(wxRendererNative *renderer); | |
04857cb7 VZ |
284 | |
285 | ||
286 | // miscellaneous stuff | |
287 | // ------------------- | |
288 | ||
289 | // this function is used for version checking: Load() refuses to load any | |
290 | // DLLs implementing an older or incompatible version; it should be | |
291 | // implemented simply by returning wxRendererVersion::Current_XXX values | |
292 | virtual wxRendererVersion GetVersion() const = 0; | |
293 | ||
294 | // virtual dtor for any base class | |
295 | virtual ~wxRendererNative(); | |
9c7f49f5 VZ |
296 | }; |
297 | ||
298 | // ---------------------------------------------------------------------------- | |
299 | // wxDelegateRendererNative: allows reuse of renderers code | |
300 | // ---------------------------------------------------------------------------- | |
301 | ||
302 | class WXDLLEXPORT wxDelegateRendererNative : public wxRendererNative | |
303 | { | |
304 | public: | |
305 | wxDelegateRendererNative() | |
306 | : m_rendererNative(GetGeneric()) { } | |
307 | ||
308 | wxDelegateRendererNative(wxRendererNative& rendererNative) | |
309 | : m_rendererNative(rendererNative) { } | |
310 | ||
311 | ||
c97c9952 | 312 | virtual int DrawHeaderButton(wxWindow *win, |
9c7f49f5 VZ |
313 | wxDC& dc, |
314 | const wxRect& rect, | |
4b94ddc4 | 315 | int flags = 0, |
80752b57 | 316 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 | 317 | wxHeaderButtonParams* params = NULL) |
c97c9952 | 318 | { return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); } |
0856300f | 319 | |
c97c9952 | 320 | virtual int DrawHeaderButtonContents(wxWindow *win, |
4b94ddc4 RD |
321 | wxDC& dc, |
322 | const wxRect& rect, | |
323 | int flags = 0, | |
80752b57 | 324 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 | 325 | wxHeaderButtonParams* params = NULL) |
c97c9952 | 326 | { return m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); } |
0856300f | 327 | |
4b94ddc4 RD |
328 | virtual int GetHeaderButtonHeight(wxWindow *win) |
329 | { return m_rendererNative.GetHeaderButtonHeight(win); } | |
b3208e11 | 330 | |
9c7f49f5 VZ |
331 | virtual void DrawTreeItemButton(wxWindow *win, |
332 | wxDC& dc, | |
333 | const wxRect& rect, | |
334 | int flags = 0) | |
335 | { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); } | |
336 | ||
b3208e11 VZ |
337 | virtual void DrawSplitterBorder(wxWindow *win, |
338 | wxDC& dc, | |
af99040c VZ |
339 | const wxRect& rect, |
340 | int flags = 0) | |
2c0e6de1 | 341 | { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); } |
b3208e11 VZ |
342 | |
343 | virtual void DrawSplitterSash(wxWindow *win, | |
344 | wxDC& dc, | |
345 | const wxSize& size, | |
62dc9cb4 | 346 | wxCoord position, |
af99040c VZ |
347 | wxOrientation orient, |
348 | int flags = 0) | |
2c0e6de1 VZ |
349 | { m_rendererNative.DrawSplitterSash(win, dc, size, |
350 | position, orient, flags); } | |
b3208e11 | 351 | |
f33cef9f VZ |
352 | virtual void DrawComboBoxDropButton(wxWindow *win, |
353 | wxDC& dc, | |
354 | const wxRect& rect, | |
355 | int flags = 0) | |
356 | { m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); } | |
357 | ||
4c85ab75 VZ |
358 | virtual void DrawDropArrow(wxWindow *win, |
359 | wxDC& dc, | |
360 | const wxRect& rect, | |
361 | int flags = 0) | |
362 | { m_rendererNative.DrawDropArrow(win, dc, rect, flags); } | |
b3208e11 | 363 | |
90b903c2 WS |
364 | virtual void DrawCheckBox(wxWindow *win, |
365 | wxDC& dc, | |
366 | const wxRect& rect, | |
367 | int flags = 0 ) | |
368 | { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); } | |
2209baae RR |
369 | |
370 | virtual void DrawPushButton(wxWindow *win, | |
371 | wxDC& dc, | |
372 | const wxRect& rect, | |
373 | int flags = 0 ) | |
374 | { m_rendererNative.DrawPushButton( win, dc, rect, flags ); } | |
375 | ||
daebb44c RR |
376 | virtual void DrawItemSelectionRect(wxWindow *win, |
377 | wxDC& dc, | |
378 | const wxRect& rect, | |
379 | int flags = 0 ) | |
380 | { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); } | |
381 | ||
af99040c VZ |
382 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) |
383 | { return m_rendererNative.GetSplitterParams(win); } | |
b3208e11 | 384 | |
04857cb7 VZ |
385 | virtual wxRendererVersion GetVersion() const |
386 | { return m_rendererNative.GetVersion(); } | |
387 | ||
9c7f49f5 VZ |
388 | protected: |
389 | wxRendererNative& m_rendererNative; | |
fc7a2a60 VZ |
390 | |
391 | DECLARE_NO_COPY_CLASS(wxDelegateRendererNative) | |
9c7f49f5 VZ |
392 | }; |
393 | ||
f0244295 VZ |
394 | // ---------------------------------------------------------------------------- |
395 | // inline functions implementation | |
396 | // ---------------------------------------------------------------------------- | |
397 | ||
398 | #ifndef wxHAS_NATIVE_RENDERER | |
399 | ||
400 | // default native renderer is the generic one then | |
401 | /* static */ inline | |
402 | wxRendererNative& wxRendererNative::GetDefault() | |
403 | { | |
404 | return GetGeneric(); | |
405 | } | |
406 | ||
407 | #endif // !wxHAS_NATIVE_RENDERER | |
408 | ||
9c7f49f5 | 409 | #endif // _WX_RENDERER_H_ |