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 WXDLLIMPEXP_FWD_CORE wxDC
;
29 class WXDLLIMPEXP_FWD_CORE wxWindow
;
31 #include "wx/gdicmn.h" // for wxPoint, wxSize
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__) && wxOSX_USE_COCOA_OR_CARBON ) || 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_FLAT
= wxCONTROL_SPECIAL
, // checkboxes only: flat border
60 wxCONTROL_CURRENT
= 0x00000010, // mouse is currently over the control
61 wxCONTROL_SELECTED
= 0x00000020, // selected item in e.g. listbox
62 wxCONTROL_CHECKED
= 0x00000040, // (check/radio button) is checked
63 wxCONTROL_CHECKABLE
= 0x00000080, // (menu) item can be checked
64 wxCONTROL_UNDETERMINED
= wxCONTROL_CHECKABLE
, // (check) undetermined state
66 wxCONTROL_FLAGS_MASK
= 0x000000ff,
68 // this is a pseudo flag not used directly by wxRenderer but rather by some
69 // controls internally
70 wxCONTROL_DIRTY
= 0x80000000
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 // wxSplitterWindow parameters
78 struct WXDLLIMPEXP_CORE wxSplitterRenderParams
80 // the only way to initialize this struct is by using this ctor
81 wxSplitterRenderParams(wxCoord widthSash_
, wxCoord border_
, bool isSens_
)
82 : widthSash(widthSash_
), border(border_
), isHotSensitive(isSens_
)
86 // the width of the splitter sash
87 const wxCoord widthSash
;
89 // the width of the border of the splitter window
92 // true if the splitter changes its appearance when the mouse is over it
93 const bool isHotSensitive
;
97 // extra optional parameters for DrawHeaderButton
98 struct WXDLLIMPEXP_CORE wxHeaderButtonParams
100 wxHeaderButtonParams()
101 : m_labelAlignment(wxALIGN_LEFT
)
104 wxColour m_arrowColour
;
105 wxColour m_selectionColour
;
106 wxString m_labelText
;
108 wxColour m_labelColour
;
109 wxBitmap m_labelBitmap
;
110 int m_labelAlignment
;
113 enum wxHeaderSortIconType
115 wxHDR_SORT_ICON_NONE
, // Header button has no sort arrow
116 wxHDR_SORT_ICON_UP
, // Header button an up sort arrow icon
117 wxHDR_SORT_ICON_DOWN
// Header button a down sort arrow icon
121 // wxRendererNative interface version
122 struct WXDLLIMPEXP_CORE wxRendererVersion
124 wxRendererVersion(int version_
, int age_
) : version(version_
), age(age_
) { }
126 // default copy ctor, assignment operator and dtor are ok
128 // the current version and age of wxRendererNative interface: different
129 // versions are incompatible (in both ways) while the ages inside the same
130 // version are upwards compatible, i.e. the version of the renderer must
131 // match the version of the main program exactly while the age may be
132 // highergreater or equal to it
134 // NB: don't forget to increment age after adding any new virtual function!
142 // check if the given version is compatible with the current one
143 static bool IsCompatible(const wxRendererVersion
& ver
)
145 return ver
.version
== Current_Version
&& ver
.age
>= Current_Age
;
152 // ----------------------------------------------------------------------------
153 // wxRendererNative: abstracts drawing methods needed by the native controls
154 // ----------------------------------------------------------------------------
156 class WXDLLIMPEXP_CORE wxRendererNative
162 // draw the header control button (used by wxListCtrl) Returns optimal
163 // width for the label contents.
164 virtual int DrawHeaderButton(wxWindow
*win
,
168 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
169 wxHeaderButtonParams
* params
=NULL
) = 0;
172 // Draw the contents of a header control button (label, sort arrows, etc.)
173 // Normally only called by DrawHeaderButton.
174 virtual int DrawHeaderButtonContents(wxWindow
*win
,
178 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
179 wxHeaderButtonParams
* params
=NULL
) = 0;
181 // Returns the default height of a header button, either a fixed platform
182 // height if available, or a generic height based on the window's font.
183 virtual int GetHeaderButtonHeight(wxWindow
*win
) = 0;
186 // draw the expanded/collapsed icon for a tree control item
187 virtual void DrawTreeItemButton(wxWindow
*win
,
192 // draw the border for sash window: this border must be such that the sash
193 // drawn by DrawSash() blends into it well
194 virtual void DrawSplitterBorder(wxWindow
*win
,
199 // draw a (vertical) sash
200 virtual void DrawSplitterSash(wxWindow
*win
,
204 wxOrientation orient
,
207 // draw a combobox dropdown button
209 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
210 virtual void DrawComboBoxDropButton(wxWindow
*win
,
215 // draw a dropdown arrow
217 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
218 virtual void DrawDropArrow(wxWindow
*win
,
225 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
226 virtual void DrawCheckBox(wxWindow
*win
,
231 // Returns the default size of a check box.
232 virtual wxSize
GetCheckBoxSize(wxWindow
*win
) = 0;
236 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
237 virtual void DrawPushButton(wxWindow
*win
,
242 // draw rectangle indicating that an item in e.g. a list control
243 // has been selected or focused
246 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
247 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
248 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
249 virtual void DrawItemSelectionRect(wxWindow
*win
,
254 // draw the focus rectangle around the label contained in the given rect
256 // only wxCONTROL_SELECTED makes sense in flags here
257 virtual void DrawFocusRect(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
= 0) = 0;
259 // Draw a native wxChoice
260 virtual void DrawChoice(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
=0) = 0;
262 // Draw a native wxComboBox
263 virtual void DrawComboBox(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
=0) = 0;
265 // Draw a native wxTextCtrl frame
266 virtual void DrawTextCtrl(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
=0) = 0;
268 // Draw a native wxRadioButton (just the graphical portion)
269 virtual void DrawRadioButton(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
=0) = 0;
271 // geometry functions
272 // ------------------
274 // get the splitter parameters: the x field of the returned point is the
275 // sash width and the y field is the border width
276 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
) = 0;
279 // pseudo constructors
280 // -------------------
282 // return the currently used renderer
283 static wxRendererNative
& Get();
285 // return the generic implementation of the renderer
286 static wxRendererNative
& GetGeneric();
288 // return the default (native) implementation for this platform
289 static wxRendererNative
& GetDefault();
292 // changing the global renderer
293 // ----------------------------
295 #if wxUSE_DYNLIB_CLASS
296 // load the renderer from the specified DLL, the returned pointer must be
297 // deleted by caller if not NULL when it is not used any more
298 static wxRendererNative
*Load(const wxString
& name
);
299 #endif // wxUSE_DYNLIB_CLASS
301 // set the renderer to use, passing NULL reverts to using the default
304 // return the previous renderer used with Set() or NULL if none
305 static wxRendererNative
*Set(wxRendererNative
*renderer
);
308 // miscellaneous stuff
309 // -------------------
311 // this function is used for version checking: Load() refuses to load any
312 // DLLs implementing an older or incompatible version; it should be
313 // implemented simply by returning wxRendererVersion::Current_XXX values
314 virtual wxRendererVersion
GetVersion() const = 0;
316 // virtual dtor for any base class
317 virtual ~wxRendererNative();
320 // ----------------------------------------------------------------------------
321 // wxDelegateRendererNative: allows reuse of renderers code
322 // ----------------------------------------------------------------------------
324 class WXDLLIMPEXP_CORE wxDelegateRendererNative
: public wxRendererNative
327 wxDelegateRendererNative()
328 : m_rendererNative(GetGeneric()) { }
330 wxDelegateRendererNative(wxRendererNative
& rendererNative
)
331 : m_rendererNative(rendererNative
) { }
334 virtual int DrawHeaderButton(wxWindow
*win
,
338 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
339 wxHeaderButtonParams
* params
= NULL
)
340 { return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
); }
342 virtual int DrawHeaderButtonContents(wxWindow
*win
,
346 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
347 wxHeaderButtonParams
* params
= NULL
)
348 { return m_rendererNative
.DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
); }
350 virtual int GetHeaderButtonHeight(wxWindow
*win
)
351 { return m_rendererNative
.GetHeaderButtonHeight(win
); }
353 virtual void DrawTreeItemButton(wxWindow
*win
,
357 { m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
); }
359 virtual void DrawSplitterBorder(wxWindow
*win
,
363 { m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
); }
365 virtual void DrawSplitterSash(wxWindow
*win
,
369 wxOrientation orient
,
371 { m_rendererNative
.DrawSplitterSash(win
, dc
, size
,
372 position
, orient
, flags
); }
374 virtual void DrawComboBoxDropButton(wxWindow
*win
,
378 { m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
); }
380 virtual void DrawDropArrow(wxWindow
*win
,
384 { m_rendererNative
.DrawDropArrow(win
, dc
, rect
, flags
); }
386 virtual void DrawCheckBox(wxWindow
*win
,
390 { m_rendererNative
.DrawCheckBox( win
, dc
, rect
, flags
); }
392 virtual wxSize
GetCheckBoxSize(wxWindow
*win
)
393 { return m_rendererNative
.GetCheckBoxSize(win
); }
395 virtual void DrawPushButton(wxWindow
*win
,
399 { m_rendererNative
.DrawPushButton( win
, dc
, rect
, flags
); }
401 virtual void DrawItemSelectionRect(wxWindow
*win
,
405 { m_rendererNative
.DrawItemSelectionRect( win
, dc
, rect
, flags
); }
407 virtual void DrawFocusRect(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
= 0)
408 { m_rendererNative
.DrawFocusRect( win
, dc
, rect
, flags
); }
410 virtual void DrawChoice(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
=0)
411 { m_rendererNative
.DrawChoice( win
, dc
, rect
, flags
); }
413 virtual void DrawComboBox(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
=0)
414 { m_rendererNative
.DrawComboBox( win
, dc
, rect
, flags
); }
416 virtual void DrawTextCtrl(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
=0)
417 { m_rendererNative
.DrawTextCtrl( win
, dc
, rect
, flags
); }
419 virtual void DrawRadioButton(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
=0)
420 { m_rendererNative
.DrawRadioButton( win
, dc
, rect
, flags
); }
422 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
)
423 { return m_rendererNative
.GetSplitterParams(win
); }
425 virtual wxRendererVersion
GetVersion() const
426 { return m_rendererNative
.GetVersion(); }
429 wxRendererNative
& m_rendererNative
;
431 DECLARE_NO_COPY_CLASS(wxDelegateRendererNative
)
434 // ----------------------------------------------------------------------------
435 // inline functions implementation
436 // ----------------------------------------------------------------------------
438 #ifndef wxHAS_NATIVE_RENDERER
440 // default native renderer is the generic one then
442 wxRendererNative
& wxRendererNative::GetDefault()
447 #endif // !wxHAS_NATIVE_RENDERER
449 #endif // _WX_RENDERER_H_