]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datavgen.cpp
Refactor: use wxBookCtrlBase::m_selection in all derived classes.
[wxWidgets.git] / src / generic / datavgen.cpp
index b80eeaf6224cbdcc888b7ac0e64c121556b8cd49..6df48842d202f708d8905282d0216a8cc831dd86 100644 (file)
@@ -95,7 +95,7 @@ void wxDataViewColumn::Init(int width, wxAlignment align, int flags)
     m_sort = false;
     m_sortAscending = true;
 }
-    
+
 void wxDataViewColumn::UpdateDisplay()
 {
     if (m_owner)
@@ -471,6 +471,7 @@ public:
     void ScrollWindow( int dx, int dy, const wxRect *rect = NULL );
     void ScrollTo( int rows, int column );
 
+    unsigned GetCurrentRow() const { return m_currentRow; }
     bool HasCurrentRow() { return m_currentRow != (unsigned int)-1; }
     void ChangeCurrentRow( unsigned int row );
 
@@ -2093,6 +2094,7 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
 bool wxDataViewMainWindow::Cleared()
 {
     DestroyTree();
+    m_selection.Clear();
 
     SortPrepare();
     BuildTree( GetOwner()->GetModel() );
@@ -3440,6 +3442,10 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         return;
     }
 
+    // set the focus to ourself if any of the mouse buttons are pressed
+    if(event.ButtonDown() && !HasFocus())
+        SetFocus();
+
     int x = event.GetX();
     int y = event.GetY();
     m_owner->CalcUnscrolledPosition( x, y, &x, &y );
@@ -3709,8 +3715,6 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
     }
     else if ((event.LeftDown() || simulateClick) && !hoverOverExpander)
     {
-        SetFocus();
-
         m_lineBeforeLastClicked = m_lineLastClicked;
         m_lineLastClicked = current;
 
@@ -3814,7 +3818,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
                         else if ( align & wxALIGN_BOTTOM )
                             rectItem.y += cell_rect.height - size.y;
                         // else: wxALIGN_TOP is the default
-                    }       
+                    }
                 }
 
                 wxPoint pos( event.GetPosition() );
@@ -4145,7 +4149,7 @@ int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
         if (column==col)
             return i;
     }
-    
+
     return wxNOT_FOUND;
 #else
     // This returns the position in pixels which is not what we want.
@@ -4174,6 +4178,24 @@ wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
                                             : GetColumn(m_sortingColumnIdx);
 }
 
+wxDataViewItem wxDataViewCtrl::DoGetCurrentItem() const
+{
+    return GetItemByRow(m_clientArea->GetCurrentRow());
+}
+
+void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item)
+{
+    const int row = m_clientArea->GetRowByItem(item);
+
+    const unsigned oldCurrent = m_clientArea->GetCurrentRow();
+    if ( static_cast<unsigned>(row) != oldCurrent )
+    {
+        m_clientArea->ChangeCurrentRow(row);
+        m_clientArea->RefreshRow(oldCurrent);
+        m_clientArea->RefreshRow(row);
+    }
+}
+
 // Selection code with wxDataViewItem as parameters
 wxDataViewItem wxDataViewCtrl::GetSelection() const
 {
@@ -4229,9 +4251,9 @@ void wxDataViewCtrl::Select( const wxDataViewItem & item )
         // Unselect all rows before select another in the single select mode
         if (m_clientArea->IsSingleSel())
             m_clientArea->SelectAllRows(false);
-            
+
         m_clientArea->SelectRow(row, true);
-        
+
         // Also set focus to the selected item
         m_clientArea->ChangeCurrentRow( row );
     }
@@ -4389,6 +4411,8 @@ int wxDataViewCtrl::GetRowByItem( const wxDataViewItem & item ) const
 
 void wxDataViewCtrl::Expand( const wxDataViewItem & item )
 {
+    ExpandAncestors( item );
+
     int row = m_clientArea->GetRowByItem( item );
     if (row != -1)
         m_clientArea->Expand(row);