bool BListView::AddList(BList* list, int32 index) { if (!fList.AddList(list, index)) return false; int32 count = list->CountItems(); if (fFirstSelected != -1 && index < fFirstSelected) fFirstSelected += count; if (fLastSelected != -1 && index < fLastSelected) fLastSelected += count; if (Window()) { BFont font; GetFont(&font); for (int32 i = index; i <= (index + count - 1); i++) { ItemAt(i)->SetTop((i > 0) ? ItemAt(i - 1)->Bottom() + 1.0 : 0.0); ItemAt(i)->Update(this, &font); } _RecalcItemTops(index + count - 1); _FixupScrollBar(); Invalidate(); // TODO } return true; }
bool BListView::AddItem(BListItem* item, int32 index) { if (!fList.AddItem(item, index)) return false; if (fFirstSelected != -1 && index <= fFirstSelected) fFirstSelected++; if (fLastSelected != -1 && index <= fLastSelected) fLastSelected++; if (Window()) { BFont font; GetFont(&font); item->SetTop((index > 0) ? ItemAt(index - 1)->Bottom() + 1.0 : 0.0); item->Update(this, &font); _RecalcItemTops(index + 1); _FixupScrollBar(); _InvalidateFrom(index); } return true; }
BListItem* BListView::RemoveItem(int32 index) { BListItem* item = ItemAt(index); if (item == NULL) return NULL; if (item->IsSelected()) Deselect(index); if (!fList.RemoveItem(item)) return NULL; if (fFirstSelected != -1 && index < fFirstSelected) fFirstSelected--; if (fLastSelected != -1 && index < fLastSelected) fLastSelected--; if (fAnchorIndex != -1 && index < fAnchorIndex) fAnchorIndex--; _RecalcItemTops(index); _InvalidateFrom(index); _FixupScrollBar(); return item; }
void BListView::AttachedToWindow() { BView::AttachedToWindow(); _FontChanged(); if (!Messenger().IsValid()) SetTarget(Window(), NULL); _FixupScrollBar(); }
void BListView::MakeEmpty() { if (fList.IsEmpty()) return; _DeselectAll(-1, -1); fList.MakeEmpty(); if (Window()) { _FixupScrollBar(); Invalidate(); } }
bool BListView::_ReplaceItem(int32 index, BListItem* item) { if (item == NULL) return false; BListItem* old = ItemAt(index); if (!old) return false; BRect frame = ItemFrame(index); bool selectionChanged = old->IsSelected() != item->IsSelected(); // replace item if (!fList.ReplaceItem(index, item)) return false; // tack selection if (selectionChanged) { int32 start = min_c(fFirstSelected, index); int32 end = max_c(fLastSelected, index); _RescanSelection(start, end); SelectionChanged(); } _RecalcItemTops(index); bool itemHeightChanged = frame != ItemFrame(index); // take care of invalidation if (Window()) { // NOTE: window looper is assumed to be locked! if (itemHeightChanged) _InvalidateFrom(index); else Invalidate(frame); } if (itemHeightChanged) _FixupScrollBar(); return true; }
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); int32 index = CountItems() - 1; item->SetTop((index > 0) ? ItemAt(index - 1)->Bottom() + 1.0 : 0.0); item->Update(this, &font); _FixupScrollBar(); InvalidateItem(CountItems() - 1); } return true; }
void BListView::FrameResized(float width, float height) { _FixupScrollBar(); }
void BOutlineListView::ExpandOrCollapse(BListItem* item, bool expand) { if (item->IsExpanded() == expand || !FullListHasItem(item)) return; item->fExpanded = expand; // TODO: merge these cases together, they are pretty similar if (expand) { uint32 level = item->fLevel; int32 fullIndex = FullListIndexOf(item); int32 index = IndexOf(item) + 1; int32 startIndex = index; int32 count = FullListCountItems() - fullIndex - 1; BListItem** items = (BListItem**)fFullList.Items() + fullIndex + 1; BFont font; GetFont(&font); while (count-- > 0) { item = items[0]; if (item->fLevel <= level) break; if (!item->IsItemVisible()) { // fix selection hints if (index <= fFirstSelected) fFirstSelected++; if (index <= fLastSelected) fLastSelected++; fList.AddItem(item, index++); item->Update(this, &font); item->SetItemVisible(true); } if (item->HasSubitems() && !item->IsExpanded()) { // Skip hidden children uint32 subLevel = item->fLevel; items++; while (--count > 0 && items[0]->fLevel > subLevel) items++; } else items++; } _RecalcItemTops(startIndex); } else { // collapse uint32 level = item->fLevel; int32 fullIndex = FullListIndexOf(item); int32 index = IndexOf(item); int32 startIndex = index; int32 max = FullListCountItems() - fullIndex - 1; int32 count = 0; bool selectionChanged = false; BListItem** items = (BListItem**)fFullList.Items() + fullIndex + 1; while (max-- > 0) { item = items[0]; if (item->fLevel <= level) break; if (item->IsItemVisible()) { fList.RemoveItem(item); item->SetItemVisible(false); if (item->IsSelected()) { selectionChanged = true; item->Deselect(); } count++; } items++; } _RecalcItemTops(startIndex); // fix selection hints // if the selected item was just removed by collapsing, select its // parent if (ListType() == B_SINGLE_SELECTION_LIST && selectionChanged) fFirstSelected = fLastSelected = index; if (index < fFirstSelected && index + count < fFirstSelected) { // all items removed were higher than the selection range, // adjust the indexes to correspond to their new visible positions fFirstSelected -= count; fLastSelected -= count; } int32 maxIndex = fList.CountItems() - 1; if (fFirstSelected > maxIndex) fFirstSelected = maxIndex; if (fLastSelected > maxIndex) fLastSelected = maxIndex; if (selectionChanged) SelectionChanged(); } _FixupScrollBar(); Invalidate(); }