]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datavgen.cpp
Relax validation of wxCheckBox flags.
[wxWidgets.git] / src / generic / datavgen.cpp
index 8f53d7663dde172426493f3dfed933f6b92b1c83..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 );
 
@@ -1378,7 +1379,7 @@ wxDragResult wxDataViewMainWindow::OnDragOver( wxDataFormat format, wxCoord x,
     m_owner->CalcUnscrolledPosition( xx, yy, &xx, &yy );
     unsigned int row = GetLineAt( yy );
 
-    if ((row >= GetRowCount()) || (yy > GetEndOfLastCol()))
+    if ((row >= GetRowCount()) || (xx > GetEndOfLastCol()))
     {
         RemoveDropHint();
         return wxDragNone;
@@ -1424,7 +1425,7 @@ bool wxDataViewMainWindow::OnDrop( wxDataFormat format, wxCoord x, wxCoord y )
     m_owner->CalcUnscrolledPosition( xx, yy, &xx, &yy );
     unsigned int row = GetLineAt( yy );
 
-    if ((row >= GetRowCount()) || (yy > GetEndOfLastCol()))
+    if ((row >= GetRowCount()) || (xx > GetEndOfLastCol()))
         return false;
 
     wxDataViewItem item = GetItemByRow( row );
@@ -1453,7 +1454,7 @@ wxDragResult wxDataViewMainWindow::OnData( wxDataFormat format, wxCoord x, wxCoo
     m_owner->CalcUnscrolledPosition( xx, yy, &xx, &yy );
     unsigned int row = GetLineAt( yy );
 
-    if ((row >= GetRowCount()) || (yy > GetEndOfLastCol()))
+    if ((row >= GetRowCount()) || (xx > GetEndOfLastCol()))
         return wxDragNone;
 
     wxDataViewItem item = GetItemByRow( 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() );
@@ -3888,9 +3892,13 @@ void wxDataViewCtrl::Init()
     m_headerArea = NULL;
 }
 
-bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
-                            const wxPoint& pos, const wxSize& size,
-                            long style, const wxValidator& validator )
+bool wxDataViewCtrl::Create(wxWindow *parent,
+                            wxWindowID id,
+                            const wxPoint& pos,
+                            const wxSize& size,
+                            long style,
+                            const wxValidator& validator,
+                            const wxString& name)
 {
 //    if ( (style & wxBORDER_MASK) == 0)
 //        style |= wxBORDER_SUNKEN;
@@ -3898,7 +3906,7 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
     Init();
 
     if (!wxControl::Create( parent, id, pos, size,
-                            style | wxScrolledWindowStyle, validator))
+                            style | wxScrolledWindowStyle, validator, name))
         return false;
 
     SetInitialSize(size);
@@ -4141,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.
@@ -4170,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
 {
@@ -4225,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 );
     }
@@ -4385,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);