ColourList Class Reference

A colour list is held by each document to store the list of available IndexedColours for use by that document. (This colour list is displayed in the ColourBar/ColourGallery via the ColGalDisplayList which references colours held in the ColourList). More...

#include <collist.h>

Inheritance diagram for ColourList:

List CCObject SimpleCCObject List of all members.

Public Member Functions

 ColourList ()
 ColourList constructor.
 ~ColourList ()
 ColourList destructor.
void Init (BaseDocument *ParentDocument)
 ColourList initialiser. MUST be called after constructing a ColourList in order to correctly initialise it. Note that if ParentDocument is not set to a useful value, some operations on colour lists (eg. the colour editor) will fail.
void AddHead (ListItem *)
 Overrides the List::AddHead method to ensure that any added item has a name which is unique within this colour list.
void AddTail (ListItem *)
 Overrides the List::AddTail method to ensure that any added item has a name which is unique within this colour list.
BOOL AddItem (IndexedColour *NewColour)
 Adds an IndexedColour item to the tail of the ColourList The name of the colour is checked, and may be changed to ensure that it is a unique identifier within the scope of this colour list.
LISTPOS InsertBefore (LISTPOS here, ListItem *item)
 Inserts a NAMED IndexedColour at a particular list position (See List base class for a further description of the actual insertion process).
ListItemInsertBefore (ListItem *here, ListItem *item)
 Inserts the 'newItem' ListItem before 'here' ListItem in the list.
LISTPOS InsertAfter (LISTPOS here, ListItem *item)
 Inserts a ListItem in the list position after the one that is passed in. Notes: To find 'here', the list must be scanned, so this is much slower on average than the other flavour of InsertAfter.
ListItemInsertAfter (ListItem *here, ListItem *item)
 Inserts the 'newItem' ListItem after 'here' ListItem in the list.
virtual void DeleteAll ()
 Deletes the list, calling the destructors of all ListItems.
UINT32 GetUndeletedCount (void)
 Count the number of non-'deleted' items in a ColourList.
IndexedColourFindUndeletedItem (INT32 Index)
 The same as the conventional List FindItem() function, except that it treats 'deleted' colours as if they are not in the list.
IndexedColourGetUndeletedHead (void)
 The same as the conventional List GetHead() function, except that it treats 'deleted' colours as if they are not in the list.
IndexedColourGetUndeletedNext (IndexedColour *ThisItem)
 The same as the conventional List GetNext() function, except that it treats 'deleted' colours as if they are not in the list.
BaseDocumentGetParentDocument (void)
 To find the parent document of this colour list.
IndexedColour ** CompileInheritanceArray (IndexedColour *Parent)
 Compiles a NULL-terminated array of pointers to ALL colours which are linked to this, both directly and indirectly (i.e. an array listing the entire inheritance 'subtree' from 'Parent', *including* 'Parent', and including named, unnamed, and 'deleted' colours).
void RemoveLinksToColour (IndexedColour *DeadColour)
 Scans the entire ColourList for any colours which reference the given IndexedColour. All these colours are converted into standalone representation of their former definition, so that all child-links of this colour are removed. It is then safe to delete the colour.
BOOL IsColourInUseInDoc (IndexedColour *TheColour, BOOL IgnoreColourGallery=FALSE)
 Determine if a colour is used in the parent document. This is similar to IndexedColour::IsInUse(), but it also traverses the linking hierarchy to see if a colour is in use indirectly (e.g. A parent of a colour that is in use is needed for the document even if it is not used directly in document.
void InvalidateInheritanceCache (void)
 Deallocates any memory used for the array of IndexedColours compiled by ColourList::CompileInheritanceArray. The next request for such an array will be regenerated from the ColourList, rather than from cache.
BOOL NamedColourExists (PCTSTR pName)
 Determine if a colour name is already in use by any colours stored in this colour list.
BOOL NamedColourExists (const StringBase *pName)
 Determine if a colour name is already in use by any colours stored in this colour list.
BOOL GenerateUniqueColourName (const StringBase *pPrefix, String_64 *pResult)
 Scans the entire ColourList to determine if the suggested name is unique within this document. If it is not, the name is altered (currently by truncating to 50 characters and appending a decimal number) to provide a unique name, which is returned in the supplied string.
ListGetUnnamedColours (void)
 To find the unnamed colours for this document.

Private Attributes

BaseDocumentParentDoc
IndexedColourArrayParent
IndexedColour ** InheritanceArray
INT32 LastUnnamedColour
List UnnamedColours

Detailed Description

A colour list is held by each document to store the list of available IndexedColours for use by that document. (This colour list is displayed in the ColourBar/ColourGallery via the ColGalDisplayList which references colours held in the ColourList).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
The ColourList also provides a couple of special access methods for determining the number of visible/undeleted colours in the document (deleted colours are still held in this list, but are marked deleted for undo purposes - if scanning the ColourList, remember to check IndexedColours IsDeleted() flag) -- See the Undeleted list operators provided by this class to save you loads of effort.

The Colour list also includes another simple List of unnamed colours which are used for local colour attributes in a document. Unnamed colours are simply stored in this list, and are simpler than named colours...

See also:
IndexedColour; ColGalDisplayList; BaseDocument; List

Definition at line 141 of file collist.h.


Constructor & Destructor Documentation

ColourList::ColourList  ) 
 

ColourList constructor.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/5/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 138 of file collist.cpp.

00139 {
00140     ParentDoc = NULL;               // Document containing this list
00141     ArrayParent = NULL;             // Current parent of the cached array
00142     InheritanceArray = NULL;        // Cached array of all offspring of ArrayParent
00143     LastUnnamedColour = 2;          // Memory to optimise unnamed-colour name generation
00144 }

ColourList::~ColourList  ) 
 

ColourList destructor.

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

Definition at line 162 of file collist.cpp.

00163 {
00164     InvalidateInheritanceCache();   // Release our memory claims
00165 
00166     UnnamedColours.DeleteAll();     // Delete any remaining unnamed colours
00167                                     // This will probably cause IxCol in use errors
00168                                     // as by now all colours should have been deleted
00169                                     // automatically when their usage reached zero.
00170 }


Member Function Documentation

void ColourList::AddHead ListItem ItemToAdd  )  [virtual]
 

Overrides the List::AddHead method to ensure that any added item has a name which is unique within this colour list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/12/94
ERROR3's if the item is not a NAMED IndexedColour

See also:
ColourList::AddItem

Reimplemented from List.

Definition at line 236 of file collist.cpp.

00237 {
00238     ERROR3IF(!IS_A(ItemToAdd, IndexedColour), "You can only insert IndexedColours into ColourLists!");
00239 
00240     IndexedColour *NewColour = (IndexedColour *) ItemToAdd;
00241 
00242     // Ensure the colour has a name which is unique within this colour list
00243     ERROR3IF(!NewColour->IsNamed(), "You can't Insert an unnamed colour before a named one!");
00244 
00245     // It's a named colour, so make sure its name is unique
00246     String_64 NewName;
00247     if (GenerateUniqueColourName(NewColour->GetName(), &NewName))
00248         NewColour->SetName(NewName);
00249 
00250     // And call the base class to add the item
00251     List::AddHead(ItemToAdd);
00252 }

BOOL ColourList::AddItem IndexedColour NewColour  ) 
 

Adds an IndexedColour item to the tail of the ColourList The name of the colour is checked, and may be changed to ensure that it is a unique identifier within the scope of this colour list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/5/94
Returns:
TRUE
This can also be used to add unnamed colours - in this case, they are just added to the list of unnamed colours held by this object.

See also:
ColourList::GenerateUniqueColourName

Definition at line 311 of file collist.cpp.

00312 {
00313     // Ensure the colour has a name which is unique within this colour list
00314     if (!NewColour->IsNamed())
00315     {
00316         UnnamedColours.AddTail(NewColour);
00317         return(TRUE);
00318     }
00319 
00320     // It's a named colour, then...
00321     String_64 NewName;
00322 
00323     if (GenerateUniqueColourName(NewColour->GetName(), &NewName))
00324         NewColour->SetName(NewName);
00325 
00326     // And add it to the tail of the list - using the base class function, not our overrides!
00327     List::AddTail(NewColour);
00328     return(TRUE);
00329 }

void ColourList::AddTail ListItem ItemToAdd  )  [virtual]
 

Overrides the List::AddTail method to ensure that any added item has a name which is unique within this colour list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/12/94
ERROR3's if the item is not a NAMED IndexedColour

See also:
ColourList::AddItem

Reimplemented from List.

Definition at line 272 of file collist.cpp.

00273 {
00274     ERROR3IF(!IS_A(ItemToAdd, IndexedColour), "You can only insert IndexedColours into ColourLists!");
00275 
00276     IndexedColour *NewColour = (IndexedColour *) ItemToAdd;
00277 
00278     // Ensure the colour has a name which is unique within this colour list
00279     ERROR3IF(!NewColour->IsNamed(), "You can't Insert an unnamed colour before a named one!");
00280 
00281     // It's a named colour, so make sure its name is unique
00282     String_64 NewName;
00283     if (GenerateUniqueColourName(NewColour->GetName(), &NewName))
00284         NewColour->SetName(NewName);
00285 
00286     // And call the base class to add the item
00287     List::AddTail(ItemToAdd);
00288 }

IndexedColour ** ColourList::CompileInheritanceArray IndexedColour Parent  ) 
 

