diff --git a/include/wx/gtk/dvrenderer.h b/include/wx/gtk/dvrenderer.h index 72f1d4a106..cb7d617830 100644 --- a/include/wx/gtk/dvrenderer.h +++ b/include/wx/gtk/dvrenderer.h @@ -12,6 +12,7 @@ #ifndef _WX_GTK_DVRENDERER_H_ #define _WX_GTK_DVRENDERER_H_ +typedef struct _GtkCellRendererText GtkCellRendererText; typedef struct _GtkTreeViewColumn GtkTreeViewColumn; // ---------------------------------------------------------------------------- @@ -72,6 +73,11 @@ public: bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs; } void GtkSetUsingDefaultAttrs(bool def) { m_usingDefaultAttrs = def; } + // return the text renderer used by this renderer for setting text cell + // specific attributes: can return NULL if this renderer doesn't render any + // text + virtual GtkCellRendererText *GtkGetTextRenderer() const { return NULL; } + protected: virtual void GtkOnCellChanged(const wxVariant& value, const wxDataViewItem& item, diff --git a/include/wx/gtk/dvrenderers.h b/include/wx/gtk/dvrenderers.h index b22ef67eea..0e8ba0a591 100644 --- a/include/wx/gtk/dvrenderers.h +++ b/include/wx/gtk/dvrenderers.h @@ -13,7 +13,6 @@ #define _WX_GTK_DVRENDERERS_H_ typedef struct _GdkRectangle GdkRectangle; -typedef struct _GtkCellRendererText GtkCellRendererText; // --------------------------------------------------------- // wxDataViewTextRenderer @@ -47,6 +46,8 @@ public: virtual bool GtkSupportsAttrs() const { return true; } virtual bool GtkSetAttr(const wxDataViewItemAttr& attr); + virtual GtkCellRendererText *GtkGetTextRenderer() const; + protected: // implementation of Set/GetValue() bool SetTextValue(const wxString& str); @@ -140,6 +141,8 @@ public: return !attr.IsDefault(); } + virtual GtkCellRendererText *GtkGetTextRenderer() const; + protected: bool Init(wxDataViewCellMode mode, int align); diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index f77f50d776..f4e95b42ea 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1681,12 +1681,16 @@ void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode) if ( gtk_check_version(2, 6, 0) != NULL ) return; + GtkCellRendererText * const rend = GtkGetTextRenderer(); + if ( !rend ) + return; + // we use the same values in wxEllipsizeMode as PangoEllipsizeMode so we // can just cast between them GValue gvalue = { 0, }; g_value_init( &gvalue, PANGO_TYPE_ELLIPSIZE_MODE ); g_value_set_enum( &gvalue, static_cast(mode) ); - g_object_set_property( G_OBJECT(m_renderer), "ellipsize", &gvalue ); + g_object_set_property( G_OBJECT(rend), "ellipsize", &gvalue ); g_value_unset( &gvalue ); } @@ -1695,9 +1699,13 @@ wxEllipsizeMode wxDataViewRenderer::GetEllipsizeMode() const if ( gtk_check_version(2, 6, 0) != NULL ) return wxELLIPSIZE_NONE; + GtkCellRendererText * const rend = GtkGetTextRenderer(); + if ( !rend ) + return wxELLIPSIZE_NONE; + GValue gvalue = { 0, }; g_value_init( &gvalue, PANGO_TYPE_ELLIPSIZE_MODE ); - g_object_get_property( G_OBJECT(m_renderer), "ellipsize", &gvalue ); + g_object_get_property( G_OBJECT(rend), "ellipsize", &gvalue ); wxEllipsizeMode mode = static_cast(g_value_get_enum( &gvalue )); g_value_unset( &gvalue ); @@ -1916,7 +1924,12 @@ void wxDataViewTextRenderer::SetAlignment( int align ) bool wxDataViewTextRenderer::GtkSetAttr(const wxDataViewItemAttr& attr) { - return GtkApplyAttr(GTK_CELL_RENDERER_TEXT(m_renderer), attr); + return GtkApplyAttr(GtkGetTextRenderer(), attr); +} + +GtkCellRendererText *wxDataViewTextRenderer::GtkGetTextRenderer() const +{ + return GTK_CELL_RENDERER_TEXT(m_renderer); } // --------------------------------------------------------- @@ -2130,29 +2143,41 @@ wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, Init(mode, align); } +GtkCellRendererText *wxDataViewCustomRenderer::GtkGetTextRenderer() const +{ + if ( !m_text_renderer ) + { + // we create it on demand so need to do it even from a const function + const_cast(this)-> + m_text_renderer = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new()); + } + + return m_text_renderer; +} + void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *WXUNUSED(dc), int WXUNUSED(state) ) { - if (!m_text_renderer) - m_text_renderer = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new()); + + GtkCellRendererText * const textRenderer = GtkGetTextRenderer(); GValue gvalue = { 0, }; g_value_init( &gvalue, G_TYPE_STRING ); g_value_set_string( &gvalue, wxGTK_CONV_FONT( text, GetOwner()->GetOwner()->GetFont() ) ); - g_object_set_property( G_OBJECT(m_text_renderer), "text", &gvalue ); + g_object_set_property( G_OBJECT(textRenderer), "text", &gvalue ); g_value_unset( &gvalue ); - GtkApplyAttr(m_text_renderer, GetAttr()); + GtkApplyAttr(textRenderer, GetAttr()); GdkRectangle cell_area; wxRectToGDKRect(cell, cell_area); cell_area.x += xoffset; cell_area.width -= xoffset; - gtk_cell_renderer_render( GTK_CELL_RENDERER(m_text_renderer), + gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer), m_renderParams.window, m_renderParams.widget, m_renderParams.background_area,