1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRendererNative class declaration
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
12 Renderers are used in wxWidgets for two similar but different things:
13 (a) wxUniversal uses them to draw everything, i.e. all the control
14 (b) all the native ports use them to draw generic controls only
16 wxUniversal needs more functionality than what is included in the base class
17 as it needs to draw stuff like scrollbars which are never going to be
18 generic. So we put the bare minimum needed by the native ports here and the
19 full wxRenderer class is declared in wx/univ/renderer.h and is only used by
20 wxUniveral (although note that native ports can load wxRenderer objects from
21 theme DLLs and use them as wxRendererNative ones, of course).
24 #ifndef _WX_RENDERER_H_
25 #define _WX_RENDERER_H_
27 class WXDLLIMPEXP_FWD_CORE wxDC
;
28 class WXDLLIMPEXP_FWD_CORE wxWindow
;
30 #include "wx/gdicmn.h" // for wxPoint, wxSize
31 #include "wx/colour.h"
33 #include "wx/bitmap.h"
34 #include "wx/string.h"
36 // some platforms have their own renderers, others use the generic one
37 #if defined(__WXMSW__) || ( defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON ) || defined(__WXGTK__)
38 #define wxHAS_NATIVE_RENDERER
40 #undef wxHAS_NATIVE_RENDERER
43 // only MSW and OS X currently provides DrawTitleBarBitmap() method
44 #if defined(__WXMSW__) || (defined(__WXMAC__) && wxUSE_LIBPNG && wxUSE_IMAGE)
45 #define wxHAS_DRAW_TITLE_BAR_BITMAP
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 // control state flags used in wxRenderer and wxColourScheme
55 wxCONTROL_DISABLED
= 0x00000001, // control is disabled
56 wxCONTROL_FOCUSED
= 0x00000002, // currently has keyboard focus
57 wxCONTROL_PRESSED
= 0x00000004, // (button) is pressed
58 wxCONTROL_SPECIAL
= 0x00000008, // control-specific bit:
59 wxCONTROL_ISDEFAULT
= wxCONTROL_SPECIAL
, // only for the buttons
60 wxCONTROL_ISSUBMENU
= wxCONTROL_SPECIAL
, // only for the menu items
61 wxCONTROL_EXPANDED
= wxCONTROL_SPECIAL
, // only for the tree items
62 wxCONTROL_SIZEGRIP
= wxCONTROL_SPECIAL
, // only for the status bar panes
63 wxCONTROL_FLAT
= wxCONTROL_SPECIAL
, // checkboxes only: flat border
64 wxCONTROL_CURRENT
= 0x00000010, // mouse is currently over the control
65 wxCONTROL_SELECTED
= 0x00000020, // selected item in e.g. listbox
66 wxCONTROL_CHECKED
= 0x00000040, // (check/radio button) is checked
67 wxCONTROL_CHECKABLE
= 0x00000080, // (menu) item can be checked
68 wxCONTROL_UNDETERMINED
= wxCONTROL_CHECKABLE
, // (check) undetermined state
70 wxCONTROL_FLAGS_MASK
= 0x000000ff,
72 // this is a pseudo flag not used directly by wxRenderer but rather by some
73 // controls internally
74 wxCONTROL_DIRTY
= 0x80000000
77 // title bar buttons supported by DrawTitleBarBitmap()
79 // NB: they have the same values as wxTOPLEVEL_BUTTON_XXX constants in
80 // wx/univ/toplevel.h as they really represent the same things
83 wxTITLEBAR_BUTTON_CLOSE
= 0x01000000,
84 wxTITLEBAR_BUTTON_MAXIMIZE
= 0x02000000,
85 wxTITLEBAR_BUTTON_ICONIZE
= 0x04000000,
86 wxTITLEBAR_BUTTON_RESTORE
= 0x08000000,
87 wxTITLEBAR_BUTTON_HELP
= 0x10000000
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 // wxSplitterWindow parameters
95 struct WXDLLIMPEXP_CORE wxSplitterRenderParams
97 // the only way to initialize this struct is by using this ctor
98 wxSplitterRenderParams(wxCoord widthSash_
, wxCoord border_
, bool isSens_
)
99 : widthSash(widthSash_
), border(border_
), isHotSensitive(isSens_
)
103 // the width of the splitter sash
104 const wxCoord widthSash
;
106 // the width of the border of the splitter window
107 const wxCoord border
;
109 // true if the splitter changes its appearance when the mouse is over it
110 const bool isHotSensitive
;
114 // extra optional parameters for DrawHeaderButton
115 struct WXDLLIMPEXP_CORE wxHeaderButtonParams
117 wxHeaderButtonParams()
118 : m_labelAlignment(wxALIGN_LEFT
)
121 wxColour m_arrowColour
;
122 wxColour m_selectionColour
;
123 wxString m_labelText
;
125 wxColour m_labelColour
;
126 wxBitmap m_labelBitmap
;
127 int m_labelAlignment
;
130 enum wxHeaderSortIconType
132 wxHDR_SORT_ICON_NONE
, // Header button has no sort arrow
133 wxHDR_SORT_ICON_UP
, // Header button an up sort arrow icon
134 wxHDR_SORT_ICON_DOWN
// Header button a down sort arrow icon
138 // wxRendererNative interface version
139 struct WXDLLIMPEXP_CORE wxRendererVersion
141 wxRendererVersion(int version_
, int age_
) : version(version_
), age(age_
) { }
143 // default copy ctor, assignment operator and dtor are ok
145 // the current version and age of wxRendererNative interface: different
146 // versions are incompatible (in both ways) while the ages inside the same
147 // version are upwards compatible, i.e. the version of the renderer must
148 // match the version of the main program exactly while the age may be
149 // highergreater or equal to it
151 // NB: don't forget to increment age after adding any new virtual function!
159 // check if the given version is compatible with the current one
160 static bool IsCompatible(const wxRendererVersion
& ver
)
162 return ver
.version
== Current_Version
&& ver
.age
>= Current_Age
;
169 // ----------------------------------------------------------------------------
170 // wxRendererNative: abstracts drawing methods needed by the native controls
171 // ----------------------------------------------------------------------------
173 class WXDLLIMPEXP_CORE wxRendererNative
179 // draw the header control button (used by wxListCtrl) Returns optimal
180 // width for the label contents.
181 virtual int DrawHeaderButton(wxWindow
*win
,
185 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
186 wxHeaderButtonParams
* params
=NULL
) = 0;
189 // Draw the contents of a header control button (label, sort arrows, etc.)
190 // Normally only called by DrawHeaderButton.
191 virtual int DrawHeaderButtonContents(wxWindow
*win
,
195 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
196 wxHeaderButtonParams
* params
=NULL
) = 0;
198 // Returns the default height of a header button, either a fixed platform
199 // height if available, or a generic height based on the window's font.
200 virtual int GetHeaderButtonHeight(wxWindow
*win
) = 0;
202 // Returns the margin on left and right sides of header button's label
203 virtual int GetHeaderButtonMargin(wxWindow
*win
) = 0;
206 // draw the expanded/collapsed icon for a tree control item
207 virtual void DrawTreeItemButton(wxWindow
*win
,
212 // draw the border for sash window: this border must be such that the sash
213 // drawn by DrawSash() blends into it well
214 virtual void DrawSplitterBorder(wxWindow
*win
,
219 // draw a (vertical) sash
220 virtual void DrawSplitterSash(wxWindow
*win
,
224 wxOrientation orient
,
227 // draw a combobox dropdown button
229 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
230 virtual void DrawComboBoxDropButton(wxWindow
*win
,
235 // draw a dropdown arrow
237 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
238 virtual void DrawDropArrow(wxWindow
*win
,
245 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
246 virtual void DrawCheckBox(wxWindow
*win
,
251 // Returns the default size of a check box.
252 virtual wxSize
GetCheckBoxSize(wxWindow
*win
) = 0;
256 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
257 virtual void DrawPushButton(wxWindow
*win
,
262 // draw rectangle indicating that an item in e.g. a list control
263 // has been selected or focused
266 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
267 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
268 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
269 virtual void DrawItemSelectionRect(wxWindow
*win
,
274 // draw the focus rectangle around the label contained in the given rect
276 // only wxCONTROL_SELECTED makes sense in flags here
277 virtual void DrawFocusRect(wxWindow
* win
,
282 // Draw a native wxChoice
283 virtual void DrawChoice(wxWindow
* win
,
288 // Draw a native wxComboBox
289 virtual void DrawComboBox(wxWindow
* win
,
294 // Draw a native wxTextCtrl frame
295 virtual void DrawTextCtrl(wxWindow
* win
,
300 // Draw a native wxRadioButton bitmap
301 virtual void DrawRadioBitmap(wxWindow
* win
,
306 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
307 // Draw one of the standard title bar buttons
309 // This is currently implemented only for MSW and OS X (for the close
310 // button only) because there is no way to render standard title bar
311 // buttons under the other platforms, the best can be done is to use normal
312 // (only) images which wxArtProvider provides for wxART_HELP and
313 // wxART_CLOSE (but not any other title bar buttons)
315 // NB: make sure PNG handler is enabled if using this function under OS X
316 virtual void DrawTitleBarBitmap(wxWindow
*win
,
319 wxTitleBarButton button
,
321 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
324 // geometry functions
325 // ------------------
327 // get the splitter parameters: the x field of the returned point is the
328 // sash width and the y field is the border width
329 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
) = 0;
332 // pseudo constructors
333 // -------------------
335 // return the currently used renderer
336 static wxRendererNative
& Get();
338 // return the generic implementation of the renderer
339 static wxRendererNative
& GetGeneric();
341 // return the default (native) implementation for this platform
342 static wxRendererNative
& GetDefault();
345 // changing the global renderer
346 // ----------------------------
348 #if wxUSE_DYNLIB_CLASS
349 // load the renderer from the specified DLL, the returned pointer must be
350 // deleted by caller if not NULL when it is not used any more
351 static wxRendererNative
*Load(const wxString
& name
);
352 #endif // wxUSE_DYNLIB_CLASS
354 // set the renderer to use, passing NULL reverts to using the default
357 // return the previous renderer used with Set() or NULL if none
358 static wxRendererNative
*Set(wxRendererNative
*renderer
);
361 // miscellaneous stuff
362 // -------------------
364 // this function is used for version checking: Load() refuses to load any
365 // DLLs implementing an older or incompatible version; it should be
366 // implemented simply by returning wxRendererVersion::Current_XXX values
367 virtual wxRendererVersion
GetVersion() const = 0;
369 // virtual dtor for any base class
370 virtual ~wxRendererNative();
373 // ----------------------------------------------------------------------------
374 // wxDelegateRendererNative: allows reuse of renderers code
375 // ----------------------------------------------------------------------------
377 class WXDLLIMPEXP_CORE wxDelegateRendererNative
: public wxRendererNative
380 wxDelegateRendererNative()
381 : m_rendererNative(GetGeneric()) { }
383 wxDelegateRendererNative(wxRendererNative
& rendererNative
)
384 : m_rendererNative(rendererNative
) { }
387 virtual int DrawHeaderButton(wxWindow
*win
,
391 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
392 wxHeaderButtonParams
* params
= NULL
)
393 { return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
); }
395 virtual int DrawHeaderButtonContents(wxWindow
*win
,
399 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
400 wxHeaderButtonParams
* params
= NULL
)
401 { return m_rendererNative
.DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
); }
403 virtual int GetHeaderButtonHeight(wxWindow
*win
)
404 { return m_rendererNative
.GetHeaderButtonHeight(win
); }
406 virtual int GetHeaderButtonMargin(wxWindow
*win
)
407 { return m_rendererNative
.GetHeaderButtonMargin(win
); }
409 virtual void DrawTreeItemButton(wxWindow
*win
,
413 { m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
); }
415 virtual void DrawSplitterBorder(wxWindow
*win
,
419 { m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
); }
421 virtual void DrawSplitterSash(wxWindow
*win
,
425 wxOrientation orient
,
427 { m_rendererNative
.DrawSplitterSash(win
, dc
, size
,
428 position
, orient
, flags
); }
430 virtual void DrawComboBoxDropButton(wxWindow
*win
,
434 { m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
); }
436 virtual void DrawDropArrow(wxWindow
*win
,
440 { m_rendererNative
.DrawDropArrow(win
, dc
, rect
, flags
); }
442 virtual void DrawCheckBox(wxWindow
*win
,
446 { m_rendererNative
.DrawCheckBox( win
, dc
, rect
, flags
); }
448 virtual wxSize
GetCheckBoxSize(wxWindow
*win
)
449 { return m_rendererNative
.GetCheckBoxSize(win
); }
451 virtual void DrawPushButton(wxWindow
*win
,
455 { m_rendererNative
.DrawPushButton( win
, dc
, rect
, flags
); }
457 virtual void DrawItemSelectionRect(wxWindow
*win
,
461 { m_rendererNative
.DrawItemSelectionRect( win
, dc
, rect
, flags
); }
463 virtual void DrawFocusRect(wxWindow
* win
,
467 { m_rendererNative
.DrawFocusRect( win
, dc
, rect
, flags
); }
469 virtual void DrawChoice(wxWindow
* win
,
473 { m_rendererNative
.DrawChoice( win
, dc
, rect
, flags
); }
475 virtual void DrawComboBox(wxWindow
* win
,
479 { m_rendererNative
.DrawComboBox( win
, dc
, rect
, flags
); }
481 virtual void DrawTextCtrl(wxWindow
* win
,
485 { m_rendererNative
.DrawTextCtrl( win
, dc
, rect
, flags
); }
487 virtual void DrawRadioBitmap(wxWindow
* win
,
491 { m_rendererNative
.DrawRadioBitmap(win
, dc
, rect
, flags
); }
493 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
494 virtual void DrawTitleBarBitmap(wxWindow
*win
,
497 wxTitleBarButton button
,
499 { m_rendererNative
.DrawTitleBarBitmap(win
, dc
, rect
, button
, flags
); }
500 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
502 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
)
503 { return m_rendererNative
.GetSplitterParams(win
); }
505 virtual wxRendererVersion
GetVersion() const
506 { return m_rendererNative
.GetVersion(); }
509 wxRendererNative
& m_rendererNative
;
511 wxDECLARE_NO_COPY_CLASS(wxDelegateRendererNative
);
514 // ----------------------------------------------------------------------------
515 // inline functions implementation
516 // ----------------------------------------------------------------------------
518 #ifndef wxHAS_NATIVE_RENDERER
520 // default native renderer is the generic one then
522 wxRendererNative
& wxRendererNative::GetDefault()
527 #endif // !wxHAS_NATIVE_RENDERER
529 #endif // _WX_RENDERER_H_