Version: 3.1.1
wxDataViewCustomRenderer Class Referenceabstract

#include <wx/dataview.h>

+ Inheritance diagram for wxDataViewCustomRenderer:

Detailed Description

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.

If wxUSE_ACCESSIBILITY setup symbol is set to 1, you might need to override also wxDataViewRenderer::GetAccessibleDescription.

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.

Library:  wxAdvanced
Category:  wxDataViewCtrl Related Classes

Public Member Functions

 wxDataViewCustomRenderer (const wxString &varianttype=GetDefaultType(), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT)
 Constructor. More...
 
virtual ~wxDataViewCustomRenderer ()
 Destructor. More...
 
virtual bool ActivateCell (const wxRect &cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col, const wxMouseEvent *mouseEvent)
 Override this to react to cell activation. More...
 
virtual wxWindowCreateEditorCtrl (wxWindow *parent, wxRect labelRect, const wxVariant &value)
 Override this to create the actual editor control once editing is about to start. More...
 
const wxDataViewItemAttrGetAttr () const
 Return the attribute to be used for rendering. More...
 
virtual wxSize GetSize () const =0
 Return size required to show content. More...
 
virtual bool GetValueFromEditorCtrl (wxWindow *editor, wxVariant &value)
 Override this so that the renderer can get the value from the editor control (pointed to by editor): More...
 
virtual bool HasEditorCtrl () const
 Override this and make it return true in order to indicate that this renderer supports in-place editing. More...
 
virtual bool LeftClick (wxPoint cursor, wxRect cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col)
 Override this to react to a left click. More...
 
virtual bool Activate (wxRect cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col)
 Override this to react to the activation of a cell. More...
 
virtual bool Render (wxRect cell, wxDC *dc, int state)=0
 Override this to render the cell. More...
 
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. More...
 
virtual bool StartDrag (const wxPoint &cursor, const wxRect &cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col)
 Override this to start a drag operation. More...
 
- Public Member Functions inherited from wxDataViewRenderer
 wxDataViewRenderer (const wxString &varianttype, wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT)
 Constructor. More...
 
void EnableEllipsize (wxEllipsizeMode mode=wxELLIPSIZE_MIDDLE)
 Enable or disable replacing parts of the item text with ellipsis to make it fit the column width. More...
 
void DisableEllipsize ()
 Disable replacing parts of the item text with ellipsis. More...
 
virtual wxString GetAccessibleDescription () const =0
 This method returns a string describing the content of the renderer to the class implementing accessibility features in wxDataViewCtrl. More...
 
virtual int GetAlignment () const
 Returns the alignment. More...
 
wxEllipsizeMode GetEllipsizeMode () const
 Returns the ellipsize mode used by the renderer. More...
 
virtual wxDataViewCellMode GetMode () const
 Returns the cell mode. More...
 
wxDataViewColumnGetOwner () const
 Returns pointer to the owning wxDataViewColumn. More...
 
virtual bool GetValue (wxVariant &value) const =0
 This methods retrieves the value from the renderer in order to transfer the value back to the data model. More...
 
wxString GetVariantType () const
 Returns a string with the type of the wxVariant supported by this renderer. More...
 
virtual void SetAlignment (int align)
 Sets the alignment of the renderer's content. More...
 
void SetOwner (wxDataViewColumn *owner)
 Sets the owning wxDataViewColumn. More...
 
virtual bool SetValue (const wxVariant &value)=0
 Set the value of the renderer (and thus its cell) to value. More...
 
void SetValueAdjuster (wxDataViewValueAdjuster *transformer)
 Set the transformer object to be used to customize values before they are rendered. More...
 
virtual bool Validate (wxVariant &value)
 Before data is committed to the data model, it is passed to this method where it can be checked for validity. More...
 
virtual bool StartEditing (const wxDataViewItem &item, wxRect labelRect)
 
virtual void CancelEditing ()
 
virtual bool FinishEditing ()
 
wxWindowGetEditorCtrl ()
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 

Static Public Member Functions

static wxString GetDefaultType ()
 Returns the wxVariant type used with this renderer. More...
 

Protected Member Functions

wxSize GetTextExtent (const wxString &str) const
 Helper for GetSize() implementations, respects attributes. More...
 
- Protected Member Functions inherited from wxDataViewRenderer
wxDataViewCtrlGetView () const
 
- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 