Compiles a NULL-terminated array of pointers to ALL colours which are linked to this, both directly and indirectly (i.e. an array listing the entire inheritance 'subtree' from 'Parent', *including* 'Parent', and including named, unnamed, and 'deleted' colours).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/11/94
Parameters:
Parent - The colour for which you want an inheritance array [INPUTS]
Returns:
If NO error occurred, this returns a pointer to a NULL terminated array of IndexedColours, with Array[0] == Parent. If an error did occur, the error is reported, and NULL is returned
This array is cached so that the cost of generating it several times in a row (as may be necessary for different clients of the ColourChangingMsg) is minimised.

Notes: The array is NULL terminated

The array INCLUDES Parent as its first member (Array[0])

The array is owned (allocated and deallocated) by the ColourList. It MUST be treated as a read-only shared array.

The array includes ALL affected indexed colours. Use IsDeleted() and IsNamed() to sort out named/unnamed colours, and deleted (hidden for undo) colours.

This is expected to be called mainly as a result of COLOURUPDATED ColourChangingMsg broadcasts. The cache is flushed automatically by the colour manager just prior to these broadcasts. If you want to use this function outside these message broadcasts, then you must invalidate the cache at an appropriate time.

See also:
ColourList::InvalidateInheritanceCache; IndexedColour::IsADescendantOf; ColourManager::ColourHasChanged

Definition at line 652 of file collist.cpp.

00653 {
00654     if (Parent != ArrayParent)
00655     {
00656         InvalidateInheritanceCache();       // Throw away any existing array
00657 
00658         // Generate the array
00659         INT32 ColourArraySize = 32;
00660         InheritanceArray = (IndexedColour**) CCMalloc(ColourArraySize * sizeof(IndexedColour *));
00661 
00662         if (InheritanceArray == NULL)
00663         {
00664             InformError();                  // Out of memory - inform the user
00665             return(NULL);
00666         }
00667 
00668         INT32 ListEnd = 1;                  // Initialise array to just the Parent
00669         InheritanceArray[0] = Parent;
00670         InheritanceArray[1] = NULL;
00671 
00672         // Do all the Named colours
00673         IndexedColour *Ptr = (IndexedColour *) GetHead();
00674         while (Ptr != NULL)
00675         {
00676             if (Ptr != Parent && Ptr->IsADescendantOf(Parent))
00677             {
00678                 // Is a descendant: add this item to the end of the list
00679                 if (ListEnd >= ColourArraySize - 1)
00680                 {
00681                     // We've filled the array - must increase the size
00682                     ColourArraySize += 32;
00683                     IndexedColour **TempArray = (IndexedColour **) CCRealloc(InheritanceArray,
00684                                                 ColourArraySize * sizeof(IndexedColour *));
00685                     if (TempArray == NULL)
00686                     {
00687                         InvalidateInheritanceCache();   // Free our existing memory claim
00688                         InformError();
00689                         return(NULL);
00690                     }
00691 
00692                     InheritanceArray = TempArray;       // It worked- set our ptr to the new block
00693                 }
00694                 
00695                 InheritanceArray[ListEnd++] = Ptr;      // Add the item and a new NULL terminator
00696                 InheritanceArray[ListEnd] = 0;          // to the end of the list
00697             }
00698 
00699             Ptr = (IndexedColour *) GetNext(Ptr);
00700         }
00701 
00702 
00703         // And likewise with all unnamed colours
00704         IndexedColour *Next;
00705         Ptr = (IndexedColour *) UnnamedColours.GetHead();
00706         while (Ptr != NULL)
00707         {
00708             // Allow for deleting this colour from underneath ourselves
00709             Next = (IndexedColour *) UnnamedColours.GetNext(Ptr);
00710 
00711             if (Ptr->IsInUse())
00712             {
00713                 if (Ptr->IsADescendantOf(Parent))
00714                 {
00715                     // Is a descendant: add this item to the end of the list
00716                     if (ListEnd >= ColourArraySize - 1)
00717                     {
00718                         // We've filled the array - must increase the size
00719                         ColourArraySize += 32;
00720                         IndexedColour **TempArray = (IndexedColour **) CCRealloc(InheritanceArray,
00721                                                     ColourArraySize * sizeof(IndexedColour *));
00722                         if (TempArray == NULL)
00723                         {
00724                             InvalidateInheritanceCache();   // Free our existing memory claim
00725                             InformError();
00726                             return(NULL);
00727                         }
00728 
00729                         InheritanceArray = TempArray;       // It worked- set our ptr to the new block
00730                     }
00731                 
00732                     InheritanceArray[ListEnd++] = Ptr;      // Add the item and a new NULL terminator
00733                     InheritanceArray[ListEnd] = 0;          // to the end of the list
00734                 }
00735             }
00736             else
00737             {
00738                 // We've found an unnamed IndexedColour which is not in use, so we can vape it
00739 TRACEUSER( "Jason", _T("CIA: Deleting unnamed colour which is not in use [%p]\n"), Ptr );
00740 //              UnnamedColours.RemoveItem(Ptr);
00741 //              delete Ptr;
00742             }
00743 
00744             Ptr = Next;
00745         }
00746 
00747 
00748         ArrayParent = Parent;
00749     }
00750 
00751 TRACEUSER( "Jason", _T("\n"));
00752 
00753     return(InheritanceArray);
00754 }

