ListRange Class Reference

This class represents a list of explicitly declared nodes (rather than the implicitly chosen nodes controlled by RangeControl flags). More...

#include <range.h>

Inheritance diagram for ListRange:

Range CCObject SimpleCCObject List of all members.

Public Member Functions

 ListRange ()
 ListRange constructor.
 ListRange (const List &srcList)
 SelRange constructor.
 ListRange (const ListRange &srcRange)
 SelRange constructor.
 ListRange (const ListRange *pSrcRange)
 SelRange constructor.
 ~ListRange ()
 SelRange destructor.
virtual NodeFindFirst (BOOL AndChildren=FALSE)
 The purpose of this function is to find the first node in a range.
virtual NodeFindLast ()
 The purpose of this function is to find the last node in a range. If the range was constructed with a NULL last node specifier then the range is scanned until the last node is found. If a non NULL last node was specified however the value of last is simply returned. It's existance is not verified !.
virtual NodeFindNext (Node *Previous, BOOL AndChildren=FALSE)
virtual NodeFindPrev (Node *pNode, BOOL AndChildren=FALSE)
virtual void AddNode (Node *pNode)
virtual NodeRemoveNode (Node *pNode)
virtual void Clear ()
virtual BOOL MatchesSelectionEffectLevel (INT32 iStackPos)
 Get the current edit context for the feather UI controls Notes: VERY IMPORTANT! The node pointers held in this range could be out of date - the nodes could have been deleted. So it's important that the pointers are only used AFTER we have verified that they actually point to something!

Protected Member Functions

virtual BOOL InRange (Node *pNode, BOOL AndChildren) const
 Private helper function for SmartFindNext. Tests whether the presented node is in the range according to the RangeControlFlags and two other locally presented flags.

Private Attributes

List nodelist
NodeListItempLastReturnedItem

Detailed Description

This class represents a list of explicitly declared nodes (rather than the implicitly chosen nodes controlled by RangeControl flags).

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/12/2003

Definition at line 773 of file range.h.


Constructor & Destructor Documentation

ListRange::ListRange  ) 
 

ListRange constructor.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/12/2003
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 6656 of file range.cpp.

06656                      :  Range(NULL, NULL, RangeControl(TRUE,FALSE,TRUE,TRUE))   // Call Range constructor
06657 {
06658     pLastReturnedItem = NULL;
06659 }

ListRange::ListRange const List srcList  ) 
 

SelRange constructor.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/12/2003
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 6680 of file range.cpp.

06680                                         : Range()
06681 {
06682     ERROR2RAW("Unimplemented!");
06683 }

ListRange::ListRange const ListRange srcRange  ) 
 

SelRange constructor.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/02/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 6705 of file range.cpp.

06705                                               : Range()
06706 {
06707     BOOL bOK = TRUE;
06708     NodeListItem* pNodeItem = (NodeListItem*)srcRange.nodelist.GetHead();
06709     while (pNodeItem)
06710     {
06711         NodeListItem* pNewNodeItem = new NodeListItem(pNodeItem->pNode);
06712         if (pNewNodeItem==NULL)
06713         {
06714             bOK = FALSE;
06715             break;
06716         }
06717         nodelist.AddTail(pNewNodeItem);
06718 
06719         pNodeItem = (NodeListItem*)srcRange.nodelist.GetNext(pNodeItem);
06720     }
06721 
06722     if (!bOK)
06723     {
06724         // Get rid of all NodeListItems in the nodelist
06725         while (nodelist.GetHead())
06726             delete nodelist.RemoveHead();
06727     }
06728     pLastReturnedItem = NULL;
06729 }

ListRange::ListRange const ListRange pSrcRange  ) 
 

SelRange constructor.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/02/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 6750 of file range.cpp.

