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_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
65 wxCONTROL_FLAGS_MASK
= 0x000000ff,
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
;
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
119 // wxRendererNative interface version
120 struct WXDLLEXPORT wxRendererVersion
122 wxRendererVersion(int version_
, int age_
) : version(version_
), age(age_
) { }
124 // default copy ctor, assignment operator and dtor are ok
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
132 // NB: don't forget to increment age after adding any new virtual function!
140 // check if the given version is compatible with the current one
141 static bool IsCompatible(const wxRendererVersion
& ver
)
143 return ver
.version
== Current_Version
&& ver
.age
>= Current_Age
;
150 // ----------------------------------------------------------------------------
151 // wxRendererNative: abstracts drawing methods needed by the native controls
152 // ----------------------------------------------------------------------------
154 class WXDLLEXPORT wxRendererNative
160 // draw the header control button (used by wxListCtrl) Returns optimal
161 // width for the label contents.
162 virtual int DrawHeaderButton(wxWindow
*win
,
166 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
167 wxHeaderButtonParams
* params
=NULL
) = 0;
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
,
176 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
177 wxHeaderButtonParams
* params
=NULL
) = 0;
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;
184 // draw the expanded/collapsed icon for a tree control item
185 virtual void DrawTreeItemButton(wxWindow
*win
,
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
,
197 // draw a (vertical) sash
198 virtual void DrawSplitterSash(wxWindow
*win
,
202 wxOrientation orient
,
205 // draw a combobox dropdown button
207 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
208 virtual void DrawComboBoxDropButton(wxWindow
*win
,
213 // draw a dropdown arrow
215 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
216 virtual void DrawDropArrow(wxWindow
*win
,
223 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
224 virtual void DrawCheckBox(wxWindow
*win
,
231 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
232 virtual void DrawPushButton(wxWindow
*win
,
237 // draw rectangle indicating that an item in e.g. a list control
238 // has been selected or focused
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
,
249 // geometry functions
250 // ------------------
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;
257 // pseudo constructors
258 // -------------------
260 // return the currently used renderer
261 static wxRendererNative
& Get();
263 // return the generic implementation of the renderer
264 static wxRendererNative
& GetGeneric();
266 // return the default (native) implementation for this platform
267 static wxRendererNative
& GetDefault();
270 // changing the global renderer
271 // ----------------------------
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
279 // set the renderer to use, passing NULL reverts to using the default
282 // return the previous renderer used with Set() or NULL if none
283 static wxRendererNative
*Set(wxRendererNative
*renderer
);
286 // miscellaneous stuff
287 // -------------------
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;
294 // virtual dtor for any base class
295 virtual ~wxRendererNative();
298 // ----------------------------------------------------------------------------
299 // wxDelegateRendererNative: allows reuse of renderers code
300 // ----------------------------------------------------------------------------
302 class WXDLLEXPORT wxDelegateRendererNative
: public wxRendererNative
305 wxDelegateRendererNative()
306 : m_rendererNative(GetGeneric()) { }
308 wxDelegateRendererNative(wxRendererNative
& rendererNative
)
309 : m_rendererNative(rendererNative
) { }
312 virtual int DrawHeaderButton(wxWindow
*win
,
316 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
317 wxHeaderButtonParams
* params
= NULL
)
318 { return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
); }
320 virtual int DrawHeaderButtonContents(wxWindow
*win
,
324 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
325 wxHeaderButtonParams
* params
= NULL
)
326 { return m_rendererNative
.DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
); }
328 virtual int GetHeaderButtonHeight(wxWindow
*win
)
329 { return m_rendererNative
.GetHeaderButtonHeight(win
); }
331 virtual void DrawTreeItemButton(wxWindow
*win
,
335 { m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
); }
337 virtual void DrawSplitterBorder(wxWindow
*win
,
341 { m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
); }
343 virtual void DrawSplitterSash(wxWindow
*win
,
347 wxOrientation orient
,
349 { m_rendererNative
.DrawSplitterSash(win
, dc
, size
,
350 position
, orient
, flags
); }
352 virtual void DrawComboBoxDropButton(wxWindow
*win
,
356 { m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
); }
358 virtual void DrawDropArrow(wxWindow
*win
,
362 { m_rendererNative
.DrawDropArrow(win
, dc
, rect
, flags
); }
364 virtual void DrawCheckBox(wxWindow
*win
,
368 { m_rendererNative
.DrawCheckBox( win
, dc
, rect
, flags
); }
370 virtual void DrawPushButton(wxWindow
*win
,
374 { m_rendererNative
.DrawPushButton( win
, dc
, rect
, flags
); }
376 virtual void DrawItemSelectionRect(wxWindow
*win
,
380 { m_rendererNative
.DrawItemSelectionRect( win
, dc
, rect
, flags
); }
382 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
)
383 { return m_rendererNative
.GetSplitterParams(win
); }
385 virtual wxRendererVersion
GetVersion() const
386 { return m_rendererNative
.GetVersion(); }
389 wxRendererNative
& m_rendererNative
;
391 DECLARE_NO_COPY_CLASS(wxDelegateRendererNative
)
394 // ----------------------------------------------------------------------------
395 // inline functions implementation
396 // ----------------------------------------------------------------------------
398 #ifndef wxHAS_NATIVE_RENDERER
400 // default native renderer is the generic one then
402 wxRendererNative
& wxRendererNative::GetDefault()
407 #endif // !wxHAS_NATIVE_RENDERER
409 #endif // _WX_RENDERER_H_