void ColourList::DeleteAll  )  [virtual]
 

Deletes the list, calling the destructors of all ListItems.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/6/96
Notes: Colours are deleted carefully to be tidy with child links (As we're deleting them all this shouldn't matter, but when children of a deleted colour are deleted, they poke its ChildUsage, and Smart Heap chokes itself in dismay. The old smartheap didn't care)

We thus vape all colour linking before deleting the colours. We don't need to be particularly gentle about this because we are deleting them all anyway.

See also:
List::DeleteAll

Reimplemented from List.

Definition at line 458 of file collist.cpp.

00459 {
00460     // Vape all colour linkages in the named colour list
00461     IndexedColour *Ptr = (IndexedColour *) GetHead();
00462     while (Ptr != NULL)
00463     {
00464         Ptr->SetLinkedParent(NULL, COLOURTYPE_NORMAL);
00465         Ptr = (IndexedColour *) GetNext(Ptr);
00466     }
00467 
00468     // And vape all colour linkages in the UNnamed colour list
00469     Ptr = (IndexedColour *) UnnamedColours.GetHead();
00470     while (Ptr != NULL)
00471     {
00472         Ptr->SetLinkedParent(NULL, COLOURTYPE_NORMAL);
00473         Ptr = (IndexedColour *) UnnamedColours.GetNext(Ptr);
00474     }
00475 
00476     // Delete all the unnamed colours now too, just to be tidy
00477     UnnamedColours.DeleteAll();
00478 
00479     // Finally, call the base class to do the actual deletions
00480     List::DeleteAll();
00481 }

IndexedColour * ColourList::FindUndeletedItem INT32  Index  ) 
 

The same as the conventional List FindItem() function, except that it treats 'deleted' colours as if they are not in the list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/6/94
Parameters:
ColourIndex - essentially a LISTPOS of the item in the Palette list [INPUTS]
Returns:
NULL if the index is past the end of the list else a pointer to the referenced IndexedColour ListItem

Definition at line 534 of file collist.cpp.

00535 {
00536     IndexedColour *Ptr = (IndexedColour *) GetHead();
00537 
00538     while (Ptr != NULL)
00539     {
00540         if (!Ptr->IsDeleted() && --Index < 0)
00541             return(Ptr);
00542 
00543         Ptr = (IndexedColour *) GetNext(Ptr);
00544     }
00545 
00546     return(NULL);
00547 }

BOOL ColourList::GenerateUniqueColourName const StringBase pPrefix,
String_64 pResult
 

Scans the entire ColourList to determine if the suggested name is unique within this document. If it is not, the name is altered (currently by truncating to 50 characters and appending a decimal number) to provide a unique name, which is returned in the supplied string.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> (From code by Tim)
Date:
16/12/94 (8/8/94)
Parameters:
pPrefix - Points to the suggested name for this colour. This may be NULL, [INPUTS] in which case a name based on the string "Unnamed" will be generated
pResult - is filled in with a unique name [OUTPUTS] NOTE that this is a String_64, the maximum length for a colour name. If the input pPrefix string is longer than will fit, it will be truncated. If truncation was necessary, this will have no effect on the return value. (IndexedColour::SetName will truncate strings longer than 64 chars as well)
Returns:
TRUE if the pResult contains a different string from that supplied in pPrefix. (pResult will always contain a valid result, but checking this flag may save you the bother of copying the string over)
This method can be called whenever you wish to generate a unique name for a colour. However, note that it is called automatically for every colour which is added to the colour list with the AddItem() method

Notes: Name matching is done using StringBase::IsIdentical, so see that method to determine the rules by which strings are matched

