From: Robert Roebling Date: Thu, 23 Feb 2006 03:04:15 +0000 (+0000) Subject: Route data from wxDataViewModel in a wxVariant X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7b4fde8255e2c5495b5c7c2b3234d19ac8c1e7cf Route data from wxDataViewModel in a wxVariant through wxDataViewCell::SetValue() to the GtkCellRendererText. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37677 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 1131a7430a..b7841cf6d7 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -51,6 +51,8 @@ public: wxDataViewTextCell( const wxString &varianttype = wxT("string"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); + bool SetValue( const wxVariant &value ); + protected: DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextCell) }; diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 35931d39bd..eda63e10dd 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -525,10 +525,53 @@ wxDataViewTextCell::wxDataViewTextCell( const wxString &varianttype, wxDataViewC m_renderer = (void*) gtk_cell_renderer_text_new(); } +bool wxDataViewTextCell::SetValue( const wxVariant &value ) +{ + wxString tmp = value; + + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_STRING ); + g_value_set_string( &gvalue, wxGTK_CONV( tmp ) ); + g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); + g_value_unset( &gvalue ); + + return true; +} + // --------------------------------------------------------- // wxDataViewColumn // --------------------------------------------------------- + +extern "C" { +static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data ); +} + + +static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, + GtkCellRenderer *renderer, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data ) +{ + g_return_if_fail (GTK_IS_WX_LIST_STORE (model)); + GtkWxListStore *list_store = (GtkWxListStore *) model; + + wxDataViewCell *cell = (wxDataViewCell*) data; + + wxVariant value = list_store->model->GetValue( (size_t) iter->user_data, + cell->GetOwner()->GetModelColumn() ); + + if (value.GetType() != cell->GetVariantType()) + wxPrintf( wxT("Wrong type\n") ); + + cell->SetValue( value ); +} + IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase) wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell, @@ -543,8 +586,8 @@ wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell, gtk_tree_view_column_pack_start( column, renderer, TRUE ); - // only correct for wxDataViewTextCell - gtk_tree_view_column_set_attributes( column, renderer, "text", model_column, NULL ); + gtk_tree_view_column_set_cell_data_func( column, renderer, + wxGtkTreeCellDataFunc, (gpointer) cell, NULL ); m_column = (void*) column; }