Implement text ellipsizing for wxDataViewCustomRenderer in wxGTK.

Add another virtual function (GtkGetTextRenderer()) to the base class which
allows us to reuse the same code setting the "ellipsize" property that we
already used for wxDataViewTextRenderer for wxDataViewCustomRenderer as well.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62608 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2009-11-11 01:50:06 +00:00
parent 061a5c21db
commit 17cbc2446b
3 changed files with 43 additions and 9 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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<PangoEllipsizeMode>(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<wxEllipsizeMode>(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<wxDataViewCustomRenderer *>(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,