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