Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes | Friends
nsSelectionState Class Reference

#include <nsSelectionState.h>

List of all members.

Public Member Functions

 nsSelectionState ()
 ~nsSelectionState ()
nsresult SaveSelection (nsISelection *aSel)
nsresult RestoreSelection (nsISelection *aSel)
PRBool IsCollapsed ()
PRBool IsEqual (nsSelectionState *aSelState)
void MakeEmpty ()
PRBool IsEmpty ()

Protected Attributes

nsVoidArray mArray

Friends

class nsRangeUpdater

Detailed Description

Definition at line 70 of file nsSelectionState.h.


Constructor & Destructor Documentation

Definition at line 52 of file nsSelectionState.cpp.

: mArray(){}

Definition at line 54 of file nsSelectionState.cpp.

{
  MakeEmpty();
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 131 of file nsSelectionState.cpp.

{
  if (1 != mArray.Count()) return PR_FALSE;
  nsRangeStore *item;
  item = (nsRangeStore*)mArray.ElementAt(0);
  if (!item) return PR_FALSE;
  nsCOMPtr<nsIDOMRange> range;
  item->GetRange(address_of(range));
  if (!range) return PR_FALSE;
  PRBool bIsCollapsed;
  range->GetCollapsed(&bIsCollapsed);
  return bIsCollapsed;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 190 of file nsSelectionState.cpp.

{
  return (mArray.Count() == 0);
}

Here is the caller graph for this function:

Definition at line 146 of file nsSelectionState.cpp.

{
  if (!aSelState) return NS_ERROR_NULL_POINTER;
  PRInt32 i, myCount = mArray.Count(), itsCount = aSelState->mArray.Count();
  if (myCount != itsCount) return PR_FALSE;
  if (myCount < 1) return PR_FALSE;

  nsRangeStore *myItem, *itsItem;
  
  for (i=0; i<myCount; i++)
  {
    myItem = (nsRangeStore*)mArray.ElementAt(i);
    itsItem = (nsRangeStore*)(aSelState->mArray.ElementAt(i));
    if (!myItem || !itsItem) return PR_FALSE;
    
    nsCOMPtr<nsIDOMRange> myRange, itsRange;
    myItem->GetRange(address_of(myRange));
    itsItem->GetRange(address_of(itsRange));
    if (!myRange || !itsRange) return PR_FALSE;
  
    PRInt16 compResult;
    myRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, itsRange, &compResult);
    if (compResult) return PR_FALSE;
    myRange->CompareBoundaryPoints(nsIDOMRange::END_TO_END, itsRange, &compResult);
    if (compResult) return PR_FALSE;
  }
  // if we got here, they are equal
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 177 of file nsSelectionState.cpp.

{
  // free any items in the array
  nsRangeStore *item;
  for (PRInt32 i = mArray.Count()-1; i >= 0; --i)
  {
    item = (nsRangeStore*)mArray.ElementAt(i);
    delete item;
  }
  mArray.Clear();
}

Here is the caller graph for this function:

Definition at line 104 of file nsSelectionState.cpp.

{
  if (!aSel) return NS_ERROR_NULL_POINTER;
  nsresult res;
  PRInt32 i, arrayCount = mArray.Count();
  nsRangeStore *item;

  // clear out selection
  aSel->RemoveAllRanges();
  
  // set the selection ranges anew
  for (i=0; i<arrayCount; i++)
  {
    item = (nsRangeStore*)mArray.ElementAt(i);
    if (!item) return NS_ERROR_UNEXPECTED;
    nsCOMPtr<nsIDOMRange> range;
    item->GetRange(address_of(range));
    if (!range) return NS_ERROR_UNEXPECTED;
   
    res = aSel->AddRange(range);
    if(NS_FAILED(res)) return res;

  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 60 of file nsSelectionState.cpp.

{
  if (!aSel) return NS_ERROR_NULL_POINTER;
  PRInt32 i,rangeCount, arrayCount = mArray.Count();
  aSel->GetRangeCount(&rangeCount);
  nsRangeStore *item;
  
  // if we need more items in the array, new them
  if (arrayCount<rangeCount)
  {
    PRInt32 count = rangeCount-arrayCount;
    for (i=0; i<count; i++)
    {
      item = new nsRangeStore;
      mArray.AppendElement(item);
    }
  }
  
  // else if we have too many, delete them
  else if (arrayCount>rangeCount)
  {
    for (i = arrayCount-1; i >= rangeCount; i--)
    {
      item = (nsRangeStore*)mArray.ElementAt(i);
      delete item;
      mArray.RemoveElementAt(i);
    }
  }
  
  // now store the selection ranges
  nsresult res = NS_OK;
  for (i=0; i<rangeCount; i++)
  {
    item = (nsRangeStore*)mArray.ElementAt(i);
    if (!item) return NS_ERROR_UNEXPECTED;
    nsCOMPtr<nsIDOMRange> range;
    res = aSel->GetRangeAt(i, getter_AddRefs(range));
    item->StoreRange(range);
  }
  
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsRangeUpdater [friend]

Definition at line 86 of file nsSelectionState.h.


Member Data Documentation

Definition at line 84 of file nsSelectionState.h.


The documentation for this class was generated from the following files: