Updates to BOutlineListView for docs

mostly param naming.

No functional change intended.
This commit is contained in:
John Scipione
2013-12-11 16:13:52 -05:00
parent 853f724631
commit 1e1afb3939
2 changed files with 96 additions and 88 deletions
+12 -15
View File
@@ -14,7 +14,7 @@ public:
BOutlineListView(BRect frame, const char* name,
list_view_type type
= B_SINGLE_SELECTION_LIST,
uint32 resizeMode
uint32 resizingMode
= B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW
| B_FRAME_EVENTS | B_NAVIGABLE);
@@ -36,8 +36,7 @@ public:
virtual void FrameResized(float newWidth, float newHeight);
virtual void MouseUp(BPoint where);
virtual bool AddUnder(BListItem* item,
BListItem* underItem);
virtual bool AddUnder(BListItem* item, BListItem* superItem);
virtual bool AddItem(BListItem* item);
virtual bool AddItem(BListItem* item, int32 fullListIndex);
@@ -49,7 +48,7 @@ public:
virtual bool RemoveItems(int32 fullListIndex, int32 count);
BListItem* FullListItemAt(int32 fullListIndex) const;
int32 FullListIndexOf(BPoint point) const;
int32 FullListIndexOf(BPoint where) const;
int32 FullListIndexOf(BListItem* item) const;
BListItem* FullListFirstItem() const;
BListItem* FullListLastItem() const;
@@ -60,11 +59,9 @@ public:
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 FullListDoForEach(bool (*func)(BListItem* item, void* arg),
void* arg);
BListItem* Superitem(const BListItem* item);
@@ -90,17 +87,17 @@ public:
void FullListSortItems(int (*compareFunc)(
const BListItem* first,
const BListItem* second));
void SortItemsUnder(BListItem* underItem,
void SortItemsUnder(BListItem* superItem,
bool oneLevelOnly, int (*compareFunc)(
const BListItem* first,
const BListItem* second));
int32 CountItemsUnder(BListItem* under,
int32 CountItemsUnder(BListItem* superItem,
bool oneLevelOnly) const;
BListItem* EachItemUnder(BListItem* underItem,
BListItem* EachItemUnder(BListItem* superItem,
bool oneLevelOnly, BListItem* (*eachFunc)(
BListItem* item, void* arg),
void* arg);
BListItem* ItemUnderAt(BListItem* underItem,
BListItem* ItemUnderAt(BListItem* superItem,
bool oneLevelOnly, int32 index) const;
protected:
@@ -114,7 +111,7 @@ private:
virtual void _ReservedOutlineListView4();
protected:
virtual void ExpandOrCollapse(BListItem* underItem,
virtual void ExpandOrCollapse(BListItem* superItem,
bool expand);
virtual BRect LatchRect(BRect itemRect, int32 level) const;
virtual void DrawLatch(BRect itemRect, int32 level,
@@ -132,7 +129,7 @@ private:
int (*compareFunc)(const BListItem* a,
const BListItem* b));
void _DestructTree(BList* tree);
BList* _BuildTree(BListItem* underItem, int32& index);
BList* _BuildTree(BListItem* superItem, int32& index);
void _CullInvisibleItems(BList &list);
bool _SwapItems(int32 first, int32 second);
+84 -73
View File
@@ -77,21 +77,24 @@ _DoSwap(BList& list, int32 firstIndex, int32 secondIndex, BList* firstItems,
BOutlineListView::BOutlineListView(BRect frame, const char* name,
list_view_type type, uint32 resizeMode, uint32 flags)
: BListView(frame, name, type, resizeMode, flags)
list_view_type type, uint32 resizingMode, uint32 flags)
:
BListView(frame, name, type, resizingMode, flags)
{
}
BOutlineListView::BOutlineListView(const char* name, list_view_type type,
uint32 flags)
: BListView(name, type, flags)
uint32 flags)
:
BListView(name, type, flags)
{
}
BOutlineListView::BOutlineListView(BMessage* archive)
: BListView(archive)
:
BListView(archive)
{
int32 i = 0;
BMessage subData;
@@ -160,23 +163,23 @@ BOutlineListView::Archive(BMessage* archive, bool deep) const
void
BOutlineListView::MouseDown(BPoint point)
BOutlineListView::MouseDown(BPoint where)
{
MakeFocus();
int32 index = IndexOf(point);
int32 index = IndexOf(where);
if (index != -1) {
BListItem* item = ItemAt(index);
if (item->fHasSubitems
&& LatchRect(ItemFrame(index), item->fLevel).Contains(point)) {
&& LatchRect(ItemFrame(index), item->fLevel).Contains(where)) {
if (item->IsExpanded())
Collapse(item);
else
Expand(item);
} else
BListView::MouseDown(point);
BListView::MouseDown(where);
}
}
@@ -242,23 +245,23 @@ BOutlineListView::MouseUp(BPoint where)
bool
BOutlineListView::AddUnder(BListItem* item, BListItem* superitem)
BOutlineListView::AddUnder(BListItem* item, BListItem* superItem)
{
if (superitem == NULL)
if (superItem == NULL)
return AddItem(item);
fFullList.AddItem(item, FullListIndexOf(superitem) + 1);
fFullList.AddItem(item, FullListIndexOf(superItem) + 1);
item->fLevel = superitem->OutlineLevel() + 1;
superitem->fHasSubitems = true;
item->fLevel = superItem->OutlineLevel() + 1;
superItem->fHasSubitems = true;
if (superitem->IsItemVisible() && superitem->IsExpanded()) {
if (superItem->IsItemVisible() && superItem->IsExpanded()) {
item->SetItemVisible(true);
int32 index = BListView::IndexOf(superitem);
int32 index = BListView::IndexOf(superItem);
BListView::AddItem(item, index + 1);
Invalidate(LatchRect(ItemFrame(index), superitem->OutlineLevel()));
Invalidate(LatchRect(ItemFrame(index), superItem->OutlineLevel()));
} else
item->SetItemVisible(false);
@@ -300,8 +303,10 @@ BOutlineListView::AddItem(BListItem* item, int32 fullListIndex)
return true;
}
if (!hadSubitems)
Invalidate(LatchRect(ItemFrame(IndexOf(super)), super->OutlineLevel()));
if (!hadSubitems) {
Invalidate(LatchRect(ItemFrame(IndexOf(super)),
super->OutlineLevel()));
}
}
int32 listIndex = _FindPreviousVisibleIndex(fullListIndex);
@@ -344,24 +349,23 @@ BOutlineListView::RemoveItem(BListItem* item)
BListItem*
BOutlineListView::RemoveItem(int32 fullIndex)
BOutlineListView::RemoveItem(int32 fullListIndex)
{
return _RemoveItem(FullListItemAt(fullIndex), fullIndex);
return _RemoveItem(FullListItemAt(fullListIndex), fullListIndex);
}
bool
BOutlineListView::RemoveItems(int32 fullIndex, int32 count)
BOutlineListView::RemoveItems(int32 fullListIndex, int32 count)
{
if (fullIndex >= FullListCountItems())
fullIndex = -1;
if (fullIndex < 0)
if (fullListIndex >= FullListCountItems())
fullListIndex = -1;
if (fullListIndex < 0)
return false;
// TODO: very bad for performance!!
while (count--) {
BOutlineListView::RemoveItem(fullIndex);
}
while (count--)
BOutlineListView::RemoveItem(fullListIndex);
return true;
}
@@ -375,9 +379,9 @@ BOutlineListView::FullListItemAt(int32 fullListIndex) const
int32
BOutlineListView::FullListIndexOf(BPoint point) const
BOutlineListView::FullListIndexOf(BPoint where) const
{
int32 index = BListView::IndexOf(point);
int32 index = BListView::IndexOf(where);
if (index > 0)
index = _FullListIndex(index);
@@ -622,26 +626,26 @@ BOutlineListView::FullListSortItems(int (*compareFunc)(const BListItem* a,
void
BOutlineListView::SortItemsUnder(BListItem* underItem, bool oneLevelOnly,
BOutlineListView::SortItemsUnder(BListItem* superItem, bool oneLevelOnly,
int (*compareFunc)(const BListItem* a, const BListItem* b))
{
// This method is quite complicated: basically, it creates a real tree
// from the items of the full list, sorts them as needed, and then
// populates the entries back into the full and display lists
int32 firstIndex = FullListIndexOf(underItem) + 1;
int32 firstIndex = FullListIndexOf(superItem) + 1;
int32 lastIndex = firstIndex;
BList* tree = _BuildTree(underItem, lastIndex);
BList* tree = _BuildTree(superItem, lastIndex);
_SortTree(tree, oneLevelOnly, compareFunc);
// Populate to the full list
_PopulateTree(tree, fFullList, firstIndex, false);
if (underItem == NULL
|| (underItem->IsItemVisible() && underItem->IsExpanded())) {
if (superItem == NULL
|| (superItem->IsItemVisible() && superItem->IsExpanded())) {
// Populate to BListView's list
firstIndex = fList.IndexOf(underItem) + 1;
firstIndex = fList.IndexOf(superItem) + 1;
lastIndex = firstIndex;
_PopulateTree(tree, fList, lastIndex, true);
@@ -664,15 +668,15 @@ BOutlineListView::SortItemsUnder(BListItem* underItem, bool oneLevelOnly,
int32
BOutlineListView::CountItemsUnder(BListItem* underItem, bool oneLevelOnly) const
BOutlineListView::CountItemsUnder(BListItem* superItem, bool oneLevelOnly) const
{
int32 i = FullListIndexOf(underItem);
int32 i = FullListIndexOf(superItem);
if (i == -1)
return 0;
++i;
int32 count = 0;
uint32 baseLevel = underItem->OutlineLevel();
uint32 baseLevel = superItem->OutlineLevel();
for (; i < FullListCountItems(); i++) {
BListItem* item = FullListItemAt(i);
@@ -691,10 +695,10 @@ BOutlineListView::CountItemsUnder(BListItem* underItem, bool oneLevelOnly) const
BListItem*
BOutlineListView::EachItemUnder(BListItem* underItem, bool oneLevelOnly,
BOutlineListView::EachItemUnder(BListItem* superItem, bool oneLevelOnly,
BListItem* (*eachFunc)(BListItem* item, void* arg), void* arg)
{
int32 i = IndexOf(underItem);
int32 i = IndexOf(superItem);
if (i == -1)
return NULL;
@@ -702,11 +706,11 @@ BOutlineListView::EachItemUnder(BListItem* underItem, bool oneLevelOnly,
BListItem* item = FullListItemAt(i);
// If we jump out of the subtree, return NULL
if (item->fLevel < underItem->OutlineLevel())
if (item->fLevel < superItem->OutlineLevel())
return NULL;
// If the level matches, check the index
if (!oneLevelOnly || item->fLevel == underItem->OutlineLevel() + 1) {
if (!oneLevelOnly || item->fLevel == superItem->OutlineLevel() + 1) {
item = eachFunc(item, arg);
if (item != NULL)
return item;
@@ -720,10 +724,10 @@ BOutlineListView::EachItemUnder(BListItem* underItem, bool oneLevelOnly,
BListItem*
BOutlineListView::ItemUnderAt(BListItem* underItem,
bool oneLevelOnly, int32 index) const
BOutlineListView::ItemUnderAt(BListItem* superItem, bool oneLevelOnly,
int32 index) const
{
int32 i = FullListIndexOf(underItem);
int32 i = FullListIndexOf(superItem);
if (i == -1)
return NULL;
@@ -731,11 +735,11 @@ BOutlineListView::ItemUnderAt(BListItem* underItem,
BListItem* item = FullListItemAt(i);
// If we jump out of the subtree, return NULL
if (item->fLevel < underItem->OutlineLevel())
if (item->fLevel < superItem->OutlineLevel())
return NULL;
// If the level matches, check the index
if (!oneLevelOnly || item->fLevel == underItem->OutlineLevel() + 1) {
if (!oneLevelOnly || item->fLevel == superItem->OutlineLevel() + 1) {
if (index == 0)
return item;
@@ -784,11 +788,11 @@ BOutlineListView::ExpandOrCollapse(BListItem* item, bool expand)
if (expand) {
uint32 level = item->fLevel;
int32 fullIndex = FullListIndexOf(item);
int32 fullListIndex = FullListIndexOf(item);
int32 index = IndexOf(item) + 1;
int32 startIndex = index;
int32 count = FullListCountItems() - fullIndex - 1;
BListItem** items = (BListItem**)fFullList.Items() + fullIndex + 1;
int32 count = FullListCountItems() - fullListIndex - 1;
BListItem** items = (BListItem**)fFullList.Items() + fullListIndex + 1;
BFont font;
GetFont(&font);
@@ -823,14 +827,14 @@ BOutlineListView::ExpandOrCollapse(BListItem* item, bool expand)
} else {
// collapse
uint32 level = item->fLevel;
int32 fullIndex = FullListIndexOf(item);
int32 fullListIndex = FullListIndexOf(item);
int32 index = IndexOf(item);
int32 startIndex = index;
int32 max = FullListCountItems() - fullIndex - 1;
int32 max = FullListCountItems() - fullListIndex - 1;
int32 count = 0;
bool selectionChanged = false;
BListItem** items = (BListItem**)fFullList.Items() + fullIndex + 1;
BListItem** items = (BListItem**)fFullList.Items() + fullListIndex + 1;
while (max-- > 0) {
item = items[0];
@@ -856,6 +860,7 @@ BOutlineListView::ExpandOrCollapse(BListItem* item, bool expand)
// 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
@@ -866,8 +871,10 @@ BOutlineListView::ExpandOrCollapse(BListItem* item, bool expand)
int32 maxIndex = fList.CountItems() - 1;
if (fFirstSelected > maxIndex)
fFirstSelected = maxIndex;
if (fLastSelected > maxIndex)
fLastSelected = maxIndex;
if (selectionChanged)
SelectionChanged();
}
@@ -942,8 +949,10 @@ BOutlineListView::_PopulateTree(BList* tree, BList& target,
items[firstIndex++] = item;
if (item->HasSubitems() && (!onlyVisible || item->IsExpanded()))
_PopulateTree(item->fTemporaryList, target, firstIndex, onlyVisible);
if (item->HasSubitems() && (!onlyVisible || item->IsExpanded())) {
_PopulateTree(item->fTemporaryList, target, firstIndex,
onlyVisible);
}
}
}
@@ -953,7 +962,8 @@ 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));
std::sort(items, items + tree->CountItems(),
ListItemComparator(compareFunc));
if (oneLevelOnly)
return;
@@ -982,16 +992,16 @@ BOutlineListView::_DestructTree(BList* tree)
BList*
BOutlineListView::_BuildTree(BListItem* underItem, int32& fullIndex)
BOutlineListView::_BuildTree(BListItem* superItem, int32& fullListIndex)
{
int32 fullCount = FullListCountItems();
uint32 level = underItem != NULL ? underItem->OutlineLevel() + 1 : 0;
uint32 level = superItem != NULL ? superItem->OutlineLevel() + 1 : 0;
BList* list = new BList;
if (underItem != NULL)
underItem->fTemporaryList = list;
if (superItem != NULL)
superItem->fTemporaryList = list;
while (fullIndex < fullCount) {
BListItem* item = FullListItemAt(fullIndex);
while (fullListIndex < fullCount) {
BListItem* item = FullListItemAt(fullListIndex);
// If we jump out of the subtree, break out
if (item->fLevel < level)
@@ -1000,11 +1010,11 @@ BOutlineListView::_BuildTree(BListItem* underItem, int32& fullIndex)
// If the level matches, put them into the list
// (we handle the case of a missing sublevel gracefully)
list->AddItem(item);
fullIndex++;
fullListIndex++;
if (item->HasSubitems()) {
// we're going deeper
_BuildTree(item, fullIndex);
_BuildTree(item, fullListIndex);
}
}
@@ -1078,19 +1088,21 @@ BOutlineListView::_SwapItems(int32 first, int32 second)
account.
*/
BListItem*
BOutlineListView::_RemoveItem(BListItem* item, int32 fullIndex)
BOutlineListView::_RemoveItem(BListItem* item, int32 fullListIndex)
{
if (item == NULL || fullIndex < 0 || fullIndex >= FullListCountItems())
if (item == NULL || fullListIndex < 0
|| fullListIndex >= FullListCountItems()) {
return NULL;
}
uint32 level = item->OutlineLevel();
int32 superIndex;
BListItem* super = _SuperitemForIndex(fullIndex, level, &superIndex);
BListItem* super = _SuperitemForIndex(fullListIndex, level, &superIndex);
if (item->IsItemVisible()) {
// remove children, too
while (fullIndex + 1 < FullListCountItems()) {
BListItem* subItem = FullListItemAt(fullIndex + 1);
while (fullListIndex + 1 < FullListCountItems()) {
BListItem* subItem = FullListItemAt(fullListIndex + 1);
if (subItem->OutlineLevel() <= level)
break;
@@ -1098,13 +1110,13 @@ BOutlineListView::_RemoveItem(BListItem* item, int32 fullIndex)
if (subItem->IsItemVisible())
BListView::RemoveItem(subItem);
fFullList.RemoveItem(fullIndex + 1);
fFullList.RemoveItem(fullListIndex + 1);
delete subItem;
}
BListView::RemoveItem(item);
}
fFullList.RemoveItem(fullIndex);
fFullList.RemoveItem(fullListIndex);
if (super != NULL) {
// we might need to change the fHasSubitems field of the parent
@@ -1155,4 +1167,3 @@ BOutlineListView::_FindPreviousVisibleIndex(int32 fullListIndex)
return -1;
}