* Added layout-friendly constructor.
* Reordered functions to match the order in the header (and vice versa). * Removed unused private functions. * Updated the header to follow our coding style. * Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31088 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _OUTLINE_LIST_VIEW_H
|
||||
@@ -15,7 +15,12 @@ class BOutlineListView : public BListView {
|
||||
public:
|
||||
BOutlineListView(BRect frame, const char* name,
|
||||
list_view_type type = B_SINGLE_SELECTION_LIST,
|
||||
uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 resizeMode
|
||||
= B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
|
||||
| B_NAVIGABLE);
|
||||
BOutlineListView(const char* name,
|
||||
list_view_type type = B_SINGLE_SELECTION_LIST,
|
||||
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
|
||||
| B_NAVIGABLE);
|
||||
BOutlineListView(BMessage* archive);
|
||||
@@ -53,7 +58,8 @@ class BOutlineListView : public BListView {
|
||||
virtual void MakeEmpty();
|
||||
bool FullListIsEmpty() const;
|
||||
void FullListDoForEach(bool (*func)(BListItem* item));
|
||||
void FullListDoForEach(bool (*func)(BListItem* item, void *), void*);
|
||||
void FullListDoForEach(
|
||||
bool (*func)(BListItem* item, void*), void*);
|
||||
|
||||
BListItem* Superitem(const BListItem* item);
|
||||
|
||||
@@ -63,7 +69,8 @@ class BOutlineListView : public BListView {
|
||||
bool IsExpanded(int32 fullListIndex);
|
||||
|
||||
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
|
||||
BMessage* specifier, int32 what, const char* property);
|
||||
BMessage* specifier, int32 what,
|
||||
const char* property);
|
||||
virtual status_t GetSupportedSuites(BMessage* data);
|
||||
virtual status_t Perform(perform_code d, void* arg);
|
||||
|
||||
@@ -74,15 +81,18 @@ class BOutlineListView : public BListView {
|
||||
virtual void AllDetached();
|
||||
virtual void DetachedFromWindow();
|
||||
|
||||
void FullListSortItems(int (*compareFunc)(const BListItem* first,
|
||||
void FullListSortItems(int (*compareFunc)(
|
||||
const BListItem* first,
|
||||
const BListItem* second));
|
||||
void SortItemsUnder(BListItem* underItem, bool oneLevelOnly,
|
||||
int (*compareFunc)(const BListItem* first,
|
||||
void SortItemsUnder(BListItem* underItem,
|
||||
bool oneLevelOnly, int (*compareFunc)(
|
||||
const BListItem* first,
|
||||
const BListItem* second));
|
||||
int32 CountItemsUnder(BListItem* under, bool oneLevelOnly) const;
|
||||
BListItem* EachItemUnder(BListItem* underItem, bool oneLevelOnly,
|
||||
BListItem* (*eachFunc)(BListItem* item, void* arg),
|
||||
void* arg);
|
||||
int32 CountItemsUnder(BListItem* under,
|
||||
bool oneLevelOnly) const;
|
||||
BListItem* EachItemUnder(BListItem* underItem,
|
||||
bool oneLevelOnly, BListItem* (*eachFunc)(
|
||||
BListItem* item, void* arg), void* arg);
|
||||
BListItem* ItemUnderAt(BListItem* underItem, bool oneLevelOnly,
|
||||
int32 index) const;
|
||||
|
||||
@@ -96,38 +106,30 @@ class BOutlineListView : public BListView {
|
||||
virtual void _ReservedOutlineListView3();
|
||||
virtual void _ReservedOutlineListView4();
|
||||
|
||||
typedef BListView _inherited;
|
||||
|
||||
int32 FullListIndex(int32 index) const;
|
||||
int32 ListViewIndex(int32 index) const;
|
||||
|
||||
protected:
|
||||
virtual void ExpandOrCollapse(BListItem* underItem, bool expand);
|
||||
virtual BRect LatchRect(BRect itemRect, int32 level) const;
|
||||
virtual void DrawLatch(BRect itemRect, int32 level, bool collapsed,
|
||||
bool highlighted, bool misTracked);
|
||||
virtual void DrawItem(BListItem* item, BRect itemRect, bool complete = false);
|
||||
virtual void DrawLatch(BRect itemRect, int32 level,
|
||||
bool collapsed, bool highlighted,
|
||||
bool misTracked);
|
||||
virtual void DrawItem(BListItem* item, BRect itemRect,
|
||||
bool complete = false);
|
||||
|
||||
private:
|
||||
int32 _FullListIndex(int32 index) const;
|
||||
|
||||
void _PopulateTree(BList* tree, BList& target,
|
||||
int32& firstIndex, bool onlyVisible);
|
||||
void _SortTree(BList* tree, bool oneLevelOnly,
|
||||
int (*compareFunc)(const BListItem* a, const BListItem* b));
|
||||
int (*compareFunc)(const BListItem* a,
|
||||
const BListItem* b));
|
||||
void _DestructTree(BList* tree);
|
||||
BList* _BuildTree(BListItem* underItem, int32& index);
|
||||
|
||||
BListItem* _RemoveItem(BListItem* item, int32 fullListIndex);
|
||||
bool _SwapItems(int32 first, int32 second);
|
||||
void _CullInvisibleItems(BList &list);
|
||||
BListItem* RemoveOne(int32 fullListIndex);
|
||||
bool _SwapItems(int32 first, int32 second);
|
||||
BListItem* _RemoveItem(BListItem* item, int32 fullListIndex);
|
||||
|
||||
static void TrackInLatchItem(void *);
|
||||
static void TrackOutLatchItem(void *);
|
||||
|
||||
bool OutlineSwapItems(int32 a, int32 b);
|
||||
bool OutlineMoveItem(int32 from, int32 to);
|
||||
bool OutlineReplaceItem(int32 index, BListItem* item);
|
||||
void CommonMoveItems(int32 from, int32 count, int32 to);
|
||||
BListItem* _SuperitemForIndex(int32 fullListIndex, int32 level,
|
||||
int32* _superIndex = NULL);
|
||||
int32 _FindPreviousVisibleIndex(int32 fullListIndex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2008, Haiku Inc.
|
||||
* Copyright 2001-2009, Haiku Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -12,22 +12,23 @@
|
||||
//! BOutlineListView represents a "nestable" list view.
|
||||
|
||||
#include <OutlineListView.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <Window.h>
|
||||
|
||||
#include <binary_compatibility/Interface.h>
|
||||
|
||||
|
||||
const float kLatchHeight = 8.0f;
|
||||
const float kLatchWidth = 4.0f;
|
||||
typedef int (*compare_func)(const BListItem* a, const BListItem* b);
|
||||
|
||||
struct ListItemComparator {
|
||||
ListItemComparator(int (*compareFunc)(const BListItem *, const BListItem *))
|
||||
: fCompareFunc(compareFunc)
|
||||
ListItemComparator(compare_func compareFunc)
|
||||
:
|
||||
fCompareFunc(compareFunc)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -37,9 +38,43 @@ struct ListItemComparator {
|
||||
}
|
||||
|
||||
private:
|
||||
int (*fCompareFunc)(const BListItem *, const BListItem *);
|
||||
compare_func fCompareFunc;
|
||||
};
|
||||
|
||||
|
||||
const float kLatchHeight = 8.0f;
|
||||
const float kLatchWidth = 4.0f;
|
||||
|
||||
|
||||
static void
|
||||
_GetSubItems(BList& sourceList, BList& destList, BListItem* parent, int32 start)
|
||||
{
|
||||
for (int32 i = start; i < sourceList.CountItems(); i++) {
|
||||
BListItem* item = (BListItem*)sourceList.ItemAt(i);
|
||||
if (item->OutlineLevel() <= parent->OutlineLevel())
|
||||
break;
|
||||
destList.AddItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
_DoSwap(BList& list, int32 firstIndex, int32 secondIndex, BList* firstItems,
|
||||
BList* secondItems)
|
||||
{
|
||||
BListItem* item = (BListItem*)list.ItemAt(firstIndex);
|
||||
list.SwapItems(firstIndex, secondIndex);
|
||||
list.RemoveItems(secondIndex + 1, secondItems->CountItems());
|
||||
list.RemoveItems(firstIndex + 1, firstItems->CountItems());
|
||||
list.AddList(secondItems, firstIndex + 1);
|
||||
int32 newIndex = list.IndexOf(item);
|
||||
if (newIndex + 1 < list.CountItems())
|
||||
list.AddList(firstItems, newIndex + 1);
|
||||
else
|
||||
list.AddList(firstItems);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
@@ -50,6 +85,13 @@ BOutlineListView::BOutlineListView(BRect frame, const char* name,
|
||||
}
|
||||
|
||||
|
||||
BOutlineListView::BOutlineListView(const char* name, list_view_type type,
|
||||
uint32 flags)
|
||||
: BListView(name, type, flags)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BOutlineListView::BOutlineListView(BMessage* archive)
|
||||
: BListView(archive)
|
||||
{
|
||||
@@ -340,7 +382,7 @@ BOutlineListView::FullListIndexOf(BPoint point) const
|
||||
int32 index = BListView::IndexOf(point);
|
||||
|
||||
if (index > 0)
|
||||
index = FullListIndex(index);
|
||||
index = _FullListIndex(index);
|
||||
|
||||
return index;
|
||||
}
|
||||
@@ -597,8 +639,8 @@ BOutlineListView::Perform(perform_code code, void* _data)
|
||||
{
|
||||
perform_data_get_height_for_width* data
|
||||
= (perform_data_get_height_for_width*)_data;
|
||||
BOutlineListView::GetHeightForWidth(data->width, &data->min, &data->max,
|
||||
&data->preferred);
|
||||
BOutlineListView::GetHeightForWidth(data->width, &data->min,
|
||||
&data->max, &data->preferred);
|
||||
return B_OK;
|
||||
}
|
||||
case PERFORM_CODE_SET_LAYOUT:
|
||||
@@ -692,7 +734,8 @@ BOutlineListView::SortItemsUnder(BListItem* underItem, bool oneLevelOnly,
|
||||
// Populate to the full list
|
||||
_PopulateTree(tree, fFullList, firstIndex, false);
|
||||
|
||||
if (underItem == NULL || (underItem->IsItemVisible() && underItem->IsExpanded())) {
|
||||
if (underItem == NULL
|
||||
|| (underItem->IsItemVisible() && underItem->IsExpanded())) {
|
||||
// Populate to BListView's list
|
||||
firstIndex = fList.IndexOf(underItem) + 1;
|
||||
lastIndex = firstIndex;
|
||||
@@ -715,91 +758,9 @@ BOutlineListView::SortItemsUnder(BListItem* underItem, bool oneLevelOnly,
|
||||
_DestructTree(tree);
|
||||
}
|
||||
|
||||
void
|
||||
BOutlineListView::_PopulateTree(BList* tree, BList& target,
|
||||
int32& firstIndex, bool onlyVisible)
|
||||
{
|
||||
BListItem** items = (BListItem**)target.Items();
|
||||
int32 count = tree->CountItems();
|
||||
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
BListItem* item = (BListItem*)tree->ItemAtFast(index);
|
||||
|
||||
items[firstIndex++] = item;
|
||||
|
||||
if (item->HasSubitems() && (!onlyVisible || item->IsExpanded()))
|
||||
_PopulateTree(item->fTemporaryList, target, firstIndex, onlyVisible);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::_SortTree(BList* tree, bool oneLevelOnly,
|
||||
int (*compareFunc)(const BListItem* a, const BListItem* b))
|
||||
{
|
||||
BListItem **items = (BListItem **)tree->Items();
|
||||
std::sort(items, items + tree->CountItems(), ListItemComparator(compareFunc));
|
||||
|
||||
if (oneLevelOnly)
|
||||
return;
|
||||
|
||||
for (int32 index = tree->CountItems(); index-- > 0;) {
|
||||
BListItem* item = (BListItem*)tree->ItemAt(index);
|
||||
|
||||
if (item->HasSubitems())
|
||||
_SortTree(item->fTemporaryList, false, compareFunc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::_DestructTree(BList* tree)
|
||||
{
|
||||
for (int32 index = tree->CountItems(); index-- > 0;) {
|
||||
BListItem* item = (BListItem*)tree->ItemAt(index);
|
||||
|
||||
if (item->HasSubitems())
|
||||
_DestructTree(item->fTemporaryList);
|
||||
}
|
||||
|
||||
delete tree;
|
||||
}
|
||||
|
||||
|
||||
BList*
|
||||
BOutlineListView::_BuildTree(BListItem* underItem, int32& fullIndex)
|
||||
{
|
||||
int32 fullCount = FullListCountItems();
|
||||
uint32 level = underItem != NULL ? underItem->OutlineLevel() + 1 : 0;
|
||||
BList* list = new BList;
|
||||
if (underItem != NULL)
|
||||
underItem->fTemporaryList = list;
|
||||
|
||||
while (fullIndex < fullCount) {
|
||||
BListItem *item = FullListItemAt(fullIndex);
|
||||
|
||||
// If we jump out of the subtree, break out
|
||||
if (item->fLevel < level)
|
||||
break;
|
||||
|
||||
// If the level matches, put them into the list
|
||||
// (we handle the case of a missing sublevel gracefully)
|
||||
list->AddItem(item);
|
||||
fullIndex++;
|
||||
|
||||
if (item->HasSubitems()) {
|
||||
// we're going deeper
|
||||
_BuildTree(item, fullIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BOutlineListView::CountItemsUnder(BListItem* underItem,
|
||||
bool oneLevelOnly) const
|
||||
BOutlineListView::CountItemsUnder(BListItem* underItem, bool oneLevelOnly) const
|
||||
{
|
||||
int32 i = FullListIndexOf(underItem);
|
||||
if (i == -1)
|
||||
@@ -883,88 +844,6 @@ BOutlineListView::ItemUnderAt(BListItem* underItem,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void _GetSubItems(BList &sourceList, BList &destList,
|
||||
BListItem *parent, int32 start)
|
||||
{
|
||||
for (int32 i = start; i < sourceList.CountItems(); i++) {
|
||||
BListItem *item = (BListItem *)sourceList.ItemAt(i);
|
||||
if (item->OutlineLevel() <= parent->OutlineLevel())
|
||||
break;
|
||||
destList.AddItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_DoSwap(BList &list, int32 firstIndex, int32 secondIndex, BList *firstItems,
|
||||
BList *secondItems)
|
||||
{
|
||||
BListItem *item = (BListItem *)list.ItemAt(firstIndex);
|
||||
list.SwapItems(firstIndex, secondIndex);
|
||||
list.RemoveItems(secondIndex + 1, secondItems->CountItems());
|
||||
list.RemoveItems(firstIndex + 1, firstItems->CountItems());
|
||||
list.AddList(secondItems, firstIndex + 1);
|
||||
int32 newIndex = list.IndexOf(item);
|
||||
if (newIndex + 1 < list.CountItems())
|
||||
list.AddList(firstItems, newIndex + 1);
|
||||
else
|
||||
list.AddList(firstItems);
|
||||
}
|
||||
|
||||
void
|
||||
BOutlineListView::_CullInvisibleItems(BList &list)
|
||||
{
|
||||
int32 index = 0;
|
||||
while (index < list.CountItems()) {
|
||||
if (reinterpret_cast<BListItem *>(list.ItemAt(index))->IsItemVisible())
|
||||
++index;
|
||||
else
|
||||
list.RemoveItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
BOutlineListView::_SwapItems(int32 first, int32 second)
|
||||
{
|
||||
// same item, do nothing
|
||||
if (first == second)
|
||||
return true;
|
||||
|
||||
// fail, first item out of bounds
|
||||
if ((first < 0) || (first >= CountItems()))
|
||||
return false;
|
||||
|
||||
// fail, second item out of bounds
|
||||
if ((second < 0) || (second >= CountItems()))
|
||||
return false;
|
||||
|
||||
int32 firstIndex = min_c(first, second);
|
||||
int32 secondIndex = max_c(first, second);
|
||||
BListItem *firstItem = ItemAt(firstIndex);
|
||||
BListItem *secondItem = ItemAt(secondIndex);
|
||||
BList firstSubItems, secondSubItems;
|
||||
|
||||
if (Superitem(firstItem) != Superitem(secondItem))
|
||||
return false;
|
||||
if (!firstItem->IsItemVisible() || !secondItem->IsItemVisible())
|
||||
return false;
|
||||
|
||||
int32 fullFirstIndex = FullListIndex(firstIndex);
|
||||
int32 fullSecondIndex = FullListIndex(secondIndex);
|
||||
_GetSubItems(fFullList, firstSubItems, firstItem, fullFirstIndex + 1);
|
||||
_GetSubItems(fFullList, secondSubItems, secondItem, fullSecondIndex + 1);
|
||||
_DoSwap(fFullList, fullFirstIndex, fullSecondIndex, &firstSubItems,
|
||||
&secondSubItems);
|
||||
|
||||
_CullInvisibleItems(firstSubItems);
|
||||
_CullInvisibleItems(secondSubItems);
|
||||
_DoSwap(fList, firstIndex, secondIndex, &firstSubItems,
|
||||
&secondSubItems);
|
||||
|
||||
_RecalcItemTops(firstIndex);
|
||||
_RescanSelection(firstIndex, secondIndex + secondSubItems.CountItems());
|
||||
Invalidate(Bounds());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
BOutlineListView::DoMiscellaneous(MiscCode code, MiscData* data)
|
||||
@@ -989,30 +868,6 @@ void BOutlineListView::_ReservedOutlineListView3() {}
|
||||
void BOutlineListView::_ReservedOutlineListView4() {}
|
||||
|
||||
|
||||
int32
|
||||
BOutlineListView::FullListIndex(int32 index) const
|
||||
{
|
||||
BListItem *item = ItemAt(index);
|
||||
|
||||
if (item == NULL)
|
||||
return -1;
|
||||
|
||||
return FullListIndexOf(item);
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BOutlineListView::ListViewIndex(int32 index) const
|
||||
{
|
||||
BListItem *item = ItemAt(index);
|
||||
|
||||
if (item == NULL)
|
||||
return -1;
|
||||
|
||||
return BListView::IndexOf(item);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::ExpandOrCollapse(BListItem* underItem, bool expand)
|
||||
{
|
||||
@@ -1081,13 +936,164 @@ BOutlineListView::DrawItem(BListItem* item, BRect itemRect, bool complete)
|
||||
if (item->fHasSubitems)
|
||||
DrawLatch(itemRect, item->fLevel, !item->IsExpanded(), false, false);
|
||||
|
||||
itemRect.left += (item->fLevel) * 10.0f + 15.0f;
|
||||
itemRect.left += item->fLevel * 10.0f + 15.0f;
|
||||
item->DrawItem(this, itemRect, complete);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\brief Removes a single item from the list and all of its children.
|
||||
int32
|
||||
BOutlineListView::_FullListIndex(int32 index) const
|
||||
{
|
||||
BListItem* item = ItemAt(index);
|
||||
|
||||
if (item == NULL)
|
||||
return -1;
|
||||
|
||||
return FullListIndexOf(item);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::_PopulateTree(BList* tree, BList& target,
|
||||
int32& firstIndex, bool onlyVisible)
|
||||
{
|
||||
BListItem** items = (BListItem**)target.Items();
|
||||
int32 count = tree->CountItems();
|
||||
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
BListItem* item = (BListItem*)tree->ItemAtFast(index);
|
||||
|
||||
items[firstIndex++] = item;
|
||||
|
||||
if (item->HasSubitems() && (!onlyVisible || item->IsExpanded()))
|
||||
_PopulateTree(item->fTemporaryList, target, firstIndex, onlyVisible);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::_SortTree(BList* tree, bool oneLevelOnly,
|
||||
int (*compareFunc)(const BListItem* a, const BListItem* b))
|
||||
{
|
||||
BListItem** items = (BListItem**)tree->Items();
|
||||
std::sort(items, items + tree->CountItems(), ListItemComparator(compareFunc));
|
||||
|
||||
if (oneLevelOnly)
|
||||
return;
|
||||
|
||||
for (int32 index = tree->CountItems(); index-- > 0;) {
|
||||
BListItem* item = (BListItem*)tree->ItemAt(index);
|
||||
|
||||
if (item->HasSubitems())
|
||||
_SortTree(item->fTemporaryList, false, compareFunc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::_DestructTree(BList* tree)
|
||||
{
|
||||
for (int32 index = tree->CountItems(); index-- > 0;) {
|
||||
BListItem* item = (BListItem*)tree->ItemAt(index);
|
||||
|
||||
if (item->HasSubitems())
|
||||
_DestructTree(item->fTemporaryList);
|
||||
}
|
||||
|
||||
delete tree;
|
||||
}
|
||||
|
||||
|
||||
BList*
|
||||
BOutlineListView::_BuildTree(BListItem* underItem, int32& fullIndex)
|
||||
{
|
||||
int32 fullCount = FullListCountItems();
|
||||
uint32 level = underItem != NULL ? underItem->OutlineLevel() + 1 : 0;
|
||||
BList* list = new BList;
|
||||
if (underItem != NULL)
|
||||
underItem->fTemporaryList = list;
|
||||
|
||||
while (fullIndex < fullCount) {
|
||||
BListItem* item = FullListItemAt(fullIndex);
|
||||
|
||||
// If we jump out of the subtree, break out
|
||||
if (item->fLevel < level)
|
||||
break;
|
||||
|
||||
// If the level matches, put them into the list
|
||||
// (we handle the case of a missing sublevel gracefully)
|
||||
list->AddItem(item);
|
||||
fullIndex++;
|
||||
|
||||
if (item->HasSubitems()) {
|
||||
// we're going deeper
|
||||
_BuildTree(item, fullIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::_CullInvisibleItems(BList& list)
|
||||
{
|
||||
int32 index = 0;
|
||||
while (index < list.CountItems()) {
|
||||
if (reinterpret_cast<BListItem*>(list.ItemAt(index))->IsItemVisible())
|
||||
++index;
|
||||
else
|
||||
list.RemoveItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BOutlineListView::_SwapItems(int32 first, int32 second)
|
||||
{
|
||||
// same item, do nothing
|
||||
if (first == second)
|
||||
return true;
|
||||
|
||||
// fail, first item out of bounds
|
||||
if ((first < 0) || (first >= CountItems()))
|
||||
return false;
|
||||
|
||||
// fail, second item out of bounds
|
||||
if ((second < 0) || (second >= CountItems()))
|
||||
return false;
|
||||
|
||||
int32 firstIndex = min_c(first, second);
|
||||
int32 secondIndex = max_c(first, second);
|
||||
BListItem* firstItem = ItemAt(firstIndex);
|
||||
BListItem* secondItem = ItemAt(secondIndex);
|
||||
BList firstSubItems, secondSubItems;
|
||||
|
||||
if (Superitem(firstItem) != Superitem(secondItem))
|
||||
return false;
|
||||
if (!firstItem->IsItemVisible() || !secondItem->IsItemVisible())
|
||||
return false;
|
||||
|
||||
int32 fullFirstIndex = _FullListIndex(firstIndex);
|
||||
int32 fullSecondIndex = _FullListIndex(secondIndex);
|
||||
_GetSubItems(fFullList, firstSubItems, firstItem, fullFirstIndex + 1);
|
||||
_GetSubItems(fFullList, secondSubItems, secondItem, fullSecondIndex + 1);
|
||||
_DoSwap(fFullList, fullFirstIndex, fullSecondIndex, &firstSubItems,
|
||||
&secondSubItems);
|
||||
|
||||
_CullInvisibleItems(firstSubItems);
|
||||
_CullInvisibleItems(secondSubItems);
|
||||
_DoSwap(fList, firstIndex, secondIndex, &firstSubItems,
|
||||
&secondSubItems);
|
||||
|
||||
_RecalcItemTops(firstIndex);
|
||||
_RescanSelection(firstIndex, secondIndex + secondSubItems.CountItems());
|
||||
Invalidate(Bounds());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Removes a single item from the list and all of its children.
|
||||
|
||||
Unlike the BeOS version, this one will actually delete the children, too,
|
||||
as there should be no reference left to them. This may cause problems for
|
||||
@@ -1133,54 +1139,7 @@ BOutlineListView::_RemoveItem(BListItem* item, int32 fullIndex)
|
||||
}
|
||||
|
||||
|
||||
BListItem *
|
||||
BOutlineListView::RemoveOne(int32 fullListIndex)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::TrackInLatchItem(void *)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::TrackOutLatchItem(void *)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BOutlineListView::OutlineSwapItems(int32 a, int32 b)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BOutlineListView::OutlineMoveItem(int32 from, int32 to)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BOutlineListView::OutlineReplaceItem(int32 index, BListItem *item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BOutlineListView::CommonMoveItems(int32 from, int32 count, int32 to)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Returns the super item before the item specified by \a fullListIndex
|
||||
/*! Returns the super item before the item specified by \a fullListIndex
|
||||
and \a level.
|
||||
*/
|
||||
BListItem*
|
||||
|
||||
Reference in New Issue
Block a user