- Fix an error in SwapItems where the item tops would not be swapped
if the items were the same height. - Modified _RecalcItemTops to allow us to specify a range instead of just a starting point. This is useful for cases like Swap, where only the items in between those being swapped need to be recalculated. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24139 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -160,7 +160,7 @@ class BListView : public BView, public BInvoker {
|
|||||||
bool _TryInitiateDrag(BPoint where);
|
bool _TryInitiateDrag(BPoint where);
|
||||||
int32 _CalcFirstSelected(int32 after);
|
int32 _CalcFirstSelected(int32 after);
|
||||||
int32 _CalcLastSelected(int32 before);
|
int32 _CalcLastSelected(int32 before);
|
||||||
void _RecalcItemTops(int32 start);
|
void _RecalcItemTops(int32 start, int32 end = -1);
|
||||||
virtual void DrawItem(BListItem* item, BRect itemRect,
|
virtual void DrawItem(BListItem* item, BRect itemRect,
|
||||||
bool complete = false);
|
bool complete = false);
|
||||||
|
|
||||||
|
|||||||
@@ -1531,25 +1531,24 @@ BListView::_SwapItems(int32 a, int32 b)
|
|||||||
// track selection
|
// track selection
|
||||||
// NOTE: this is only important if the selection status
|
// NOTE: this is only important if the selection status
|
||||||
// of both items is not the same
|
// of both items is not the same
|
||||||
|
int32 first = min_c(a, b);
|
||||||
|
int32 last = max_c(a, b);
|
||||||
if (ItemAt(a)->IsSelected() != ItemAt(b)->IsSelected()) {
|
if (ItemAt(a)->IsSelected() != ItemAt(b)->IsSelected()) {
|
||||||
int32 first = min_c(a, b);
|
if (first < fFirstSelected || last > fLastSelected)
|
||||||
int32 last = max_c(a, b);
|
_RescanSelection(min_c(first, fFirstSelected), min_c(last, fLastSelected));
|
||||||
if (first < fFirstSelected || last > fLastSelected) {
|
|
||||||
first = min_c(first, fFirstSelected);
|
|
||||||
last = max_c(last, fLastSelected);
|
|
||||||
_RescanSelection(first, last);
|
|
||||||
}
|
|
||||||
// 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(b)->SetTop(aFrame.top);
|
||||||
|
|
||||||
// take care of invalidation
|
// take care of invalidation
|
||||||
if (Window()) {
|
if (Window()) {
|
||||||
// NOTE: window looper is assumed to be locked!
|
// NOTE: window looper is assumed to be locked!
|
||||||
if (aFrame.Height() != bFrame.Height()) {
|
if (aFrame.Height() != bFrame.Height()) {
|
||||||
ItemAt(a)->SetTop(bFrame.top);
|
_RecalcItemTops(first, last);
|
||||||
ItemAt(b)->SetTop(aFrame.top);
|
|
||||||
// items in between shifted visually
|
// items in between shifted visually
|
||||||
Invalidate(aFrame | bFrame);
|
Invalidate(aFrame | bFrame);
|
||||||
} else {
|
} else {
|
||||||
@@ -1676,14 +1675,18 @@ BListView::_RescanSelection(int32 from, int32 to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BListView::_RecalcItemTops(int32 start)
|
BListView::_RecalcItemTops(int32 start, int32 end)
|
||||||
{
|
{
|
||||||
int32 count = CountItems();
|
int32 count = CountItems();
|
||||||
if ((start < 0) || (start >= count))
|
if ((start < 0) || (start >= count))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (end >= 0)
|
||||||
|
count = end + 1;
|
||||||
|
|
||||||
float top = (start == 0) ? 0.0 : ItemAt(start - 1)->Bottom() + 1.0;
|
float top = (start == 0) ? 0.0 : ItemAt(start - 1)->Bottom() + 1.0;
|
||||||
|
|
||||||
for (int32 i = start; i < CountItems(); i++) {
|
for (int32 i = start; i < count; i++) {
|
||||||
BListItem *item = ItemAt(i);
|
BListItem *item = ItemAt(i);
|
||||||
item->SetTop(top);
|
item->SetTop(top);
|
||||||
top += ceilf(item->Height());
|
top += ceilf(item->Height());
|
||||||
|
|||||||
Reference in New Issue
Block a user