]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/dataview.cpp
added wxUTF8StringBuffer for writing UTF8 data into wxString efficiently, similarly...
[wxWidgets.git] / src / gtk / dataview.cpp
index dd8038be46b23da2804121ec789145d74950861c..c74207cd42464426eea0a1d9b67566afeb78a4d3 100644 (file)
@@ -629,6 +629,12 @@ void     wxgtk_tree_model_set_sort_column_id  (GtkTreeSortable        *sortable,
     gtk_tree_sortable_sort_column_changed (sortable);
     
     tree_model->internal->GetDataViewModel()->Resort();
+
+    wxDataViewCtrl *dv = tree_model->internal->GetOwner();    
+    wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() );
+    // TODO event.SetDataViewColumn( column );
+    event.SetModel( dv->GetModel() );
+    dv->GetEventHandler()->ProcessEvent( event );
 }
 
 void     wxgtk_tree_model_set_sort_func         (GtkTreeSortable        *sortable,
@@ -1842,7 +1848,7 @@ gtk_dataview_header_button_press_callback( GtkWidget *widget,
         event.SetDataViewColumn( column );
         event.SetModel( dv->GetModel() );
         if (dv->GetEventHandler()->ProcessEvent( event ))
-            return TRUE;
+            return FALSE;
     }
 
     return FALSE;
@@ -2714,7 +2720,7 @@ wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCt
         return;
 
     wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, dv->GetId() );
-    // TODO: item
+    event.SetItem( dv->GetSelection() );
     event.SetModel( dv->GetModel() );
     dv->GetEventHandler()->ProcessEvent( event );
 }
@@ -2989,6 +2995,22 @@ wxDataViewItem wxDataViewCtrl::GetSelection()
     
     if (m_windowStyle & wxDV_MULTIPLE)
     {
+        // Report the first one
+        GtkTreeModel *model;
+        GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
+    
+        if (list)
+        {
+            GtkTreePath *path = (GtkTreePath*) list->data;
+            GtkTreeIter iter;
+            m_internal->get_iter( &iter, path );
+            
+            // delete list
+            g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL );
+            g_list_free( list );
+            
+            return wxDataViewItem( (void*) iter.user_data );
+        }
     }
     else
     {
@@ -3005,36 +3027,133 @@ wxDataViewItem wxDataViewCtrl::GetSelection()
 
 int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
 {
+    sel.Clear();
+
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+    if (HasFlag(wxDV_MULTIPLE))
+    {
+        GtkTreeModel *model;
+        GList *list = gtk_tree_selection_get_selected_rows( selection, &model );
+
+        int count = 0;
+        while (list)
+        {
+            GtkTreePath *path = (GtkTreePath*) list->data;
+            
+            GtkTreeIter iter;
+            m_internal->get_iter( &iter, path );
+
+            sel.Add( wxDataViewItem( (void*) iter.user_data ) );
+
+            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
+    {
+        GtkTreeModel *model;
+        GtkTreeIter iter;
+        gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter );
+        if (has_selection)
+        {
+            sel.Add( wxDataViewItem( (void*) iter.user_data) );
+            return 1;
+        }
+    }
+
     return 0;
 }
 
 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
 {
+    GtkDisableSelectionEvents();
+    
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+
+    gtk_tree_selection_unselect_all( selection );
+    
+    size_t i;
+    for (i = 0; i < sel.GetCount(); i++)
+    {
+        GtkTreeIter iter;
+        iter.user_data = (gpointer) sel[i].GetID();
+        gtk_tree_selection_select_iter( selection, &iter );
+    }
+    
+    GtkEnableSelectionEvents();
 }
 
 void wxDataViewCtrl::Select( const wxDataViewItem & item )
 {
+    GtkDisableSelectionEvents();
+
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+
+    GtkTreeIter iter;
+    iter.user_data = (gpointer) item.GetID();
+    gtk_tree_selection_select_iter( selection, &iter );
+
+    GtkEnableSelectionEvents();
 }
 
 void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
 {
+    GtkDisableSelectionEvents();
+
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+
+    GtkTreeIter iter;
+    iter.user_data = (gpointer) item.GetID();
+    gtk_tree_selection_unselect_iter( selection, &iter );
+
+    GtkEnableSelectionEvents();
 }
 
 bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
 {
-    return false;
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+
+    GtkTreeIter iter;
+    iter.user_data = (gpointer) item.GetID();
+    
+    return gtk_tree_selection_iter_is_selected( selection, &iter );
 }
 
 void wxDataViewCtrl::SelectAll()
 {
+    GtkDisableSelectionEvents();
+    
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+    
+    gtk_tree_selection_select_all( selection );
+    
+    GtkEnableSelectionEvents();
 }
 
 void wxDataViewCtrl::UnselectAll()
 {
+    GtkDisableSelectionEvents();
+    
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+    
+    gtk_tree_selection_unselect_all( selection );
+    
+    GtkEnableSelectionEvents();
 }
 
-void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item )
+void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, wxDataViewColumn *column )
 {
+    GtkTreeIter iter;
+    iter.user_data = (gpointer) item.GetID();
+    GtkTreePath *path = m_internal->get_path( &iter );
+    gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview), path, NULL, false, 0.0, 0.0 );
+    gtk_tree_path_free( path );
 }
 
 void wxDataViewCtrl::DoSetExpanderColumn()
@@ -3048,15 +3167,15 @@ void wxDataViewCtrl::DoSetIndent()
 void wxDataViewCtrl::GtkDisableSelectionEvents()
 {
     GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
-    g_signal_connect_after (selection, "changed",
-                            G_CALLBACK (wxdataview_selection_changed_callback), this);
+    g_signal_handlers_disconnect_by_func( selection,
+                            (gpointer) (wxdataview_selection_changed_callback), this);
 }
 
 void wxDataViewCtrl::GtkEnableSelectionEvents()
 {
     GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
-    g_signal_handlers_disconnect_by_func( selection,
-                            (gpointer) (wxdataview_selection_changed_callback), this);
+    g_signal_connect_after (selection, "changed",
+                            G_CALLBACK (wxdataview_selection_changed_callback), this);
 }
 
 // static