]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/dataview.cpp
Added test bitmap.
[wxWidgets.git] / src / gtk / dataview.cpp
index 8b02377e0ef2e1c89ce8964713de5a63804b5675..f03d36bcdbc07418c5563cfe8dcc53d026a19a56 100644 (file)
 
 #ifndef wxUSE_GENERICDATAVIEWCTRL
 
+#ifndef WX_PRECOMP
+    #include "wx/log.h"
+    #include "wx/dcclient.h"
+    #include "wx/sizer.h"
+#endif
+
 #include "wx/stockitem.h"
-#include "wx/dcclient.h"
 #include "wx/calctrl.h"
 #include "wx/popupwin.h"
-#include "wx/sizer.h"
-#include "wx/log.h"
 
 #include "wx/gtk/private.h"
 #include "wx/gtk/win_gtk.h"
@@ -780,12 +783,26 @@ bool wxGtkDataViewListModelNotifier::RowPrepended()
 
 bool wxGtkDataViewListModelNotifier::RowInserted( size_t before )
 {
-    return false;
+    GtkTreeIter iter;
+    iter.stamp = m_gtk_store->stamp;
+    iter.user_data = (gpointer) before;
+
+    GtkTreePath *path = gtk_tree_path_new ();
+    gtk_tree_path_append_index (path, (gint) before);
+    gtk_tree_model_row_inserted (GTK_TREE_MODEL (m_gtk_store), path, &iter);
+    gtk_tree_path_free (path);
+
+    return true;
 }
 
 bool wxGtkDataViewListModelNotifier::RowDeleted( size_t row )
 {
-    return false;
+    GtkTreePath *path = gtk_tree_path_new ();
+    gtk_tree_path_append_index (path, (gint) row);
+    gtk_tree_model_row_deleted (GTK_TREE_MODEL (m_gtk_store), path);
+    gtk_tree_path_free (path);
+
+    return true;
 }
 
 bool wxGtkDataViewListModelNotifier::RowChanged( size_t row )
@@ -902,7 +919,7 @@ static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer,
     model->ValueChanged( model_col, model_row );
 }
 
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewTextCell, wxDataViewCell)
+IMPLEMENT_CLASS(wxDataViewTextCell, wxDataViewCell)
 
 wxDataViewTextCell::wxDataViewTextCell( const wxString &varianttype, wxDataViewCellMode mode ) :
     wxDataViewCell( varianttype, mode )
@@ -947,6 +964,48 @@ bool wxDataViewTextCell::GetValue( wxVariant &value )
     return true;
 }
 
+// --------------------------------------------------------- 
+// wxDataViewBitmapCell
+// --------------------------------------------------------- 
+
+IMPLEMENT_CLASS(wxDataViewBitmapCell, wxDataViewCell)
+
+wxDataViewBitmapCell::wxDataViewBitmapCell( const wxString &varianttype, wxDataViewCellMode mode ) :
+    wxDataViewCell( varianttype, mode )
+{
+    m_renderer = (void*) gtk_cell_renderer_pixbuf_new();
+}
+
+bool wxDataViewBitmapCell::SetValue( const wxVariant &value )
+{
+    if (value.GetType() == wxT("wxBitmap"))
+    {
+        // We could also use the type safe wxGetVariantCast here
+        const wxBitmap *bitmap = (const wxBitmap*) value.GetWxObjectPtr();
+        if (!bitmap) 
+            return false;
+        
+        // This may create a Pixbuf representation in the
+        // wxBitmap object (and it will stay there)
+        GdkPixbuf *pixbuf = bitmap->GetPixbuf();
+        
+        GValue gvalue = { 0, };
+        g_value_init( &gvalue, G_TYPE_OBJECT );
+        g_value_set_object( &gvalue, pixbuf );
+        g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue );
+        g_value_unset( &gvalue );
+        
+        return true;
+    }
+    
+    return false;
+}
+
+bool wxDataViewBitmapCell::GetValue( wxVariant &value )
+{
+    return false;
+}
+    
 // ---------------------------------------------------------
 // wxDataViewToggleCell
 // ---------------------------------------------------------
