]> git.saurik.com Git - wxWidgets.git/commitdiff
fixes for crashes after DeleteItem and DeleteAllItems
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 10 Jul 2001 11:32:31 +0000 (11:32 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 10 Jul 2001 11:32:31 +0000 (11:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10933 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/listctrl.cpp

index 339d5dacd4ceae573c25b811983d3db837f1e8e0..a2c0f37a5c176ad6c3702ec6e53a6366c4acc81f 100644 (file)
@@ -571,12 +571,17 @@ public:
     void ReverseHighlight( size_t line )
         { HighlightLine(line, !IsHighlighted(line)); RefreshLine(line); }
 
+    // return true if the line is highlighted
+    bool IsHighlighted(size_t line) const;
+
     // refresh one or several lines at once
     void RefreshLine( size_t line );
     void RefreshLines( size_t lineFrom, size_t lineTo );
 
-    // return true if the line is highlighted
-    bool IsHighlighted(size_t line) const;
+    // refresh all lines below the given one: the difference with
+    // RefreshLines() is that the index here might not be a valid one (happens
+    // when the last line is deleted)
+    void RefreshAfter( size_t lineFrom );
 
     // the methods which are forwarded to wxListLineData itself in list/icon
     // modes but are here because the lines don't store their positions in the
@@ -2340,6 +2345,8 @@ void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
     // we suppose that they are ordered by caller
     wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") );
 
+    wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") );
+
     if ( HasFlag(wxLC_REPORT) )
     {
         size_t visibleFrom, visibleTo;
@@ -2369,6 +2376,36 @@ void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
     }
 }
 
+void wxListMainWindow::RefreshAfter( size_t lineFrom )
+{
+    if ( HasFlag(wxLC_REPORT) )
+    {
+        size_t visibleFrom;
+        GetVisibleLinesRange(&visibleFrom, NULL);
+
+        if ( lineFrom < visibleFrom )
+            lineFrom = visibleFrom;
+
+        wxRect rect;
+        rect.x = 0;
+        rect.y = GetLineY(lineFrom);
+
+        wxSize size = GetClientSize();
+        rect.width = size.x;
+        // refresh till the bottom of the window
+        rect.height = size.y - rect.y;
+
+        CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+        RefreshRect( rect );
+    
+    }
+    else // !report
+    {
+        // TODO: how to do it more efficiently?
+        m_dirty = TRUE;
+    }
+}
+
 void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
 {
     // Note: a wxPaintDC must be constructed even if no drawing is
@@ -3702,15 +3739,9 @@ void wxListMainWindow::DeleteItem( long lindex )
 
     if ( InReportView() )
     {
-        if ( m_lineTo == GetItemCount() - 1 )
-        {
-            m_lineTo--;
-        }
+        ResetVisibleLinesRange();
     }
 
-    // refresh before removing the line
-    RefreshLines(index, GetItemCount() - 1);
-
     if ( IsVirtual() )
     {
         m_countVirt--;
@@ -3721,6 +3752,8 @@ void wxListMainWindow::DeleteItem( long lindex )
     {
         m_lines.RemoveAt( index );
     }
+
+    RefreshAfter(index);
 }
 
 void wxListMainWindow::DeleteColumn( int col )
@@ -3761,6 +3794,11 @@ void wxListMainWindow::DeleteAllItems()
         ResetVisibleLinesRange();
     }
 
+    if ( InReportView() )
+    {
+        ResetVisibleLinesRange();
+    }
+
     m_lines.Clear();
 
     m_selStore.Clear();
@@ -4002,6 +4040,9 @@ void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to)
             m_lineTo = count - 1;
     }
 
+    wxASSERT_MSG( m_lineFrom <= m_lineTo && m_lineTo < GetItemCount(),
+                  _T("GetVisibleLinesRange() returns incorrect result") );
+
     if ( from )
         *from = m_lineFrom;
     if ( to )