Fixed wrong selection updating when adding items - this fixes bug #279.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16993 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-04-03 22:57:23 +00:00
parent 52f8cb492d
commit 227bf1b686
2 changed files with 18 additions and 17 deletions
+16 -15
View File
@@ -450,7 +450,7 @@ BListView::TargetedByScrollView(BScrollView *view)
fScrollView = view; fScrollView = view;
} }
// ScrollTo
void void
BListView::ScrollTo(BPoint point) BListView::ScrollTo(BPoint point)
{ {
@@ -458,17 +458,17 @@ BListView::ScrollTo(BPoint point)
fWidth = Bounds().right; fWidth = Bounds().right;
} }
// AddItem
bool bool
BListView::AddItem(BListItem *item, int32 index) BListView::AddItem(BListItem *item, int32 index)
{ {
if (!fList.AddItem(item, index)) if (!fList.AddItem(item, index))
return false; return false;
if (fFirstSelected != -1 && index < fFirstSelected) if (fFirstSelected != -1 && index <= fFirstSelected)
fFirstSelected++; fFirstSelected++;
if (fLastSelected != -1 && index < fLastSelected) if (fLastSelected != -1 && index <= fLastSelected)
fLastSelected++; fLastSelected++;
if (Window()) { if (Window()) {
@@ -484,13 +484,15 @@ BListView::AddItem(BListItem *item, int32 index)
return true; return true;
} }
// AddItem
bool bool
BListView::AddItem(BListItem* item) BListView::AddItem(BListItem* item)
{ {
if (!fList.AddItem(item)) if (!fList.AddItem(item))
return false; return false;
// No need to adapt selection, as this item is the last in the list
if (Window()) { if (Window()) {
BFont font; BFont font;
GetFont(&font); GetFont(&font);
@@ -763,18 +765,18 @@ BListView::InvalidateItem(int32 index)
void void
BListView::ScrollToSelection() BListView::ScrollToSelection()
{ {
BRect item_frame = ItemFrame ( CurrentSelection ( 0 ) ); BRect itemFrame = ItemFrame(CurrentSelection(0));
if ( Bounds ().Intersects ( item_frame.InsetByCopy ( 0.0f, 2.0f ) ) ) if (Bounds().Intersects(itemFrame.InsetByCopy(0.0f, 2.0f)))
return; return;
if ( item_frame.top < Bounds ().top ) if (itemFrame.top < Bounds().top)
ScrollTo ( 0, item_frame.top ); ScrollTo(0, itemFrame.top);
else else
ScrollTo ( 0, item_frame.bottom - Bounds ().Height () ); ScrollTo(0, itemFrame.bottom - Bounds().Height());
} }
// Select
void void
BListView::Select(int32 index, bool extend) BListView::Select(int32 index, bool extend)
{ {
@@ -784,7 +786,7 @@ BListView::Select(int32 index, bool extend)
InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED); InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
} }
// Select
void void
BListView::Select(int32 start, int32 finish, bool extend) BListView::Select(int32 start, int32 finish, bool extend)
{ {
@@ -799,11 +801,10 @@ bool
BListView::IsItemSelected(int32 index) const BListView::IsItemSelected(int32 index) const
{ {
BListItem *item = ItemAt(index); BListItem *item = ItemAt(index);
if (item) if (item)
return item->IsSelected(); return item->IsSelected();
else
return false; return false;
} }
// CurrentSelection // CurrentSelection
+2 -2
View File
@@ -225,9 +225,9 @@ BOutlineListView::AddItem(BListItem* item, int32 fullListIndex)
return true; return true;
} }
int32 list_index = FindPreviousVisibleIndex(fullListIndex); int32 listIndex = FindPreviousVisibleIndex(fullListIndex);
return BListView::AddItem(item, IndexOf(FullListItemAt(list_index)) + 1); return BListView::AddItem(item, IndexOf(FullListItemAt(listIndex)) + 1);
} }