If the colour is unnamed (pPrefix == NULL, *pPrefix is a NULL string, or the name is "Unnamed" (_R(IDS_UNNAMEDCOLOUR)), then the code is optimised to provide a new name for it extra fast.

See also:
ColourList::AddItem; IndexedColour::SetName; StringBase::IsIdentical

Definition at line 1005 of file collist.cpp.

01006 {
01007     if (pResult == NULL)
01008     {
01009         ERROR3("ColourList::GenerateUniqueColourName: pResult is NULL!");
01010         return(FALSE);
01011     }
01012 
01013     if (pPrefix != NULL && !NamedColourExists(pPrefix))
01014     {
01015         // Either the List is empty, or this name is unique, so return it (ensuring < 64 chars)
01016         pPrefix->Left(pResult, 63);
01017         return(FALSE);
01018     }
01019 
01020     // Copy the prefix into this string.
01021     String_64 NewName;
01022     BOOL Unnamed = FALSE;                               // Remember if it is 'unnamed'
01023 
01024     if (pPrefix != NULL)
01025         pPrefix->Left(&NewName, 50);                    // Copy into NewName, truncating
01026 
01027     String_64 NoName(_R(IDS_UNNAMEDCOLOUR));
01028     if ((pPrefix == NULL) || (NewName.Length() == 0))   // Has no name, so call it "Unnamed"
01029     {
01030         Unnamed = TRUE;
01031         NewName = NoName;
01032     }
01033     else if (NewName.IsIdentical(NoName))               // Is called 'Unnamed', so remember that
01034     {
01035         Unnamed = TRUE;
01036     }
01037 
01038     INT32 PrefixLen = NewName.Length();
01039     if (PrefixLen > 50)
01040     {
01041         // Limit prefix length to 50 chars - this means we can add numbers up to
01042         // 10-odd digits long in order to make it unique - should be enough!
01043         PrefixLen = 50;
01044     }
01045 
01046 
01047     TCHAR *pPrefixEnd = (TCHAR *) NewName;
01048     pPrefixEnd += PrefixLen;
01049 
01050     // Is this name ok?
01051     if (!NamedColourExists(NewName))
01052     {
01053         (*pResult) = NewName;               // Yes - return it.
01054         return(TRUE);
01055     }
01056 
01057     // Start adding numbers to make it unique
01058     INT32 i = (Unnamed) ? LastUnnamedColour : 2;
01059 
01060     while (TRUE)
01061     {
01062         // If this doesn't terminate [Tim] will eat [his] Archimedes!
01063         camSnprintf( pPrefixEnd, 64, _T(" %ld"), i++ );
01064 
01065         // Is this name ok?
01066         if (!NamedColourExists(NewName))
01067         {
01068             (*pResult) = NewName;           // Yes - return it
01069 
01070             if (Unnamed)                    // Update unnamed colour generation number
01071                 LastUnnamedColour = i;
01072 
01073             return(TRUE);
01074         }
01075     }
01076 
01077     *pResult = NewName;     // Ensure stable return, though this should never happen
01078     return(TRUE);
01079 }

BaseDocument * ColourList::GetParentDocument void   )  [inline]
 

To find the parent document of this colour list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/11/94
Returns:
The document in which this colour list resides

Definition at line 235 of file collist.h.

00236 {
00237     ERROR3IF(ParentDoc == NULL, "Uninitialised ColourList detected!");
00238     return(ParentDoc);
00239 }

UINT32 ColourList::GetUndeletedCount void   ) 
 

Count the number of non-'deleted' items in a ColourList.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The number of IndexedColours in this ColourList which are not 'deleted' so as to be hidden from view by the undo system.

Definition at line 500 of file collist.cpp.

00501 {
00502     ListItem *Ptr = GetHead();
00503     UINT32 Count = 0;
00504 
00505     while (Ptr != NULL)
00506     {
00507         if ( !((IndexedColour *)Ptr)->IsDeleted() )
00508             Count++;
00509 
00510         Ptr = GetNext(Ptr);
00511     }
00512 
00513     return(Count);
00514 }

IndexedColour * ColourList::GetUndeletedHead void   ) 
 

The same as the conventional List GetHead() function, except that it treats 'deleted' colours as if they are not in the list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/3/95
Returns:
NULL if the list contains no 'live' (non-deleted) colours else a pointer to the first IndexedColour ListItem in the list

Definition at line 566 of file collist.cpp.

00567 {
00568     IndexedColour *Ptr = (IndexedColour *) GetHead();
00569 
00570     while (Ptr != NULL && Ptr->IsDeleted())
00571         Ptr = (IndexedColour *) GetNext(Ptr);
00572 
00573     return(Ptr);
00574 }

IndexedColour * ColourList::GetUndeletedNext IndexedColour ThisItem  ) 
 

The same as the conventional List GetNext() function, except that it treats 'deleted' colours as if they are not in the list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/3/95
Returns:
NULL if the list contains no more 'live' (non-deleted) colours else a pointer to the next 'live' IndexedColour in the list

Definition at line 593 of file collist.cpp.

00594 {
00595     ERROR2IF(ThisItem == NULL, NULL,
00596                 "ColourList::GetUndeletedNext - NULL parameter is illegal");
00597 
00598     IndexedColour *Ptr = (IndexedColour *) GetNext(ThisItem);
00599 
00600     while (Ptr != NULL && Ptr->IsDeleted())
00601         Ptr = (IndexedColour *) GetNext(Ptr);
00602 
00603     return(Ptr);
00604 }

List * ColourList::GetUnnamedColours void   )  [inline]
 

To find the unnamed colours for this document.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/3/95
Returns:
The storage-list containing this document's unnamed colours

Definition at line 254 of file collist.h.

