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