]> git.saurik.com Git - wxWidgets.git/blame - include/wx/renderer.h
fix the tests to pass with both gcc and msvc (2nd part of patch 1462778)
[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
MB
31#include "wx/gdicmn.h" // for wxPoint
32
f0244295 33// some platforms have their own renderers, others use the generic one
82ef81ed 34#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXGTK__)
f0244295
VZ
35 #define wxHAS_NATIVE_RENDERER
36#else
37 #undef wxHAS_NATIVE_RENDERER
38#endif
39
9c7f49f5
VZ
40// ----------------------------------------------------------------------------
41// constants
42// ----------------------------------------------------------------------------
43
44// control state flags used in wxRenderer and wxColourScheme
45enum
46{
47 wxCONTROL_DISABLED = 0x00000001, // control is disabled
48 wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus
49 wxCONTROL_PRESSED = 0x00000004, // (button) is pressed
50 wxCONTROL_ISDEFAULT = 0x00000008, // only applies to the buttons
51 wxCONTROL_ISSUBMENU = wxCONTROL_ISDEFAULT, // only for menu items
52 wxCONTROL_EXPANDED = wxCONTROL_ISDEFAULT, // only for the tree items
53 wxCONTROL_CURRENT = 0x00000010, // mouse is currently over the control
54 wxCONTROL_SELECTED = 0x00000020, // selected item in e.g. listbox
55 wxCONTROL_CHECKED = 0x00000040, // (check/radio button) is checked
56 wxCONTROL_CHECKABLE = 0x00000080, // (menu) item can be checked
415a0ff1 57 wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state
9c7f49f5
VZ
58
59 wxCONTROL_FLAGS_MASK = 0x000000ff,
60
61 // this is a pseudo flag not used directly by wxRenderer but rather by some
62 // controls internally
63 wxCONTROL_DIRTY = 0x80000000
64};
65
af99040c
VZ
66// ----------------------------------------------------------------------------
67// helper structs
68// ----------------------------------------------------------------------------
69
70// wxSplitterWindow parameters
71struct WXDLLEXPORT wxSplitterRenderParams
72{
73 // the only way to initialize this struct is by using this ctor
74 wxSplitterRenderParams(wxCoord widthSash_, wxCoord border_, bool isSens_)
75 : widthSash(widthSash_), border(border_), isHotSensitive(isSens_)
76 {
77 }
78
79 // the width of the splitter sash
80 const wxCoord widthSash;
81
82 // the width of the border of the splitter window
83 const wxCoord border;
84
85 // true if the splitter changes its appearance when the mouse is over it
86 const bool isHotSensitive;
87};
88
04857cb7
VZ
89// wxRendererNative interface version
90struct WXDLLEXPORT wxRendererVersion
91{
92 wxRendererVersion(int version_, int age_) : version(version_), age(age_) { }
93
94 // default copy ctor, assignment operator and dtor are ok
95
96 // the current version and age of wxRendererNative interface: different
97 // versions are incompatible (in both ways) while the ages inside the same
98 // version are upwards compatible, i.e. the version of the renderer must
99 // match the version of the main program exactly while the age may be
100 // highergreater or equal to it
101 //
102 // NB: don't forget to increment age after adding any new virtual function!
103 enum
104 {
105 Current_Version = 1,
106 Current_Age = 5
107 };
108
109
110 // check if the given version is compatible with the current one
111 static bool IsCompatible(const wxRendererVersion& ver)
112 {
113 return ver.version == Current_Version && ver.age >= Current_Age;
114 }
115
116 const int version;
117 const int age;
118};
119
9c7f49f5
VZ
120// ----------------------------------------------------------------------------
121// wxRendererNative: abstracts drawing methods needed by the native controls
122// ----------------------------------------------------------------------------
123
124class WXDLLEXPORT wxRendererNative
125{
126public:
127 // drawing functions
128 // -----------------
129
130 // draw the header control button (used by wxListCtrl)
131 virtual void DrawHeaderButton(wxWindow *win,
132 wxDC& dc,
133 const wxRect& rect,
134 int flags = 0) = 0;
135
136 // draw the expanded/collapsed icon for a tree control item
137 virtual void DrawTreeItemButton(wxWindow *win,
138 wxDC& dc,
139 const wxRect& rect,
140 int flags = 0) = 0;
141
b3208e11
VZ
142 // draw the border for sash window: this border must be such that the sash
143 // drawn by DrawSash() blends into it well
144 virtual void DrawSplitterBorder(wxWindow *win,
145 wxDC& dc,
af99040c
VZ
146 const wxRect& rect,
147 int flags = 0) = 0;
b3208e11
VZ
148
149 // draw a (vertical) sash
150 virtual void DrawSplitterSash(wxWindow *win,
151 wxDC& dc,
152 const wxSize& size,
62dc9cb4 153 wxCoord position,
af99040c
VZ
154 wxOrientation orient,
155 int flags = 0) = 0;
b3208e11 156
f33cef9f
VZ
157 // draw a combobox dropdown button
158 //
4c85ab75 159 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
f33cef9f
VZ
160 virtual void DrawComboBoxDropButton(wxWindow *win,
161 wxDC& dc,
162 const wxRect& rect,
163 int flags = 0) = 0;
164
4c85ab75
VZ
165 // draw a dropdown arrow
166 //
167 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
168 virtual void DrawDropArrow(wxWindow *win,
169 wxDC& dc,
170 const wxRect& rect,
171 int flags = 0) = 0;
b3208e11 172
862d8041
RR
173 // draw check button
174 //
175 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
90b903c2
WS
176 virtual void DrawCheckBox(wxWindow *win,
177 wxDC& dc,
178 const wxRect& rect,
179 int flags = 0) = 0;
2209baae
RR
180
181 // draw blank button
182 //
183 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
184 virtual void DrawPushButton(wxWindow *win,
185 wxDC& dc,
186 const wxRect& rect,
187 int flags = 0) = 0;
188
daebb44c
RR
189 // draw rectangle indicating that an item in e.g. a list control
190 // has been selected or focused
191 //
192 // flags may use
193 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
194 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
195 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
196 virtual void DrawItemSelectionRect(wxWindow *win,
197 wxDC& dc,
198 const wxRect& rect,
199 int flags = 0) = 0;
200
b3208e11
VZ
201 // geometry functions
202 // ------------------
203
204 // get the splitter parameters: the x field of the returned point is the
205 // sash width and the y field is the border width
af99040c 206 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0;
b3208e11 207
9c7f49f5
VZ
208
209 // pseudo constructors
210 // -------------------
211
212 // return the currently used renderer
213 static wxRendererNative& Get();
214
215 // return the generic implementation of the renderer
216 static wxRendererNative& GetGeneric();
f0244295
VZ
217
218 // return the default (native) implementation for this platform
219 static wxRendererNative& GetDefault();
9f2be125
VZ
220
221
222 // changing the global renderer
223 // ----------------------------
224
225#if wxUSE_DYNLIB_CLASS
226 // load the renderer from the specified DLL, the returned pointer must be
227 // deleted by caller if not NULL when it is not used any more
228 static wxRendererNative *Load(const wxString& name);
229#endif // wxUSE_DYNLIB_CLASS
230
231 // set the renderer to use, passing NULL reverts to using the default
232 // renderer
233 //
234 // return the previous renderer used with Set() or NULL if none
235 static wxRendererNative *Set(wxRendererNative *renderer);
04857cb7
VZ
236
237
238 // miscellaneous stuff
239 // -------------------
240
241 // this function is used for version checking: Load() refuses to load any
242 // DLLs implementing an older or incompatible version; it should be
243 // implemented simply by returning wxRendererVersion::Current_XXX values
244 virtual wxRendererVersion GetVersion() const = 0;
245
246 // virtual dtor for any base class
247 virtual ~wxRendererNative();
9c7f49f5
VZ
248};
249
250// ----------------------------------------------------------------------------
251// wxDelegateRendererNative: allows reuse of renderers code
252// ----------------------------------------------------------------------------
253
254class WXDLLEXPORT wxDelegateRendererNative : public wxRendererNative
255{
256public:
257 wxDelegateRendererNative()
258 : m_rendererNative(GetGeneric()) { }
259
260 wxDelegateRendererNative(wxRendererNative& rendererNative)
261 : m_rendererNative(rendererNative) { }
262
263
264 virtual void DrawHeaderButton(wxWindow *win,
265 wxDC& dc,
266 const wxRect& rect,
267 int flags = 0)
268 { m_rendererNative.DrawHeaderButton(win, dc, rect, flags); }
b3208e11 269
9c7f49f5
VZ
270 virtual void DrawTreeItemButton(wxWindow *win,
271 wxDC& dc,
272 const wxRect& rect,
273 int flags = 0)
274 { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); }
275
b3208e11
VZ
276 virtual void DrawSplitterBorder(wxWindow *win,
277 wxDC& dc,
af99040c
VZ
278 const wxRect& rect,
279 int flags = 0)
2c0e6de1 280 { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); }
b3208e11
VZ
281
282 virtual void DrawSplitterSash(wxWindow *win,
283 wxDC& dc,
284 const wxSize& size,
62dc9cb4 285 wxCoord position,
af99040c
VZ
286 wxOrientation orient,
287 int flags = 0)
2c0e6de1
VZ
288 { m_rendererNative.DrawSplitterSash(win, dc, size,
289 position, orient, flags); }
b3208e11 290
f33cef9f
VZ
291 virtual void DrawComboBoxDropButton(wxWindow *win,
292 wxDC& dc,
293 const wxRect& rect,
294 int flags = 0)
295 { m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); }
296
4c85ab75
VZ
297 virtual void DrawDropArrow(wxWindow *win,
298 wxDC& dc,
299 const wxRect& rect,
300 int flags = 0)
301 { m_rendererNative.DrawDropArrow(win, dc, rect, flags); }
b3208e11 302
90b903c2
WS
303 virtual void DrawCheckBox(wxWindow *win,
304 wxDC& dc,
305 const wxRect& rect,
306 int flags = 0 )
307 { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); }
2209baae
RR
308
309 virtual void DrawPushButton(wxWindow *win,
310 wxDC& dc,
311 const wxRect& rect,
312 int flags = 0 )
313 { m_rendererNative.DrawPushButton( win, dc, rect, flags ); }
314
daebb44c
RR
315 virtual void DrawItemSelectionRect(wxWindow *win,
316 wxDC& dc,
317 const wxRect& rect,
318 int flags = 0 )
319 { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); }
320
af99040c
VZ
321 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
322 { return m_rendererNative.GetSplitterParams(win); }
b3208e11 323
04857cb7
VZ
324 virtual wxRendererVersion GetVersion() const
325 { return m_rendererNative.GetVersion(); }
326
9c7f49f5
VZ
327protected:
328 wxRendererNative& m_rendererNative;
fc7a2a60
VZ
329
330 DECLARE_NO_COPY_CLASS(wxDelegateRendererNative)
9c7f49f5
VZ
331};
332
f0244295
VZ
333// ----------------------------------------------------------------------------
334// inline functions implementation
335// ----------------------------------------------------------------------------
336
337#ifndef wxHAS_NATIVE_RENDERER
338
339// default native renderer is the generic one then
340/* static */ inline
341wxRendererNative& wxRendererNative::GetDefault()
342{
343 return GetGeneric();
344}
345
346#endif // !wxHAS_NATIVE_RENDERER
347
9c7f49f5 348#endif // _WX_RENDERER_H_