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