Add wxDataViewValueAdjuster
Add wxDataViewRenderer:: SetValueAdjuster() and a wxDataViewValueAdjuster class. This can be used to customize rendering of values depending on whether they are highlighted (selection) or not, without having to implement an entire new custom renderer.
This commit is contained in:
committed by
Václav Slavík
parent
13862ad8e6
commit
ff1dba498e
@@ -96,6 +96,16 @@ enum wxDataViewCellRenderState
|
||||
wxDATAVIEW_CELL_FOCUSED = 8
|
||||
};
|
||||
|
||||
// helper for fine-tuning rendering of values depending on row's state
|
||||
class WXDLLIMPEXP_ADV wxDataViewValueAdjuster
|
||||
{
|
||||
public:
|
||||
virtual ~wxDataViewValueAdjuster() {}
|
||||
|
||||
// changes the value to have appearance suitable for highlighted rows
|
||||
virtual wxVariant MakeHighlighted(const wxVariant& value) const { return value; }
|
||||
};
|
||||
|
||||
class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
|
||||
{
|
||||
public:
|
||||
@@ -190,6 +200,10 @@ public:
|
||||
// Send wxEVT_DATAVIEW_ITEM_EDITING_STARTED event.
|
||||
void NotifyEditingStarted(const wxDataViewItem& item);
|
||||
|
||||
// Sets the transformer for fine-tuning rendering of values depending on row's state
|
||||
void SetValueAdjuster(wxDataViewValueAdjuster *transformer)
|
||||
{ delete m_valueAdjuster; m_valueAdjuster = transformer; }
|
||||
|
||||
protected:
|
||||
// These methods are called from PrepareForItem() and should do whatever is
|
||||
// needed for the current platform to ensure that the item is rendered
|
||||
@@ -197,6 +211,10 @@ protected:
|
||||
virtual void SetAttr(const wxDataViewItemAttr& attr) = 0;
|
||||
virtual void SetEnabled(bool enabled) = 0;
|
||||
|
||||
// Return whether the currently rendered item is on a highlighted row
|
||||
// (typically selection with dark background). For internal use only.
|
||||
virtual bool IsHighlighted() const = 0;
|
||||
|
||||
// Called from {Cancel,Finish}Editing() to cleanup m_editorCtrl
|
||||
void DestroyEditControl();
|
||||
|
||||
@@ -211,6 +229,8 @@ protected:
|
||||
wxWeakRef<wxWindow> m_editorCtrl;
|
||||
wxDataViewItem m_item; // Item being currently edited, if valid.
|
||||
|
||||
wxDataViewValueAdjuster *m_valueAdjuster;
|
||||
|
||||
// internal utility, may be used anywhere the window associated with the
|
||||
// renderer is required
|
||||
wxDataViewCtrl* GetView() const;
|
||||
|
@@ -52,6 +52,12 @@ public:
|
||||
const wxMouseEvent* WXUNUSED(mouseEvent))
|
||||
{ return false; }
|
||||
|
||||
void SetState(int state) { m_state = state; }
|
||||
|
||||
protected:
|
||||
virtual bool IsHighlighted() const wxOVERRIDE
|
||||
{ return m_state & wxDATAVIEW_CELL_SELECTED; }
|
||||
|
||||
private:
|
||||
int m_align;
|
||||
wxDataViewCellMode m_mode;
|
||||
@@ -60,6 +66,8 @@ private:
|
||||
|
||||
wxDC *m_dc;
|
||||
|
||||
int m_state;
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer);
|
||||
};
|
||||
|
||||
|
@@ -64,6 +64,8 @@ public:
|
||||
// different from the editor control widget for the custom renderers
|
||||
virtual GtkWidget* GtkGetEditorWidget() const;
|
||||
|
||||
void GtkSetCurrentItem(const wxDataViewItem& item) { m_itemBeingRendered = item; }
|
||||
|
||||
private:
|
||||
// Change the mode at GTK level without touching m_mode, this is useful for
|
||||
// temporarily making the renderer insensitive but does mean that GetMode()
|
||||
@@ -74,6 +76,8 @@ protected:
|
||||
virtual void SetAttr(const wxDataViewItemAttr& attr) wxOVERRIDE;
|
||||
virtual void SetEnabled(bool enabled) wxOVERRIDE;
|
||||
|
||||
virtual bool IsHighlighted() const wxOVERRIDE;
|
||||
|
||||
virtual void GtkOnCellChanged(const wxVariant& value,
|
||||
const wxDataViewItem& item,
|
||||
unsigned col);
|
||||
@@ -93,6 +97,9 @@ protected:
|
||||
// doing this
|
||||
bool m_usingDefaultAttrs;
|
||||
|
||||
// the item currently being rendered
|
||||
wxDataViewItem m_itemBeingRendered;
|
||||
|
||||
protected:
|
||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer);
|
||||
};
|
||||
|
@@ -93,6 +93,8 @@ protected:
|
||||
void SetEnabled(bool WXUNUSED(enabled)) wxOVERRIDE { };
|
||||
#endif
|
||||
|
||||
virtual bool IsHighlighted() const wxOVERRIDE;
|
||||
|
||||
private:
|
||||
// contains the alignment flags
|
||||
int m_alignment;
|
||||
|
Reference in New Issue
Block a user