From c2a738e372126950e5c70f72a3e8876f1ac89bf5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 10 Nov 2009 17:41:22 +0000 Subject: [PATCH] Avoid setting attributes in GTK wxDataViewRenderer if not supported. If the native renderer doesn't support the properties which we map our attributes to, trying to set them is useless and results in GTK+ warnings so don't do it. Add wxDataViewRenderer::GtkSupportsAttrs() which can be overridden to indicate whether the renderer supports attributes or not. We probably could use g_object_class_find_property() instead to detect it automatically but for now these properties are all supported only by GtkCellRendererText and not supported anywhere else so using a single virtual function seems tidier. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62591 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/dvrenderer.h | 8 ++++++++ include/wx/gtk/dvrenderers.h | 2 ++ src/gtk/dataview.cpp | 10 +++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/wx/gtk/dvrenderer.h b/include/wx/gtk/dvrenderer.h index 9513104c1c..e019c00883 100644 --- a/include/wx/gtk/dvrenderer.h +++ b/include/wx/gtk/dvrenderer.h @@ -53,6 +53,14 @@ public: void GtkInitHandlers(); void GtkUpdateAlignment(); + // should be overridden to return true if the renderer supports properties + // corresponding to wxDataViewItemAttr field, see wxGtkTreeCellDataFunc() + // for details + virtual bool GtkSupportsAttrs() const { return false; } + + // these functions are only called if GtkSupportsAttrs() returns true and + // are used to remember whether the renderer currently uses the default + // attributes or if we changed (and not reset them) bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs; } void GtkSetUsingDefaultAttrs(bool def) { m_usingDefaultAttrs = def; } diff --git a/include/wx/gtk/dvrenderers.h b/include/wx/gtk/dvrenderers.h index 74c866ed40..845a938d34 100644 --- a/include/wx/gtk/dvrenderers.h +++ b/include/wx/gtk/dvrenderers.h @@ -41,6 +41,8 @@ public: virtual void SetAlignment( int align ); + virtual bool GtkSupportsAttrs() const { return true; } + protected: // implementation of Set/GetValue() bool SetTextValue(const wxString& str); diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 26a3f53f28..5a5b89c2da 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -2587,7 +2587,15 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column), cell->SetValue( value ); - // deal with attributes + // deal with attributes if we can handle them here: currently this is only + // the case for wxDataViewTextRenderer (and derived) class(es) because + // GtkCellRendererText is the only GTK renderer that we use which supports + // the properties below (foreground_gdk, style, weight) -- if any other + // renderers added in the future support them too, they should simply + // override their GtkSupportsAttrs() to return true + if ( !cell->GtkSupportsAttrs() ) + return; + wxDataViewItemAttr attr; if ( !wx_model->GetAttr( item, cell->GetOwner()->GetModelColumn(), attr ) && cell->GtkIsUsingDefaultAttrs() ) -- 2.45.2