@@ -986,7 +1045,7 @@ static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer,
     model->ValueChanged( model_col, model_row );
 }
 
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleCell, wxDataViewCell)
+IMPLEMENT_CLASS(wxDataViewToggleCell, wxDataViewCell)
 
 wxDataViewToggleCell::wxDataViewToggleCell( const wxString &varianttype,
                         wxDataViewCellMode mode ) :
@@ -1071,7 +1130,7 @@ public:
 // wxDataViewCustomCell
 // ---------------------------------------------------------
 
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomCell, wxDataViewCell)
+IMPLEMENT_CLASS(wxDataViewCustomCell, wxDataViewCell)
 
 wxDataViewCustomCell::wxDataViewCustomCell( const wxString &varianttype,
                           wxDataViewCellMode mode, bool no_init ) :
@@ -1128,7 +1187,7 @@ wxDC *wxDataViewCustomCell::GetDC()
 // wxDataViewProgressCell
 // ---------------------------------------------------------
 
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressCell, wxDataViewCustomCell)
+IMPLEMENT_CLASS(wxDataViewProgressCell, wxDataViewCustomCell)
 
 wxDataViewProgressCell::wxDataViewProgressCell( const wxString &label,
     const wxString &varianttype, wxDataViewCellMode mode ) :
@@ -1254,7 +1313,7 @@ void wxDataViewDateCellPopupTransient::OnCalendar( wxCalendarEvent &event )
     DismissAndNotify();
 }
 
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateCell, wxDataViewCustomCell)
+IMPLEMENT_CLASS(wxDataViewDateCell, wxDataViewCustomCell)
 
 wxDataViewDateCell::wxDataViewDateCell( const wxString &varianttype,
                         wxDataViewCellMode mode ) :
@@ -1333,15 +1392,17 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column,
     list_store->model->GetValue( value, cell->GetOwner()->GetModelColumn(), model_row );
 
     if (value.GetType() != cell->GetVariantType())
-        wxLogError( wxT("Wrong type\n") );
+        wxLogError( wxT("Wrong type, required: %s but: %s"), 
+                    value.GetType().c_str(), 
+                    cell->GetVariantType().c_str() );
 
     cell->SetValue( value );
 }
 
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase)
+IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase)
 
-wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell,
-    size_t model_column, int flags ) :
+wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell, size_t model_column,
+    int fixed_width, wxDataViewColumnSizing sizing, int flags ) :
     wxDataViewColumnBase( title, cell, model_column, flags )
 {
     GtkCellRenderer *renderer = (GtkCellRenderer *) cell->GetGtkHandle();
@@ -1350,6 +1411,16 @@ wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell,
 
     gtk_tree_view_column_set_title( column, wxGTK_CONV(title) );
 
+    if (sizing == wxDATAVIEW_COL_WIDTH_FIXED)
+        gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_FIXED );
+    else if (sizing == wxDATAVIEW_COL_WIDTH_GROW)
+        gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_GROW_ONLY );
+    else
+        gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_AUTOSIZE );
+
+    if (fixed_width > 0)
+        gtk_tree_view_column_set_fixed_width( column, fixed_width );
+
     gtk_tree_view_column_pack_start( column, renderer, TRUE );
 
     gtk_tree_view_column_set_cell_data_func( column, renderer,
@@ -1370,6 +1441,21 @@ void wxDataViewColumn::SetTitle( const wxString &title )
     gtk_tree_view_column_set_title( column, wxGTK_CONV(title) );
 }
 
+int wxDataViewColumn::GetWidth()
+{
+    return gtk_tree_view_column_get_width( (GtkTreeViewColumn *)m_column );
+}
+
+void wxDataViewColumn::SetFixedWidth( int width )
+{
+    gtk_tree_view_column_set_fixed_width( (GtkTreeViewColumn *)m_column, width );
+}
+
+int wxDataViewColumn::GetFixedWidth()
+{
+    return gtk_tree_view_column_get_fixed_width( (GtkTreeViewColumn *)m_column );
+}
+
 //-----------------------------------------------------------------------------
 // wxDataViewCtrl
 //-----------------------------------------------------------------------------
@@ -1410,6 +1496,12 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
     m_treeview = gtk_tree_view_new();
     gtk_container_add (GTK_CONTAINER (m_widget), m_treeview);
 
+    if (style & wxDV_MULTIPLE)
+    {
+        GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+        gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
+    }
+
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget),
         GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
     gtk_widget_show (m_treeview);