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 // only MSW and OS X currently provides DrawTitleBarBitmap() method
45 #if defined(__WXMSW__) || (defined(__WXMAC__) && wxUSE_LIBPNG && wxUSE_IMAGE)
46 #define wxHAS_DRAW_TITLE_BAR_BITMAP
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 // control state flags used in wxRenderer and wxColourScheme
56 wxCONTROL_DISABLED
= 0x00000001, // control is disabled
57 wxCONTROL_FOCUSED
= 0x00000002, // currently has keyboard focus
58 wxCONTROL_PRESSED
= 0x00000004, // (button) is pressed
59 wxCONTROL_SPECIAL
= 0x00000008, // control-specific bit:
60 wxCONTROL_ISDEFAULT
= wxCONTROL_SPECIAL
, // only for the buttons
61 wxCONTROL_ISSUBMENU
= wxCONTROL_SPECIAL
, // only for the menu items
62 wxCONTROL_EXPANDED
= wxCONTROL_SPECIAL
, // only for the tree items
63 wxCONTROL_SIZEGRIP
= wxCONTROL_SPECIAL
, // only for the status bar panes
64 wxCONTROL_FLAT
= wxCONTROL_SPECIAL
, // checkboxes only: flat border
65 wxCONTROL_CURRENT
= 0x00000010, // mouse is currently over the control
66 wxCONTROL_SELECTED
= 0x00000020, // selected item in e.g. listbox
67 wxCONTROL_CHECKED
= 0x00000040, // (check/radio button) is checked
68 wxCONTROL_CHECKABLE
= 0x00000080, // (menu) item can be checked
69 wxCONTROL_UNDETERMINED
= wxCONTROL_CHECKABLE
, // (check) undetermined state
71 wxCONTROL_FLAGS_MASK
= 0x000000ff,
73 // this is a pseudo flag not used directly by wxRenderer but rather by some
74 // controls internally
75 wxCONTROL_DIRTY
= 0x80000000
78 // title bar buttons supported by DrawTitleBarBitmap()
80 // NB: they have the same values as wxTOPLEVEL_BUTTON_XXX constants in
81 // wx/univ/toplevel.h as they really represent the same things
84 wxTITLEBAR_BUTTON_CLOSE
= 0x01000000,
85 wxTITLEBAR_BUTTON_MAXIMIZE
= 0x02000000,
86 wxTITLEBAR_BUTTON_ICONIZE
= 0x04000000,
87 wxTITLEBAR_BUTTON_RESTORE
= 0x08000000,
88 wxTITLEBAR_BUTTON_HELP
= 0x10000000
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 // wxSplitterWindow parameters
96 struct WXDLLIMPEXP_CORE wxSplitterRenderParams
98 // the only way to initialize this struct is by using this ctor
99 wxSplitterRenderParams(wxCoord widthSash_
, wxCoord border_
, bool isSens_
)
100 : widthSash(widthSash_
), border(border_
), isHotSensitive(isSens_
)
104 // the width of the splitter sash
105 const wxCoord widthSash
;
107 // the width of the border of the splitter window
108 const wxCoord border
;
110 // true if the splitter changes its appearance when the mouse is over it
111 const bool isHotSensitive
;
115 // extra optional parameters for DrawHeaderButton
116 struct WXDLLIMPEXP_CORE wxHeaderButtonParams
118 wxHeaderButtonParams()
119 : m_labelAlignment(wxALIGN_LEFT
)
122 wxColour m_arrowColour
;
123 wxColour m_selectionColour
;
124 wxString m_labelText
;
126 wxColour m_labelColour
;
127 wxBitmap m_labelBitmap
;
128 int m_labelAlignment
;
131 enum wxHeaderSortIconType
133 wxHDR_SORT_ICON_NONE
, // Header button has no sort arrow
134 wxHDR_SORT_ICON_UP
, // Header button an up sort arrow icon
135 wxHDR_SORT_ICON_DOWN
// Header button a down sort arrow icon
139 // wxRendererNative interface version
140 struct WXDLLIMPEXP_CORE wxRendererVersion
142 wxRendererVersion(int version_
, int age_
) : version(version_
), age(age_
) { }
144 // default copy ctor, assignment operator and dtor are ok
146 // the current version and age of wxRendererNative interface: different
147 // versions are incompatible (in both ways) while the ages inside the same
148 // version are upwards compatible, i.e. the version of the renderer must
149 // match the version of the main program exactly while the age may be
150 // highergreater or equal to it
152 // NB: don't forget to increment age after adding any new virtual function!
160 // check if the given version is compatible with the current one
161 static bool IsCompatible(const wxRendererVersion
& ver
)
163 return ver
.version
== Current_Version
&& ver
.age
>= Current_Age
;
170 // ----------------------------------------------------------------------------
171 // wxRendererNative: abstracts drawing methods needed by the native controls
172 // ----------------------------------------------------------------------------
174 class WXDLLIMPEXP_CORE wxRendererNative
180 // draw the header control button (used by wxListCtrl) Returns optimal
181 // width for the label contents.
182 virtual int DrawHeaderButton(wxWindow
*win
,
186 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
187 wxHeaderButtonParams
* params
=NULL
) = 0;
190 // Draw the contents of a header control button (label, sort arrows, etc.)
191 // Normally only called by DrawHeaderButton.
192 virtual int DrawHeaderButtonContents(wxWindow
*win
,
196 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
197 wxHeaderButtonParams
* params
=NULL
) = 0;
199 // Returns the default height of a header button, either a fixed platform
200 // height if available, or a generic height based on the window's font.
201 virtual int GetHeaderButtonHeight(wxWindow
*win
) = 0;
204 // draw the expanded/collapsed icon for a tree control item
205 virtual void DrawTreeItemButton(wxWindow
*win
,
210 // draw the border for sash window: this border must be such that the sash
211 // drawn by DrawSash() blends into it well
212 virtual void DrawSplitterBorder(wxWindow
*win
,
217 // draw a (vertical) sash
218 virtual void DrawSplitterSash(wxWindow
*win
,
222 wxOrientation orient
,
225 // draw a combobox dropdown button
227 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
228 virtual void DrawComboBoxDropButton(wxWindow
*win
,
233 // draw a dropdown arrow
235 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
236 virtual void DrawDropArrow(wxWindow
*win
,
243 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
244 virtual void DrawCheckBox(wxWindow
*win
,
249 // Returns the default size of a check box.
250 virtual wxSize
GetCheckBoxSize(wxWindow
*win
) = 0;
254 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
255 virtual void DrawPushButton(wxWindow
*win
,
260 // draw rectangle indicating that an item in e.g. a list control
261 // has been selected or focused
264 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
265 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
266 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
267 virtual void DrawItemSelectionRect(wxWindow
*win
,
272 // draw the focus rectangle around the label contained in the given rect
274 // only wxCONTROL_SELECTED makes sense in flags here
275 virtual void DrawFocusRect(wxWindow
* win
,
280 // Draw a native wxChoice
281 virtual void DrawChoice(wxWindow
* win
,
286 // Draw a native wxComboBox
287 virtual void DrawComboBox(wxWindow
* win
,
292 // Draw a native wxTextCtrl frame
293 virtual void DrawTextCtrl(wxWindow
* win
,
298 // Draw a native wxRadioButton bitmap
299 virtual void DrawRadioBitmap(wxWindow
* win
,
304 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
305 // Draw one of the standard title bar buttons
307 // This is currently implemented only for MSW because there is no way to
308 // render standard title bar buttons under the other platforms, the best
309 // can be done is to use normal (only) images which wxArtProvider provides
310 // for wxART_HELP and wxART_CLOSE (but not any other title bar buttons)
311 virtual void DrawTitleBarBitmap(wxWindow
*win
,
314 wxTitleBarButton button
,
316 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
319 // geometry functions
320 // ------------------
322 // get the splitter parameters: the x field of the returned point is the
323 // sash width and the y field is the border width
324 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
) = 0;
327 // pseudo constructors
328 // -------------------
330 // return the currently used renderer
331 static wxRendererNative
& Get();
333 // return the generic implementation of the renderer
334 static wxRendererNative
& GetGeneric();
336 // return the default (native) implementation for this platform
337 static wxRendererNative
& GetDefault();
340 // changing the global renderer
341 // ----------------------------
343 #if wxUSE_DYNLIB_CLASS
344 // load the renderer from the specified DLL, the returned pointer must be
345 // deleted by caller if not NULL when it is not used any more
346 static wxRendererNative
*Load(const wxString
& name
);
347 #endif // wxUSE_DYNLIB_CLASS
349 // set the renderer to use, passing NULL reverts to using the default
352 // return the previous renderer used with Set() or NULL if none
353 static wxRendererNative
*Set(wxRendererNative
*renderer
);
356 // miscellaneous stuff
357 // -------------------
359 // this function is used for version checking: Load() refuses to load any
360 // DLLs implementing an older or incompatible version; it should be
361 // implemented simply by returning wxRendererVersion::Current_XXX values
362 virtual wxRendererVersion
GetVersion() const = 0;
364 // virtual dtor for any base class
365 virtual ~wxRendererNative();
368 // ----------------------------------------------------------------------------
369 // wxDelegateRendererNative: allows reuse of renderers code
370 // ----------------------------------------------------------------------------
372 class WXDLLIMPEXP_CORE wxDelegateRendererNative
: public wxRendererNative
375 wxDelegateRendererNative()
376 : m_rendererNative(GetGeneric()) { }
378 wxDelegateRendererNative(wxRendererNative
& rendererNative
)
379 : m_rendererNative(rendererNative
) { }
382 virtual int DrawHeaderButton(wxWindow
*win
,
386 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
387 wxHeaderButtonParams
* params
= NULL
)
388 { return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
); }
390 virtual int DrawHeaderButtonContents(wxWindow
*win
,
394 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
395 wxHeaderButtonParams
* params
= NULL
)
396 { return m_rendererNative
.DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
); }
398 virtual int GetHeaderButtonHeight(wxWindow
*win
)
399 { return m_rendererNative
.GetHeaderButtonHeight(win
); }
401 virtual void DrawTreeItemButton(wxWindow
*win
,
405 { m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
); }
407 virtual void DrawSplitterBorder(wxWindow
*win
,
411 { m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
); }
413 virtual void DrawSplitterSash(wxWindow
*win
,
417 wxOrientation orient
,
419 { m_rendererNative
.DrawSplitterSash(win
, dc
, size
,
420 position
, orient
, flags
); }
422 virtual void DrawComboBoxDropButton(wxWindow
*win
,
426 { m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
); }
428 virtual void DrawDropArrow(wxWindow
*win
,
432 { m_rendererNative
.DrawDropArrow(win
, dc
, rect
, flags
); }
434 virtual void DrawCheckBox(wxWindow
*win
,
438 { m_rendererNative
.DrawCheckBox( win
, dc
, rect
, flags
); }
440 virtual wxSize
GetCheckBoxSize(wxWindow
*win
)
441 { return m_rendererNative
.GetCheckBoxSize(win
); }
443 virtual void DrawPushButton(wxWindow
*win
,
447 { m_rendererNative
.DrawPushButton( win
, dc
, rect
, flags
); }
449 virtual void DrawItemSelectionRect(wxWindow
*win
,
453 { m_rendererNative
.DrawItemSelectionRect( win
, dc
, rect
, flags
); }
455 virtual void DrawFocusRect(wxWindow
* win
,
459 { m_rendererNative
.DrawFocusRect( win
, dc
, rect
, flags
); }
461 virtual void DrawChoice(wxWindow
* win
,
465 { m_rendererNative
.DrawChoice( win
, dc
, rect
, flags
); }
467 virtual void DrawComboBox(wxWindow
* win
,
471 { m_rendererNative
.DrawComboBox( win
, dc
, rect
, flags
); }
473 virtual void DrawTextCtrl(wxWindow
* win
,
477 { m_rendererNative
.DrawTextCtrl( win
, dc
, rect
, flags
); }
479 virtual void DrawRadioBitmap(wxWindow
* win
,
483 { m_rendererNative
.DrawRadioBitmap(win
, dc
, rect
, flags
); }
485 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
486 virtual void DrawTitleBarBitmap(wxWindow
*win
,
489 wxTitleBarButton button
,
491 { m_rendererNative
.DrawTitleBarBitmap(win
, dc
, rect
, button
, flags
); }
492 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
494 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
)
495 { return m_rendererNative
.GetSplitterParams(win
); }
497 virtual wxRendererVersion
GetVersion() const
498 { return m_rendererNative
.GetVersion(); }
501 wxRendererNative
& m_rendererNative
;
503 wxDECLARE_NO_COPY_CLASS(wxDelegateRendererNative
);
506 // ----------------------------------------------------------------------------
507 // inline functions implementation
508 // ----------------------------------------------------------------------------
510 #ifndef wxHAS_NATIVE_RENDERER
512 // default native renderer is the generic one then
514 wxRendererNative
& wxRendererNative::GetDefault()
519 #endif // !wxHAS_NATIVE_RENDERER
521 #endif // _WX_RENDERER_H_