00255 {
00256     return(&UnnamedColours);
00257 }

void ColourList::Init BaseDocument ParentDocument  ) 
 

ColourList initialiser. MUST be called after constructing a ColourList in order to correctly initialise it. Note that if ParentDocument is not set to a useful value, some operations on colour lists (eg. the colour editor) will fail.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/11/94
Parameters:
ParentDocument - the parent document of this colour list [INPUTS]

Definition at line 187 of file collist.cpp.

00188 {
00189     ERROR3IF(ParentDocument == NULL, "NULL ParentDoc in ColourList::Init()");
00190     ParentDoc = ParentDocument;
00191 }

ListItem * ColourList::InsertAfter ListItem here,
ListItem item
[virtual]
 

Inserts the 'newItem' ListItem after 'here' ListItem in the list.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/4/93
Parameters:
ListItem to be inserted [INPUTS] ListItem after insertion
None [OUTPUTS]
Returns:
ListItem inserted NULL if list empty or ListItem not found or parameters are NULL

Errors: In the debug build, this checks that the item you wish to insert after is actually in the list, and that the item you are inserting is not already in the list - an ENSURE failure results if not.

Reimplemented from List.

Definition at line 416 of file collist.cpp.

00417 {
00418     ERROR3IF(!IS_A(item, IndexedColour), "You can only insert IndexedColours into ColourLists!");
00419 
00420     IndexedColour *NewColour = (IndexedColour *) item;
00421 
00422     // Ensure the colour has a name which is unique within this colour list
00423     ERROR3IF(!NewColour->IsNamed(), "You can't Insert an unnamed colour before a named one!");
00424 
00425     // It's a named colour, so make sure its name is unique
00426     String_64 NewName;
00427     if (GenerateUniqueColourName(NewColour->GetName(), &NewName))
00428         NewColour->SetName(NewName);
00429 
00430     // And add it to the tail of the list - using the base class function, not our overrides!
00431     return(List::InsertAfter(here, item));
00432 }

LISTPOS ColourList::InsertAfter LISTPOS  here,
ListItem item
[virtual]
 

Inserts a ListItem in the list position after the one that is passed in. Notes: To find 'here', the list must be scanned, so this is much slower on average than the other flavour of InsertAfter.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/4/93
Parameters:
ListItem to be inserted [INPUTS] List position
None [OUTPUTS]
Returns:
List position new item is inserted at. INVALID_LISTPOS when the list position goes beyond the list size INVALID_NEWITEM when new list item is NULL

Errors: This ALWAYS checks that the item you wish to insert after is actually in the list, and that the item you are inserting is not already in the list - an ENSURE failure results if not.

Reimplemented from List.

Definition at line 398 of file collist.cpp.

00399 {
00400     ERROR3IF(!IS_A(item, IndexedColour), "You can only insert IndexedColours into ColourLists!");
00401 
00402     IndexedColour *NewColour = (IndexedColour *) item;
00403 
00404     // Ensure the colour has a name which is unique within this colour list
00405     ERROR3IF(!NewColour->IsNamed(), "You can't Insert an unnamed colour before a named one!");
00406 
00407     // It's a named colour, so make sure its name is unique
00408     String_64 NewName;
00409     if (GenerateUniqueColourName(NewColour->GetName(), &NewName))
00410         NewColour->SetName(NewName);
00411 
00412     // And add it to the tail of the list - using the base class function, not our overrides!
00413     return(List::InsertAfter(here, item));
00414 }

ListItem * ColourList::InsertBefore ListItem here,
ListItem item
[virtual]
 

Inserts the 'newItem' ListItem before 'here' ListItem in the list.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/4/93
Parameters:
ListItem to be inserted [INPUTS] ListItem before insertion
None [OUTPUTS]
Returns:
ListItem inserted INVALID_NEWITEM when the new item is NULL NULL if list empty or ListItem not found or parameters are NULL

Errors: In the debug build, this checks that the item you wish to insert before is actually in the list, and that the item you are inserting is not already in the list - an ENSURE failure results if not.

Reimplemented from List.

Definition at line 380 of file collist.cpp.

00381 {
00382     ERROR3IF(!IS_A(item, IndexedColour), "You can only insert IndexedColours into ColourLists!");
00383 
00384     IndexedColour *NewColour = (IndexedColour *) item;
00385 
00386     // Ensure the colour has a name which is unique within this colour list
00387     ERROR3IF(!NewColour->IsNamed(), "You can't Insert an unnamed colour before a named one!");
00388 
00389     // It's a named colour, so make sure its name is unique
00390     String_64 NewName;
00391     if (GenerateUniqueColourName(NewColour->GetName(), &NewName))
00392         NewColour->SetName(NewName);
00393 
00394     // And add it to the tail of the list - using the base class function, not our overrides!
00395     return(List::InsertBefore(here, item));
00396 }

