]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed bug with deletion of several last items in wxListCtrl, added tests for it in...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 23 Jul 2001 14:57:01 +0000 (14:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 23 Jul 2001 14:57:01 +0000 (14:57 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11162 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/listctrl/listtest.cpp
src/generic/listctrl.cpp

index 91341cae92636f71c616442db65b4e75b85d3852..d1c8d7d4af8d20c7d7e64cbb6871aa4e6dfc4a49 100644 (file)
@@ -681,9 +681,20 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
             break;
 
         case WXK_DELETE:
-            DeleteItem(event.GetIndex());
+            {
+                long item = GetNextItem(-1,
+                                        wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+                while ( item != -1 )
+                {
+                    DeleteItem(item);
+
+                    wxLogMessage(_T("Item %ld deleted"), item);
 
-            wxLogMessage(_T("Item %d deleted"), event.GetIndex());
+                    // -1 because the indices were shifted by DeleteItem()
+                    item = GetNextItem(item - 1,
+                                       wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+                }
+            }
             break;
 
         case WXK_INSERT:
index fa1cc35090e26ec946932cc4a9aabc9bb628e6db..8a3993b3f9899e0205f2d27ace3a167cd29e5c79 100644 (file)
@@ -2403,7 +2403,7 @@ void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
         rect.x = 0;
         rect.y = GetLineY(lineFrom);
         rect.width = GetClientSize().x;
-        rect.height = GetLineY(lineTo) - rect.y;
+        rect.height = GetLineY(lineTo) - rect.y + GetLineHeight();
 
         CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
         RefreshRect( rect );
@@ -2486,11 +2486,15 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
         CalcUnscrolledPosition(0, 0, &xOrig, &yOrig);
 
         // tell the caller cache to cache the data
-        wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT, GetParent()->GetId());
-        evCache.SetEventObject( GetParent() );
-        evCache.m_oldItemIndex = visibleFrom;
-        evCache.m_itemIndex = visibleTo;
-        GetParent()->GetEventHandler()->ProcessEvent( evCache );
+        if ( IsVirtual() )
+        {
+            wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT,
+                                GetParent()->GetId());
+            evCache.SetEventObject( GetParent() );
+            evCache.m_oldItemIndex = visibleFrom;
+            evCache.m_itemIndex = visibleTo;
+            GetParent()->GetEventHandler()->ProcessEvent( evCache );
+        }
 
         for ( size_t line = visibleFrom; line <= visibleTo; line++ )
         {
@@ -2608,7 +2612,12 @@ void wxListMainWindow::SendNotify( size_t line,
     if ( point != wxDefaultPosition )
         le.m_pointDrag = point;
 
-    GetLine(line)->GetItem( 0, le.m_item );
+    if ( command != wxEVT_COMMAND_LIST_DELETE_ITEM )
+    {
+        GetLine(line)->GetItem( 0, le.m_item );
+    }
+    //else: there may be no more such item
+
     GetParent()->GetEventHandler()->ProcessEvent( le );
 }
 
@@ -3796,20 +3805,12 @@ void wxListMainWindow::DeleteItem( long lindex )
 
     size_t index = (size_t)lindex;
 
-    m_dirty = TRUE;
-
     // select the next item when the selected one is deleted
-    if ( m_current == index )
+    if ( m_current >= index )
     {
-        // the last valid index after deleting the item will be count-2
-        if ( m_current == count - 1 )
-        {
-            m_current--;
-        }
+        m_current--;
     }
 
-    SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM );
-
     if ( InReportView() )
     {
         ResetVisibleLinesRange();
@@ -3827,6 +3828,9 @@ void wxListMainWindow::DeleteItem( long lindex )
     }
 
     m_dirty = TRUE;
+
+    SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM );
+
     RefreshAfter(index);
 }