Contents Up Previous Next

wxRendererNative

First, a brief introduction to wxRenderer and why it is needed.

Usually wxWidgets uses the underlying low level GUI system to draw all the controls - this is what we mean when we say that it is a "native'' framework. However not all controls exist under all (or even any) platforms and in this case wxWidgets provides a default, generic, implementation of them written in wxWidgets itself.

These controls don't have the native appearance if only the standard line drawing and other graphics primitives are used, because the native appearance is different under different platforms while the lines are always drawn in the same way.

This is why we have renderers: wxRenderer is a class which virtualizes the drawing, i.e. it abstracts the drawing operations and allows you to draw say, a button, without caring about exactly how this is done. Of course, as we can draw the button differently in different renderers, this also allows us to emulate the native look and feel.

So the renderers work by exposing a large set of high-level drawing functions which are used by the generic controls. There is always a default global renderer but it may be changed or extended by the user, see Render sample.

All drawing functions take some standard parameters:

Note that each drawing function restores the wxDC attributes if it changes them, so it is safe to assume that the same pen, brush and colours that were active before the call to this function are still in effect after it.

Constants

The following rendering flags are defined:

enum
{
    wxCONTROL_DISABLED   = 0x00000001,  // control is disabled
    wxCONTROL_FOCUSED    = 0x00000002,  // currently has keyboard focus
    wxCONTROL_PRESSED    = 0x00000004,  // (button) is pressed
    wxCONTROL_ISDEFAULT  = 0x00000008,  // only applies to the buttons
    wxCONTROL_ISSUBMENU  = wxCONTROL_ISDEFAULT, // only for menu items
    wxCONTROL_EXPANDED   = wxCONTROL_ISDEFAULT, // only for the tree items
    wxCONTROL_CURRENT    = 0x00000010,  // mouse is currently over the control
    wxCONTROL_SELECTED   = 0x00000020,  // selected item in e.g. listbox
    wxCONTROL_CHECKED    = 0x00000040,  // (check/radio button) is checked
    wxCONTROL_CHECKABLE  = 0x00000080,  // (menu) item can be checked
    wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE  // (check) undetermined state
};
Derived from

No base class

Include files

<wx/renderer.h>

Members

wxRendererNative::~wxRendererNative
wxRendererNative::DrawCheckBox
wxRendererNative::DrawComboBoxDropButton
wxRendererNative::DrawDropArrow
wxRendererNative::DrawHeaderButton
wxRendererNative::DrawItemSelectionRect
wxRendererNative::DrawPushButton
wxRendererNative::DrawSplitterBorder
wxRendererNative::DrawSplitterSash
wxRendererNative::DrawTreeItemButton
wxRendererNative::Get
wxRendererNative::GetDefault
wxRendererNative::GetGeneric
wxRendererNative::GetHeaderButtonHeight
wxRendererNative::GetSplitterParams
wxRendererNative::GetVersion
wxRendererNative::Load
wxRendererNative::Set


wxRendererNative::~wxRendererNative

~wxRendererNative()

Virtual destructor as for any base class.


wxRendererNative::DrawCheckBox

void DrawCheckBox(wxWindow *win, wxDC& dc, const wxRect& rect, int flags)

Draw a check box (used by wxDataViewCtrl).

flags may have the wxCONTROL_CHECKED, wxCONTROL_CURRENT or wxCONTROL_UNDETERMINED bit set.


wxRendererNative::DrawComboBoxDropButton

void DrawComboBoxDropButton(wxWindow *win, wxDC& dc, const wxRect& rect, int flags)

Draw a button like the one used by wxComboBox to show a drop down window. The usual appearance is a downwards pointing arrow.

flags may have the wxCONTROL_PRESSED or wxCONTROL_CURRENT bit set.


wxRendererNative::DrawDropArrow

void DrawDropArrow(wxWindow *win, wxDC& dc, const wxRect& rect, int flags)

Draw a drop down arrow that is suitable for use outside a combo box. Arrow will have transparent background.

rect is not entirely filled by the arrow. Instead, you should use bounding rectangle of a drop down button which arrow matches the size you need. flags may have the wxCONTROL_PRESSED or wxCONTROL_CURRENT bit set.


