]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/datavgen.cpp
No changes, just use CPPUNIT_ASSERT_EQUAL() instead of CPPUNIT_ASSERT().
[wxWidgets.git] / src / generic / datavgen.cpp
index d2f8fe01bf5269793f54fe3e3d9a08925212f74f..af9e477cb7df341a6e7d1581a5c5cc90eacb292a 100644 (file)
@@ -1969,40 +1969,41 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func )
 
 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
 {
-    GetOwner()->InvalidateColBestWidths();
 
     if (IsVirtualList())
     {
         wxDataViewVirtualListModel *list_model =
             (wxDataViewVirtualListModel*) GetOwner()->GetModel();
         m_count = list_model->GetCount();
-        UpdateDisplay();
-        return true;
     }
+    else
+    {
+        SortPrepare();
 
-    SortPrepare();
+        wxDataViewTreeNode * node;
+        node = FindNode(parent);
 
-    wxDataViewTreeNode * node;
-    node = FindNode(parent);
+        if( node == NULL )
+            return false;
 
-    if( node == NULL )
-        return false;
+        node->SetHasChildren( true );
 
-    node->SetHasChildren( true );
+        if( g_model->IsContainer( item ) )
+        {
+            wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
+            newnode->SetItem(item);
+            newnode->SetHasChildren( true );
+            node->AddNode( newnode);
+        }
+        else
+            node->AddLeaf( item.GetID() );
 
-    if( g_model->IsContainer( item ) )
-    {
-        wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
-        newnode->SetItem(item);
-        newnode->SetHasChildren( true );
-        node->AddNode( newnode);
-    }
-    else
-        node->AddLeaf( item.GetID() );
+        node->ChangeSubTreeCount(1);
 
-    node->ChangeSubTreeCount(1);
+        m_count = -1;
+    }
 
-    m_count = -1;
+    GetOwner()->UpdateColBestWidths();
     UpdateDisplay();
 
     return true;
@@ -2013,8 +2014,6 @@ static void DestroyTreeHelper( wxDataViewTreeNode * node);
 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
                                        const wxDataViewItem& item)
 {
-    GetOwner()->InvalidateColBestWidths();
-
     if (IsVirtualList())
     {
         wxDataViewVirtualListModel *list_model =
@@ -2127,6 +2126,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
     if( m_currentRow > GetRowCount() )
         ChangeCurrentRow(m_count - 1);
 
+    GetOwner()->UpdateColBestWidths();
     UpdateDisplay();
 
     return true;
@@ -2134,11 +2134,11 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
 
 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
 {
-    GetOwner()->InvalidateColBestWidths();
-
     SortPrepare();
     g_model->Resort();
 
+    GetOwner()->UpdateColBestWidths();
+
     // Send event
     wxWindow *parent = GetParent();
     wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
@@ -2166,8 +2166,6 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
     if (view_column == -1)
         return false;
 
-    GetOwner()->InvalidateColBestWidth(view_column);
-
     // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
 /*#define MAX_VIRTUAL_WIDTH       100000
 
@@ -2180,6 +2178,8 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
     SortPrepare();
     g_model->Resort();
 
+    GetOwner()->UpdateColBestWidth(view_column);
+
     // Send event
     wxWindow *parent = GetParent();
     wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
@@ -2195,14 +2195,13 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
 
 bool wxDataViewMainWindow::Cleared()
 {
-    GetOwner()->InvalidateColBestWidths();
-
     DestroyTree();
     m_selection.Clear();
 
     SortPrepare();
     BuildTree( GetOwner()->GetModel() );
 
+    GetOwner()->UpdateColBestWidths();
     UpdateDisplay();
 
     return true;
@@ -3585,8 +3584,11 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
         return;
     }
 
-    // Test whether the mouse is hovered on the tree item button
+    // Test whether the mouse is hovering over the expander (a.k.a tree "+"
+    // button) and also determine the offset of the real cell start, skipping
+    // the indentation and the expander itself.
     bool hoverOverExpander = false;
+    int expanderOffset = 0;
     if ((!IsList()) && (GetOwner()->GetExpanderColumn() == col))
     {
         wxDataViewTreeNode * node = GetTreeNodeByRow(current);
@@ -3600,6 +3602,9 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             wxRect rect( xpos + indent,
                         GetLineStart( current ) + (GetLineHeight(current) - m_lineHeight)/2,
                         m_lineHeight, m_lineHeight);
+
+            expanderOffset = indent + m_lineHeight;
+
             if( rect.Contains(x, y) )
             {
                 // So the mouse is over the expander
@@ -3890,8 +3895,10 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
             // notify cell about click
             cell->PrepareForItem(model, item, col->GetModelColumn());
 
-            wxRect cell_rect( xpos, GetLineStart( current ),
-                              col->GetWidth(), GetLineHeight( current ) );
+            wxRect cell_rect( xpos + expanderOffset,
+                              GetLineStart( current ),
+                              col->GetWidth() - expanderOffset,
+                              GetLineHeight( current ) );
 
             // Report position relative to the cell's custom area, i.e.
             // no the entire space as given by the control but the one
@@ -4401,7 +4408,7 @@ bool wxDataViewCtrl::ClearColumns()
     return true;
 }
 
-void wxDataViewCtrl::InvalidateColBestWidth(int idx)
+void wxDataViewCtrl::UpdateColBestWidth(int idx)
 {
     m_colsBestWidths[idx] = 0;
 
@@ -4409,7 +4416,7 @@ void wxDataViewCtrl::InvalidateColBestWidth(int idx)
         m_headerArea->UpdateColumn(idx);
 }
 
-void wxDataViewCtrl::InvalidateColBestWidths()
+void wxDataViewCtrl::UpdateColBestWidths()
 {
     m_colsBestWidths.clear();
     m_colsBestWidths.resize(m_cols.size());