2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-03-23 07:39:31 +00:00
|
|
|
|
2006-02-13 16:02:08 +00:00
|
|
|
#include "nsString.h"
|
2002-03-29 02:46:01 +00:00
|
|
|
#include "nsTreeRows.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2001-03-23 07:39:31 +00:00
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::Subtree*
|
|
|
|
nsTreeRows::EnsureSubtreeFor(Subtree* aParent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aChildIndex)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
Subtree* subtree = GetSubtreeFor(aParent, aChildIndex);
|
|
|
|
|
|
|
|
if (! subtree) {
|
|
|
|
subtree = aParent->mRows[aChildIndex].mSubtree = new Subtree(aParent);
|
|
|
|
InvalidateCachedRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
return subtree;
|
|
|
|
}
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::Subtree*
|
|
|
|
nsTreeRows::GetSubtreeFor(const Subtree* aParent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aChildIndex,
|
|
|
|
int32_t* aSubtreeSize)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParent, "no parent");
|
|
|
|
NS_PRECONDITION(aChildIndex >= 0, "bad child index");
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
Subtree* result = nullptr;
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
if (aChildIndex < aParent->mCount)
|
|
|
|
result = aParent->mRows[aChildIndex].mSubtree;
|
|
|
|
|
|
|
|
if (aSubtreeSize)
|
|
|
|
*aSubtreeSize = result ? result->mSubtreeSize : 0;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTreeRows::RemoveSubtreeFor(Subtree* aParent, int32_t aChildIndex)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParent, "no parent");
|
|
|
|
NS_PRECONDITION(aChildIndex >= 0 && aChildIndex < aParent->mCount, "bad child index");
|
|
|
|
|
|
|
|
Row& row = aParent->mRows[aChildIndex];
|
|
|
|
|
|
|
|
if (row.mSubtree) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t subtreeSize = row.mSubtree->GetSubtreeSize();
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
delete row.mSubtree;
|
2012-07-30 14:20:58 +00:00
|
|
|
row.mSubtree = nullptr;
|
2001-03-23 07:39:31 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
for (Subtree* subtree = aParent; subtree != nullptr; subtree = subtree->mParent)
|
2001-03-23 07:39:31 +00:00
|
|
|
subtree->mSubtreeSize -= subtreeSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateCachedRow();
|
|
|
|
}
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator
|
|
|
|
nsTreeRows::First()
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
iterator result;
|
2002-01-16 23:45:42 +00:00
|
|
|
result.Append(&mRoot, 0);
|
2001-03-23 07:39:31 +00:00
|
|
|
result.SetRowIndex(0);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator
|
|
|
|
nsTreeRows::Last()
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
iterator result;
|
|
|
|
|
|
|
|
// Build up a path along the rightmost edge of the tree
|
|
|
|
Subtree* current = &mRoot;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t count = current->Count();
|
2001-08-24 18:28:15 +00:00
|
|
|
do {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t last = count - 1;
|
2002-01-16 23:45:42 +00:00
|
|
|
result.Append(current, last);
|
2012-07-30 14:20:58 +00:00
|
|
|
current = count ? GetSubtreeFor(current, last) : nullptr;
|
2001-08-24 18:28:15 +00:00
|
|
|
} while (current && ((count = current->Count()) != 0));
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
// Now, at the bottom rightmost leaf, advance us one off the end.
|
2007-04-19 19:27:11 +00:00
|
|
|
result.GetTop().mChildIndex++;
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
// Our row index will be the size of the root subree, plus one.
|
|
|
|
result.SetRowIndex(mRoot.GetSubtreeSize() + 1);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTreeRows::operator[](int32_t aRow)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
// See if we're just lucky, and end up with something
|
|
|
|
// nearby. (This tends to happen a lot due to the way that we get
|
|
|
|
// asked for rows n' stuff.)
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t last = mLastRow.GetRowIndex();
|
2001-03-23 07:39:31 +00:00
|
|
|
if (last != -1) {
|
|
|
|
if (aRow == last)
|
|
|
|
return mLastRow;
|
|
|
|
else if (last + 1 == aRow)
|
|
|
|
return ++mLastRow;
|
|
|
|
else if (last - 1 == aRow)
|
|
|
|
return --mLastRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nope. Construct a path to the specified index. This is a little
|
|
|
|
// bit better than O(n), because we can skip over subtrees. (So it
|
|
|
|
// ends up being approximately linear in the subtree size, instead
|
|
|
|
// of the entire view size. But, most of the time, big views are
|
|
|
|
// flat. Oh well.)
|
|
|
|
iterator result;
|
|
|
|
Subtree* current = &mRoot;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index = 0;
|
2001-03-23 07:39:31 +00:00
|
|
|
result.SetRowIndex(aRow);
|
|
|
|
|
|
|
|
do {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t subtreeSize;
|
2001-03-23 07:39:31 +00:00
|
|
|
Subtree* subtree = GetSubtreeFor(current, index, &subtreeSize);
|
|
|
|
|
|
|
|
if (subtreeSize >= aRow) {
|
2002-01-16 23:45:42 +00:00
|
|
|
result.Append(current, index);
|
2001-03-23 07:39:31 +00:00
|
|
|
current = subtree;
|
|
|
|
index = 0;
|
|
|
|
--aRow;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++index;
|
|
|
|
aRow -= subtreeSize + 1;
|
|
|
|
}
|
|
|
|
} while (aRow >= 0);
|
|
|
|
|
|
|
|
mLastRow = result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator
|
2006-02-13 16:02:08 +00:00
|
|
|
nsTreeRows::FindByResource(nsIRDFResource* aResource)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
// XXX Mmm, scan through the rows one-by-one...
|
|
|
|
iterator last = Last();
|
|
|
|
iterator iter;
|
|
|
|
|
2006-02-13 16:02:08 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsAutoString resourceid;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool stringmode = false;
|
2006-02-13 16:02:08 +00:00
|
|
|
|
2001-03-23 07:39:31 +00:00
|
|
|
for (iter = First(); iter != last; ++iter) {
|
2006-02-13 16:02:08 +00:00
|
|
|
if (!stringmode) {
|
|
|
|
nsCOMPtr<nsIRDFResource> findres;
|
|
|
|
rv = iter->mMatch->mResult->GetResource(getter_AddRefs(findres));
|
|
|
|
if (NS_FAILED(rv)) return last;
|
|
|
|
|
|
|
|
if (findres == aResource)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (! findres) {
|
|
|
|
const char *uri;
|
|
|
|
aResource->GetValueConst(&uri);
|
|
|
|
CopyUTF8toUTF16(uri, resourceid);
|
|
|
|
|
|
|
|
// set stringmode and fall through
|
2011-10-17 14:59:28 +00:00
|
|
|
stringmode = true;
|
2006-02-13 16:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// additional check because previous block could change stringmode
|
|
|
|
if (stringmode) {
|
|
|
|
nsAutoString findid;
|
|
|
|
rv = iter->mMatch->mResult->GetId(findid);
|
|
|
|
if (NS_FAILED(rv)) return last;
|
|
|
|
|
|
|
|
if (resourceid.Equals(findid))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-03-23 07:39:31 +00:00
|
|
|
|
2006-02-13 16:02:08 +00:00
|
|
|
return iter;
|
|
|
|
}
|
2001-03-23 07:39:31 +00:00
|
|
|
|
2006-02-13 16:02:08 +00:00
|
|
|
nsTreeRows::iterator
|
|
|
|
nsTreeRows::Find(nsIXULTemplateResult *aResult)
|
|
|
|
{
|
|
|
|
// XXX Mmm, scan through the rows one-by-one...
|
|
|
|
iterator last = Last();
|
|
|
|
iterator iter;
|
|
|
|
|
|
|
|
for (iter = First(); iter != last; ++iter) {
|
|
|
|
if (aResult == iter->mMatch->mResult)
|
|
|
|
break;
|
2001-03-23 07:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::Clear()
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
mRoot.Clear();
|
|
|
|
InvalidateCachedRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
2002-03-29 02:46:01 +00:00
|
|
|
// nsTreeRows::Subtree
|
2001-03-23 07:39:31 +00:00
|
|
|
//
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::Subtree::~Subtree()
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::Subtree::Clear()
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = mCount - 1; i >= 0; --i)
|
2001-03-23 07:39:31 +00:00
|
|
|
delete mRows[i].mSubtree;
|
|
|
|
|
|
|
|
delete[] mRows;
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mRows = nullptr;
|
2001-06-13 03:42:44 +00:00
|
|
|
mCount = mCapacity = mSubtreeSize = 0;
|
2001-03-23 07:39:31 +00:00
|
|
|
}
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTreeRows::Subtree::InsertRowAt(nsTemplateMatch* aMatch, int32_t aIndex)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
if (mCount >= mCapacity || aIndex >= mCapacity) {
|
2013-01-15 12:22:03 +00:00
|
|
|
int32_t newCapacity = std::max(mCapacity * 2, aIndex + 1);
|
2001-03-23 07:39:31 +00:00
|
|
|
Row* newRows = new Row[newCapacity];
|
|
|
|
if (! newRows)
|
2002-01-16 23:45:42 +00:00
|
|
|
return iterator();
|
2001-03-23 07:39:31 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = mCount - 1; i >= 0; --i)
|
2001-03-23 07:39:31 +00:00
|
|
|
newRows[i] = mRows[i];
|
|
|
|
|
|
|
|
delete[] mRows;
|
|
|
|
|
|
|
|
mRows = newRows;
|
|
|
|
mCapacity = newCapacity;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = mCount - 1; i >= aIndex; --i)
|
2001-03-23 07:39:31 +00:00
|
|
|
mRows[i + 1] = mRows[i];
|
|
|
|
|
|
|
|
mRows[aIndex].mMatch = aMatch;
|
2001-07-17 18:31:03 +00:00
|
|
|
mRows[aIndex].mContainerType = eContainerType_Unknown;
|
|
|
|
mRows[aIndex].mContainerState = eContainerState_Unknown;
|
2003-03-16 11:29:02 +00:00
|
|
|
mRows[aIndex].mContainerFill = eContainerFill_Unknown;
|
2012-07-30 14:20:58 +00:00
|
|
|
mRows[aIndex].mSubtree = nullptr;
|
2001-03-23 07:39:31 +00:00
|
|
|
++mCount;
|
|
|
|
|
2002-01-16 23:45:42 +00:00
|
|
|
// Now build an iterator that points to the newly inserted element.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rowIndex = 0;
|
2002-01-16 23:45:42 +00:00
|
|
|
iterator result;
|
|
|
|
result.Push(this, aIndex);
|
|
|
|
|
|
|
|
for ( ; --aIndex >= 0; ++rowIndex) {
|
|
|
|
// Account for open subtrees in the absolute row index.
|
|
|
|
const Subtree *subtree = mRows[aIndex].mSubtree;
|
|
|
|
if (subtree)
|
|
|
|
rowIndex += subtree->mSubtreeSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
Subtree *subtree = this;
|
|
|
|
do {
|
|
|
|
// Note that the subtree's size has expanded.
|
2001-03-23 07:39:31 +00:00
|
|
|
++subtree->mSubtreeSize;
|
|
|
|
|
2002-01-16 23:45:42 +00:00
|
|
|
Subtree *parent = subtree->mParent;
|
|
|
|
if (! parent)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Account for open subtrees in the absolute row index.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t count = parent->Count();
|
2002-01-16 23:45:42 +00:00
|
|
|
for (aIndex = 0; aIndex < count; ++aIndex, ++rowIndex) {
|
|
|
|
const Subtree *child = (*parent)[aIndex].mSubtree;
|
|
|
|
if (subtree == child)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
rowIndex += child->mSubtreeSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aIndex < count, "couldn't find subtree in parent");
|
|
|
|
|
|
|
|
result.Push(parent, aIndex);
|
|
|
|
subtree = parent;
|
|
|
|
++rowIndex; // One for the parent row.
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
result.SetRowIndex(rowIndex);
|
|
|
|
return result;
|
2001-03-23 07:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTreeRows::Subtree::RemoveRowAt(int32_t aIndex)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0 && aIndex < Count(), "bad index");
|
|
|
|
if (aIndex < 0 || aIndex >= Count())
|
|
|
|
return;
|
|
|
|
|
2002-01-16 23:45:42 +00:00
|
|
|
// How big is the subtree we're going to be removing?
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t subtreeSize = mRows[aIndex].mSubtree
|
2001-03-23 07:39:31 +00:00
|
|
|
? mRows[aIndex].mSubtree->GetSubtreeSize()
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
++subtreeSize;
|
|
|
|
|
|
|
|
delete mRows[aIndex].mSubtree;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = aIndex + 1; i < mCount; ++i)
|
2001-03-23 07:39:31 +00:00
|
|
|
mRows[i - 1] = mRows[i];
|
|
|
|
|
|
|
|
--mCount;
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
for (Subtree* subtree = this; subtree != nullptr; subtree = subtree->mParent)
|
2001-03-23 07:39:31 +00:00
|
|
|
subtree->mSubtreeSize -= subtreeSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
2002-03-29 02:46:01 +00:00
|
|
|
// nsTreeRows::iterator
|
2001-03-23 07:39:31 +00:00
|
|
|
//
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator::iterator(const iterator& aIterator)
|
2007-04-19 19:27:11 +00:00
|
|
|
: mRowIndex(aIterator.mRowIndex),
|
|
|
|
mLink(aIterator.mLink)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator&
|
|
|
|
nsTreeRows::iterator::operator=(const iterator& aIterator)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
|
|
|
mRowIndex = aIterator.mRowIndex;
|
2007-04-19 19:27:11 +00:00
|
|
|
mLink = aIterator.mLink;
|
2001-03-23 07:39:31 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTreeRows::iterator::Append(Subtree* aParent, int32_t aChildIndex)
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
2007-04-19 19:27:11 +00:00
|
|
|
Link *link = mLink.AppendElement();
|
|
|
|
if (link) {
|
|
|
|
link->mParent = aParent;
|
|
|
|
link->mChildIndex = aChildIndex;
|
2001-03-23 07:39:31 +00:00
|
|
|
}
|
|
|
|
else
|
2007-04-19 19:27:11 +00:00
|
|
|
NS_ERROR("out of memory");
|
2001-03-23 07:39:31 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 23:45:42 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTreeRows::iterator::Push(Subtree *aParent, int32_t aChildIndex)
|
2002-01-16 23:45:42 +00:00
|
|
|
{
|
2007-04-19 19:27:11 +00:00
|
|
|
Link *link = mLink.InsertElementAt(0);
|
|
|
|
if (link) {
|
|
|
|
link->mParent = aParent;
|
|
|
|
link->mChildIndex = aChildIndex;
|
2002-01-16 23:45:42 +00:00
|
|
|
}
|
|
|
|
else
|
2007-04-19 19:27:11 +00:00
|
|
|
NS_ERROR("out of memory");
|
2002-01-16 23:45:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator::operator==(const iterator& aIterator) const
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
2007-04-19 19:27:11 +00:00
|
|
|
if (GetDepth() != aIterator.GetDepth())
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-03-23 07:39:31 +00:00
|
|
|
|
2007-04-19 19:27:11 +00:00
|
|
|
if (GetDepth() == 0)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2001-03-23 07:39:31 +00:00
|
|
|
|
2007-04-19 19:27:11 +00:00
|
|
|
return GetTop() == aIterator.GetTop();
|
2001-03-23 07:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator::Next()
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
2007-04-19 19:27:11 +00:00
|
|
|
NS_PRECONDITION(GetDepth() > 0, "cannot increment an uninitialized iterator");
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
// Increment the absolute row index
|
|
|
|
++mRowIndex;
|
|
|
|
|
2007-04-19 19:27:11 +00:00
|
|
|
Link& top = GetTop();
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
// Is there a child subtree? If so, descend into the child
|
|
|
|
// subtree.
|
|
|
|
Subtree* subtree = top.GetRow().mSubtree;
|
|
|
|
|
|
|
|
if (subtree && subtree->Count()) {
|
2002-01-16 23:45:42 +00:00
|
|
|
Append(subtree, 0);
|
2001-03-23 07:39:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Have we exhausted the current subtree?
|
|
|
|
if (top.mChildIndex >= top.mParent->Count() - 1) {
|
|
|
|
// Yep. See if we've just iterated path the last element in
|
|
|
|
// the tree, period. Walk back up the stack, looking for any
|
|
|
|
// unfinished subtrees.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t unfinished;
|
2007-04-19 19:27:11 +00:00
|
|
|
for (unfinished = GetDepth() - 2; unfinished >= 0; --unfinished) {
|
2001-03-23 07:39:31 +00:00
|
|
|
const Link& link = mLink[unfinished];
|
|
|
|
if (link.mChildIndex < link.mParent->Count() - 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no unfinished subtrees in the stack, then this
|
|
|
|
// iterator is exhausted. Leave it in the same state that
|
|
|
|
// Last() does.
|
2001-03-28 22:42:49 +00:00
|
|
|
if (unfinished < 0) {
|
|
|
|
top.mChildIndex++;
|
2001-03-23 07:39:31 +00:00
|
|
|
return;
|
2001-03-28 22:42:49 +00:00
|
|
|
}
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
// Otherwise, we ran off the end of one of the inner
|
|
|
|
// subtrees. Pop up to the next unfinished level in the stack.
|
2007-04-19 19:27:11 +00:00
|
|
|
mLink.SetLength(unfinished + 1);
|
2001-03-23 07:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Advance to the next child in this subtree
|
2007-04-19 19:27:11 +00:00
|
|
|
++(GetTop().mChildIndex);
|
2001-03-23 07:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-29 02:46:01 +00:00
|
|
|
nsTreeRows::iterator::Prev()
|
2001-03-23 07:39:31 +00:00
|
|
|
{
|
2007-04-19 19:27:11 +00:00
|
|
|
NS_PRECONDITION(GetDepth() > 0, "cannot increment an uninitialized iterator");
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
// Decrement the absolute row index
|
|
|
|
--mRowIndex;
|
|
|
|
|
|
|
|
// Move to the previous child in this subtree
|
2007-04-19 19:27:11 +00:00
|
|
|
--(GetTop().mChildIndex);
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
// Have we exhausted the current subtree?
|
2007-04-19 19:27:11 +00:00
|
|
|
if (GetTop().mChildIndex < 0) {
|
2001-03-23 07:39:31 +00:00
|
|
|
// Yep. See if we've just iterated back to the first element
|
|
|
|
// in the tree, period. Walk back up the stack, looking for
|
|
|
|
// any unfinished subtrees.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t unfinished;
|
2007-04-19 19:27:11 +00:00
|
|
|
for (unfinished = GetDepth() - 2; unfinished >= 0; --unfinished) {
|
2001-03-23 07:39:31 +00:00
|
|
|
const Link& link = mLink[unfinished];
|
|
|
|
if (link.mChildIndex >= 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no unfinished subtrees in the stack, then this
|
|
|
|
// iterator is exhausted. Leave it in the same state that
|
|
|
|
// First() does.
|
|
|
|
if (unfinished < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Otherwise, we ran off the end of one of the inner
|
|
|
|
// subtrees. Pop up to the next unfinished level in the stack.
|
2007-04-19 19:27:11 +00:00
|
|
|
mLink.SetLength(unfinished + 1);
|
2001-03-23 07:39:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is there a child subtree immediately prior to our current
|
|
|
|
// position? If so, descend into it, grovelling down to the
|
|
|
|
// deepest, rightmost left edge.
|
2007-04-19 19:27:11 +00:00
|
|
|
Subtree* parent = GetTop().GetParent();
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index = GetTop().GetChildIndex();
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
Subtree* subtree = (*parent)[index].mSubtree;
|
|
|
|
|
|
|
|
if (subtree && subtree->Count()) {
|
|
|
|
do {
|
|
|
|
index = subtree->Count() - 1;
|
2002-01-16 23:45:42 +00:00
|
|
|
Append(subtree, index);
|
2001-03-23 07:39:31 +00:00
|
|
|
|
|
|
|
parent = subtree;
|
|
|
|
subtree = (*parent)[index].mSubtree;
|
|
|
|
} while (subtree && subtree->Count());
|
|
|
|
}
|
|
|
|
}
|