wxRendererNative::DrawHeaderButton

int DrawHeaderButton(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0, wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, wxHeaderButtonParams* params = NULL)

Draw the header control button (used, for example, by wxListCtrl). Depending on platforms the flags parameter may support the wxCONTROL_SELECTED wxCONTROL_DISABLED and wxCONTROL_CURRENT bits. The sortArrow parameter can be one of wxHDR_SORT_ICON_NONE, wxHDR_SORT_ICON_UP, or wxHDR_SORT_ICON_DOWN. Additional values controlling the drawing of a text or bitmap label can be passed in params. The value returned is the optimal width to contain the the unabreviated label text or bitmap, the sort arrow if present, and internal margins.


wxRendererNative::DrawItemSelectionRect

void DrawItemSelectionRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0)

Draw a selection rectangle underneath the text as used e.g. in a wxListCtrl. The supported flags are wxCONTROL_SELECTED for items which are selected (e.g. often a blue rectangle) and wxCONTROL_CURRENT for the item that has the focus (often a dotted line around the item's text). wxCONTROL_FOCUSED may be used to indicate if the control has the focus (othewise the the selection rectangle is e.g. often grey and not blue). This may be ignored by the renderer or deduced by the code directly from the win.


wxRendererNative::DrawPushButton

void DrawPushButton(wxWindow *win, wxDC& dc, const wxRect& rect, int flags)

Draw a blank push button that looks very similar to wxButton.

flags may have the wxCONTROL_PRESSED, wxCONTROL_CURRENT or wxCONTROL_ISDEFAULT bit set.


wxRendererNative::DrawSplitterBorder

void DrawSplitterBorder(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0)

Draw the border for sash window: this border must be such that the sash drawn by DrawSash blends into it well.


wxRendererNative::DrawSplitterSash

void DrawSplitterSash(wxWindow* win, wxDC& dc, const wxSize& size, wxCoord position, wxOrientation orient, int flags = 0)

Draw a sash. The orient parameter defines whether the sash should be vertical or horizontal and how the position should be interpreted.


wxRendererNative::DrawTreeItemButton

void DrawTreeItemButton(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0)

Draw the expanded/collapsed icon for a tree control item. To draw an expanded button the flags parameter must contain wxCONTROL_EXPANDED bit.


wxRendererNative::Get

wxRendererNative& Get()

Return the currently used renderer.


wxRendererNative::GetDefault

wxRendererNative& GetDefault()

Return the default (native) implementation for this platform -- this is also the one used by default but this may be changed by calling Set in which case the return value of this method may be different from the return value of Get.


wxRendererNative::GetGeneric

wxRendererNative& GetGeneric()

Return the generic implementation of the renderer. Under some platforms, this is the default renderer implementation, others have platform-specific default renderer which can be retrieved by calling GetDefault.


wxRendererNative::GetHeaderButtonHeight

int GetHeaderButtonHeight(const wxWindow* win)

Returns the height of a header button, either a fixed platform height if available, or a generic height based on the window's font.


wxRendererNative::GetSplitterParams

wxSplitterRenderParams GetSplitterParams(const wxWindow* win)

Get the splitter parameters, see wxSplitterRenderParams.


wxRendererNative::GetVersion

wxRendererVersion GetVersion() const

This function is used for version checking: Load refuses to load any shared libraries implementing an older or incompatible version.

The implementation of this method is always the same in all renderers (simply construct wxRendererVersion using the wxRendererVersion::Current_XXX values), but it has to be in the derived, not base, class, to detect mismatches between the renderers versions and so you have to implement it anew in all renderers.


wxRendererNative::Load

wxRendererNative* Load(const wxString& name)

Load the renderer from the specified DLL, the returned pointer must be deleted by caller if not NULL when it is not used any more.

The name should be just the base name of the renderer and not the full name of the DLL file which is constructed differently (using wxDynamicLibrary::CanonicalizePluginName) on different systems.


wxRendererNative::Set

wxRendererNative* Set(wxRendererNative* renderer)

Set the renderer to use, passing NULL reverts to using the default renderer (the global renderer must always exist).

Return the previous renderer used with Set() or NULL if none.