From: Vadim Zeitlin Date: Thu, 21 Jul 2011 13:50:22 +0000 (+0000) Subject: Fix the alignment used by custom wxDVC renderers in wxGTK by default. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3e81bbbf6c49a3bc8765817ddf7a1e83ae418f7d Fix the alignment used by custom wxDVC renderers in wxGTK by default. Correctly initialize the alignment used by the text renderer used by wxDataViewCustomRenderer in wxGTK implementation of wxDataViewCtrl. Closes #12298. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68323 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/dvrenderer.h b/include/wx/gtk/dvrenderer.h index 7f8d3d4782..c6ecb397e4 100644 --- a/include/wx/gtk/dvrenderer.h +++ b/include/wx/gtk/dvrenderer.h @@ -52,7 +52,7 @@ public: GtkCellRenderer* GetGtkHandle() { return m_renderer; } void GtkInitHandlers(); - void GtkUpdateAlignment(); + void GtkUpdateAlignment() { GtkApplyAlignment(m_renderer); } // should be overridden to return true if the renderer supports properties // corresponding to wxDataViewItemAttr field, see wxGtkTreeCellDataFunc() @@ -85,6 +85,9 @@ protected: const wxDataViewItem& item, unsigned col); + // Apply our effective alignment (i.e. m_alignment if specified or the + // associated column alignment by default) to the given renderer. + void GtkApplyAlignment(GtkCellRenderer *renderer); GtkCellRenderer *m_renderer; int m_alignment; diff --git a/include/wx/gtk/dvrenderers.h b/include/wx/gtk/dvrenderers.h index 528a7a1235..563d30944d 100644 --- a/include/wx/gtk/dvrenderers.h +++ b/include/wx/gtk/dvrenderers.h @@ -147,6 +147,10 @@ protected: bool Init(wxDataViewCellMode mode, int align); private: + // Called from GtkGetTextRenderer() to really create the renderer if + // necessary. + void GtkInitTextRenderer(); + wxDC *m_dc; GtkCellRendererText *m_text_renderer; diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 8aba4f4d77..2f7e57112f 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1835,7 +1835,7 @@ wxDataViewCellMode wxDataViewRenderer::GetMode() const return ret; } -void wxDataViewRenderer::GtkUpdateAlignment() +void wxDataViewRenderer::GtkApplyAlignment(GtkCellRenderer *renderer) { int align = m_alignment; @@ -1861,7 +1861,7 @@ void wxDataViewRenderer::GtkUpdateAlignment() GValue gvalue = { 0, }; g_value_init( &gvalue, G_TYPE_FLOAT ); g_value_set_float( &gvalue, xalign ); - g_object_set_property( G_OBJECT(m_renderer), "xalign", &gvalue ); + g_object_set_property( G_OBJECT(renderer), "xalign", &gvalue ); g_value_unset( &gvalue ); // vertical alignment: @@ -1875,7 +1875,7 @@ void wxDataViewRenderer::GtkUpdateAlignment() GValue gvalue2 = { 0, }; g_value_init( &gvalue2, G_TYPE_FLOAT ); g_value_set_float( &gvalue2, yalign ); - g_object_set_property( G_OBJECT(m_renderer), "yalign", &gvalue2 ); + g_object_set_property( G_OBJECT(renderer), "yalign", &gvalue2 ); g_value_unset( &gvalue2 ); } @@ -2359,14 +2359,20 @@ wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, Init(mode, align); } +void wxDataViewCustomRenderer::GtkInitTextRenderer() +{ + m_text_renderer = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new()); + g_object_ref_sink(m_text_renderer); + + GtkApplyAlignment(GTK_CELL_RENDERER(m_text_renderer)); +} + 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()); - g_object_ref_sink(m_text_renderer); + const_cast(this)->GtkInitTextRenderer(); } return m_text_renderer;