Changeset 24139

Show
Ignore:
Timestamp:
02/26/08 08:27:24 (9 months ago)
Author:
anevilyak
Message:

- 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.

Location:
haiku/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/headers/os/interface/ListView.h

    r24092 r24139  
    161161                                int32           _CalcFirstSelected(int32 after); 
    162162                                int32           _CalcLastSelected(int32 before); 
    163                                 void            _RecalcItemTops(int32 start); 
     163                                void            _RecalcItemTops(int32 start, int32 end = -1); 
    164164                virtual void            DrawItem(BListItem* item, BRect itemRect, 
    165165                                                                bool complete = false); 
  • haiku/trunk/src/kits/interface/ListView.cpp

    r24092 r24139  
    15321532        // NOTE: this is only important if the selection status 
    15331533        // of both items is not the same 
     1534        int32 first = min_c(a, b); 
     1535        int32 last = max_c(a, b); 
    15341536        if (ItemAt(a)->IsSelected() != ItemAt(b)->IsSelected()) { 
    1535                 int32 first = min_c(a, b); 
    1536                 int32 last = max_c(a, b); 
    1537                 if (first < fFirstSelected || last > fLastSelected) { 
    1538                         first = min_c(first, fFirstSelected); 
    1539                         last = max_c(last, fLastSelected); 
    1540                         _RescanSelection(first, last); 
    1541                 } 
     1537                if (first < fFirstSelected || last > fLastSelected)  
     1538                        _RescanSelection(min_c(first, fFirstSelected), min_c(last, fLastSelected)); 
    15421539                // though the actually selected items stayed the 
    15431540                // same, the selection has still changed 
     
    15451542        } 
    15461543 
     1544        ItemAt(a)->SetTop(bFrame.top); 
     1545        ItemAt(b)->SetTop(aFrame.top); 
     1546         
    15471547        // take care of invalidation 
    15481548        if (Window()) { 
    15491549                // NOTE: window looper is assumed to be locked! 
    15501550                if (aFrame.Height() != bFrame.Height()) { 
    1551                         ItemAt(a)->SetTop(bFrame.top); 
    1552                         ItemAt(b)->SetTop(aFrame.top); 
     1551                        _RecalcItemTops(first, last); 
    15531552                        // items in between shifted visually 
    15541553                        Invalidate(aFrame | bFrame); 
     
    16771676 
    16781677void 
    1679 BListView::_RecalcItemTops(int32 start) 
     1678BListView::_RecalcItemTops(int32 start, int32 end) 
    16801679{ 
    16811680        int32 count = CountItems(); 
    16821681        if ((start < 0) || (start >= count)) 
    16831682                return; 
     1683 
     1684        if (end >= 0) 
     1685                count = end + 1; 
     1686 
    16841687        float top = (start == 0) ? 0.0 : ItemAt(start - 1)->Bottom() + 1.0; 
    16851688 
    1686         for (int32 i = start; i < CountItems(); i++) { 
     1689        for (int32 i = start; i < count; i++) { 
    16871690                BListItem *item = ItemAt(i); 
    16881691                item->SetTop(top);