Fix several problems in BListView:

- SwapItems() did not correctly swap the item tops of the two items being swapped. This would result in quite broken/confusing behavior due to the view having the wrong idea of their current position.
- SwapItems() also did not pass the correct range to _RescanSelection(). This could result in the selection range getting quite confused when swapping items.
- _RescanSelection() did not always correctly reset fLastSelection, though this mostly only would've resulted in unnecessary but harmless work.

Fixes ticket #4253 and possibly some others.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35571 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent
2010-02-22 01:40:24 +00:00
parent 45912b67a3
commit e4a439b4a0
+6 -4
View File
@@ -1685,14 +1685,14 @@ BListView::_SwapItems(int32 a, int32 b)
int32 last = max_c(a, b); int32 last = max_c(a, b);
if (ItemAt(a)->IsSelected() != ItemAt(b)->IsSelected()) { if (ItemAt(a)->IsSelected() != ItemAt(b)->IsSelected()) {
if (first < fFirstSelected || last > fLastSelected) if (first < fFirstSelected || last > fLastSelected)
_RescanSelection(min_c(first, fFirstSelected), min_c(last, fLastSelected)); _RescanSelection(min_c(first, fFirstSelected), max_c(last, fLastSelected));
// though the actually selected items stayed the // though the actually selected items stayed the
// same, the selection has still changed // same, the selection has still changed
SelectionChanged(); SelectionChanged();
} }
ItemAt(a)->SetTop(bFrame.top); ItemAt(a)->SetTop(aFrame.top);
ItemAt(b)->SetTop(aFrame.top); ItemAt(b)->SetTop(bFrame.top);
// take care of invalidation // take care of invalidation
if (Window()) { if (Window()) {
@@ -1801,7 +1801,7 @@ BListView::_RescanSelection(int32 from, int32 to)
from = max_c(0, from); from = max_c(0, from);
to = min_c(to, CountItems() - 1); to = min_c(to, CountItems() - 1);
if (fAnchorIndex != -1) { if (fAnchorIndex != -1) {
if (fAnchorIndex == from) if (fAnchorIndex == from)
fAnchorIndex = to; fAnchorIndex = to;
@@ -1818,6 +1818,8 @@ BListView::_RescanSelection(int32 from, int32 to)
if (fFirstSelected > from) if (fFirstSelected > from)
from = fFirstSelected; from = fFirstSelected;
fLastSelected = fFirstSelected;
for (int32 i = from; i <= to; i++) { for (int32 i = from; i <= to; i++) {
if (ItemAt(i)->IsSelected()) if (ItemAt(i)->IsSelected())
fLastSelected = i; fLastSelected = i;