]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/dataview.cpp
No changes, just use CPPUNIT_ASSERT_EQUAL() instead of CPPUNIT_ASSERT().
[wxWidgets.git] / src / gtk / dataview.cpp
index 2f7e57112f4c0c7ea2287f25a2c2cd812669a563..b664d402d58257bab1283a061a0e987901c94980 100644 (file)
@@ -34,6 +34,7 @@
 #include "wx/gtk/dcclient.h"
 
 #include "wx/gtk/private/gdkconv.h"
+#include "wx/gtk/private/list.h"
 using namespace wxGTKImpl;
 
 class wxGtkDataViewModelNotifier;
@@ -98,6 +99,26 @@ private:
     wxDECLARE_NO_COPY_CLASS(wxGtkTreePath);
 };
 
+// ----------------------------------------------------------------------------
+// wxGtkTreePathList: self-destroying list of GtkTreePath objects.
+// ----------------------------------------------------------------------------
+
+class wxGtkTreePathList : public wxGtkList
+{
+public:
+    // Ctor takes ownership of the list.
+    explicit wxGtkTreePathList(GList* list)
+        : wxGtkList(list)
+    {
+    }
+
+    ~wxGtkTreePathList()
+    {
+        // Delete the list contents, wxGtkList will delete the list itself.
+        g_list_foreach(m_list, (GFunc)gtk_tree_path_free, NULL);
+    }
+};
+
 // ----------------------------------------------------------------------------
 // wxGtkTreeSelectionLock: prevent selection from changing during the
 //                                 lifetime of this object
@@ -300,7 +321,7 @@ private:
 static
 int LINKAGEMODE wxGtkTreeModelChildCmp( void** id1, void** id2 )
 {
-    int ret = gs_internal->GetDataViewModel()->Compare( *id1, *id2,
+    int ret = gs_internal->GetDataViewModel()->Compare( wxDataViewItem(*id1), wxDataViewItem(*id2),
         gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
 
     return ret;
@@ -3334,7 +3355,7 @@ int wxGtkTreeModelChildWithPosCmp( const void* data1, const void* data2, const v
 static
 int LINKAGEMODE wxGtkTreeModelChildPtrCmp( void*** data1, void*** data2 )
 {
-    return gs_internal->GetDataViewModel()->Compare( **data1, **data2,
+    return gs_internal->GetDataViewModel()->Compare( wxDataViewItem(**data1), wxDataViewItem(**data2),
         gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
 }
 
@@ -3578,6 +3599,7 @@ gboolean wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource *WXUNUSED(drag
     GtkTreePath *path )
 {
     delete m_dragDataObject;
+    m_dragDataObject = NULL;
 
     wxDataViewItem item(GetOwner()->GTKPathToItem(path));
     if ( !item )
@@ -4810,13 +4832,9 @@ int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
 {
     GtkTreeViewColumn *gtk_column = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle());
 
-    GList *list = gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview) );
-
-    gint pos = g_list_index( list, (gconstpointer)  gtk_column );
+    wxGtkList list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview)));
 
-    g_list_free( list );
-
-    return pos;
+    return g_list_index( list, (gconstpointer)  gtk_column );
 }
 
 wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
@@ -4955,23 +4973,17 @@ int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
     if (HasFlag(wxDV_MULTIPLE))
     {
         GtkTreeModel *model;
-        GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
+        wxGtkTreePathList list(gtk_tree_selection_get_selected_rows(selection, &model));
 
         int count = 0;
-        while (list)
+        for ( GList* current = list; current; current = g_list_next(current) )
         {
             GtkTreePath *path = (GtkTreePath*) list->data;
 
             sel.Add(GTKPathToItem(path));
-
-            list = g_list_next( list );
             count++;
         }
 
-        // delete list
-        g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
-        g_list_free( list );
-
         return count;
     }
     else