Additional Inherited Members

- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

wxDataViewCustomRenderer::wxDataViewCustomRenderer ( const wxString varianttype = GetDefaultType(),
wxDataViewCellMode  mode = wxDATAVIEW_CELL_INERT,
int  align = wxDVR_DEFAULT_ALIGNMENT 
)

Constructor.

virtual wxDataViewCustomRenderer::~wxDataViewCustomRenderer ( )
virtual

Destructor.

Member Function Documentation

virtual bool wxDataViewCustomRenderer::Activate ( wxRect  cell,
wxDataViewModel model,
const wxDataViewItem item,
unsigned int  col 
)
virtual

Override this to react to the activation of a cell.

Deprecated:
Use ActivateCell instead.
virtual bool wxDataViewCustomRenderer::ActivateCell ( const wxRect cell,
wxDataViewModel model,
const wxDataViewItem item,
unsigned int  col,
const wxMouseEvent mouseEvent 
)
virtual

Override this to react to cell activation.

Activating a cell is an alternative to showing inline editor when the value can be edited in a simple way that doesn't warrant full editor control. The most typical use of cell activation is toggling the checkbox in wxDataViewToggleRenderer; others would be e.g. an embedded volume slider or a five-star rating column.

The exact means of activating a cell are platform-dependent, but they are usually similar to those used for inline editing of values. Typically, a cell would be activated by Space or Enter keys or by left mouse click.

This method will only be called if the cell has the wxDATAVIEW_CELL_ACTIVATABLE mode.

Parameters
cellCoordinates of the activated cell's area.
modelThe model to manipulate in response.
itemActivated item.
colActivated column of item.
mouseEventIf the activation was triggered by mouse click, contains the corresponding event. Is NULL otherwise (for keyboard activation). Mouse coordinates are adjusted to be relative to the cell.
Since
2.9.3
Note
Do not confuse this method with item activation in wxDataViewCtrl and the wxEVT_DATAVIEW_ITEM_ACTIVATED event. That one is used for activating the item (or, to put it differently, the entire row) similarly to analogous messages in wxTreeCtrl and wxListCtrl, and the effect differs (play a song, open a file etc.). Cell activation, on the other hand, is all about interacting with the individual cell.
See also
CreateEditorCtrl()
virtual wxWindow* wxDataViewCustomRenderer::CreateEditorCtrl ( wxWindow parent,
wxRect  labelRect,
const wxVariant value 
)
virtual

Override this to create the actual editor control once editing is about to start.

This method will only be called if the cell has the wxDATAVIEW_CELL_EDITABLE mode. Editing is typically triggered by slowly double-clicking the cell or by a platform-dependent keyboard shortcut (F2 is typical on Windows, Space and/or Enter is common elsewhere and supported on Windows too).

Parameters
parentThe parent of the editor control.
labelRectIndicates the position and size of the editor control. The control should be created in place of the cell and labelRect should be respected as much as possible.
valueInitial value of the editor.

An example:

{
long l = value;
return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString,
labelRect.GetTopLeft(), labelRect.GetSize(), 0, 0, 100, l );
}
See also
ActivateCell()

Reimplemented from wxDataViewRenderer.

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.

Since
2.9.1
static wxString wxDataViewCustomRenderer::GetDefaultType ( )
static

Returns the wxVariant type used with this renderer.

Since
3.1.0
virtual wxSize wxDataViewCustomRenderer::GetSize ( ) const
pure virtual

Return size required to show content.

wxSize wxDataViewCustomRenderer::GetTextExtent ( const wxString str) const
protected

Helper for GetSize() implementations, respects attributes.

virtual bool wxDataViewCustomRenderer::GetValueFromEditorCtrl ( wxWindow 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;
}

Reimplemented from wxDataViewRenderer.

virtual bool wxDataViewCustomRenderer::HasEditorCtrl ( ) const
virtual

Override this and make it return true in order to indicate that this renderer supports in-place editing.

Reimplemented from wxDataViewRenderer.

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.

Deprecated:
Use ActivateCell instead.
virtual bool wxDataViewCustomRenderer::Render ( wxRect  cell,
wxDC dc,
int  state 
)
pure virtual

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 ( const wxPoint cursor,
const wxRect cell,
wxDataViewModel model,
const wxDataViewItem item,
unsigned int  col 
)
virtual

Override this to start a drag operation.

Not yet supported.