From 91c6cc0e71bf9b49dbcb4d69ecfe30801a31aeb2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Jul 2001 14:57:01 +0000 Subject: [PATCH] fixed bug with deletion of several last items in wxListCtrl, added tests for it in the sample git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11162 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/listctrl/listtest.cpp | 15 ++++++++++++-- src/generic/listctrl.cpp | 38 +++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 91341cae92..d1c8d7d4af 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -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: diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index fa1cc35090..8a3993b3f9 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -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); } -- 2.47.2