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