06750                                                : Range()
06751 {
06752     if (pSrcRange==NULL)
06753         return;
06754 
06755     BOOL bOK = TRUE;
06756     NodeListItem* pNodeItem = (NodeListItem*)pSrcRange->nodelist.GetHead();
06757     while (pNodeItem)
06758     {
06759         NodeListItem* pNewNodeItem = new NodeListItem(pNodeItem->pNode);
06760         if (pNewNodeItem==NULL)
06761         {
06762             bOK = FALSE;
06763             break;
06764         }
06765         nodelist.AddTail(pNewNodeItem);
06766 
06767         pNodeItem = (NodeListItem*)pSrcRange->nodelist.GetNext(pNodeItem);
06768     }
06769 
06770     if (!bOK)
06771     {
06772         // Get rid of all NodeListItems in the nodelist
06773         while (nodelist.GetHead())
06774             delete nodelist.RemoveHead();
06775     }
06776     pLastReturnedItem = NULL;
06777 }

ListRange::~ListRange  ) 
 

SelRange destructor.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/12/2003
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 6799 of file range.cpp.

06800 {
06801     // Get rid of all NodeListItems in the nodelist
06802     while (nodelist.GetHead())
06803         delete nodelist.RemoveHead();
06804 
06805     pLastReturnedItem = NULL;
06806 }


Member Function Documentation

void ListRange::AddNode Node pNode  )  [virtual]
 

Definition at line 7027 of file range.cpp.

07028 {
07029 #ifdef _DEBUG_LISTCHECKS
07030     ERROR3IF(InRange(pNode, FALSE), "Attempt to add duplicate node to ListRange!\n");
07031 #endif
07032 
07033     NodeListItem* pNodeItem = new NodeListItem(pNode);
07034     nodelist.AddTail(pNodeItem);
07035 }

void ListRange::Clear  )  [virtual]
 

Definition at line 7093 of file range.cpp.

07094 {
07095     // Get rid of all NodeListItems in the nodelist
07096     while (nodelist.GetHead())
07097         delete nodelist.RemoveHead();
07098 
07099     pLastReturnedItem = NULL;
07100 }

Node * ListRange::FindFirst BOOL  AndChildren = FALSE  )  [virtual]
 

The purpose of this function is to find the first node in a range.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 11/12/2003
Date:
25/6/93
Returns:
If the range contains any members then A pointer to the first node in the range is returned Else NULL is returned
See also:
Range::FindNext
Returns:
Errors: An assertion failure will occur if:
There are no more nodes to search and the last node to search was not found.

Reimplemented from Range.

Definition at line 6833 of file range.cpp.

06834 {
06835     // Preconditions...
06836     ERROR2IF(this==NULL,NULL,"FindFirst called on NULL range");
06837 //  ERROR2IF(AndChildren, NULL, "ListRange can't honour AndChildren requests yet");
06838 
06839     NodeListItem* pNodeItem = (NodeListItem*)nodelist.GetHead();
06840     pLastReturnedItem = pNodeItem;
06841     if (pNodeItem)
06842     {
06843         if (AndChildren)
06844             return pNodeItem->pNode->FindFirstDepthFirst();
06845         else
06846             return pNodeItem->pNode;
06847     }
06848 
06849     return NULL;
06850 }

Node * ListRange::FindLast  )  [virtual]
 

The purpose of this function is to find the last node in a range. If the range was constructed with a NULL last node specifier then the range is scanned until the last node is found. If a non NULL last node was specified however the value of last is simply returned. It's existance is not verified !.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/6/93
Returns:
If the range contains any members then A pointer to the last node in the range is returned Else NULL is returned
See also:
Range::FindFirst Range::FindNext
Returns:
Errors: An assertion failure will occur if:
There are no more nodes to search and the last node to search was not found.

Reimplemented from Range.

Definition at line 7009 of file range.cpp.

07010 {
07011     ERROR2IF(this==NULL,NULL,"FindFirst called on NULL range");
07012 
07013 //  BOOL found = FALSE;
07014     NodeListItem* pNodeItem = (NodeListItem*)nodelist.GetTail();
07015     pLastReturnedItem = pNodeItem;
07016     if (pNodeItem)
07017         return pNodeItem->pNode;
07018 
07019     return NULL;
07020 }

Node * ListRange::FindNext Node Previous,
BOOL  AndChildren = FALSE
[virtual]
 

Reimplemented from Range.

Definition at line 6874 of file range.cpp.

