]> git.saurik.com Git - wxWidgets.git/blame - include/wx/renderer.h
Somehow, setting a tint color makes gauge work :/.
[wxWidgets.git] / include / wx / renderer.h
CommitLineData
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
77ffb593 7// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
65571936 8// Licence: wxWindows licence
9c7f49f5
VZ
9///////////////////////////////////////////////////////////////////////////////
10
11/*
77ffb593 12 Renderers are used in wxWidgets for two similar but different things:
9c7f49f5
VZ
13 (a) wxUniversal uses them to draw everything, i.e. all the control
14 (b) all the native ports use them to draw generic controls only
15
16 wxUniversal needs more functionality than what is included in the base class
17 as it needs to draw stuff like scrollbars which are never going to be
18 generic. So we put the bare minimum needed by the native ports here and the
19 full wxRenderer class is declared in wx/univ/renderer.h and is only used by
20 wxUniveral (although note that native ports can load wxRenderer objects from
21 theme DLLs and use them as wxRendererNative ones, of course).
22 */
23
24#ifndef _WX_RENDERER_H_
25#define _WX_RENDERER_H_
26
b5dbe15d
VS
27class WXDLLIMPEXP_FWD_CORE wxDC;
28class WXDLLIMPEXP_FWD_CORE wxWindow;
38c4cb6a 29
e8759560 30#include "wx/gdicmn.h" // for wxPoint, wxSize
0856300f
WS
31#include "wx/colour.h"
32#include "wx/font.h"
33#include "wx/bitmap.h"
34#include "wx/string.h"
7df07b10 35
f0244295 36// some platforms have their own renderers, others use the generic one
ac9e3f1f 37#if defined(__WXMSW__) || ( defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON ) || defined(__WXGTK__)
f0244295
VZ
38 #define wxHAS_NATIVE_RENDERER
39#else
40 #undef wxHAS_NATIVE_RENDERER
41#endif
42
ec20a753
VZ
43// only MSW and OS X currently provides DrawTitleBarBitmap() method
44#if defined(__WXMSW__) || (defined(__WXMAC__) && wxUSE_LIBPNG && wxUSE_IMAGE)
b50d93d1
VZ
45 #define wxHAS_DRAW_TITLE_BAR_BITMAP
46#endif
47
9c7f49f5
VZ
48// ----------------------------------------------------------------------------
49// constants
50// ----------------------------------------------------------------------------
51
52// control state flags used in wxRenderer and wxColourScheme
53enum
54{
55 wxCONTROL_DISABLED = 0x00000001, // control is disabled
56 wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus
57 wxCONTROL_PRESSED = 0x00000004, // (button) is pressed
fb61f58a
VZ
58 wxCONTROL_SPECIAL = 0x00000008, // control-specific bit:
59 wxCONTROL_ISDEFAULT = wxCONTROL_SPECIAL, // only for the buttons
60 wxCONTROL_ISSUBMENU = wxCONTROL_SPECIAL, // only for the menu items
61 wxCONTROL_EXPANDED = wxCONTROL_SPECIAL, // only for the tree items
62 wxCONTROL_SIZEGRIP = wxCONTROL_SPECIAL, // only for the status bar panes
8a461249 63 wxCONTROL_FLAT = wxCONTROL_SPECIAL, // checkboxes only: flat border
9c7f49f5
VZ
64 wxCONTROL_CURRENT = 0x00000010, // mouse is currently over the control
65 wxCONTROL_SELECTED = 0x00000020, // selected item in e.g. listbox
66 wxCONTROL_CHECKED = 0x00000040, // (check/radio button) is checked
67 wxCONTROL_CHECKABLE = 0x00000080, // (menu) item can be checked
415a0ff1 68 wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state
9c7f49f5 69
a61c9122 70 wxCONTROL_FLAGS_MASK = 0x000000ff,
9c7f49f5
VZ
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
b50d93d1
VZ
77// title bar buttons supported by DrawTitleBarBitmap()
78//
79// NB: they have the same values as wxTOPLEVEL_BUTTON_XXX constants in
80// wx/univ/toplevel.h as they really represent the same things
81enum wxTitleBarButton
82{
83 wxTITLEBAR_BUTTON_CLOSE = 0x01000000,
84 wxTITLEBAR_BUTTON_MAXIMIZE = 0x02000000,
3427bc78 85 wxTITLEBAR_BUTTON_ICONIZE = 0x04000000,
b50d93d1
VZ
86 wxTITLEBAR_BUTTON_RESTORE = 0x08000000,
87 wxTITLEBAR_BUTTON_HELP = 0x10000000
88};
89
af99040c
VZ
90// ----------------------------------------------------------------------------
91// helper structs
92// ----------------------------------------------------------------------------
93
94// wxSplitterWindow parameters
53a2db12 95struct WXDLLIMPEXP_CORE wxSplitterRenderParams
af99040c
VZ
96{
97 // the only way to initialize this struct is by using this ctor
98 wxSplitterRenderParams(wxCoord widthSash_, wxCoord border_, bool isSens_)
99 : widthSash(widthSash_), border(border_), isHotSensitive(isSens_)
100 {
101 }
102
103 // the width of the splitter sash
104 const wxCoord widthSash;
105
106 // the width of the border of the splitter window
107 const wxCoord border;
108
109 // true if the splitter changes its appearance when the mouse is over it
110 const bool isHotSensitive;
111};
112
4b94ddc4
RD
113
114// extra optional parameters for DrawHeaderButton
53a2db12 115struct WXDLLIMPEXP_CORE wxHeaderButtonParams
4b94ddc4
RD
116{
117 wxHeaderButtonParams()
118 : m_labelAlignment(wxALIGN_LEFT)
119 { }
0856300f 120
4b94ddc4
RD
121 wxColour m_arrowColour;
122 wxColour m_selectionColour;
123 wxString m_labelText;
124 wxFont m_labelFont;
125 wxColour m_labelColour;
126 wxBitmap m_labelBitmap;
127 int m_labelAlignment;
128};
129
1e417065
VZ
130enum wxHeaderSortIconType
131{
80752b57 132 wxHDR_SORT_ICON_NONE, // Header button has no sort arrow
1e417065
VZ
133 wxHDR_SORT_ICON_UP, // Header button an up sort arrow icon
134 wxHDR_SORT_ICON_DOWN // Header button a down sort arrow icon
80752b57
RD
135};
136
4b94ddc4 137
04857cb7 138// wxRendererNative interface version
53a2db12 139struct WXDLLIMPEXP_CORE wxRendererVersion
04857cb7
VZ
140{
141 wxRendererVersion(int version_, int age_) : version(version_), age(age_) { }
142
143 // default copy ctor, assignment operator and dtor are ok
144
145 // the current version and age of wxRendererNative interface: different
146 // versions are incompatible (in both ways) while the ages inside the same
147 // version are upwards compatible, i.e. the version of the renderer must
148 // match the version of the main program exactly while the age may be
149 // highergreater or equal to it
150 //
151 // NB: don't forget to increment age after adding any new virtual function!
152 enum
153 {
154 Current_Version = 1,
155 Current_Age = 5
156 };
157
158
159 // check if the given version is compatible with the current one
160 static bool IsCompatible(const wxRendererVersion& ver)
161 {
162 return ver.version == Current_Version && ver.age >= Current_Age;
163 }
164
165 const int version;
166 const int age;
167};
168
9c7f49f5
VZ
169// ----------------------------------------------------------------------------
170// wxRendererNative: abstracts drawing methods needed by the native controls
171// ----------------------------------------------------------------------------
172
53a2db12 173class WXDLLIMPEXP_CORE wxRendererNative
9c7f49f5
VZ
174{
175public:
176 // drawing functions
177 // -----------------
178
c97c9952
RD
179 // draw the header control button (used by wxListCtrl) Returns optimal
180 // width for the label contents.
181 virtual int DrawHeaderButton(wxWindow *win,
9c7f49f5
VZ
182 wxDC& dc,
183 const wxRect& rect,
4b94ddc4 184 int flags = 0,
80752b57 185 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4
RD
186 wxHeaderButtonParams* params=NULL) = 0;
187
188
189 // Draw the contents of a header control button (label, sort arrows, etc.)
190 // Normally only called by DrawHeaderButton.
c97c9952 191 virtual int DrawHeaderButtonContents(wxWindow *win,
4b94ddc4
RD
192 wxDC& dc,
193 const wxRect& rect,
194 int flags = 0,
80752b57 195 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4
RD
196 wxHeaderButtonParams* params=NULL) = 0;
197
198 // Returns the default height of a header button, either a fixed platform
199 // height if available, or a generic height based on the window's font.
200 virtual int GetHeaderButtonHeight(wxWindow *win) = 0;
201
9aebcb5e
VS
202 // Returns the margin on left and right sides of header button's label
203 virtual int GetHeaderButtonMargin(wxWindow *win) = 0;
204
9c7f49f5
VZ
205
206 // draw the expanded/collapsed icon for a tree control item
207 virtual void DrawTreeItemButton(wxWindow *win,
208 wxDC& dc,
209 const wxRect& rect,
210 int flags = 0) = 0;
211
b3208e11
VZ
212 // draw the border for sash window: this border must be such that the sash
213 // drawn by DrawSash() blends into it well
214 virtual void DrawSplitterBorder(wxWindow *win,
215 wxDC& dc,
af99040c
VZ
216 const wxRect& rect,
217 int flags = 0) = 0;
b3208e11
VZ
218
219 // draw a (vertical) sash
220 virtual void DrawSplitterSash(wxWindow *win,
221 wxDC& dc,
222 const wxSize& size,
62dc9cb4 223 wxCoord position,
af99040c
VZ
224 wxOrientation orient,
225 int flags = 0) = 0;
b3208e11 226
f33cef9f
VZ
227 // draw a combobox dropdown button
228 //
4c85ab75 229 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
f33cef9f
VZ
230 virtual void DrawComboBoxDropButton(wxWindow *win,
231 wxDC& dc,
232 const wxRect& rect,
233 int flags = 0) = 0;
234
4c85ab75
VZ
235 // draw a dropdown arrow
236 //
237 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
238 virtual void DrawDropArrow(wxWindow *win,
239 wxDC& dc,
240 const wxRect& rect,
241 int flags = 0) = 0;
b3208e11 242
862d8041
RR
243 // draw check button
244 //
245 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
90b903c2
WS
246 virtual void DrawCheckBox(wxWindow *win,
247 wxDC& dc,
248 const wxRect& rect,
249 int flags = 0) = 0;
2209baae 250
e8759560 251 // Returns the default size of a check box.
191e43fd 252 virtual wxSize GetCheckBoxSize(wxWindow *win) = 0;
e8759560 253
2209baae
RR
254 // draw blank button
255 //
256 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
257 virtual void DrawPushButton(wxWindow *win,
258 wxDC& dc,
259 const wxRect& rect,
260 int flags = 0) = 0;
261
daebb44c
RR
262 // draw rectangle indicating that an item in e.g. a list control
263 // has been selected or focused
264 //
0856300f 265 // flags may use
daebb44c
RR
266 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
267 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
268 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
269 virtual void DrawItemSelectionRect(wxWindow *win,
270 wxDC& dc,
271 const wxRect& rect,
272 int flags = 0) = 0;
273
6d789987
JS
274 // draw the focus rectangle around the label contained in the given rect
275 //
276 // only wxCONTROL_SELECTED makes sense in flags here
99c4be68
VZ
277 virtual void DrawFocusRect(wxWindow* win,
278 wxDC& dc,
279 const wxRect& rect,
280 int flags = 0) = 0;
6d789987 281
e4131985 282 // Draw a native wxChoice
99c4be68
VZ
283 virtual void DrawChoice(wxWindow* win,
284 wxDC& dc,
285 const wxRect& rect,
286 int flags = 0) = 0;
e4131985
KO
287
288 // Draw a native wxComboBox
99c4be68
VZ
289 virtual void DrawComboBox(wxWindow* win,
290 wxDC& dc,
291 const wxRect& rect,
292 int flags = 0) = 0;
e4131985
KO
293
294 // Draw a native wxTextCtrl frame
99c4be68
VZ
295 virtual void DrawTextCtrl(wxWindow* win,
296 wxDC& dc,
297 const wxRect& rect,
298 int flags = 0) = 0;
e4131985 299
6e6b532c
VZ
300 // Draw a native wxRadioButton bitmap
301 virtual void DrawRadioBitmap(wxWindow* win,
302 wxDC& dc,
303 const wxRect& rect,
304 int flags = 0) = 0;
e4131985 305
b50d93d1
VZ
306#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
307 // Draw one of the standard title bar buttons
308 //
3427bc78
VZ
309 // This is currently implemented only for MSW and OS X (for the close
310 // button only) because there is no way to render standard title bar
311 // buttons under the other platforms, the best can be done is to use normal
312 // (only) images which wxArtProvider provides for wxART_HELP and
313 // wxART_CLOSE (but not any other title bar buttons)
314 //
315 // NB: make sure PNG handler is enabled if using this function under OS X
b50d93d1
VZ
316 virtual void DrawTitleBarBitmap(wxWindow *win,
317 wxDC& dc,
318 const wxRect& rect,
319 wxTitleBarButton button,
320 int flags = 0) = 0;
321#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
322
323
b3208e11
VZ
324 // geometry functions
325 // ------------------
326
327 // get the splitter parameters: the x field of the returned point is the
328 // sash width and the y field is the border width
af99040c 329 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0;
b3208e11 330
9c7f49f5
VZ
331
332 // pseudo constructors
333 // -------------------
334
335 // return the currently used renderer
336 static wxRendererNative& Get();
337
338 // return the generic implementation of the renderer
339 static wxRendererNative& GetGeneric();
f0244295
VZ
340
341 // return the default (native) implementation for this platform
342 static wxRendererNative& GetDefault();
9f2be125
VZ
343
344
345 // changing the global renderer
346 // ----------------------------
347
348#if wxUSE_DYNLIB_CLASS
349 // load the renderer from the specified DLL, the returned pointer must be
350 // deleted by caller if not NULL when it is not used any more
351 static wxRendererNative *Load(const wxString& name);
352#endif // wxUSE_DYNLIB_CLASS
353
354 // set the renderer to use, passing NULL reverts to using the default
355 // renderer
356 //
357 // return the previous renderer used with Set() or NULL if none
358 static wxRendererNative *Set(wxRendererNative *renderer);
04857cb7
VZ
359
360
361 // miscellaneous stuff
362 // -------------------
363
364 // this function is used for version checking: Load() refuses to load any
365 // DLLs implementing an older or incompatible version; it should be
366 // implemented simply by returning wxRendererVersion::Current_XXX values
367 virtual wxRendererVersion GetVersion() const = 0;
368
369 // virtual dtor for any base class
370 virtual ~wxRendererNative();
9c7f49f5
VZ
371};
372
373// ----------------------------------------------------------------------------
374// wxDelegateRendererNative: allows reuse of renderers code
375// ----------------------------------------------------------------------------
376
53a2db12 377class WXDLLIMPEXP_CORE wxDelegateRendererNative : public wxRendererNative
9c7f49f5
VZ
378{
379public:
380 wxDelegateRendererNative()
381 : m_rendererNative(GetGeneric()) { }
382
383 wxDelegateRendererNative(wxRendererNative& rendererNative)
384 : m_rendererNative(rendererNative) { }
385
386
c97c9952 387 virtual int DrawHeaderButton(wxWindow *win,
9c7f49f5
VZ
388 wxDC& dc,
389 const wxRect& rect,
4b94ddc4 390 int flags = 0,
80752b57 391 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 392 wxHeaderButtonParams* params = NULL)
c97c9952 393 { return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
0856300f 394
c97c9952 395 virtual int DrawHeaderButtonContents(wxWindow *win,
4b94ddc4
RD
396 wxDC& dc,
397 const wxRect& rect,
398 int flags = 0,
80752b57 399 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 400 wxHeaderButtonParams* params = NULL)
c97c9952 401 { return m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); }
0856300f 402
4b94ddc4
RD
403 virtual int GetHeaderButtonHeight(wxWindow *win)
404 { return m_rendererNative.GetHeaderButtonHeight(win); }
b3208e11 405
9aebcb5e
VS
406 virtual int GetHeaderButtonMargin(wxWindow *win)
407 { return m_rendererNative.GetHeaderButtonMargin(win); }
408
9c7f49f5
VZ
409 virtual void DrawTreeItemButton(wxWindow *win,
410 wxDC& dc,
411 const wxRect& rect,
412 int flags = 0)
413 { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); }
414
b3208e11
VZ
415 virtual void DrawSplitterBorder(wxWindow *win,
416 wxDC& dc,
af99040c
VZ
417 const wxRect& rect,
418 int flags = 0)
2c0e6de1 419 { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); }
b3208e11
VZ
420
421 virtual void DrawSplitterSash(wxWindow *win,
422 wxDC& dc,
423 const wxSize& size,
62dc9cb4 424 wxCoord position,
af99040c
VZ
425 wxOrientation orient,
426 int flags = 0)
2c0e6de1
VZ
427 { m_rendererNative.DrawSplitterSash(win, dc, size,
428 position, orient, flags); }
b3208e11 429
f33cef9f
VZ
430 virtual void DrawComboBoxDropButton(wxWindow *win,
431 wxDC& dc,
432 const wxRect& rect,
433 int flags = 0)
434 { m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); }
435
4c85ab75
VZ
436 virtual void DrawDropArrow(wxWindow *win,
437 wxDC& dc,
438 const wxRect& rect,
439 int flags = 0)
440 { m_rendererNative.DrawDropArrow(win, dc, rect, flags); }
b3208e11 441
90b903c2
WS
442 virtual void DrawCheckBox(wxWindow *win,
443 wxDC& dc,
444 const wxRect& rect,
99c4be68 445 int flags = 0)
90b903c2 446 { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); }
2209baae 447
191e43fd
FM
448 virtual wxSize GetCheckBoxSize(wxWindow *win)
449 { return m_rendererNative.GetCheckBoxSize(win); }
e8759560 450
2209baae
RR
451 virtual void DrawPushButton(wxWindow *win,
452 wxDC& dc,
453 const wxRect& rect,
99c4be68 454 int flags = 0)
2209baae
RR
455 { m_rendererNative.DrawPushButton( win, dc, rect, flags ); }
456
daebb44c
RR
457 virtual void DrawItemSelectionRect(wxWindow *win,
458 wxDC& dc,
459 const wxRect& rect,
99c4be68 460 int flags = 0)
daebb44c
RR
461 { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); }
462
99c4be68
VZ
463 virtual void DrawFocusRect(wxWindow* win,
464 wxDC& dc,
465 const wxRect& rect,
466 int flags = 0)
6d789987
JS
467 { m_rendererNative.DrawFocusRect( win, dc, rect, flags ); }
468
99c4be68
VZ
469 virtual void DrawChoice(wxWindow* win,
470 wxDC& dc,
471 const wxRect& rect,
472 int flags = 0)
e4131985
KO
473 { m_rendererNative.DrawChoice( win, dc, rect, flags); }
474
99c4be68
VZ
475 virtual void DrawComboBox(wxWindow* win,
476 wxDC& dc,
477 const wxRect& rect,
478 int flags = 0)
e4131985
KO
479 { m_rendererNative.DrawComboBox( win, dc, rect, flags); }
480
99c4be68
VZ
481 virtual void DrawTextCtrl(wxWindow* win,
482 wxDC& dc,
483 const wxRect& rect,
484 int flags = 0)
e4131985
KO
485 { m_rendererNative.DrawTextCtrl( win, dc, rect, flags); }
486
6e6b532c
VZ
487 virtual void DrawRadioBitmap(wxWindow* win,
488 wxDC& dc,
489 const wxRect& rect,
490 int flags = 0)
491 { m_rendererNative.DrawRadioBitmap(win, dc, rect, flags); }
e4131985 492
b50d93d1
VZ
493#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
494 virtual void DrawTitleBarBitmap(wxWindow *win,
495 wxDC& dc,
496 const wxRect& rect,
497 wxTitleBarButton button,
498 int flags = 0)
499 { m_rendererNative.DrawTitleBarBitmap(win, dc, rect, button, flags); }
500#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
501
af99040c
VZ
502 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
503 { return m_rendererNative.GetSplitterParams(win); }
b3208e11 504
04857cb7
VZ
505 virtual wxRendererVersion GetVersion() const
506 { return m_rendererNative.GetVersion(); }
507
9c7f49f5
VZ
508protected:
509 wxRendererNative& m_rendererNative;
fc7a2a60 510
c0c133e1 511 wxDECLARE_NO_COPY_CLASS(wxDelegateRendererNative);
9c7f49f5
VZ
512};
513
f0244295
VZ
514// ----------------------------------------------------------------------------
515// inline functions implementation
516// ----------------------------------------------------------------------------
517
518#ifndef wxHAS_NATIVE_RENDERER
519
520// default native renderer is the generic one then
521/* static */ inline
522wxRendererNative& wxRendererNative::GetDefault()
523{
524 return GetGeneric();
525}
526
527#endif // !wxHAS_NATIVE_RENDERER
528
9c7f49f5 529#endif // _WX_RENDERER_H_