]> git.saurik.com Git - wxWidgets.git/blob - include/wx/renderer.h
compilation fix for VC6 with wxUSE_STL=1
[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 WXDLLEXPORT wxDC;
29 class WXDLLEXPORT wxWindow;
30
31 #include "wx/gdicmn.h" // for wxPoint
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__) || 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_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
63 wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state
64
65 wxCONTROL_FLAGS_MASK = 0x000000ff,
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
72 // ----------------------------------------------------------------------------
73 // helper structs
74 // ----------------------------------------------------------------------------
75
76 // wxSplitterWindow parameters
77 struct 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
95
96 // extra optional parameters for DrawHeaderButton
97 struct WXDLLEXPORT wxHeaderButtonParams
98 {
99 wxHeaderButtonParams()
100 : m_labelAlignment(wxALIGN_LEFT)
101 { }
102
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
112 enum 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
118
119 // wxRendererNative interface version
120 struct 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
150 // ----------------------------------------------------------------------------
151 // wxRendererNative: abstracts drawing methods needed by the native controls
152 // ----------------------------------------------------------------------------
153
154 class WXDLLEXPORT wxRendererNative
155 {
156 public:
157 // drawing functions
158 // -----------------
159
160 // draw the header control button (used by wxListCtrl) Returns optimal
161 // width for the label contents.
162 virtual int DrawHeaderButton(wxWindow *win,
163 wxDC& dc,
164 const wxRect& rect,
165 int flags = 0,
166 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
167 wxHeaderButtonParams* params=NULL) = 0;
168
169
170 // Draw the contents of a header control button (label, sort arrows, etc.)
171 // Normally only called by DrawHeaderButton.
172 virtual int DrawHeaderButtonContents(wxWindow *win,
173 wxDC& dc,
174 const wxRect& rect,
175 int flags = 0,
176 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
177 wxHeaderButtonParams* params=NULL) = 0;
178
179 // Returns the default height of a header button, either a fixed platform
180 // height if available, or a generic height based on the window's font.
181 virtual int GetHeaderButtonHeight(wxWindow *win) = 0;
182
183
184 // draw the expanded/collapsed icon for a tree control item
185 virtual void DrawTreeItemButton(wxWindow *win,
186 wxDC& dc,
187 const wxRect& rect,
188 int flags = 0) = 0;
189
190 // draw the border for sash window: this border must be such that the sash
191 // drawn by DrawSash() blends into it well
192 virtual void DrawSplitterBorder(wxWindow *win,
193 wxDC& dc,
194 const wxRect& rect,
195 int flags = 0) = 0;
196
197 // draw a (vertical) sash
198 virtual void DrawSplitterSash(wxWindow *win,
199 wxDC& dc,
200 const wxSize& size,
201 wxCoord position,
202 wxOrientation orient,
203 int flags = 0) = 0;
204
205 // draw a combobox dropdown button
206 //
207 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
208 virtual void DrawComboBoxDropButton(wxWindow *win,
209 wxDC& dc,
210 const wxRect& rect,
211 int flags = 0) = 0;
212
213 // draw a dropdown arrow
214 //
215 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
216 virtual void DrawDropArrow(wxWindow *win,
217 wxDC& dc,
218 const wxRect& rect,
219 int flags = 0) = 0;
220
221 // draw check button
222 //
223 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
224 virtual void DrawCheckBox(wxWindow *win,
225 wxDC& dc,
226 const wxRect& rect,
227 int flags = 0) = 0;
228
229 // draw blank button
230 //
231 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
232 virtual void DrawPushButton(wxWindow *win,
233 wxDC& dc,
234 const wxRect& rect,
235 int flags = 0) = 0;
236
237 // draw rectangle indicating that an item in e.g. a list control
238 // has been selected or focused
239 //
240 // flags may use
241 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
242 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
243 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
244 virtual void DrawItemSelectionRect(wxWindow *win,
245 wxDC& dc,
246 const wxRect& rect,
247 int flags = 0) = 0;
248
249 // geometry functions
250 // ------------------
251
252 // get the splitter parameters: the x field of the returned point is the
253 // sash width and the y field is the border width
254 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0;
255
256
257 // pseudo constructors
258 // -------------------
259
260 // return the currently used renderer
261 static wxRendererNative& Get();
262
263 // return the generic implementation of the renderer
264 static wxRendererNative& GetGeneric();
265
266 // return the default (native) implementation for this platform
267 static wxRendererNative& GetDefault();
268
269
270 // changing the global renderer
271 // ----------------------------
272
273 #if wxUSE_DYNLIB_CLASS
274 // load the renderer from the specified DLL, the returned pointer must be
275 // deleted by caller if not NULL when it is not used any more
276 static wxRendererNative *Load(const wxString& name);
277 #endif // wxUSE_DYNLIB_CLASS
278
279 // set the renderer to use, passing NULL reverts to using the default
280 // renderer
281 //
282 // return the previous renderer used with Set() or NULL if none
283 static wxRendererNative *Set(wxRendererNative *renderer);
284
285
286 // miscellaneous stuff
287 // -------------------
288
289 // this function is used for version checking: Load() refuses to load any
290 // DLLs implementing an older or incompatible version; it should be
291 // implemented simply by returning wxRendererVersion::Current_XXX values
292 virtual wxRendererVersion GetVersion() const = 0;
293
294 // virtual dtor for any base class
295 virtual ~wxRendererNative();
296 };
297
298 // ----------------------------------------------------------------------------
299 // wxDelegateRendererNative: allows reuse of renderers code
300 // ----------------------------------------------------------------------------
301
302 class WXDLLEXPORT wxDelegateRendererNative : public wxRendererNative
303 {
304 public:
305 wxDelegateRendererNative()
306 : m_rendererNative(GetGeneric()) { }
307
308 wxDelegateRendererNative(wxRendererNative& rendererNative)
309 : m_rendererNative(rendererNative) { }
310
311
312 virtual int DrawHeaderButton(wxWindow *win,
313 wxDC& dc,
314 const wxRect& rect,
315 int flags = 0,
316 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
317 wxHeaderButtonParams* params = NULL)
318 { return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
319
320 virtual int DrawHeaderButtonContents(wxWindow *win,
321 wxDC& dc,
322 const wxRect& rect,
323 int flags = 0,
324 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
325 wxHeaderButtonParams* params = NULL)
326 { return m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); }
327
328 virtual int GetHeaderButtonHeight(wxWindow *win)
329 { return m_rendererNative.GetHeaderButtonHeight(win); }
330
331 virtual void DrawTreeItemButton(wxWindow *win,
332 wxDC& dc,
333 const wxRect& rect,
334 int flags = 0)
335 { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); }
336
337 virtual void DrawSplitterBorder(wxWindow *win,
338 wxDC& dc,
339 const wxRect& rect,
340 int flags = 0)
341 { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); }
342
343 virtual void DrawSplitterSash(wxWindow *win,
344 wxDC& dc,
345 const wxSize& size,
346 wxCoord position,
347 wxOrientation orient,
348 int flags = 0)
349 { m_rendererNative.DrawSplitterSash(win, dc, size,
350 position, orient, flags); }
351
352 virtual void DrawComboBoxDropButton(wxWindow *win,
353 wxDC& dc,
354 const wxRect& rect,
355 int flags = 0)
356 { m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); }
357
358 virtual void DrawDropArrow(wxWindow *win,
359 wxDC& dc,
360 const wxRect& rect,
361 int flags = 0)
362 { m_rendererNative.DrawDropArrow(win, dc, rect, flags); }
363
364 virtual void DrawCheckBox(wxWindow *win,
365 wxDC& dc,
366 const wxRect& rect,
367 int flags = 0 )
368 { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); }
369
370 virtual void DrawPushButton(wxWindow *win,
371 wxDC& dc,
372 const wxRect& rect,
373 int flags = 0 )
374 { m_rendererNative.DrawPushButton( win, dc, rect, flags ); }
375
376 virtual void DrawItemSelectionRect(wxWindow *win,
377 wxDC& dc,
378 const wxRect& rect,
379 int flags = 0 )
380 { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); }
381
382 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
383 { return m_rendererNative.GetSplitterParams(win); }
384
385 virtual wxRendererVersion GetVersion() const
386 { return m_rendererNative.GetVersion(); }
387
388 protected:
389 wxRendererNative& m_rendererNative;
390
391 DECLARE_NO_COPY_CLASS(wxDelegateRendererNative)
392 };
393
394 // ----------------------------------------------------------------------------
395 // inline functions implementation
396 // ----------------------------------------------------------------------------
397
398 #ifndef wxHAS_NATIVE_RENDERER
399
400 // default native renderer is the generic one then
401 /* static */ inline
402 wxRendererNative& wxRendererNative::GetDefault()
403 {
404 return GetGeneric();
405 }
406
407 #endif // !wxHAS_NATIVE_RENDERER
408
409 #endif // _WX_RENDERER_H_