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
58 wxCONTROL_UPICON
= 0x00000100, // header button has an up arrow icon
59 wxCONTROL_DOWNICON
= 0x00000200, // header button has a down arrow icon
61 wxCONTROL_FLAGS_MASK
= 0x000002ff,
63 // this is a pseudo flag not used directly by wxRenderer but rather by some
64 // controls internally
65 wxCONTROL_DIRTY
= 0x80000000
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 // wxSplitterWindow parameters
73 struct WXDLLEXPORT wxSplitterRenderParams
75 // the only way to initialize this struct is by using this ctor
76 wxSplitterRenderParams(wxCoord widthSash_
, wxCoord border_
, bool isSens_
)
77 : widthSash(widthSash_
), border(border_
), isHotSensitive(isSens_
)
81 // the width of the splitter sash
82 const wxCoord widthSash
;
84 // the width of the border of the splitter window
87 // true if the splitter changes its appearance when the mouse is over it
88 const bool isHotSensitive
;
92 // extra optional parameters for DrawHeaderButton
93 struct WXDLLEXPORT wxHeaderButtonParams
95 wxHeaderButtonParams()
96 : m_labelAlignment(wxALIGN_LEFT
)
99 wxColour m_arrowColour
;
100 wxColour m_selectionColour
;
101 wxString m_labelText
;
103 wxColour m_labelColour
;
104 wxBitmap m_labelBitmap
;
105 int m_labelAlignment
;
109 // wxRendererNative interface version
110 struct WXDLLEXPORT wxRendererVersion
112 wxRendererVersion(int version_
, int age_
) : version(version_
), age(age_
) { }
114 // default copy ctor, assignment operator and dtor are ok
116 // the current version and age of wxRendererNative interface: different
117 // versions are incompatible (in both ways) while the ages inside the same
118 // version are upwards compatible, i.e. the version of the renderer must
119 // match the version of the main program exactly while the age may be
120 // highergreater or equal to it
122 // NB: don't forget to increment age after adding any new virtual function!
130 // check if the given version is compatible with the current one
131 static bool IsCompatible(const wxRendererVersion
& ver
)
133 return ver
.version
== Current_Version
&& ver
.age
>= Current_Age
;
140 // ----------------------------------------------------------------------------
141 // wxRendererNative: abstracts drawing methods needed by the native controls
142 // ----------------------------------------------------------------------------
144 class WXDLLEXPORT wxRendererNative
150 // draw the header control button (used by wxListCtrl)
151 virtual void DrawHeaderButton(wxWindow
*win
,
155 wxHeaderButtonParams
* params
=NULL
) = 0;
158 // Draw the contents of a header control button (label, sort arrows, etc.)
159 // Normally only called by DrawHeaderButton.
160 virtual void DrawHeaderButtonContents(wxWindow
*win
,
164 wxHeaderButtonParams
* params
=NULL
) = 0;
166 // Returns the default height of a header button, either a fixed platform
167 // height if available, or a generic height based on the window's font.
168 virtual int GetHeaderButtonHeight(wxWindow
*win
) = 0;
171 // draw the expanded/collapsed icon for a tree control item
172 virtual void DrawTreeItemButton(wxWindow
*win
,
177 // draw the border for sash window: this border must be such that the sash
178 // drawn by DrawSash() blends into it well
179 virtual void DrawSplitterBorder(wxWindow
*win
,
184 // draw a (vertical) sash
185 virtual void DrawSplitterSash(wxWindow
*win
,
189 wxOrientation orient
,
192 // draw a combobox dropdown button
194 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
195 virtual void DrawComboBoxDropButton(wxWindow
*win
,
200 // draw a dropdown arrow
202 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
203 virtual void DrawDropArrow(wxWindow
*win
,
210 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
211 virtual void DrawCheckBox(wxWindow
*win
,
218 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
219 virtual void DrawPushButton(wxWindow
*win
,
224 // draw rectangle indicating that an item in e.g. a list control
225 // has been selected or focused
228 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
229 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
230 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
231 virtual void DrawItemSelectionRect(wxWindow
*win
,
236 // geometry functions
237 // ------------------
239 // get the splitter parameters: the x field of the returned point is the
240 // sash width and the y field is the border width
241 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
) = 0;
244 // pseudo constructors
245 // -------------------
247 // return the currently used renderer
248 static wxRendererNative
& Get();
250 // return the generic implementation of the renderer
251 static wxRendererNative
& GetGeneric();
253 // return the default (native) implementation for this platform
254 static wxRendererNative
& GetDefault();
257 // changing the global renderer
258 // ----------------------------
260 #if wxUSE_DYNLIB_CLASS
261 // load the renderer from the specified DLL, the returned pointer must be
262 // deleted by caller if not NULL when it is not used any more
263 static wxRendererNative
*Load(const wxString
& name
);
264 #endif // wxUSE_DYNLIB_CLASS
266 // set the renderer to use, passing NULL reverts to using the default
269 // return the previous renderer used with Set() or NULL if none
270 static wxRendererNative
*Set(wxRendererNative
*renderer
);
273 // miscellaneous stuff
274 // -------------------
276 // this function is used for version checking: Load() refuses to load any
277 // DLLs implementing an older or incompatible version; it should be
278 // implemented simply by returning wxRendererVersion::Current_XXX values
279 virtual wxRendererVersion
GetVersion() const = 0;
281 // virtual dtor for any base class
282 virtual ~wxRendererNative();
285 // ----------------------------------------------------------------------------
286 // wxDelegateRendererNative: allows reuse of renderers code
287 // ----------------------------------------------------------------------------
289 class WXDLLEXPORT wxDelegateRendererNative
: public wxRendererNative
292 wxDelegateRendererNative()
293 : m_rendererNative(GetGeneric()) { }
295 wxDelegateRendererNative(wxRendererNative
& rendererNative
)
296 : m_rendererNative(rendererNative
) { }
299 virtual void DrawHeaderButton(wxWindow
*win
,
303 wxHeaderButtonParams
* params
= NULL
)
304 { m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, params
); }
307 virtual void DrawHeaderButtonContents(wxWindow
*win
,
311 wxHeaderButtonParams
* params
= NULL
)
312 { m_rendererNative
.DrawHeaderButtonContents(win
, dc
, rect
, flags
, params
); }
315 virtual int GetHeaderButtonHeight(wxWindow
*win
)
316 { return m_rendererNative
.GetHeaderButtonHeight(win
); }
318 virtual void DrawTreeItemButton(wxWindow
*win
,
322 { m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
); }
324 virtual void DrawSplitterBorder(wxWindow
*win
,
328 { m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
); }
330 virtual void DrawSplitterSash(wxWindow
*win
,
334 wxOrientation orient
,
336 { m_rendererNative
.DrawSplitterSash(win
, dc
, size
,
337 position
, orient
, flags
); }
339 virtual void DrawComboBoxDropButton(wxWindow
*win
,
343 { m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
); }
345 virtual void DrawDropArrow(wxWindow
*win
,
349 { m_rendererNative
.DrawDropArrow(win
, dc
, rect
, flags
); }
351 virtual void DrawCheckBox(wxWindow
*win
,
355 { m_rendererNative
.DrawCheckBox( win
, dc
, rect
, flags
); }
357 virtual void DrawPushButton(wxWindow
*win
,
361 { m_rendererNative
.DrawPushButton( win
, dc
, rect
, flags
); }
363 virtual void DrawItemSelectionRect(wxWindow
*win
,
367 { m_rendererNative
.DrawItemSelectionRect( win
, dc
, rect
, flags
); }
369 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
)
370 { return m_rendererNative
.GetSplitterParams(win
); }
372 virtual wxRendererVersion
GetVersion() const
373 { return m_rendererNative
.GetVersion(); }
376 wxRendererNative
& m_rendererNative
;
378 DECLARE_NO_COPY_CLASS(wxDelegateRendererNative
)
381 // ----------------------------------------------------------------------------
382 // inline functions implementation
383 // ----------------------------------------------------------------------------
385 #ifndef wxHAS_NATIVE_RENDERER
387 // default native renderer is the generic one then
389 wxRendererNative
& wxRendererNative::GetDefault()
394 #endif // !wxHAS_NATIVE_RENDERER
396 #endif // _WX_RENDERER_H_