LISTPOS ColourList::InsertBefore LISTPOS  here,
ListItem item
[virtual]
 

Inserts a NAMED IndexedColour at a particular list position (See List base class for a further description of the actual insertion process).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/8/95
Parameters:
here - the list item to insert before. NULL is not allowed (List is unhelpful) [INPUTS] item - the item to insert before/after the 'here' item
Returns:
The position/item which was inserted
These methods are a veneer onto the normal list calls, which ensure that all inserted colours are given unique names within this list.

Note: IMPORTANT: NOTE that at present, these are NOT VIRTUAL, so you MUST call them using a ColourList pointer rather than a generic List pointer!

See also:
List; List::InsertBefore; ColourList::GenerateUniqueColourName

Reimplemented from List.

Definition at line 362 of file collist.cpp.

00363 {
00364     ERROR3IF(!IS_A(item, IndexedColour), "You can only insert IndexedColours into ColourLists!");
00365 
00366     IndexedColour *NewColour = (IndexedColour *) item;
00367 
00368     // Ensure the colour has a name which is unique within this colour list
00369     ERROR3IF(!NewColour->IsNamed(), "You can't Insert an unnamed colour before a named one!");
00370 
00371     // It's a named colour, so make sure its name is unique
00372     String_64 NewName;
00373     if (GenerateUniqueColourName(NewColour->GetName(), &NewName))
00374         NewColour->SetName(NewName);
00375 
00376     // And add it to the tail of the list - using the base class function, not our overrides!
00377     return(List::InsertBefore(here, item));
00378 }

void ColourList::InvalidateInheritanceCache void   ) 
 

Deallocates any memory used for the array of IndexedColours compiled by ColourList::CompileInheritanceArray. The next request for such an array will be regenerated from the ColourList, rather than from cache.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/11/94
This is automatically called by the ColourManager immediately prior to a ColourChangingMsg COLOURUPDATED message broadcast.

See also:
ColourList::CompileInheritanceArray

Definition at line 211 of file collist.cpp.

00212 {
00213     if (InheritanceArray != NULL)
00214         CCFree(InheritanceArray);
00215 
00216     InheritanceArray = NULL;
00217     ArrayParent = NULL;
00218 }

BOOL ColourList::IsColourInUseInDoc IndexedColour TheColour,
BOOL  IgnoreColourGallery = FALSE
 

Determine if a colour is used in the parent document. This is similar to IndexedColour::IsInUse(), but it also traverses the linking hierarchy to see if a colour is in use indirectly (e.g. A parent of a colour that is in use is needed for the document even if it is not used directly in document.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/95
Parameters:
TheColour - Points to the colour to check [INPUTS] IgnoreColourGallery - TRUE to ignore usage in the colour gallery. DO NOT USE this parameter. It is a special-case for the colour gallery to use to ignore the usage that that gallery has of the colour.
Returns:
TRUE if the colour is in use in the document
See also:
IndexedColour::IsInUse

Definition at line 859 of file collist.cpp.

00860 {
00861     ERROR3IF(TheColour == NULL, "Illegal NULL param");
00862 
00863     // First, is it directly in-use?
00864     if (TheColour->IsInUse(IgnoreColourGallery))
00865         return(TRUE);
00866 
00867     // Is it a parent of other colours? If not, then it is not in use
00868     if (!TheColour->IsNamed() || !TheColour->HasLinkedChildren())
00869         return(FALSE);
00870 
00871     // It has descendants, so scan the inheritance tree to determine if any of them are in use
00872     // Scan through the named colours (NOTE: We also scan 'deleted' colours, as a parent colour
00873     // may be indirectly in use in the undo record)
00874     IndexedColour *Ptr = (IndexedColour *) GetHead();
00875     while (Ptr != NULL)                                             // For all colours in the list...
00876     {
00877         if (Ptr != TheColour && Ptr->IsADescendantOf(TheColour))    // If this one is a descendant...
00878         {               
00879             if (Ptr->IsInUse(IgnoreColourGallery))                  // and it's in use, then we are
00880                 return(TRUE);                                       // in use, and can return now.
00881         }
00882 
00883         Ptr = (IndexedColour *) GetNext(Ptr);
00884     }
00885 
00886     // And scan through the unnamed colours as well
00887     Ptr = (IndexedColour *) UnnamedColours.GetHead();
00888     while (Ptr != NULL)                                             // For all colours in the list...
00889     {
00890         if (Ptr != TheColour && Ptr->IsADescendantOf(TheColour))    // If this one is a descendant...
00891         {               
00892             if (Ptr->IsInUse())                                     // and it's in use, then we are
00893                 return(TRUE);                                       // in use, and can return now.
00894         }
00895 
00896         Ptr = (IndexedColour *) UnnamedColours.GetNext(Ptr);
00897     }
00898 
00899     // OK, we're obviously not in use then
00900     return(FALSE);  
00901 }

BOOL ColourList::NamedColourExists const StringBase pName  ) 
 

