1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxRendererNative
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @anchor wxCONTROL_FLAGS
12 The following rendering flags are defined for wxRendererNative:
16 /** Control is disabled. */
17 wxCONTROL_DISABLED
= 0x00000001,
19 /** Currently has keyboard focus. */
20 wxCONTROL_FOCUSED
= 0x00000002,
22 /** (Button) is pressed. */
23 wxCONTROL_PRESSED
= 0x00000004,
25 /** Control-specific bit. */
26 wxCONTROL_SPECIAL
= 0x00000008,
28 /** Only for the buttons. */
29 wxCONTROL_ISDEFAULT
= wxCONTROL_SPECIAL
,
31 /** Only for the menu items. */
32 wxCONTROL_ISSUBMENU
= wxCONTROL_SPECIAL
,
34 /** Only for the tree items. */
35 wxCONTROL_EXPANDED
= wxCONTROL_SPECIAL
,
37 /** Only for the status bar panes. */
38 wxCONTROL_SIZEGRIP
= wxCONTROL_SPECIAL
,
40 /** Checkboxes only: flat border. */
41 wxCONTROL_FLAT
= wxCONTROL_SPECIAL
,
43 /** Mouse is currently over the control. */
44 wxCONTROL_CURRENT
= 0x00000010,
46 /** Selected item in e.g. listbox. */
47 wxCONTROL_SELECTED
= 0x00000020,
49 /** (Check/radio button) is checked. */
50 wxCONTROL_CHECKED
= 0x00000040,
52 /** (Menu) item can be checked. */
53 wxCONTROL_CHECKABLE
= 0x00000080,
55 /** (Check) undetermined state. */
56 wxCONTROL_UNDETERMINED
= wxCONTROL_CHECKABLE
60 @struct wxSplitterRenderParams
63 This is just a simple @c struct used as a return value of
64 wxRendererNative::GetSplitterParams().
66 It doesn't have any methods and all of its fields are constant, so they can
67 only be examined but not modified.
72 struct wxSplitterRenderParams
75 The only way to initialize this struct is by using this ctor.
77 wxSplitterRenderParams(wxCoord widthSash_
, wxCoord border_
, bool isSens_
);
80 The width of the border drawn by the splitter inside it, may be 0.
85 @true if the sash changes appearance when the mouse passes over it, @false
88 const bool isHotSensitive
;
91 The width of the splitter sash.
93 const wxCoord widthSash
;
97 @struct wxHeaderButtonParams
100 This @c struct can optionally be used with
101 wxRendererNative::DrawHeaderButton() to specify custom values used to draw
102 the text or bitmap label.
107 struct wxHeaderButtonParams
109 wxHeaderButtonParams();
111 wxColour m_arrowColour
;
112 wxColour m_selectionColour
;
113 wxString m_labelText
;
115 wxColour m_labelColour
;
116 wxBitmap m_labelBitmap
;
117 int m_labelAlignment
;
121 Used to specify the type of sort arrow used with
122 wxRendererNative::DrawHeaderButton().
124 enum wxHeaderSortIconType
126 wxHDR_SORT_ICON_NONE
, ///< Don't draw a sort arrow.
127 wxHDR_SORT_ICON_UP
, ///< Draw a sort arrow icon pointing up.
128 wxHDR_SORT_ICON_DOWN
///< Draw a sort arrow icon pointing down.
134 @class wxDelegateRendererNative
135 @wxheader{renderer.h}
137 wxDelegateRendererNative allows reuse of renderers code by forwarding all the
138 wxRendererNative methods to the given object and
139 thus allowing you to only modify some of its methods -- without having to
140 reimplement all of them.
142 Note that the "normal", inheritance-based approach, doesn't work with the
143 renderers as it is impossible to derive from a class unknown at compile-time
144 and the renderer is only chosen at run-time. So suppose that you want to only
145 add something to the drawing of the tree control buttons but leave all the
146 other methods unchanged -- the only way to do it, considering that the renderer
147 class which you want to customize might not even be written yet when you write
148 your code (it could be written later and loaded from a DLL during run-time), is
151 Except for the constructor, it has exactly the same methods as
152 wxRendererNative and their implementation is
153 trivial: they are simply forwarded to the real renderer. Note that the "real"
154 renderer may, in turn, be a wxDelegateRendererNative as well and that there may
155 be arbitrarily many levels like this -- but at the end of the chain there must
156 be a real renderer which does the drawing.
161 @see wxRendererNative
163 class wxDelegateRendererNative
: public wxRendererNative
167 The default constructor does the same thing as the other one except that it
168 uses the @ref wxRendererNative::GetGeneric() "generic renderer" instead of the
169 user-specified @a rendererNative.
171 In any case, this sets up the delegate renderer object to follow all calls to
172 the specified real renderer.
174 wxDelegateRendererNative();
176 This constructor uses the user-specified @a rendererNative to set up the delegate
177 renderer object to follow all calls to the specified real renderer.
180 This object does not take ownership of (i.e. won't delete) @a rendererNative.
182 wxDelegateRendererNative(wxRendererNative
& rendererNative
);
184 // The rest of these functions inherit the documentation from wxRendererNative
186 virtual int DrawHeaderButton(wxWindow
*win
, wxDC
& dc
,
187 const wxRect
& rect
, int flags
= 0,
188 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
189 wxHeaderButtonParams
* params
= NULL
);
191 virtual int DrawHeaderButtonContents(wxWindow
*win
, wxDC
& dc
,
192 const wxRect
& rect
, int flags
= 0,
193 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
194 wxHeaderButtonParams
* params
= NULL
);
196 virtual int GetHeaderButtonHeight(wxWindow
*win
);
198 virtual void DrawTreeItemButton(wxWindow
*win
, wxDC
& dc
,
199 const wxRect
& rect
, int flags
= 0);
201 virtual void DrawSplitterBorder(wxWindow
*win
, wxDC
& dc
,
202 const wxRect
& rect
, int flags
= 0);
204 virtual void DrawSplitterSash(wxWindow
*win
, wxDC
& dc
,
205 const wxSize
& size
, wxCoord position
,
206 wxOrientation orient
, int flags
= 0);
208 virtual void DrawComboBoxDropButton(wxWindow
*win
, wxDC
& dc
,
209 const wxRect
& rect
, int flags
= 0);
211 virtual void DrawDropArrow(wxWindow
*win
, wxDC
& dc
,
212 const wxRect
& rect
, int flags
= 0);
214 virtual void DrawCheckBox(wxWindow
*win
, wxDC
& dc
,
215 const wxRect
& rect
, int flags
= 0 );
217 virtual void DrawPushButton(wxWindow
*win
, wxDC
& dc
,
218 const wxRect
& rect
, int flags
= 0 );
220 virtual void DrawItemSelectionRect(wxWindow
*win
, wxDC
& dc
,
221 const wxRect
& rect
, int flags
= 0 );
223 virtual void DrawFocusRect(wxWindow
* win
, wxDC
& dc
,
224 const wxRect
& rect
, int flags
= 0);
226 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
228 virtual wxRendererVersion
GetVersion() const;
234 @class wxRendererNative
235 @wxheader{renderer.h}
237 First, a brief introduction to wxRendererNative and why it is needed.
239 Usually wxWidgets uses the underlying low level GUI system to draw all the
240 controls - this is what we mean when we say that it is a "native" framework.
241 However not all controls exist under all (or even any) platforms and in this
242 case wxWidgets provides a default, generic, implementation of them written in
245 These controls don't have the native appearance if only the standard
246 line drawing and other graphics primitives are used, because the native
247 appearance is different under different platforms while the lines are always
248 drawn in the same way.
250 This is why we have renderers: wxRendererNative is a class which virtualizes the
251 drawing, i.e. it abstracts the drawing operations and allows you to draw say, a
252 button, without caring about exactly how this is done. Of course, as we
253 can draw the button differently in different renderers, this also allows us to
254 emulate the native look and feel.
256 So the renderers work by exposing a large set of high-level drawing functions
257 which are used by the generic controls. There is always a default global
258 renderer but it may be changed or extended by the user, see
259 @ref page_samples_render.
261 All drawing functions take some standard parameters:
263 @li @a win - The window being drawn. It is normally not used and when
264 it is it should only be used as a generic wxWindow
265 (in order to get its low level handle, for example), but you should
266 not assume that it is of some given type as the same renderer
267 function may be reused for drawing different kinds of control.
268 @li @a dc - The wxDC to draw on. Only this device
269 context should be used for drawing. It is not necessary to restore
270 pens and brushes for it on function exit but, on the other hand, you
271 shouldn't assume that it is in any specific state on function entry:
272 the rendering functions should always prepare it.
273 @li @a rect - The bounding rectangle for the element to be drawn.
274 @li @a flags - The optional flags (none by default) which can be a
275 combination of the @ref wxCONTROL_FLAGS.
277 Note that each drawing function restores the wxDC attributes if
278 it changes them, so it is safe to assume that the same pen, brush and colours
279 that were active before the call to this function are still in effect after it.
284 class wxRendererNative
288 Virtual destructor as for any base class.
293 Draw a check box (used by wxDataViewCtrl).
295 @a flags may have the @c wxCONTROL_CHECKED, @c wxCONTROL_CURRENT or
296 @c wxCONTROL_UNDETERMINED bit set, see @ref wxCONTROL_FLAGS.
298 virtual void DrawCheckBox(wxWindow
* win
, wxDC
& dc
,
299 const wxRect
& rect
, int flags
);
302 Draw a button like the one used by wxComboBox to show a
303 drop down window. The usual appearance is a downwards pointing arrow.
305 @a flags may have the @c wxCONTROL_PRESSED or @c wxCONTROL_CURRENT bit set,
306 see @ref wxCONTROL_FLAGS.
308 virtual void DrawComboBoxDropButton(wxWindow
* win
, wxDC
& dc
,
313 Draw a drop down arrow that is suitable for use outside a combo box. Arrow will
314 have transparent background.
316 @a rect is not entirely filled by the arrow. Instead, you should use bounding
317 rectangle of a drop down button which arrow matches the size you need.
319 @a flags may have the @c wxCONTROL_PRESSED or @c wxCONTROL_CURRENT bit set,
320 see @ref wxCONTROL_FLAGS.
322 virtual void DrawDropArrow(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
,
326 Draw a focus rectangle using the specified rectangle.
329 The only supported flags is @c wxCONTROL_SELECTED for items which are selected.
330 see @ref wxCONTROL_FLAGS.
332 virtual void DrawFocusRect(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
,
336 Draw the header control button (used, for example, by wxListCtrl).
338 Depending on platforms the @a flags parameter may support the @c wxCONTROL_SELECTED
339 @c wxCONTROL_DISABLED and @c wxCONTROL_CURRENT bits, see @ref wxCONTROL_FLAGS.
342 The optimal width to contain the the unabreviated label text or
343 bitmap, the sort arrow if present, and internal margins.
345 virtual int DrawHeaderButton(wxWindow
* win
, wxDC
& dc
,
346 const wxRect
& rect
, int flags
= 0,
347 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
348 wxHeaderButtonParams
* params
= NULL
);
351 Draw the contents of a header control button (label, sort arrows,
352 etc.). This function is normally only called by DrawHeaderButton().
354 Depending on platforms the @a flags parameter may support the @c wxCONTROL_SELECTED
355 @c wxCONTROL_DISABLED and @c wxCONTROL_CURRENT bits, see @ref wxCONTROL_FLAGS.
358 The optimal width to contain the the unabreviated label text or
359 bitmap, the sort arrow if present, and internal margins.
361 virtual int DrawHeaderButtonContents(wxWindow
*win
, wxDC
& dc
,
362 const wxRect
& rect
, int flags
= 0,
363 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
364 wxHeaderButtonParams
* params
= NULL
);
367 Draw a selection rectangle underneath the text as used e.g. in a
370 The supported @a flags are @c wxCONTROL_SELECTED for items
371 which are selected (e.g. often a blue rectangle) and @c wxCONTROL_CURRENT
372 for the item that has the focus (often a dotted line around the item's text).
373 @c wxCONTROL_FOCUSED may be used to indicate if the control has the focus
374 (othewise the the selection rectangle is e.g. often grey and not blue).
375 This may be ignored by the renderer or deduced by the code directly from
378 virtual void DrawItemSelectionRect(wxWindow
* win
, wxDC
& dc
,
379 const wxRect
& rect
, int flags
= 0);
382 Draw a blank push button that looks very similar to wxButton.
384 @a flags may have the @c wxCONTROL_PRESSED, @c wxCONTROL_CURRENT or
385 @c wxCONTROL_ISDEFAULT bit set, see @ref wxCONTROL_FLAGS.
387 virtual void DrawPushButton(wxWindow
* win
, wxDC
& dc
,
388 const wxRect
& rect
, int flags
);
391 Draw the border for sash window: this border must be such that the sash
392 drawn by DrawSplitterSash() blends into it well.
394 virtual void DrawSplitterBorder(wxWindow
* win
, wxDC
& dc
,
395 const wxRect
& rect
, int flags
= 0);
398 Draw a sash. The @a orient parameter defines whether the sash should be
399 vertical or horizontal and how the @a position should be interpreted.
401 virtual void DrawSplitterSash(wxWindow
* win
, wxDC
& dc
,
402 const wxSize
& size
, wxCoord position
,
403 wxOrientation orient
, int flags
= 0);
406 Draw the expanded/collapsed icon for a tree control item.
408 To draw an expanded button the @a flags parameter must contain @c wxCONTROL_EXPANDED bit,
409 see @ref wxCONTROL_FLAGS.
411 virtual void DrawTreeItemButton(wxWindow
* win
, wxDC
& dc
,
412 const wxRect
& rect
, int flags
= 0);
415 Return the currently used renderer.
417 static wxRendererNative
Get();
420 Return the default (native) implementation for this platform -- this is also
421 the one used by default but this may be changed by calling
422 Set() in which case the return value of this
423 method may be different from the return value of Get().
425 static wxRendererNative
GetDefault();
428 Return the generic implementation of the renderer. Under some platforms, this
429 is the default renderer implementation, others have platform-specific default
430 renderer which can be retrieved by calling GetDefault().
432 static wxRendererNative
GetGeneric();
435 Returns the height of a header button, either a fixed platform height if
437 generic height based on the window's font.
439 virtual int GetHeaderButtonHeight(wxWindow
* win
);
442 Get the splitter parameters, see
443 wxSplitterRenderParams.
445 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
* win
);
448 This function is used for version checking: Load()
449 refuses to load any shared libraries implementing an older or incompatible
453 The implementation of this method is always the same in all renderers (simply
454 construct wxRendererVersion using the @c wxRendererVersion::Current_XXX values),
455 but it has to be in the derived, not base, class, to detect mismatches between
456 the renderers versions and so you have to implement it anew in all renderers.
458 virtual wxRendererVersion
GetVersion() const;
461 Load the renderer from the specified DLL, the returned pointer must be
462 deleted by caller if not @NULL when it is not used any more.
464 The @a name should be just the base name of the renderer and not the full
465 name of the DLL file which is constructed differently (using
466 wxDynamicLibrary::CanonicalizePluginName())
467 on different systems.
469 static wxRendererNative
* Load(const wxString
& name
);
472 Set the renderer to use, passing @NULL reverts to using the default
473 renderer (the global renderer must always exist).
475 Return the previous renderer used with Set() or @NULL if none.
477 static wxRendererNative
* Set(wxRendererNative
* renderer
);
483 @struct wxRendererVersion
484 @wxheader{renderer.h}
486 This simple struct represents the wxRendererNative
487 interface version and is only used as the return value of
488 wxRendererNative::GetVersion().
490 The version has two components: the version itself and the age. If the main
491 program and the renderer have different versions they are never compatible with
492 each other because the version is only changed when an existing virtual
493 function is modified or removed. The age, on the other hand, is incremented
494 each time a new virtual method is added and so, at least for the compilers
495 using a common C++ object model, the calling program is compatible with any
496 renderer which has the age greater or equal to its age. This verification is
497 done by IsCompatible() method.
502 struct wxRendererVersion
505 Checks if the main program is compatible with the renderer having the version
506 @e ver, returns @true if it is and @false otherwise.
508 This method is used by wxRendererNative::Load() to determine whether a
509 renderer can be used.
511 static bool IsCompatible(const wxRendererVersion
& ver
);
519 The version component.