Implement icon text column using native GTK renderers in wxDVC.
This has a possible advantage of a more native look and feel (although it's hard to tell the difference between drawing the icon ourselves and how the default GTK+ renderer does it to be honest) and a very real advantage of allowing to edit in place cells with icons. It also reduces code duplication in GTK implementation. Modify the sample to make the icon-text column in the list model editable to show that it works. This required storing the values of the second column as well, so do it in its own array and to avoid calling it "m_array2", rename the existing m_array to m_textColValues (which accounts for most of the diff in the sample) and call the new one m_iconColValues. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62423 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
|
||||
class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal;
|
||||
|
||||
typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// wxDataViewRenderer
|
||||
@@ -37,7 +38,22 @@ public:
|
||||
virtual void SetAlignment( int align );
|
||||
virtual int GetAlignment() const;
|
||||
|
||||
// implementation
|
||||
|
||||
// GTK-specific implementation
|
||||
// ---------------------------
|
||||
|
||||
// pack the GTK cell renderers used by this renderer to the given column
|
||||
//
|
||||
// by default only a single m_renderer is used but some renderers use more
|
||||
// than one GTK cell renderer
|
||||
virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
|
||||
|
||||
// called when the cell value was edited by user with the new value
|
||||
//
|
||||
// it validates the new value and notifies the model about the change by
|
||||
// calling GtkOnCellChanged() if it was accepted
|
||||
void GtkOnTextEdited(const gchar *itempath, const wxString& value);
|
||||
|
||||
GtkCellRenderer* GetGtkHandle() { return m_renderer; }
|
||||
void GtkInitHandlers();
|
||||
void GtkUpdateAlignment();
|
||||
@@ -46,6 +62,11 @@ public:
|
||||
void GtkSetUsingDefaultAttrs(bool def) { m_usingDefaultAttrs = def; }
|
||||
|
||||
protected:
|
||||
virtual void GtkOnCellChanged(const wxVariant& value,
|
||||
const wxDataViewItem& item,
|
||||
unsigned col);
|
||||
|
||||
|
||||
GtkCellRenderer *m_renderer;
|
||||
int m_alignment;
|
||||
|
||||
@@ -68,12 +89,30 @@ public:
|
||||
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
||||
int align = wxDVR_DEFAULT_ALIGNMENT );
|
||||
|
||||
bool SetValue( const wxVariant &value );
|
||||
bool GetValue( wxVariant &value ) const;
|
||||
virtual bool SetValue( const wxVariant &value )
|
||||
{
|
||||
return SetTextValue(value);
|
||||
}
|
||||
|
||||
void SetAlignment( int align );
|
||||
virtual bool GetValue( wxVariant &value ) const
|
||||
{
|
||||
wxString str;
|
||||
if ( !GetTextValue(str) )
|
||||
return false;
|
||||
|
||||
value = str;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void SetAlignment( int align );
|
||||
|
||||
protected:
|
||||
// implementation of Set/GetValue()
|
||||
bool SetTextValue(const wxString& str);
|
||||
bool GetTextValue(wxString& str) const;
|
||||
|
||||
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
|
||||
};
|
||||
|
||||
@@ -156,7 +195,7 @@ private:
|
||||
wxDC *m_dc;
|
||||
|
||||
public:
|
||||
// Internal, temporay for RenderText.
|
||||
// Internal, temporary for RenderText.
|
||||
GtkCellRenderer *m_text_renderer;
|
||||
GdkWindow *window;
|
||||
GtkWidget *widget;
|
||||
@@ -200,7 +239,7 @@ protected:
|
||||
// wxDataViewIconTextRenderer
|
||||
// ---------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
|
||||
class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
|
||||
{
|
||||
public:
|
||||
wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
|
||||
@@ -211,17 +250,19 @@ public:
|
||||
bool SetValue( const wxVariant &value );
|
||||
bool GetValue( wxVariant &value ) const;
|
||||
|
||||
virtual bool Render( wxRect cell, wxDC *dc, int state );
|
||||
virtual wxSize GetSize() const;
|
||||
virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
|
||||
|
||||
virtual bool HasEditorCtrl() const { return true; }
|
||||
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
|
||||
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
|
||||
protected:
|
||||
virtual void GtkOnCellChanged(const wxVariant& value,
|
||||
const wxDataViewItem& item,
|
||||
unsigned col);
|
||||
|
||||
private:
|
||||
wxDataViewIconText m_value;
|
||||
|
||||
protected:
|
||||
// we use the base class m_renderer for the text and this one for the icon
|
||||
GtkCellRenderer *m_rendererIcon;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user