1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRendererNative class declaration
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
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
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).
25 #ifndef _WX_RENDERER_H_
26 #define _WX_RENDERER_H_
28 class WXDLLEXPORT wxDC
;
29 class WXDLLEXPORT wxWindow
;
31 #include "wx/gdicmn.h" // for wxPoint
32 #include "wx/colour.h"
34 #include "wx/bitmap.h"
35 #include "wx/string.h"
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
41 #undef wxHAS_NATIVE_RENDERER
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // control state flags used in wxRenderer and wxColourScheme
51 wxCONTROL_DISABLED
= 0x00000001, // control is disabled
52 wxCONTROL_FOCUSED
= 0x00000002, // currently has keyboard focus
53 wxCONTROL_PRESSED
= 0x00000004, // (button) is pressed
54 wxCONTROL_ISDEFAULT
= 0x00000008, // only applies to the buttons
55 wxCONTROL_ISSUBMENU
= wxCONTROL_ISDEFAULT
, // only for menu items
56 wxCONTROL_EXPANDED
= wxCONTROL_ISDEFAULT
, // only for the tree items
57 wxCONTROL_CURRENT
= 0x00000010, // mouse is currently over the control
58 wxCONTROL_SELECTED
= 0x00000020, // selected item in e.g. listbox
59 wxCONTROL_CHECKED
= 0x00000040, // (check/radio button) is checked
60 wxCONTROL_CHECKABLE
= 0x00000080, // (menu) item can be checked
61 wxCONTROL_UNDETERMINED
= wxCONTROL_CHECKABLE
, // (check) undetermined state
62 wxCONTROL_UPICON
= 0x00000100, // header button has an up arrow icon
63 wxCONTROL_DOWNICON
= 0x00000200, // header button has a down arrow icon
65 wxCONTROL_FLAGS_MASK
= 0x000002ff,
67 // this is a pseudo flag not used directly by wxRenderer but rather by some
68 // controls internally
69 wxCONTROL_DIRTY
= 0x80000000
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 // wxSplitterWindow parameters
77 struct WXDLLEXPORT wxSplitterRenderParams
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_
)
85 // the width of the splitter sash
86 const wxCoord widthSash
;
88 // the width of the border of the splitter window
91 // true if the splitter changes its appearance when the mouse is over it
92 const bool isHotSensitive
;
96 // extra optional parameters for DrawHeaderButton
97 struct WXDLLEXPORT wxHeaderButtonParams
99 wxHeaderButtonParams()
100 : m_labelAlignment(wxALIGN_LEFT
)
103 wxColour m_arrowColour
;
104 wxColour m_selectionColour
;
105 wxString m_labelText
;
107 wxColour m_labelColour
;
108 wxBitmap m_labelBitmap
;
109 int m_labelAlignment
;
113 // wxRendererNative interface version
114 struct WXDLLEXPORT wxRendererVersion
116 wxRendererVersion(int version_
, int age_
) : version(version_
), age(age_
) { }
118 // default copy ctor, assignment operator and dtor are ok
120 // the current version and age of wxRendererNative interface: different
121 // versions are incompatible (in both ways) while the ages inside the same
122 // version are upwards compatible, i.e. the version of the renderer must
123 // match the version of the main program exactly while the age may be
124 // highergreater or equal to it
126 // NB: don't forget to increment age after adding any new virtual function!
134 // check if the given version is compatible with the current one
135 static bool IsCompatible(const wxRendererVersion
& ver
)
137 return ver
.version
== Current_Version
&& ver
.age
>= Current_Age
;
144 // ----------------------------------------------------------------------------
145 // wxRendererNative: abstracts drawing methods needed by the native controls
146 // ----------------------------------------------------------------------------
148 class WXDLLEXPORT wxRendererNative
154 // draw the header control button (used by wxListCtrl)
155 virtual void DrawHeaderButton(wxWindow
*win
,
159 wxHeaderButtonParams
* params
=NULL
) = 0;
162 // Draw the contents of a header control button (label, sort arrows, etc.)
163 // Normally only called by DrawHeaderButton.
164 virtual void DrawHeaderButtonContents(wxWindow
*win
,
168 wxHeaderButtonParams
* params
=NULL
) = 0;
170 // Returns the default height of a header button, either a fixed platform
171 // height if available, or a generic height based on the window's font.
172 virtual int GetHeaderButtonHeight(wxWindow
*win
) = 0;
175 // draw the expanded/collapsed icon for a tree control item
176 virtual void DrawTreeItemButton(wxWindow
*win
,
181 // draw the border for sash window: this border must be such that the sash
182 // drawn by DrawSash() blends into it well
183 virtual void DrawSplitterBorder(wxWindow
*win
,
188 // draw a (vertical) sash
189 virtual void DrawSplitterSash(wxWindow
*win
,
193 wxOrientation orient
,
196 // draw a combobox dropdown button
198 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
199 virtual void DrawComboBoxDropButton(wxWindow
*win
,
204 // draw a dropdown arrow
206 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
207 virtual void DrawDropArrow(wxWindow
*win
,
214 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
215 virtual void DrawCheckBox(wxWindow
*win
,
222 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
223 virtual void DrawPushButton(wxWindow
*win
,
228 // draw rectangle indicating that an item in e.g. a list control
229 // has been selected or focused
232 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
233 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
234 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
235 virtual void DrawItemSelectionRect(wxWindow
*win
,
240 // geometry functions
241 // ------------------
243 // get the splitter parameters: the x field of the returned point is the
244 // sash width and the y field is the border width
245 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
) = 0;
248 // pseudo constructors
249 // -------------------
251 // return the currently used renderer
252 static wxRendererNative
& Get();
254 // return the generic implementation of the renderer
255 static wxRendererNative
& GetGeneric();
257 // return the default (native) implementation for this platform
258 static wxRendererNative
& GetDefault();
261 // changing the global renderer
262 // ----------------------------
264 #if wxUSE_DYNLIB_CLASS
265 // load the renderer from the specified DLL, the returned pointer must be
266 // deleted by caller if not NULL when it is not used any more
267 static wxRendererNative
*Load(const wxString
& name
);
268 #endif // wxUSE_DYNLIB_CLASS
270 // set the renderer to use, passing NULL reverts to using the default
273 // return the previous renderer used with Set() or NULL if none
274 static wxRendererNative
*Set(wxRendererNative
*renderer
);
277 // miscellaneous stuff
278 // -------------------
280 // this function is used for version checking: Load() refuses to load any
281 // DLLs implementing an older or incompatible version; it should be
282 // implemented simply by returning wxRendererVersion::Current_XXX values
283 virtual wxRendererVersion
GetVersion() const = 0;
285 // virtual dtor for any base class
286 virtual ~wxRendererNative();
289 // ----------------------------------------------------------------------------
290 // wxDelegateRendererNative: allows reuse of renderers code
291 // ----------------------------------------------------------------------------
293 class WXDLLEXPORT wxDelegateRendererNative
: public wxRendererNative
296 wxDelegateRendererNative()
297 : m_rendererNative(GetGeneric()) { }
299 wxDelegateRendererNative(wxRendererNative
& rendererNative
)
300 : m_rendererNative(rendererNative
) { }
303 virtual void DrawHeaderButton(wxWindow
*win
,
307 wxHeaderButtonParams
* params
= NULL
)
308 { m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, params
); }
311 virtual void DrawHeaderButtonContents(wxWindow
*win
,
315 wxHeaderButtonParams
* params
= NULL
)
316 { m_rendererNative
.DrawHeaderButtonContents(win
, dc
, rect
, flags
, params
); }
319 virtual int GetHeaderButtonHeight(wxWindow
*win
)
320 { return m_rendererNative
.GetHeaderButtonHeight(win
); }
322 virtual void DrawTreeItemButton(wxWindow
*win
,
326 { m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
); }
328 virtual void DrawSplitterBorder(wxWindow
*win
,
332 { m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
); }
334 virtual void DrawSplitterSash(wxWindow
*win
,
338 wxOrientation orient
,
340 { m_rendererNative
.DrawSplitterSash(win
, dc
, size
,
341 position
, orient
, flags
); }
343 virtual void DrawComboBoxDropButton(wxWindow
*win
,
347 { m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
); }
349 virtual void DrawDropArrow(wxWindow
*win
,
353 { m_rendererNative
.DrawDropArrow(win
, dc
, rect
, flags
); }
355 virtual void DrawCheckBox(wxWindow
*win
,
359 { m_rendererNative
.DrawCheckBox( win
, dc
, rect
, flags
); }
361 virtual void DrawPushButton(wxWindow
*win
,
365 { m_rendererNative
.DrawPushButton( win
, dc
, rect
, flags
); }
367 virtual void DrawItemSelectionRect(wxWindow
*win
,
371 { m_rendererNative
.DrawItemSelectionRect( win
, dc
, rect
, flags
); }
373 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
)
374 { return m_rendererNative
.GetSplitterParams(win
); }
376 virtual wxRendererVersion
GetVersion() const
377 { return m_rendererNative
.GetVersion(); }
380 wxRendererNative
& m_rendererNative
;
382 DECLARE_NO_COPY_CLASS(wxDelegateRendererNative
)
385 // ----------------------------------------------------------------------------
386 // inline functions implementation
387 // ----------------------------------------------------------------------------
389 #ifndef wxHAS_NATIVE_RENDERER
391 // default native renderer is the generic one then
393 wxRendererNative
& wxRendererNative::GetDefault()
398 #endif // !wxHAS_NATIVE_RENDERER
400 #endif // _WX_RENDERER_H_