From cd03af05a4e04d2ac751e88acaf8b13f83da3820 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Wed, 8 Apr 2009 00:09:33 +0000 Subject: [PATCH] Various cleanups to how the selection indices are maintained when part of the selection is occluded by a collapse operation, which could cause a crash in some instances. This fixes ticket #3711. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30015 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/OutlineListView.cpp | 31 +++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/kits/interface/OutlineListView.cpp b/src/kits/interface/OutlineListView.cpp index b27ed1774c..c863ff8883 100644 --- a/src/kits/interface/OutlineListView.cpp +++ b/src/kits/interface/OutlineListView.cpp @@ -483,6 +483,8 @@ BOutlineListView::Collapse(BListItem* item) int32 startIndex = index; int32 max = FullListCountItems() - fullIndex - 1; int32 count = 0; + bool selectionChanged = false; + BListItem** items = (BListItem**)fFullList.Items() + fullIndex + 1; while (max-- > 0) { @@ -493,9 +495,10 @@ BOutlineListView::Collapse(BListItem* item) if (item->IsItemVisible()) { fList.RemoveItem(item); item->SetItemVisible(false); - if (item->IsSelected()) + if (item->IsSelected()) { + selectionChanged = true; item->Deselect(); - + } count++; } @@ -504,19 +507,21 @@ BOutlineListView::Collapse(BListItem* item) _RecalcItemTops(startIndex); // fix selection hints - // TODO: revise for multi selection lists - if (index < fFirstSelected) { - if (index + count < fFirstSelected) { - fFirstSelected -= count; - fLastSelected -= count; - } else { - // select top item - //fFirstSelected = fLastSelected = index; - //item->Select(); - Select(index); - } + if (index < fFirstSelected && index + count < fFirstSelected) { + // all items removed were higher than the selection range, + // adjust the indexes to correspond to their new visible positions + fFirstSelected -= count; + fLastSelected -= count; } + int32 maxIndex = fList.CountItems() - 1; + if (fFirstSelected > maxIndex) + fFirstSelected = maxIndex; + if (fLastSelected > maxIndex) + fLastSelected = maxIndex; + if (selectionChanged) + SelectionChanged(); + _FixupScrollBar(); Invalidate(); }