]> git.saurik.com Git - wxWidgets.git/blame - include/wx/renderer.h
added EVT_DATAVIEW_CACHE_HINT event (closes #9891)
[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
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
65571936 9// Licence: wxWindows licence
9c7f49f5
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12/*
77ffb593 13 Renderers are used in wxWidgets for two similar but different things:
9c7f49f5
VZ
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
b5dbe15d
VS
28class WXDLLIMPEXP_FWD_CORE wxDC;
29class WXDLLIMPEXP_FWD_CORE wxWindow;
38c4cb6a 30
e8759560 31#include "wx/gdicmn.h" // for wxPoint, wxSize
0856300f
WS
32#include "wx/colour.h"
33#include "wx/font.h"
34#include "wx/bitmap.h"
35#include "wx/string.h"
7df07b10 36
f0244295 37// some platforms have their own renderers, others use the generic one
ac9e3f1f 38#if defined(__WXMSW__) || ( defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON ) || defined(__WXGTK__)
f0244295
VZ
39 #define wxHAS_NATIVE_RENDERER
40#else
41 #undef wxHAS_NATIVE_RENDERER
42#endif
43
9c7f49f5
VZ
44// ----------------------------------------------------------------------------
45// constants
46// ----------------------------------------------------------------------------
47
48// control state flags used in wxRenderer and wxColourScheme
49enum
50{
51 wxCONTROL_DISABLED = 0x00000001, // control is disabled
52 wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus
53 wxCONTROL_PRESSED = 0x00000004, // (button) is pressed
fb61f58a
VZ
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
8a461249 59 wxCONTROL_FLAT = wxCONTROL_SPECIAL, // checkboxes only: flat border
9c7f49f5
VZ
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
415a0ff1 64 wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state
9c7f49f5 65
a61c9122 66 wxCONTROL_FLAGS_MASK = 0x000000ff,
9c7f49f5
VZ
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
af99040c
VZ
73// ----------------------------------------------------------------------------
74// helper structs
75// ----------------------------------------------------------------------------
76
77// wxSplitterWindow parameters
53a2db12 78struct WXDLLIMPEXP_CORE wxSplitterRenderParams
af99040c
VZ
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
4b94ddc4
RD
96
97// extra optional parameters for DrawHeaderButton
53a2db12 98struct WXDLLIMPEXP_CORE wxHeaderButtonParams
4b94ddc4
RD
99{
100 wxHeaderButtonParams()
101 : m_labelAlignment(wxALIGN_LEFT)
102 { }
0856300f 103
4b94ddc4
RD
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
1e417065
VZ
113enum wxHeaderSortIconType
114{
80752b57 115 wxHDR_SORT_ICON_NONE, // Header button has no sort arrow
1e417065
VZ
116 wxHDR_SORT_ICON_UP, // Header button an up sort arrow icon
117 wxHDR_SORT_ICON_DOWN // Header button a down sort arrow icon
80752b57
RD
118};
119
4b94ddc4 120
04857cb7 121// wxRendererNative interface version
53a2db12 122struct WXDLLIMPEXP_CORE wxRendererVersion
04857cb7
VZ
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
9c7f49f5
VZ
152// ----------------------------------------------------------------------------
153// wxRendererNative: abstracts drawing methods needed by the native controls
154// ----------------------------------------------------------------------------
155
53a2db12 156class WXDLLIMPEXP_CORE wxRendererNative
9c7f49f5
VZ
157{
158public:
159 // drawing functions
160 // -----------------
161
c97c9952
RD
162 // draw the header control button (used by wxListCtrl) Returns optimal
163 // width for the label contents.
164 virtual int DrawHeaderButton(wxWindow *win,
9c7f49f5
VZ
165 wxDC& dc,
166 const wxRect& rect,
4b94ddc4 167 int flags = 0,
80752b57 168 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4
RD
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.
c97c9952 174 virtual int DrawHeaderButtonContents(wxWindow *win,
4b94ddc4
RD
175 wxDC& dc,
176 const wxRect& rect,
177 int flags = 0,
80752b57 178 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4
RD
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
9c7f49f5
VZ
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
b3208e11
VZ
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,
af99040c
VZ
196 const wxRect& rect,
197 int flags = 0) = 0;
b3208e11
VZ
198
199 // draw a (vertical) sash
200 virtual void DrawSplitterSash(wxWindow *win,
201 wxDC& dc,
202 const wxSize& size,
62dc9cb4 203 wxCoord position,
af99040c
VZ
204 wxOrientation orient,
205 int flags = 0) = 0;
b3208e11 206
f33cef9f
VZ
207 // draw a combobox dropdown button
208 //
4c85ab75 209 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
f33cef9f
VZ
210 virtual void DrawComboBoxDropButton(wxWindow *win,
211 wxDC& dc,
212 const wxRect& rect,
213 int flags = 0) = 0;
214
4c85ab75
VZ
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;
b3208e11 222
862d8041
RR
223 // draw check button
224 //
225 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
90b903c2
WS
226 virtual void DrawCheckBox(wxWindow *win,
227 wxDC& dc,
228 const wxRect& rect,
229 int flags = 0) = 0;
2209baae 230
e8759560 231 // Returns the default size of a check box.
191e43fd 232 virtual wxSize GetCheckBoxSize(wxWindow *win) = 0;
e8759560 233
2209baae
RR
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
daebb44c
RR
242 // draw rectangle indicating that an item in e.g. a list control
243 // has been selected or focused
244 //
0856300f 245 // flags may use
daebb44c
RR
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
6d789987
JS
254 // draw the focus rectangle around the label contained in the given rect
255 //
256 // only wxCONTROL_SELECTED makes sense in flags here
99c4be68
VZ
257 virtual void DrawFocusRect(wxWindow* win,
258 wxDC& dc,
259 const wxRect& rect,
260 int flags = 0) = 0;
6d789987 261
e4131985 262 // Draw a native wxChoice
99c4be68
VZ
263 virtual void DrawChoice(wxWindow* win,
264 wxDC& dc,
265 const wxRect& rect,
266 int flags = 0) = 0;
e4131985
KO
267
268 // Draw a native wxComboBox
99c4be68
VZ
269 virtual void DrawComboBox(wxWindow* win,
270 wxDC& dc,
271 const wxRect& rect,
272 int flags = 0) = 0;
e4131985
KO
273
274 // Draw a native wxTextCtrl frame
99c4be68
VZ
275 virtual void DrawTextCtrl(wxWindow* win,
276 wxDC& dc,
277 const wxRect& rect,
278 int flags = 0) = 0;
e4131985
KO
279
280 // Draw a native wxRadioButton (just the graphical portion)
a2ee1945 281 virtual void DrawRadioButton(wxWindow* win,
99c4be68
VZ
282 wxDC& dc,
283 const wxRect& rect,
284 int flags = 0) = 0;
e4131985 285
b3208e11
VZ
286 // geometry functions
287 // ------------------
288
289 // get the splitter parameters: the x field of the returned point is the
290 // sash width and the y field is the border width
af99040c 291 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0;
b3208e11 292
9c7f49f5
VZ
293
294 // pseudo constructors
295 // -------------------
296
297 // return the currently used renderer
298 static wxRendererNative& Get();
299
300 // return the generic implementation of the renderer
301 static wxRendererNative& GetGeneric();
f0244295
VZ
302
303 // return the default (native) implementation for this platform
304 static wxRendererNative& GetDefault();
9f2be125
VZ
305
306
307 // changing the global renderer
308 // ----------------------------
309
310#if wxUSE_DYNLIB_CLASS
311 // load the renderer from the specified DLL, the returned pointer must be
312 // deleted by caller if not NULL when it is not used any more
313 static wxRendererNative *Load(const wxString& name);
314#endif // wxUSE_DYNLIB_CLASS
315
316 // set the renderer to use, passing NULL reverts to using the default
317 // renderer
318 //
319 // return the previous renderer used with Set() or NULL if none
320 static wxRendererNative *Set(wxRendererNative *renderer);
04857cb7
VZ
321
322
323 // miscellaneous stuff
324 // -------------------
325
326 // this function is used for version checking: Load() refuses to load any
327 // DLLs implementing an older or incompatible version; it should be
328 // implemented simply by returning wxRendererVersion::Current_XXX values
329 virtual wxRendererVersion GetVersion() const = 0;
330
331 // virtual dtor for any base class
332 virtual ~wxRendererNative();
9c7f49f5
VZ
333};
334
335// ----------------------------------------------------------------------------
336// wxDelegateRendererNative: allows reuse of renderers code
337// ----------------------------------------------------------------------------
338
53a2db12 339class WXDLLIMPEXP_CORE wxDelegateRendererNative : public wxRendererNative
9c7f49f5
VZ
340{
341public:
342 wxDelegateRendererNative()
343 : m_rendererNative(GetGeneric()) { }
344
345 wxDelegateRendererNative(wxRendererNative& rendererNative)
346 : m_rendererNative(rendererNative) { }
347
348
c97c9952 349 virtual int DrawHeaderButton(wxWindow *win,
9c7f49f5
VZ
350 wxDC& dc,
351 const wxRect& rect,
4b94ddc4 352 int flags = 0,
80752b57 353 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 354 wxHeaderButtonParams* params = NULL)
c97c9952 355 { return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
0856300f 356
c97c9952 357 virtual int DrawHeaderButtonContents(wxWindow *win,
4b94ddc4
RD
358 wxDC& dc,
359 const wxRect& rect,
360 int flags = 0,
80752b57 361 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 362 wxHeaderButtonParams* params = NULL)
c97c9952 363 { return m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); }
0856300f 364
4b94ddc4
RD
365 virtual int GetHeaderButtonHeight(wxWindow *win)
366 { return m_rendererNative.GetHeaderButtonHeight(win); }
b3208e11 367
9c7f49f5
VZ
368 virtual void DrawTreeItemButton(wxWindow *win,
369 wxDC& dc,
370 const wxRect& rect,
371 int flags = 0)
372 { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); }
373
b3208e11
VZ
374 virtual void DrawSplitterBorder(wxWindow *win,
375 wxDC& dc,
af99040c
VZ
376 const wxRect& rect,
377 int flags = 0)
2c0e6de1 378 { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); }
b3208e11
VZ
379
380 virtual void DrawSplitterSash(wxWindow *win,
381 wxDC& dc,
382 const wxSize& size,
62dc9cb4 383 wxCoord position,
af99040c
VZ
384 wxOrientation orient,
385 int flags = 0)
2c0e6de1
VZ
386 { m_rendererNative.DrawSplitterSash(win, dc, size,
387 position, orient, flags); }
b3208e11 388
f33cef9f
VZ
389 virtual void DrawComboBoxDropButton(wxWindow *win,
390 wxDC& dc,
391 const wxRect& rect,
392 int flags = 0)
393 { m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); }
394
4c85ab75
VZ
395 virtual void DrawDropArrow(wxWindow *win,
396 wxDC& dc,
397 const wxRect& rect,
398 int flags = 0)
399 { m_rendererNative.DrawDropArrow(win, dc, rect, flags); }
b3208e11 400
90b903c2
WS
401 virtual void DrawCheckBox(wxWindow *win,
402 wxDC& dc,
403 const wxRect& rect,
99c4be68 404 int flags = 0)
90b903c2 405 { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); }
2209baae 406
191e43fd
FM
407 virtual wxSize GetCheckBoxSize(wxWindow *win)
408 { return m_rendererNative.GetCheckBoxSize(win); }
e8759560 409
2209baae
RR
410 virtual void DrawPushButton(wxWindow *win,
411 wxDC& dc,
412 const wxRect& rect,
99c4be68 413 int flags = 0)
2209baae
RR
414 { m_rendererNative.DrawPushButton( win, dc, rect, flags ); }
415
daebb44c
RR
416 virtual void DrawItemSelectionRect(wxWindow *win,
417 wxDC& dc,
418 const wxRect& rect,
99c4be68 419 int flags = 0)
daebb44c
RR
420 { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); }
421
99c4be68
VZ
422 virtual void DrawFocusRect(wxWindow* win,
423 wxDC& dc,
424 const wxRect& rect,
425 int flags = 0)
6d789987
JS
426 { m_rendererNative.DrawFocusRect( win, dc, rect, flags ); }
427
99c4be68
VZ
428 virtual void DrawChoice(wxWindow* win,
429 wxDC& dc,
430 const wxRect& rect,
431 int flags = 0)
e4131985
KO
432 { m_rendererNative.DrawChoice( win, dc, rect, flags); }
433
99c4be68
VZ
434 virtual void DrawComboBox(wxWindow* win,
435 wxDC& dc,
436 const wxRect& rect,
437 int flags = 0)
e4131985
KO
438 { m_rendererNative.DrawComboBox( win, dc, rect, flags); }
439
99c4be68
VZ
440 virtual void DrawTextCtrl(wxWindow* win,
441 wxDC& dc,
442 const wxRect& rect,
443 int flags = 0)
e4131985
KO
444 { m_rendererNative.DrawTextCtrl( win, dc, rect, flags); }
445
a2ee1945 446 virtual void DrawRadioButton(wxWindow* win,
99c4be68
VZ
447 wxDC& dc,
448 const wxRect& rect,
449 int flags = 0)
a2ee1945 450 { m_rendererNative.DrawRadioButton( win, dc, rect, flags); }
e4131985 451
af99040c
VZ
452 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
453 { return m_rendererNative.GetSplitterParams(win); }
b3208e11 454
04857cb7
VZ
455 virtual wxRendererVersion GetVersion() const
456 { return m_rendererNative.GetVersion(); }
457
9c7f49f5
VZ
458protected:
459 wxRendererNative& m_rendererNative;
fc7a2a60 460
c0c133e1 461 wxDECLARE_NO_COPY_CLASS(wxDelegateRendererNative);
9c7f49f5
VZ
462};
463
f0244295
VZ
464// ----------------------------------------------------------------------------
465// inline functions implementation
466// ----------------------------------------------------------------------------
467
468#ifndef wxHAS_NATIVE_RENDERER
469
470// default native renderer is the generic one then
471/* static */ inline
472wxRendererNative& wxRendererNative::GetDefault()
473{
474 return GetGeneric();
475}
476
477#endif // !wxHAS_NATIVE_RENDERER
478
9c7f49f5 479#endif // _WX_RENDERER_H_