06875 {
06876     // Preconditions
06877     // No need to check that "this" is NULL because that's already been done
06878     // in FindFirst.
06879     ERROR2IF(pPrevious == NULL, NULL, "NULL pointer passed to Range::FindNext");
06880 //  ERROR2IF(AndChildren, NULL, "ListRange can't honour AndChildren requests yet");
06881 
06882     BOOL found = FALSE;
06883     NodeListItem* pNodeItem = (NodeListItem*)nodelist.GetHead();
06884 
06885     // ------------------
06886     // Optimisation
06887     if (pLastReturnedItem)
06888     {
06889         if (pLastReturnedItem->pNode == pPrevious)
06890             pNodeItem = pLastReturnedItem;
06891         else if (AndChildren && pLastReturnedItem->pNode->IsNodeInSubtree(pPrevious))
06892             pNodeItem = pLastReturnedItem;
06893     }
06894     // ------------------
06895 
06896     while (pNodeItem && !found)
06897     {
06898         found = (pNodeItem->pNode == pPrevious);
06899         if (!found && AndChildren)
06900         {
06901             // If this list item contains the previous context node
06902             // Then we are still traversing the subtree of that list item
06903             // So get the next item in the subtree
06904             if (pNodeItem->pNode->IsNodeInSubtree(pPrevious))
06905             {
06906                 pLastReturnedItem = pNodeItem;
06907                 return pPrevious->FindNextDepthFirst(pNodeItem->pNode);
06908             }
06909         }
06910 
06911         pNodeItem = (NodeListItem*)nodelist.GetNext(pNodeItem);
06912     }
06913 
06914     pLastReturnedItem = pNodeItem;
06915 
06916     if (pNodeItem && found)
06917         if (AndChildren)
06918             return pNodeItem->pNode->FindFirstDepthFirst();
06919         else
06920             return pNodeItem->pNode;
06921 
06922     return NULL;
06923 }

Node * ListRange::FindPrev Node pNode,
BOOL  AndChildren = FALSE
[virtual]
 

Reimplemented from Range.

Definition at line 6947 of file range.cpp.

06948 {
06949     // Preconditions
06950     // No need to check that "this" is NULL because that's already been done
06951     // in FindFirst.
06952     ERROR2IF(pNode == NULL, NULL, "NULL pointer passed to Range::FindNext");
06953     ERROR2IF(AndChildren, NULL, "ListRange::FindPrev can't honour AndChildren requests yet");
06954 
06955     BOOL found = FALSE;
06956     NodeListItem* pNodeItem = (NodeListItem*)nodelist.GetTail();
06957 
06958     // ------------------
06959     // Optimisation
06960     if (pLastReturnedItem && pLastReturnedItem->pNode == pNode)
06961         pNodeItem = pLastReturnedItem;
06962     // ------------------
06963 
06964     while (pNodeItem && !found)
06965     {
06966         found = (pNodeItem->pNode == pNode);
06967 
06968         pNodeItem = (NodeListItem*)nodelist.GetPrev(pNodeItem);
06969     }
06970 
06971     pLastReturnedItem = pNodeItem;
06972 
06973     if (pNodeItem && found)
06974         return pNodeItem->pNode;
06975 
06976     return NULL;
06977 }

BOOL ListRange::InRange Node pNode,
BOOL  AndChildren
const [protected, virtual]
 

Private helper function for SmartFindNext. Tests whether the presented node is in the range according to the RangeControlFlags and two other locally presented flags.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/11/94 Rewritten: 08/12/2004
Parameters:
pNode Pointer to node to test for inclusion in the range [INPUTS] AndChildren Children of the primary range are allowed to be returned
- [OUTPUTS]
Returns:
TRUE if node is in this range (ignoring CrossLayer flag) FALSE if not
Version 2, 08/12/2004 Simplified and adjusted to deal with selection inside Compound Parents Controllers and PostProcessors

This function should ONLY be called on nodes that /could/ be members of Range Not Layers or Paper nodes!

Scope: Protected

See also:
Range::SmartFindNext
Returns:
Errors: When attempting to return children and finds no parent link.

Reimplemented from Range.

Definition at line 7070 of file range.cpp.

