]> git.saurik.com Git - wxWidgets.git/commitdiff
More selection work in GTK+ version.
authorRobert Roebling <robert@roebling.de>
Tue, 3 Oct 2006 17:28:19 +0000 (17:28 +0000)
committerRobert Roebling <robert@roebling.de>
Tue, 3 Oct 2006 17:28:19 +0000 (17:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41601 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataview.h
include/wx/generic/dataview.h
include/wx/gtk/dataview.h
samples/dataview/dataview.cpp
src/generic/datavgen.cpp
src/gtk/dataview.cpp

index 225e52ef6bc8f82b11ca4c2541cc0ca78ea674af..90b75a42f7a06cc021606549e8234a999f9efbb7 100644 (file)
@@ -24,7 +24,7 @@
 
 #if defined(__WXGTK20__)
     // for testing
-    #define wxUSE_GENERICDATAVIEWCTRL 1
+    // #define wxUSE_GENERICDATAVIEWCTRL 1
 #elif defined(__WXMAC__)
     #define wxUSE_GENERICDATAVIEWCTRL 1
 #else
@@ -312,6 +312,7 @@ public:
 
     virtual void SetSelection( int row ) = 0; // -1 for unselect
     inline void ClearSelection() { SetSelection( -1 ); }
+    virtual void Unselect( unsigned int row ) = 0;
     virtual void SetSelectionRange( unsigned int from, unsigned int to ) = 0;
     virtual void SetSelections( const wxArrayInt& aSelections) = 0;
     
index d16295a0a5c5db2bfd3b0d434382a0bbf61d77e4..d227215da651ac89679eeb0aadb35a2cbf758eab 100644 (file)
@@ -267,6 +267,7 @@ public:
     virtual void SetSelection( int row ); // -1 for unselect
     virtual void SetSelectionRange( unsigned int from, unsigned int to );
     virtual void SetSelections( const wxArrayInt& aSelections);
+    virtual void Unselect( unsigned int row );
     
     virtual bool IsSelected( unsigned int row ) const;
     virtual int GetSelection() const;
index 8aaa0b455d333d17dab7fc06672a138ab30c0099..163cbbfb9b861c2c55232dd24ec606574b6e3a7d 100644 (file)
@@ -245,6 +245,7 @@ public:
     virtual void SetSelection( int row ); // -1 for unselect
     virtual void SetSelectionRange( unsigned int from, unsigned int to );
     virtual void SetSelections( const wxArrayInt& aSelections);
+    virtual void Unselect( unsigned int row );
     
     virtual bool IsSelected( unsigned int row ) const;
     virtual int GetSelection() const;
index 62d42221051105f917117fd08099cff5c2717899..fb385b20128509423eba9cddd7d8347e6c15c5a2 100644 (file)
@@ -294,6 +294,9 @@ enum my_events
     ID_INSERT_ROW_LEFT,
     ID_DELETE_ROW_LEFT,
     ID_EDIT_ROW_LEFT,
+    
+    ID_SELECT,
+    ID_UNSELECT_ALL,
 
     ID_APPEND_ROW_RIGHT,
     ID_PREPEND_ROW_RIGHT,
@@ -327,6 +330,9 @@ public:
     void OnDeleteRowRight(wxCommandEvent& event);
     void OnEditRowRight(wxCommandEvent& event);
 
+    void OnSelect(wxCommandEvent& event);
+    void OnUnselectAll(wxCommandEvent& event);
+    
     void OnSelectedUnsorted(wxDataViewEvent &event);
     void OnSelectedSorted(wxDataViewEvent &event);
 
@@ -461,6 +467,8 @@ BEGIN_EVENT_TABLE(MySortingFrame,wxFrame)
     EVT_BUTTON( ID_PREPEND_ROW_LEFT, MySortingFrame::OnPrependRowLeft )
     EVT_BUTTON( ID_INSERT_ROW_LEFT, MySortingFrame::OnInsertRowLeft )
     EVT_BUTTON( ID_DELETE_ROW_LEFT, MySortingFrame::OnDeleteRowLeft )
+    EVT_BUTTON( ID_SELECT, MySortingFrame::OnSelect )
+    EVT_BUTTON( ID_UNSELECT_ALL, MySortingFrame::OnUnselectAll )
     EVT_DATAVIEW_ROW_SELECTED( ID_SORTED, MySortingFrame::OnSelectedSorted )
     EVT_DATAVIEW_ROW_SELECTED( ID_UNSORTED, MySortingFrame::OnSelectedUnsorted )
 END_EVENT_TABLE()
@@ -528,6 +536,9 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int
     left_sizer->Add( new wxButton( this, ID_INSERT_ROW_LEFT, wxT("Insert") ), 0, wxALL, 5 );
     left_sizer->Add( new wxButton( this, ID_DELETE_ROW_LEFT, wxT("Delete second") ), 0, wxALL, 5 );
     left_sizer->Add( new wxButton( this, ID_EDIT_ROW_LEFT, wxT("Edit") ), 0, wxALL, 5 );
+    left_sizer->Add( 5,5 );
+    left_sizer->Add( new wxButton( this, ID_SELECT, wxT("Select third") ), 0, wxALL, 5 );
+    left_sizer->Add( new wxButton( this, ID_UNSELECT_ALL, wxT("Unselect all") ), 0, wxALL, 5 );
     button_sizer->Add( left_sizer );
     button_sizer->Add( 10, 10, 2 );
     wxFlexGridSizer *right_sizer = new wxFlexGridSizer( 2 );
@@ -561,7 +572,11 @@ MySortingFrame::~MySortingFrame()
 
 void MySortingFrame::OnSelectedUnsorted(wxDataViewEvent &event)
 {
-    wxLogMessage( wxT("OnSelected from unsorted list, selected %d"), (int) event.GetRow() );
+    int row = event.GetRow();
+    wxLogMessage( wxT("OnSelected from unsorted list, selected %d"), row );
+    if (row >= 0)
+        wxLogMessage( wxT("wxDataViewCtrl::IsSelected( %d ): %d (as int)"), 
+                    row, (int) dataview_right->IsSelected( row ) );
 }
 
 void MySortingFrame::OnSelectedSorted(wxDataViewEvent &event)
@@ -582,6 +597,16 @@ void MySortingFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
     dialog.ShowModal();
 }
 
