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.