]> git.saurik.com Git - wxWidgets.git/commitdiff
Route data from wxDataViewModel in a wxVariant
authorRobert Roebling <robert@roebling.de>
Thu, 23 Feb 2006 03:04:15 +0000 (03:04 +0000)
committerRobert Roebling <robert@roebling.de>
Thu, 23 Feb 2006 03:04:15 +0000 (03:04 +0000)
   through wxDataViewCell::SetValue() to the
   GtkCellRendererText.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37677 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/dataview.h
src/gtk/dataview.cpp

index 1131a7430adef7a084315facd2b25db134dafb8a..b7841cf6d7670837d9660239e28716dfc4a659ad 100644 (file)
@@ -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)
 };
index 35931d39bd4760b6fb2b1fb31f9b9d599ed224b6..eda63e10dd405b80af4cbf6a239b6aea7ab6e90c 100644 (file)
@@ -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;
 }