+void MySortingFrame::OnSelect(wxCommandEvent& WXUNUSED(event))
+{
+    dataview_left->SetSelection( 2 );
+}
+
+void MySortingFrame::OnUnselectAll(wxCommandEvent& WXUNUSED(event))
+{
+    dataview_left->ClearSelection();
+}
+
 void MySortingFrame::OnAppendRowLeft(wxCommandEvent& WXUNUSED(event))
 {
     wxTextEntryDialog dialog( this, wxT("Enter text to append") );
index 31c438a633c1d793ddbe4c4ccfabf7aea6af9059..dbe4a306c5e84d77c67d6f24258cd5cc979874bf 100644 (file)
@@ -1809,6 +1809,10 @@ void wxDataViewCtrl::SetSelections( const wxArrayInt& aSelections)
 {
 }
     
+void wxDataViewCtrl::Unselect( unsigned int row )
+{
+}
+
 bool wxDataViewCtrl::IsSelected( unsigned int row ) const
 {
     return false;
index a94171c65bbbd50b7a35aa77ba7a8fc3ce930087..445ba528523311f9479c72e3c016230c3893551b 100644 (file)
@@ -1583,6 +1583,33 @@ bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
 
 void wxDataViewCtrl::SetSelection( int row )
 {
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+    
+    if (row < 0)
+    {
+        gtk_tree_selection_unselect_all( selection );
+    }
+    else
+    {
+        GtkTreePath *path = gtk_tree_path_new ();
+        gtk_tree_path_append_index( path, row );
+        
+        gtk_tree_selection_select_path( selection, path );
+        
+        gtk_tree_path_free( path );
+    }
+}
+
+void wxDataViewCtrl::Unselect( unsigned int row )
+{
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+    
+    GtkTreePath *path = gtk_tree_path_new ();
+    gtk_tree_path_append_index( path, row );
+        
+    gtk_tree_selection_unselect_path( selection, path );
+        
+    gtk_tree_path_free( path );
 }
 
 void wxDataViewCtrl::SetSelectionRange( unsigned int from, unsigned int to )
@@ -1595,7 +1622,16 @@ void wxDataViewCtrl::SetSelections( const wxArrayInt& aSelections)
     
 bool wxDataViewCtrl::IsSelected( unsigned int row ) const
 {
-    return false;
+    GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+    
+    GtkTreePath *path = gtk_tree_path_new ();
+    gtk_tree_path_append_index( path, row );
+    
+    gboolean ret =  gtk_tree_selection_path_is_selected( selection, path );
+    
+    gtk_tree_path_free( path );
+    
+    return ret;
 }
 
 int wxDataViewCtrl::GetSelection() const