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