Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
nsTreeRange Struct Reference
Collaboration diagram for nsTreeRange:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsTreeRange (nsTreeSelection *aSel, PRInt32 aSingleVal)
 nsTreeRange (nsTreeSelection *aSel, PRInt32 aMin, PRInt32 aMax)
 ~nsTreeRange ()
void Connect (nsTreeRange *aPrev=nsnull, nsTreeRange *aNext=nsnull)
nsresult RemoveRange (PRInt32 aStart, PRInt32 aEnd)
nsresult Remove (PRInt32 aIndex)
nsresult Add (PRInt32 aIndex)
PRBool Contains (PRInt32 aIndex)
PRInt32 Count ()
void Invalidate ()
void RemoveAllBut (PRInt32 aIndex)
void Insert (nsTreeRange *aRange)

Public Attributes

nsTreeSelectionmSelection
nsTreeRangemPrev
nsTreeRangemNext
PRInt32 mMin
PRInt32 mMax

Detailed Description

Definition at line 59 of file nsTreeSelection.cpp.


Constructor & Destructor Documentation

nsTreeRange::nsTreeRange ( nsTreeSelection aSel,
PRInt32  aSingleVal 
) [inline]

Definition at line 69 of file nsTreeSelection.cpp.

    :mSelection(aSel), mPrev(nsnull), mNext(nsnull), mMin(aSingleVal), mMax(aSingleVal) {};

Here is the caller graph for this function:

nsTreeRange::nsTreeRange ( nsTreeSelection aSel,
PRInt32  aMin,
PRInt32  aMax 
) [inline]

Definition at line 71 of file nsTreeSelection.cpp.

    :mSelection(aSel), mPrev(nsnull), mNext(nsnull), mMin(aMin), mMax(aMax) {};

Definition at line 74 of file nsTreeSelection.cpp.

{ delete mNext; };

Member Function Documentation

nsresult nsTreeRange::Add ( PRInt32  aIndex) [inline]

Definition at line 164 of file nsTreeSelection.cpp.

                               {
    if (aIndex < mMin) {
      // We have found a spot to insert.
      if (aIndex + 1 == mMin)
        mMin = aIndex;
      else if (mPrev && mPrev->mMax+1 == aIndex)
        mPrev->mMax = aIndex;
      else {
        // We have to create a new range.
        nsTreeRange* newRange = new nsTreeRange(mSelection, aIndex);
        if (!newRange)
          return NS_ERROR_OUT_OF_MEMORY;

        newRange->Connect(mPrev, this);
      }
    }
    else if (mNext)
      mNext->Add(aIndex);
    else {
      // Insert on to the end.
      if (mMax+1 == aIndex)
        mMax = aIndex;
      else {
        // We have to create a new range.
        nsTreeRange* newRange = new nsTreeRange(mSelection, aIndex);
        if (!newRange)
          return NS_ERROR_OUT_OF_MEMORY;

        newRange->Connect(this, nsnull);
      }
    }
    return NS_OK;
  };

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTreeRange::Connect ( nsTreeRange aPrev = nsnull,
nsTreeRange aNext = nsnull 
) [inline]

Definition at line 76 of file nsTreeSelection.cpp.

                                                                         {
    if (aPrev)
      aPrev->mNext = this;
    else
      mSelection->mFirstRange = this;

    if (aNext)
      aNext->mPrev = this;

    mPrev = aPrev;
    mNext = aNext;
  };

Here is the caller graph for this function:

PRBool nsTreeRange::Contains ( PRInt32  aIndex) [inline]

Definition at line 198 of file nsTreeSelection.cpp.

                                  {
    if (aIndex >= mMin && aIndex <= mMax)
      return PR_TRUE;

    if (mNext)
      return mNext->Contains(aIndex);

    return PR_FALSE;
  };

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 208 of file nsTreeSelection.cpp.

                  {
    PRInt32 total = mMax - mMin + 1;
    if (mNext)
      total += mNext->Count();
    return total;
  };

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTreeRange::Insert ( nsTreeRange aRange) [inline]