07071 {
07072     ERROR2IF(AndChildren, FALSE, "ListRange can't honour AndChildren requests yet");
07073 
07074     BOOL found = FALSE;
07075     NodeListItem* pNodeItem = (NodeListItem*)nodelist.GetHead();
07076     while (pNodeItem && !found)
07077     {
07078         found = (pNodeItem->pNode == pNode);
07079 
07080         pNodeItem = (NodeListItem*)nodelist.GetNext(pNodeItem);
07081     }
07082 
07083 //  pLastReturnedItem = pNodeItem;
07084 
07085     return found;
07086 }

BOOL ListRange::MatchesSelectionEffectLevel INT32  iStackPos  )  [virtual]
 

Get the current edit context for the feather UI controls Notes: VERY IMPORTANT! The node pointers held in this range could be out of date - the nodes could have been deleted. So it's important that the pointers are only used AFTER we have verified that they actually point to something!

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/05/2005
Parameters:
iStackPos - index into effects stack [INPUTS]
- [OUTPUTS]
Returns:
TRUE if this range matches the specifed level in the Effects stack FALSE otherwise
More: The implementation assumes that the nodes will be stored in the lists in the same order. This is not a good idea! A better algorithm, avoiding O(n^2) problems, would be to check the two lists are the same length, then go through them both clearing a marker flag on every node, then scan one list setting the marker flag, finally scan the other list checking whether all nodes are marked. Er, but what about the possible dead pointers in one of the lists?

Definition at line 7130 of file range.cpp.

07131 {
07132     if (iStackPos==STACKPOS_INVALID)
07133         return FALSE;
07134 
07135     SelRange* pSelRange = GetApplication()->FindSelection();
07136     EffectsStack* pStack = pSelRange->GetEffectsStack();        // From cache
07137     if (pStack==NULL || pStack->IsEmpty())
07138         return FALSE;
07139 
07140     INT32 iPos = iStackPos;
07141     Range* pLevelRange = pStack->GetLevelRange(&iPos);
07142     if (pLevelRange==NULL)
07143         return FALSE;
07144 
07145     Node* pNode = pLevelRange->FindFirst();
07146     Node* pEditNode = FindFirst();
07147     while (pNode && pEditNode)
07148     {
07149         // If the pointers are the same then we can reasonably assume
07150         // the the pointer stored in s_pEditRange is still valid...
07151         if (pNode!=pEditNode)
07152             return FALSE;
07153 
07154         // Now we know the pointer at least points to SOME kind of node
07155         // Check whether Another node has been allocated into the same
07156         // address as a deleted node...
07157         if (pNode->GetTag() != pEditNode->GetTag())
07158             return FALSE;
07159 
07160         pNode = pLevelRange->FindNext(pNode);
07161         pEditNode = FindNext(pEditNode);
07162     }
07163 
07164     // If either pointer is non-null then we stopped without matching every case
07165     // So must return NULL
07166     if (pNode || pEditNode)
07167         return FALSE;
07168 
07169     return TRUE;
07170 }

Node * ListRange::RemoveNode Node pNode  )  [virtual]
 

Definition at line 7042 of file range.cpp.

07043 {
07044     BOOL found = FALSE;
07045     Node* pFoundNode = NULL;
07046     NodeListItem* pNodeItem = (NodeListItem*)nodelist.GetHead();
07047     while (pNodeItem && pFoundNode==NULL)
07048     {
07049         found = (pNodeItem->pNode == pNode);
07050 
07051         if (found)
07052             pFoundNode = pNode;
07053         else
07054             pNodeItem = (NodeListItem*)nodelist.GetNext(pNodeItem);
07055     }
07056 
07057     if (pNodeItem && pFoundNode)
07058         nodelist.RemoveItem(pNodeItem);
07059 
07060     pLastReturnedItem = NULL;
07061 
07062     return pFoundNode;
07063 }


Member Data Documentation

List ListRange::nodelist [private]
 

Definition at line 798 of file range.h.

NodeListItem* ListRange::pLastReturnedItem [private]
 

Definition at line 799 of file range.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:56:02 2007 for Camelot by  doxygen 1.4.4