#include <wx/dataview.h>
You need to derive a new class from wxDataViewCustomRenderer in order to write a new renderer.
You need to override at least wxDataViewRenderer::SetValue, wxDataViewRenderer::GetValue, wxDataViewCustomRenderer::GetSize and wxDataViewCustomRenderer::Render.
If you want your renderer to support in-place editing then you also need to override wxDataViewCustomRenderer::HasEditorCtrl, wxDataViewCustomRenderer::CreateEditorCtrl and wxDataViewCustomRenderer::GetValueFromEditorCtrl.
Note that a special event handler will be pushed onto that editor control which handles <ENTER> and focus out events in order to end the editing.
Public Member Functions | |
wxDataViewCustomRenderer (const wxString &varianttype="string", wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=-1, bool no_init=false) | |
Constructor. | |
virtual | ~wxDataViewCustomRenderer () |
Destructor. | |
virtual bool | Activate (wxRect cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col) |
Override this to react to double clicks or ENTER. | |
virtual wxControl * | CreateEditorCtrl (wxWindow *parent, wxRect labelRect, const wxVariant &value) |
Override this to create the actual editor control once editing is about to start. | |
const wxDataViewItemAttr & | GetAttr () const |
Return the attribute to be used for rendering. | |
virtual wxSize | GetSize () const =0 |
Return size required to show content. | |
virtual bool | GetValueFromEditorCtrl (wxControl *editor, wxVariant &value) |
Override this so that the renderer can get the value from the editor control (pointed to by editor):. | |
virtual bool | HasEditorCtrl () const |
Override this and make it return true in order to indicate that this renderer supports in-place editing. | |
virtual bool | LeftClick (wxPoint cursor, wxRect cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col) |
Override this to react to a left click. | |
virtual bool | Render (wxRect cell, wxDC *dc, int state)=0 |
Override this to render the cell. | |
void | RenderText (const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state) |
This method should be called from within Render() whenever you need to render simple text. | |
virtual bool | StartDrag (wxPoint cursor, wxRect cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col) |
Override this to start a drag operation. |
wxDataViewCustomRenderer::wxDataViewCustomRenderer | ( | const wxString & | varianttype = "string" , |
|
wxDataViewCellMode | mode = wxDATAVIEW_CELL_INERT , |
|||
int | align = -1 , |
|||
bool | no_init = false | |||
) |
Constructor.
virtual wxDataViewCustomRenderer::~wxDataViewCustomRenderer | ( | ) | [virtual] |
Destructor.
virtual bool wxDataViewCustomRenderer::Activate | ( | wxRect | cell, | |
wxDataViewModel * | model, | |||
const wxDataViewItem & | item, | |||
unsigned int | col | |||
) | [virtual] |
Override this to react to double clicks or ENTER.
This method will only be called in wxDATAVIEW_CELL_ACTIVATABLE mode.
virtual wxControl* wxDataViewCustomRenderer::CreateEditorCtrl | ( | wxWindow * | parent, | |
wxRect | labelRect, | |||
const wxVariant & | value | |||
) | [virtual] |
Override this to create the actual editor control once editing is about to start.
parent is the parent of the editor control, labelRect indicates the position and size of the editor control and value is its initial value:
{ long l = value; return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString, labelRect.GetTopLeft(), labelRect.GetSize(), 0, 0, 100, l ); }
const wxDataViewItemAttr& wxDataViewCustomRenderer::GetAttr | ( | ) | const |
Return the attribute to be used for rendering.
This function may be called from Render() implementation to use the attributes defined for the item if the renderer supports them.
Notice that when Render() is called, the wxDC object passed to it is already set up to use the correct attributes (e.g. its font is set to bold or italic version if wxDataViewItemAttr::GetBold() or GetItalic() returns true) so it may not be necessary to call it explicitly if you only want to render text using the items attributes.
virtual wxSize wxDataViewCustomRenderer::GetSize | ( | ) | const [pure virtual] |
Return size required to show content.
virtual bool wxDataViewCustomRenderer::GetValueFromEditorCtrl | ( | wxControl * | editor, | |
wxVariant & | value | |||
) | [virtual] |
Override this so that the renderer can get the value from the editor control (pointed to by editor):.
{ wxSpinCtrl *sc = (wxSpinCtrl*) editor; long l = sc->GetValue(); value = l; return true; }
virtual bool wxDataViewCustomRenderer::HasEditorCtrl | ( | ) | const [virtual] |
Override this and make it return true in order to indicate that this renderer supports in-place editing.
virtual bool wxDataViewCustomRenderer::LeftClick | ( | wxPoint | cursor, | |
wxRect | cell, | |||
wxDataViewModel * | model, | |||
const wxDataViewItem & | item, | |||
unsigned int | col | |||
) | [virtual] |
Override this to react to a left click.
This method will only be called in wxDATAVIEW_CELL_ACTIVATABLE
mode.
Override this to render the cell.
Before this is called, wxDataViewRenderer::SetValue was called so that this instance knows what to render.
void wxDataViewCustomRenderer::RenderText | ( | const wxString & | text, | |
int | xoffset, | |||
wxRect | cell, | |||
wxDC * | dc, | |||
int | state | |||
) |
This method should be called from within Render() whenever you need to render simple text.
This will ensure that the correct colour, font and vertical alignment will be chosen so the text will look the same as text drawn by native renderers.
virtual bool wxDataViewCustomRenderer::StartDrag | ( | wxPoint | cursor, | |
wxRect | cell, | |||
wxDataViewModel * | model, | |||
const wxDataViewItem & | item, | |||
unsigned int | col | |||
) | [virtual] |
Override this to start a drag operation.
Not yet supported.
![]() |
[ top ] |