Determine if a colour name is already in use by any colours stored in this colour list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/12/94
Parameters:
pName - the name to look for. [INPUTS]
Returns:
TRUE if the name is already in use; FALSE otherwise.
See also:
ColourList::GenerateUniqueColourName

Definition at line 958 of file collist.cpp.

00959 {
00960     return(NamedColourExists((const TCHAR *)(*pName)));
00961 }

BOOL ColourList::NamedColourExists PCTSTR  pName  ) 
 

Determine if a colour name is already in use by any colours stored in this colour list.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> (Jason copied this code here from colcomp.cpp)
Date:
08/08/94 (19/12/94)
Parameters:
pName - the name to look for. [INPUTS]
Returns:
TRUE if the name is already in use; FALSE otherwise.
See also:
ColourList::GenerateUniqueColourName

Definition at line 920 of file collist.cpp.

00921 {
00922     IndexedColour *pItem = (IndexedColour *) GetHead();
00923 
00924     while (pItem != NULL)
00925     {
00926         if (!pItem->IsDeleted() && pItem->IsNamed() &&
00927             (pItem->GetName()->IsIdentical(pName)) )
00928         {
00929             // The name is the same - it's a match
00930             return(TRUE);
00931         }
00932 
00933         // Try the next colour
00934         pItem = (IndexedColour *) GetNext(pItem);
00935     }
00936 
00937     // No match for this name
00938     return(FALSE);
00939 }

void ColourList::RemoveLinksToColour IndexedColour DeadColour  ) 
 

Scans the entire ColourList for any colours which reference the given IndexedColour. All these colours are converted into standalone representation of their former definition, so that all child-links of this colour are removed. It is then safe to delete the colour.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/94
Parameters:
DeadColour - The colour for which all ParentColour references are to be [INPUTS] removed.
This is done automatically for colours deleted by the HideColours method of the colour manager; however, deletion only occurs for real when the undo record containing the deleted colours is deleted.

NOTE that this does NOT remove the colour from the ColourList It also does NOT delete the colour.

See also:
ColourManager::HideColours

Definition at line 784 of file collist.cpp.

00785 {
00786     // Search through the named colours
00787     IndexedColour *Ptr = (IndexedColour *) GetHead();
00788 
00789     while (Ptr != NULL)                                     // For all colours in the list...
00790     {
00791         if (Ptr->FindLastLinkedParent() == DeadColour)      // If they reference DeadColour...
00792         {               
00793             IndexedColourType TheType = COLOURTYPE_NORMAL;
00794 
00795             if (Ptr->GetType() == COLOURTYPE_SPOT)
00796                 TheType = COLOURTYPE_SPOT;
00797 
00798             Ptr->SetLinkedParent(NULL, TheType);            // Convert to unlinked (normal/spot) colour
00799         }
00800 
00801         Ptr = (IndexedColour *) GetNext(Ptr);
00802     }
00803 
00804 
00805     // And drag through the unnamed colours as well
00806     Ptr = (IndexedColour *) UnnamedColours.GetHead();
00807     IndexedColour *Next;
00808 
00809     while (Ptr != NULL)                                     // For all colours in the list...
00810     {
00811         Next = (IndexedColour *) UnnamedColours.GetNext(Ptr);
00812         if (Ptr->FindLastLinkedParent() == DeadColour)      // If they reference DeadColour...
00813         {               
00814             IndexedColourType TheType = COLOURTYPE_NORMAL;
00815 
00816             if (Ptr->GetType() == COLOURTYPE_SPOT)
00817                 TheType = COLOURTYPE_SPOT;
00818 
00819             Ptr->SetLinkedParent(NULL, TheType);            // Convert to unlinked (normal/spot) colour
00820         }
00821 // This could be dangerous - what if the deleted colour is in the inheritance array?
00822 //      if (!Ptr->IsInUse())
00823 //      {
00824 //          // We've found an unnamed colour which is not in use - we can vape it
00825 //TRACEUSER( "Jason", _T("RLTC: Deleting unnamed colour which is not in use [%x]\n"), (INT32)Ptr);
00826 //          UnnamedColours.RemoveItem(Ptr);
00827 //          delete Ptr;
00828 //      }
00829 
00830         Ptr = Next;
00831     }
00832 }


Member Data Documentation

IndexedColour* ColourList::ArrayParent [private]
 

Definition at line 200 of file collist.h.

IndexedColour** ColourList::InheritanceArray [private]
 

Definition at line 201 of file collist.h.

INT32 ColourList::LastUnnamedColour [private]
 

Definition at line 213 of file collist.h.

BaseDocument* ColourList::ParentDoc [private]
 

Definition at line 181 of file collist.h.

List ColourList::UnnamedColours [private]
 

Definition at line 219 of file collist.h.


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