Definition at line 246 of file nsTreeSelection.cpp.

                                   {
    if (mMin >= aRange->mMax)
      aRange->Connect(mPrev, this);
    else if (mNext)
      mNext->Insert(aRange);
    else 
      aRange->Connect(this, nsnull);
  };

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 215 of file nsTreeSelection.cpp.

                    {
    mSelection->mTree->InvalidateRange(mMin, mMax);
    if (mNext)
      mNext->Invalidate();
  };

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTreeRange::Remove ( PRInt32  aIndex) [inline]

Definition at line 129 of file nsTreeSelection.cpp.

                                  {
    if (aIndex >= mMin && aIndex <= mMax) {
      // We have found the range that contains us.
      if (mMin == mMax) {
        // Delete the whole range.
        if (mPrev)
          mPrev->mNext = mNext;
        if (mNext)
          mNext->mPrev = mPrev;
        nsTreeRange* first = mSelection->mFirstRange;
        if (first == this)
          mSelection->mFirstRange = mNext;
        mNext = mPrev = nsnull;
        delete this;
      }
      else if (aIndex == mMin)
        mMin++;
      else if (aIndex == mMax)
        mMax--;
      else {
        // We have to break this range.
        nsTreeRange* newRange = new nsTreeRange(mSelection, aIndex + 1, mMax);
        if (!newRange)
          return NS_ERROR_OUT_OF_MEMORY;

        newRange->Connect(this, mNext);
        mMax = aIndex - 1;
      }
    }
    else if (mNext)
      return mNext->Remove(aIndex);

    return NS_OK;
  };

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTreeRange::RemoveAllBut ( PRInt32  aIndex) [inline]

Definition at line 221 of file nsTreeSelection.cpp.

                                    {
    if (aIndex >= mMin && aIndex <= mMax) {

      // Invalidate everything in this list.
      mSelection->mFirstRange->Invalidate();

      mMin = aIndex;
      mMax = aIndex;
      
      nsTreeRange* first = mSelection->mFirstRange;
      if (mPrev)
        mPrev->mNext = mNext;
      if (mNext)
        mNext->mPrev = mPrev;
      mNext = mPrev = nsnull;
      
      if (first != this) {
        delete mSelection->mFirstRange;
        mSelection->mFirstRange = this;
      }
    }
    else if (mNext)
      mNext->RemoveAllBut(aIndex);
  };

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTreeRange::RemoveRange ( PRInt32  aStart,
PRInt32  aEnd 
) [inline]

Definition at line 89 of file nsTreeSelection.cpp.

                                                     {
    // This should so be a loop... sigh...
    // We start past the range to remove, so no more to remove
    if (aEnd < mMin)
      return NS_OK;
    // We are the last range to be affected
    if (aEnd < mMax) {
      if (aStart <= mMin) {
        // Just chop the start of the range off
        mMin = aEnd + 1;
      } else {
        // We need to split the range
        nsTreeRange* range = new nsTreeRange(mSelection, aEnd + 1, mMax);
        if (!range)
          return NS_ERROR_OUT_OF_MEMORY;

        mMax = aStart - 1;
        range->Connect(this, mNext);
      }
      return NS_OK;
    }
    nsTreeRange* next = mNext;
    if (aStart <= mMin) {
      // The remove includes us, remove ourselves from the list
      if (mPrev)
        mPrev->mNext = next;
      else
        mSelection->mFirstRange = next;

      if (next)
        next->mPrev = mPrev;
      mPrev = mNext = nsnull;
      delete this;
    } else if (aStart <= mMax) {
      // Just chop the end of the range off
      mMax = aStart - 1;
    }
    return next ? next->RemoveRange(aStart, aEnd) : NS_OK;
  };

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 67 of file nsTreeSelection.cpp.

Definition at line 66 of file nsTreeSelection.cpp.

Definition at line 64 of file nsTreeSelection.cpp.

Definition at line 63 of file nsTreeSelection.cpp.

Definition at line 61 of file nsTreeSelection.cpp.


The documentation for this struct was generated from the following file: