From 227bf1b686df36027cecf5a8c8d6bce9527f4cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 3 Apr 2006 22:57:23 +0000 Subject: [PATCH] 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 --- src/kits/interface/ListView.cpp | 31 +++++++++++++------------- src/kits/interface/OutlineListView.cpp | 4 ++-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/kits/interface/ListView.cpp b/src/kits/interface/ListView.cpp index 460d657789..ecdec30d33 100644 --- a/src/kits/interface/ListView.cpp +++ b/src/kits/interface/ListView.cpp @@ -450,7 +450,7 @@ BListView::TargetedByScrollView(BScrollView *view) fScrollView = view; } -// ScrollTo + void BListView::ScrollTo(BPoint point) { @@ -458,17 +458,17 @@ BListView::ScrollTo(BPoint point) fWidth = Bounds().right; } -// AddItem + bool BListView::AddItem(BListItem *item, int32 index) { if (!fList.AddItem(item, index)) return false; - if (fFirstSelected != -1 && index < fFirstSelected) + if (fFirstSelected != -1 && index <= fFirstSelected) fFirstSelected++; - if (fLastSelected != -1 && index < fLastSelected) + if (fLastSelected != -1 && index <= fLastSelected) fLastSelected++; if (Window()) { @@ -484,13 +484,15 @@ BListView::AddItem(BListItem *item, int32 index) return true; } -// AddItem + bool BListView::AddItem(BListItem* item) { if (!fList.AddItem(item)) return false; + // No need to adapt selection, as this item is the last in the list + if (Window()) { BFont font; GetFont(&font); @@ -763,18 +765,18 @@ BListView::InvalidateItem(int32 index) void 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; - if ( item_frame.top < Bounds ().top ) - ScrollTo ( 0, item_frame.top ); + if (itemFrame.top < Bounds().top) + ScrollTo(0, itemFrame.top); else - ScrollTo ( 0, item_frame.bottom - Bounds ().Height () ); + ScrollTo(0, itemFrame.bottom - Bounds().Height()); } -// Select + void BListView::Select(int32 index, bool extend) { @@ -784,7 +786,7 @@ BListView::Select(int32 index, bool extend) InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED); } -// Select + void BListView::Select(int32 start, int32 finish, bool extend) { @@ -799,11 +801,10 @@ bool BListView::IsItemSelected(int32 index) const { BListItem *item = ItemAt(index); - if (item) return item->IsSelected(); - else - return false; + + return false; } // CurrentSelection diff --git a/src/kits/interface/OutlineListView.cpp b/src/kits/interface/OutlineListView.cpp index 9db9998902..9d8e440e6d 100644 --- a/src/kits/interface/OutlineListView.cpp +++ b/src/kits/interface/OutlineListView.cpp @@ -225,9 +225,9 @@ BOutlineListView::AddItem(BListItem* item, int32 fullListIndex) 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); }