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
33 // some platforms have their own renderers, others use the generic one
34 #if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXGTK__)
35 #define wxHAS_NATIVE_RENDERER
37 #undef wxHAS_NATIVE_RENDERER
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // control state flags used in wxRenderer and wxColourScheme
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
57 wxCONTROL_UNDETERMINED
= wxCONTROL_CHECKABLE
, // (check) undetermined state
59 wxCONTROL_FLAGS_MASK
= 0x000000ff,
61 // this is a pseudo flag not used directly by wxRenderer but rather by some
62 // controls internally
63 wxCONTROL_DIRTY
= 0x80000000
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 // wxSplitterWindow parameters
71 struct WXDLLEXPORT wxSplitterRenderParams
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_
)
79 // the width of the splitter sash
80 const wxCoord widthSash
;
82 // the width of the border of the splitter window
85 // true if the splitter changes its appearance when the mouse is over it
86 const bool isHotSensitive
;
89 // wxRendererNative interface version
90 struct WXDLLEXPORT wxRendererVersion
92 wxRendererVersion(int version_
, int age_
) : version(version_
), age(age_
) { }
94 // default copy ctor, assignment operator and dtor are ok
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
102 // NB: don't forget to increment age after adding any new virtual function!
110 // check if the given version is compatible with the current one
111 static bool IsCompatible(const wxRendererVersion
& ver
)
113 return ver
.version
== Current_Version
&& ver
.age
>= Current_Age
;
120 // ----------------------------------------------------------------------------
121 // wxRendererNative: abstracts drawing methods needed by the native controls
122 // ----------------------------------------------------------------------------
124 class WXDLLEXPORT wxRendererNative
130 // draw the header control button (used by wxListCtrl)
131 virtual void DrawHeaderButton(wxWindow
*win
,
136 // draw the expanded/collapsed icon for a tree control item
137 virtual void DrawTreeItemButton(wxWindow
*win
,
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
,
149 // draw a (vertical) sash
150 virtual void DrawSplitterSash(wxWindow
*win
,
154 wxOrientation orient
,
157 // draw a combobox dropdown button
159 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
160 virtual void DrawComboBoxDropButton(wxWindow
*win
,
165 // draw a dropdown arrow
167 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
168 virtual void DrawDropArrow(wxWindow
*win
,
176 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
177 virtual void DrawCheckButton(wxWindow
*win
,
182 // geometry functions
183 // ------------------
185 // get the splitter parameters: the x field of the returned point is the
186 // sash width and the y field is the border width
187 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
) = 0;
190 // pseudo constructors
191 // -------------------
193 // return the currently used renderer
194 static wxRendererNative
& Get();
196 // return the generic implementation of the renderer
197 static wxRendererNative
& GetGeneric();
199 // return the default (native) implementation for this platform
200 static wxRendererNative
& GetDefault();
203 // changing the global renderer
204 // ----------------------------
206 #if wxUSE_DYNLIB_CLASS
207 // load the renderer from the specified DLL, the returned pointer must be
208 // deleted by caller if not NULL when it is not used any more
209 static wxRendererNative
*Load(const wxString
& name
);
210 #endif // wxUSE_DYNLIB_CLASS
212 // set the renderer to use, passing NULL reverts to using the default
215 // return the previous renderer used with Set() or NULL if none
216 static wxRendererNative
*Set(wxRendererNative
*renderer
);
219 // miscellaneous stuff
220 // -------------------
222 // this function is used for version checking: Load() refuses to load any
223 // DLLs implementing an older or incompatible version; it should be
224 // implemented simply by returning wxRendererVersion::Current_XXX values
225 virtual wxRendererVersion
GetVersion() const = 0;
227 // virtual dtor for any base class
228 virtual ~wxRendererNative();
231 // ----------------------------------------------------------------------------
232 // wxDelegateRendererNative: allows reuse of renderers code
233 // ----------------------------------------------------------------------------
235 class WXDLLEXPORT wxDelegateRendererNative
: public wxRendererNative
238 wxDelegateRendererNative()
239 : m_rendererNative(GetGeneric()) { }
241 wxDelegateRendererNative(wxRendererNative
& rendererNative
)
242 : m_rendererNative(rendererNative
) { }
245 virtual void DrawHeaderButton(wxWindow
*win
,
249 { m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
); }
251 virtual void DrawTreeItemButton(wxWindow
*win
,
255 { m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
); }
257 virtual void DrawSplitterBorder(wxWindow
*win
,
261 { m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
); }
263 virtual void DrawSplitterSash(wxWindow
*win
,
267 wxOrientation orient
,
269 { m_rendererNative
.DrawSplitterSash(win
, dc
, size
,
270 position
, orient
, flags
); }
272 virtual void DrawComboBoxDropButton(wxWindow
*win
,
276 { m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
); }
278 virtual void DrawDropArrow(wxWindow
*win
,
282 { m_rendererNative
.DrawDropArrow(win
, dc
, rect
, flags
); }
284 virtual void DrawCheckButton(wxWindow
*win
,
288 { m_rendererNative
.DrawCheckButton( win
, dc
, rect
, flags
); }
290 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
)
291 { return m_rendererNative
.GetSplitterParams(win
); }
293 virtual wxRendererVersion
GetVersion() const
294 { return m_rendererNative
.GetVersion(); }
297 wxRendererNative
& m_rendererNative
;
299 DECLARE_NO_COPY_CLASS(wxDelegateRendererNative
)
302 // ----------------------------------------------------------------------------
303 // inline functions implementation
304 // ----------------------------------------------------------------------------
306 #ifndef wxHAS_NATIVE_RENDERER
308 // default native renderer is the generic one then
310 wxRendererNative
& wxRendererNative::GetDefault()
315 #endif // !wxHAS_NATIVE_RENDERER
317 #endif // _WX_RENDERER_H_