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
This commit is contained in:
Vadim Zeitlin
2001-07-23 14:57:01 +00:00
parent d9ff0f91fb
commit 91c6cc0e71
2 changed files with 34 additions and 19 deletions

View File

@@ -681,9 +681,20 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
break; break;
case WXK_DELETE: case WXK_DELETE:
DeleteItem(event.GetIndex()); {
long item = GetNextItem(-1,
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
while ( item != -1 )
{
DeleteItem(item);
wxLogMessage(_T("Item %d deleted"), event.GetIndex()); wxLogMessage(_T("Item %ld deleted"), item);
// -1 because the indices were shifted by DeleteItem()
item = GetNextItem(item - 1,
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
}
}
break; break;
case WXK_INSERT: case WXK_INSERT:

View File

@@ -2403,7 +2403,7 @@ void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
rect.x = 0; rect.x = 0;
rect.y = GetLineY(lineFrom); rect.y = GetLineY(lineFrom);
rect.width = GetClientSize().x; 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 ); CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
RefreshRect( rect ); RefreshRect( rect );
@@ -2486,11 +2486,15 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
CalcUnscrolledPosition(0, 0, &xOrig, &yOrig); CalcUnscrolledPosition(0, 0, &xOrig, &yOrig);
// tell the caller cache to cache the data // tell the caller cache to cache the data
wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT, GetParent()->GetId()); if ( IsVirtual() )
evCache.SetEventObject( GetParent() ); {
evCache.m_oldItemIndex = visibleFrom; wxListEvent evCache(wxEVT_COMMAND_LIST_CACHE_HINT,
evCache.m_itemIndex = visibleTo; GetParent()->GetId());
GetParent()->GetEventHandler()->ProcessEvent( evCache ); evCache.SetEventObject( GetParent() );
evCache.m_oldItemIndex = visibleFrom;
evCache.m_itemIndex = visibleTo;
GetParent()->GetEventHandler()->ProcessEvent( evCache );
}
for ( size_t line = visibleFrom; line <= visibleTo; line++ ) for ( size_t line = visibleFrom; line <= visibleTo; line++ )
{ {
@@ -2608,7 +2612,12 @@ void wxListMainWindow::SendNotify( size_t line,
if ( point != wxDefaultPosition ) if ( point != wxDefaultPosition )
le.m_pointDrag = point; 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 ); GetParent()->GetEventHandler()->ProcessEvent( le );
} }
@@ -3796,20 +3805,12 @@ void wxListMainWindow::DeleteItem( long lindex )
size_t index = (size_t)lindex; size_t index = (size_t)lindex;
m_dirty = TRUE;
// select the next item when the selected one is deleted // 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 m_current--;
if ( m_current == count - 1 )
{
m_current--;
}
} }
SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM );
if ( InReportView() ) if ( InReportView() )
{ {
ResetVisibleLinesRange(); ResetVisibleLinesRange();
@@ -3827,6 +3828,9 @@ void wxListMainWindow::DeleteItem( long lindex )
} }
m_dirty = TRUE; m_dirty = TRUE;
SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM );
RefreshAfter(index); RefreshAfter(index);
} }