From: Robert Roebling Date: Tue, 3 Oct 2006 14:59:48 +0000 (+0000) Subject: Implemented GetSelection() and GetSelections(). X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6ee2c58bd8c50bee46936d0f88ccb41793400382?ds=inline Implemented GetSelection() and GetSelections(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41592 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index bbfdec8ec0..ebd34b371f 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1485,29 +1485,7 @@ static void wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCtrl *dv ) { wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ROW_SELECTED, dv->GetId() ); - if (dv->HasFlag(wxDV_MULTIPLE)) - { - GtkTreeModel *model; - GList *list = gtk_tree_selection_get_selected_rows( selection, &model ); - - // do something - // ... - - // delete list - g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL ); - g_list_free( list ); - } - else - { - GtkTreeModel *model; - GtkTreeIter iter; - gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter ); - if (has_selection) - { - unsigned int row = (wxUIntPtr) iter.user_data; - event.SetRow( row ); - } - } + event.SetRow( dv->GetSelection() ); event.SetModel( dv->GetModel() ); dv->GetEventHandler()->ProcessEvent( event ); } @@ -1622,11 +1600,86 @@ bool wxDataViewCtrl::IsSelected( unsigned int row ) const int wxDataViewCtrl::GetSelection() const { + 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 ); + + // do something + if (list) + { + // list = g_list_nth( list, 0 ); should be a noop + GtkTreePath *path = (GtkTreePath*) list->data; + + unsigned int row = (unsigned int)gtk_tree_path_get_indices (path)[0]; + + // delete list + g_list_foreach( list, (GFunc) gtk_tree_path_free, NULL ); + g_list_free( list ); + + return (int) row; + } + } + else + { + + GtkTreeModel *model; + GtkTreeIter iter; + gboolean has_selection = gtk_tree_selection_get_selected( selection, &model, &iter ); + if (has_selection) + { + unsigned int row = (wxUIntPtr) iter.user_data; + return (int) row; + } + } + return -1; } int wxDataViewCtrl::GetSelections(wxArrayInt& aSelections) const { + aSelections.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) + { + + // list = g_list_nth( list, 0 ); should be a noop + GtkTreePath *path = (GtkTreePath*) list->data; + + unsigned int row = (unsigned int)gtk_tree_path_get_indices (path)[0]; + + aSelections.Add( (int) row ); + + list = g_list_next( list ); + } + + // 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) + { + unsigned int row = (wxUIntPtr) iter.user_data; + aSelections.Add( (int) row ); + return 1; + } + } + return 0; }