OpHideColours Class Reference

#include <colormgr.h>

Inheritance diagram for OpHideColours:

UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpHideColours ()
 OpHideColours constructor (Creates an undoable operation).
void Do (OpDescriptor *)
 (Performs the colour change operation) OpHideColours has a special overloaded Do operator which takes parameters describing what is to be done - that version of Do must be used
void DoWithParam (OpDescriptor *, OpParam *Param)
 Performs the colour change operation, as described by 'Param'.
virtual BOOL Undo ()
 Undoes whatever Do() or Redo() did.
virtual BOOL Redo ()
 Redoes whatever Undo() undid.
virtual void GetOpName (String_256 *)
 Redoes whatever Undo() undid.

Static Public Member Functions

static BOOL Init ()
 OpHideColours initialiser method.
static OpState GetState (String_256 *, OpDescriptor *)
 For finding the OpHideColours' state.

Private Member Functions

NodeAttributeHideAttrNode (Node *CurNode, DocColour *TheColour)
 Checks if the given colour references an IndexedColour in the given NULL terminated list of colours. If this is the case, then the node containing the colour attribute is hidden and replaced with a clone of itself. This clone is returned, so that the caller can then change the contained DocColour(s) appropriately.
void KillColourRef (DocColour *Perpetrator, IndexedColourPtr *ColourMap)
 If the given DocColour refers to an IndexedColour, it is redefined as a Local colour based on the IndexedColour's definition.
void HideColourRefs (void)
 Traverses the entire Camelot tree and replaces all references to indexed colours with immediate DocColour equivalents. The original attributes are hidden to allow undo.
void RemoveColour (DocColour *Ref, INT32 *LastColour)
 Removes the indexedcolour (if any) referenced by the given DocColour from the 'Colours' list of colours-to-delete.
void RemoveReferencedColours (void)
 Traverses the entire Camelot tree and removes all IndexedColours that are referenced therein from our list of colours-to-delete.

Private Attributes

IndexedColour ** Colours
ColourListParentColList
BOOL HideThem

Detailed Description

Definition at line 308 of file colormgr.h.


Constructor & Destructor Documentation

OpHideColours::OpHideColours  ) 
 

OpHideColours constructor (Creates an undoable operation).

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

Errors: -

See also:
-

Definition at line 2186 of file colormgr.cpp.

02186                             : UndoableOperation()                               
02187 {                              
02188     Colours = NULL;     // For safety, ensure initialised
02189     ParentColList = NULL;
02190     HideThem = TRUE;
02191 }


Member Function Documentation

void OpHideColours::Do OpDescriptor NotUsed  )  [virtual]
 

(Performs the colour change operation) OpHideColours has a special overloaded Do operator which takes parameters describing what is to be done - that version of Do must be used

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

Errors: Always generates an ENSURE failure because this Do doesn't.

See also:
-

Reimplemented from Operation.

Definition at line 2281 of file colormgr.cpp.

02282 {
02283     ERROR3("OpHideColours does not provide a Do() function - use DoWithParam");
02284     End();
02285 }

void OpHideColours::DoWithParam OpDescriptor pOp,
OpParam Param
[virtual]
 

Performs the colour change operation, as described by 'Param'.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/6/94
Parameters:
pOp - OpDescriptor as for all Do() functions [INPUTS] Param - Actually points to a HideColoursInfo structure, detailing what to hide/unhide, and how to do it.
- [OUTPUTS]
Returns:
-

Reimplemented from Operation.

Definition at line 2304 of file colormgr.cpp.

02305 {
02306     HideColoursInfo *WhatToDo = (HideColoursInfo *) Param;
02307     // If Forced-delete is desired, then ensure that all DocColours referencing
02308     // any of our list of IndexedColours are forced to 'immediate' definitions
02309 
02310     // Make sure that this operation is applied within the document which owns the colour list!
02311     pOurDoc = (Document *) WhatToDo->ParentList->GetParentDocument();
02312     pOurView = NULL;
02313     if (!pOurDoc->IsKindOf(CC_RUNTIME_CLASS(Document)))
02314     {
02315         pOurDoc = NULL;     // Arrrgh! It must be a basedoc or something!
02316         End();
02317         return;
02318     }
02319 
02320     ParentColList = WhatToDo->ParentList;
02321     Colours  = WhatToDo->Colours;
02322     HideThem = WhatToDo->HideThem;
02323 
02324     if (HideThem)
02325     {
02326         if (WhatToDo->ForceDelete)
02327             HideColourRefs();
02328         else
02329             RemoveReferencedColours();
02330     }
02331 
02332     if (Colours[0] == NULL)
02333     {
02334         End();
02335         return;
02336     }
02337 
02338     // Create an action to undo the IndexedColour hide operation, and if we 
02339     // succeed, then {un}hide the colours (Do) and inform the world of the change
02340     ActionHideColours *AHC;
02341     if (ActionHideColours::Init(this, &UndoActions, sizeof(ActionHideColours),
02342                             WhatToDo->ParentList, WhatToDo->Colours,
02343                             ((WhatToDo->HideThem) ? FALSE : TRUE),
02344                             (Action**)(&AHC)) == AC_OK)
02345     {
02346         // Now, hide/unhide all the colours remaining in the list
02347         INT32 Index = 0;
02348         while (WhatToDo->Colours[Index] != NULL)
02349         {
02350             WhatToDo->Colours[Index]->SetDeleted(WhatToDo->HideThem);
02351             Index++;
02352         }
02353 
02354         // We have made the change, so broadcast that the list for this doc has changed
02355         ColourManager::ColourListHasChanged(ParentColList);
02356     }
02357 
02358     End();
02359 }

void OpHideColours::GetOpName String_256 Result  )  [virtual]
 

Redoes whatever Undo() undid.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/6/94
Parameters:
Result - returned filled-in with the name [OUTPUTS]
Returns:
-

Reimplemented from Operation.

Definition at line 2430 of file colormgr.cpp.

02431 {
02432     ERROR3IF(Result == NULL, "Illegal null param");
02433 
02434     if (HideThem)
02435         Result->MakeMsg(_R(IDS_DELETECOLOURS));
02436     else
02437         Result->MakeMsg(_R(IDS_CREATECOLOURS));
02438 }

OpState OpHideColours::GetState String_256 UIDescription,
OpDescriptor
[static]
 

For finding the OpHideColours' state.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The state of the OpHideColours operation

Definition at line 2255 of file colormgr.cpp.

02256 {
02257     OpState OpSt;
02258     return(OpSt);
02259 }

NodeAttribute * OpHideColours::HideAttrNode Node CurNode,
DocColour TheColour
[private]
 

Checks if the given colour references an IndexedColour in the given NULL terminated list of colours. If this is the case, then the node containing the colour attribute is hidden and replaced with a clone of itself. This clone is returned, so that the caller can then change the contained DocColour(s) appropriately.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/6/94
Parameters:
CurNode - The Attribute node containing the colour [INPUTS] TheColour - the colour in the node which we may want to hide
- [OUTPUTS]
Returns:
NULL, or the cloned node.

Definition at line 2460 of file colormgr.cpp.

02461 {
02462     IndexedColour *ParentCol = TheColour->FindParentIndexedColour();
02463 
02464     if (ParentCol != NULL)
02465     {
02466         INT32 i = 0;
02467         while (Colours[i] != NULL && Colours[i] != ParentCol)
02468             i++;
02469 
02470         if (Colours[i] != ParentCol)
02471             return(NULL);
02472         
02473         Node *ParentNode = CurNode->FindParent();
02474         NodeAttribute *NodeToClone = (NodeAttribute *) CurNode;
02475         NodeAttribute *Clone;
02476 
02477         ALLOC_WITH_FAIL(Clone, ((NodeAttribute *)NodeToClone->SimpleCopy()), this);
02478         if (Clone != NULL)
02479         {
02480             // Hide the original Attribute
02481             DoHideNode(CurNode, TRUE);
02482 
02483             // Add the clone into the tree
02484             Clone->AttachNode(ParentNode, FIRSTCHILD);
02485             HideNodeAction* TheUndoAction; 
02486 
02487             // Create an action to hide the attribute when we undo
02488             if (HideNodeAction::Init(this, &UndoActions, Clone, TRUE,
02489                                      (Action**)(&TheUndoAction)) == AC_FAIL)
02490             {   
02491                 Clone->CascadeDelete();     // Delink the node/subtree from the
02492                 delete Clone;               // document tree and delete it
02493             }
02494             else
02495                 return(Clone);
02496         }
02497     }
02498 
02499     return(NULL);
02500 }

void OpHideColours::HideColourRefs void   )  [private]
 

Traverses the entire Camelot tree and replaces all references to indexed colours with immediate DocColour equivalents. The original attributes are hidden to allow undo.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/6/94

Definition at line 2623 of file colormgr.cpp.

02624 {
02625     INT32 NumCols = 0;
02626 
02627     while (Colours[NumCols] != NULL)        // Find the last colour in the list
02628         NumCols++;
02629 
02630 
02631     IndexedColourPtr *ColourMap;
02632     ALLOC_WITH_FAIL(ColourMap, new IndexedColourPtr[NumCols+1], this);
02633 
02634     // If ALLOC_WITH_FAIL fails, we back down to making the colours immediate DocColours
02635     // rather than failing completely.
02636 
02637     // Clear the array to all NULL pointers
02638     if (ColourMap != NULL)
02639     {
02640         for (INT32 i = 0; i <= NumCols; i++)
02641             ColourMap[i] = NULL;
02642     }
02643 
02644 
02645     Node *CurNode = Node::DocFindFirstDepthFirst(GetWorkingDoc());
02646     Node *NextNode;
02647     Node *NewNode;
02648 
02649     while (CurNode != NULL)
02650     {
02651         // We may be about to chop this node out of the tree, so get the next node now
02652         NextNode = CurNode->DocFindNextDepthFirst();
02653     
02654         NewNode = NULL;
02655 
02656         // Use to scan the colour fields of the attribute.
02657         UINT32 Context = 0;
02658         DocColour *pColour;
02659 
02660         if (CurNode->IsAnAttribute())
02661         {
02662             NodeAttribute *pNodeAttr = (NodeAttribute *) CurNode;
02663     
02664             do
02665             {
02666                 // Get the next colour field from the attribute
02667                 pColour = pNodeAttr->EnumerateColourFields(Context++);
02668 
02669                 // If there is another colour field, see if we need to hide it
02670                 if (pColour != NULL && pColour->FindParentIndexedColour() != NULL)
02671                     NewNode = HideAttrNode(CurNode, pColour);
02672             } 
02673             while ((NewNode == NULL) && (pColour != NULL));
02674                 // Keep going until we run out of colour fields, or we find one
02675                 // that requires the node to be hidden
02676 
02677 
02678             if (NewNode != NULL)
02679             {
02680                 // Forcibly change the NewNode DocColours to be local
02681                 pNodeAttr = (NodeAttribute *) NewNode;
02682                 Context = 0;    // Start at the first colour field again
02683 
02684                 do
02685                 {
02686                     // Get the next colour field from the attribute
02687                     pColour = pNodeAttr->EnumerateColourFields(Context++);
02688 
02689                     // If there is another colour, kill its reference, if any
02690                     if (pColour != NULL)
02691                         KillColourRef(pColour, ColourMap);
02692                 } while (pColour != NULL);
02693             }
02694 
02695         }   // end if
02696 
02697         CurNode = NextNode;
02698     }   // end while
02699 
02700     // And get rid of our working array
02701     delete [] ColourMap;
02702 } 

BOOL OpHideColours::Init void   )  [static]
 

OpHideColours initialiser method.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the operation could be successfully initialised FALSE if no more memory could be allocated
Notes: This provides TWO OpDescriptors (Hide colours and Show colours). The same actual Op is invoked for both hiding and showing colours, but it is invoked via different op descriptors, to provide different names for the undo ("undo delete colours" or "undo create colours")

Reimplemented from SimpleCCObject.

Definition at line 2216 of file colormgr.cpp.

02217 {
02218     BOOL Result = RegisterOpDescriptor(0,
02219                                  _R(IDS_OPHIDECOLOURS),
02220                                  CC_RUNTIME_CLASS(OpHideColours),
02221                                  OPTOKEN_HIDECOLOURS,
02222                                  OpHideColours::GetState,
02223                                  0, /* help ID */
02224                                  0, /* Bubble help ID */
02225                                  0  /* bitmap ID */
02226                                 );
02227     if (Result)
02228         Result = RegisterOpDescriptor(0,
02229                                  _R(IDS_OPSHOWCOLOURS),
02230                                  CC_RUNTIME_CLASS(OpHideColours),
02231                                  OPTOKEN_SHOWCOLOURS,
02232                                  OpHideColours::GetState,
02233                                  0, /* help ID */
02234                                  0, /* Bubble help ID */
02235                                  0  /* bitmap ID */
02236                                 );
02237     return(Result);
02238 }

void OpHideColours::KillColourRef DocColour Perpetrator,
IndexedColourPtr ColourMap
[private]
 

If the given DocColour refers to an IndexedColour, it is redefined as a Local colour based on the IndexedColour's definition.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/6/94
Parameters:
Perpetrator - The DocColour to be neutered [INPUTS]
ColourMap - NULL, or an array of IndexedColour pointers which map Colours[] into new local colour pointers. If the mapping entry is NULL, a mapping is set up, else the existing mapping is used. If ColourMap is NULL or memory cannot be allocated for the new mapping, this method will revert to making the colours immediate DocColours (which means it'll work in a falback mode)

This releases the DocColour's claim on the IxCol, thus allowing the latter to be deleted. Used for forced-delete

A new local colour is created (if necessary) and placed in the colour map entry corresponding to the index of the source colour in Colours[]. This is used for look-up, so that many colours using the same colour style can share the same resulting local colour definition, saving gobs of memory.

Scope: private

Definition at line 2535 of file colormgr.cpp.

02536 {
02537     IndexedColour *Parent = Perpetrator->FindParentIndexedColour();
02538 
02539     if (Parent == NULL)
02540         return;
02541 
02542     INT32 i = 0;
02543     if (ColourMap != NULL)
02544     {
02545         // Find the colour map entry index
02546         while (Colours[i] != NULL && Colours[i] != Parent)
02547             i++;
02548 
02549         // If there is no mapping yet, create a new local colour to map to this Parent colour
02550         if (Colours[i] != NULL && ColourMap != NULL && ColourMap[i] == NULL)
02551         {
02552             ColourMap[i] = new IndexedColour(*(Colours[i]));
02553             if (ColourMap[i] != NULL)
02554             {
02555                 ColourMap[i]->SetUnnamed(); // Ensure it's unnamed
02556 
02557                 ERROR3IF(GetWorkingDoc() == NULL, "NULL working doc in OpHideColours");
02558 
02559                 // Add the local colour to the unnamed colour list
02560                 // (A nasty sequence of derefs, but these are all guaranteed to work)
02561                 GetWorkingDoc()->GetIndexedColours()->GetUnnamedColours()->AddTail(ColourMap[i]);
02562 
02563                 // Make sure the new local colour is legal (if its parent is deleted or is
02564                 // just about to become deleted, then we must make the new colour stand-alone.
02565                 // (In the case of undo, we needen't worry about being able to restore the
02566                 // parent link, because the undo will also hide this attribute and return to
02567                 // the original one which references the old parent-colour chain)
02568                 IndexedColour *LinkedParent = ColourMap[i]->FindLinkedParent();
02569 
02570                 if (LinkedParent != NULL)
02571                 {
02572                     // Is the parent already deleted?
02573                     BOOL MustMakeStandalone = LinkedParent->IsDeleted();
02574 
02575                     // If not, is it one of the colours we are currently deleting?
02576                     if (!MustMakeStandalone)
02577                     {
02578                         INT32 j = 0;
02579                         while (Colours[j] != NULL && Colours[j] != LinkedParent)
02580                             j++;
02581 
02582                         if (Colours[j] != NULL)     // LinkedParent is in our list to be deleted!
02583                             MustMakeStandalone = TRUE;
02584                     }
02585 
02586                     // It's parent is dodgy, so make it stand-alone
02587                     if (MustMakeStandalone)
02588                         ColourMap[i]->SetLinkedParent(NULL, COLOURTYPE_NORMAL);
02589                 }
02590             }
02591         }
02592     }
02593 
02594     if (ColourMap != NULL && Colours[i] != NULL && ColourMap[i] != NULL)
02595     {
02596         // We have a mapping - change the colour to reference the relevant local colour
02597         Perpetrator->MakeRefToIndexedColour(ColourMap[i]);
02598     }
02599     else
02600     {
02601         // Serious failure - make the DocColour immediate
02602         ColourGeneric Bob;
02603 
02604         Parent->GetSourceColour(&Bob);
02605         *Perpetrator = DocColour(Parent->GetColourModel(), &Bob);
02606     }
02607 }

BOOL OpHideColours::Redo  )  [virtual]
 

Redoes whatever Undo() undid.

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

Reimplemented from Operation.

Definition at line 2403 of file colormgr.cpp.

02404 {
02405     BOOL Result = Operation::Redo();
02406     if (Result)
02407     {
02408         // We have made the change, so broadcast that the list for this doc has changed
02409         ColourManager::ColourListHasChanged(ParentColList);
02410     }
02411 
02412     return (Result);
02413 }

void OpHideColours::RemoveColour DocColour Ref,
INT32 *  LastColour
[private]
 

Removes the indexedcolour (if any) referenced by the given DocColour from the 'Colours' list of colours-to-delete.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-
Notes: This assumes that any given colour will only appear in the list once It shifts all colours down by one place, as it is essential that the list ordering is retained.
Returns:
Errors: -
See also:
-

Definition at line 2726 of file colormgr.cpp.

02727 {
02728     IndexedColour *Col = Ref->FindParentIndexedColour();
02729     
02730     if (Col == NULL)                            // No colour referenced
02731         return;
02732 
02733     INT32 i;
02734     for (i = 0; i <= *LastColour; i++)      // Search for colour to delete
02735     {
02736         if (Col == Colours[i])
02737             break;
02738     }
02739 
02740     if (Col == Colours[i])                      // We found something to delete
02741     {
02742         while (i < *LastColour)                 // Shift remaining list down one place
02743         {
02744             Colours[i] = Colours[i+1];
02745             i++;
02746         }
02747 
02748         Colours[*LastColour] = NULL;            // Add new NULL terminator
02749         (*LastColour)--;                        // Decrement LastColour index
02750     }
02751 }

void OpHideColours::RemoveReferencedColours void   )  [private]
 

Traverses the entire Camelot tree and removes all IndexedColours that are referenced therein from our list of colours-to-delete.

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

Errors: -

See also:
-

Definition at line 2771 of file colormgr.cpp.

02772 {
02773     INT32 LastColour = 0;
02774 
02775     while (Colours[LastColour] != NULL)     // Find the last colour in the list
02776         LastColour++;
02777 
02778     if ((--LastColour) < 0)
02779         return;
02780 
02781     // Search the entire tree, removing all IndexedColours (from the WhatToDo
02782     // list) which are still in use in live parts of the tree. These cannot
02783     // be deleted, and so should be removed from further consideration
02784     ERROR3IF(GetWorkingDoc() == NULL, "OpHideColours called with NULL Document");
02785     
02786     Node *CurNode = GetWorkingDoc()->GetFirstNode();
02787     Node *NextNode;
02788     while (CurNode != NULL)
02789     {
02790         // Have to remember this now, as we may be about to chop this node out of the tree!
02791         NextNode = CurNode->DocFindNextDepthFirst();
02792 
02793         if (CurNode->IsAnAttribute())
02794         {
02795             // These variables are used to scan the colour fields in the attribute.
02796             NodeAttribute *pNodeAttr = (NodeAttribute *) CurNode;
02797             DocColour *pColour;
02798             UINT32 Context = 0;
02799 
02800             do
02801             {
02802                 // Get the next colour field from the attribute
02803                 pColour = pNodeAttr->EnumerateColourFields(Context++);
02804 
02805                 // If there is another colour field, see if we need to hide it.
02806                 if (pColour != NULL)
02807                     RemoveColour(pColour, &LastColour);
02808             } 
02809             // Keep going until we run out of colour fields
02810             while (pColour != NULL);
02811         }
02812 
02813         CurNode = NextNode;
02814     }
02815 }

BOOL OpHideColours::Undo  )  [virtual]
 

Undoes whatever Do() or Redo() did.

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

Reimplemented from Operation.

Definition at line 2376 of file colormgr.cpp.

02377 {
02378     BOOL Result = Operation::Undo();
02379     if (Result)
02380     {
02381         // We have made the change, so broadcast that the list for this doc has changed
02382         ColourManager::ColourListHasChanged(ParentColList);
02383     }
02384 
02385     return (Result); 
02386 }       


Member Data Documentation

IndexedColour** OpHideColours::Colours [private]
 

Definition at line 325 of file colormgr.h.

BOOL OpHideColours::HideThem [private]
 

Definition at line 327 of file colormgr.h.

ColourList* OpHideColours::ParentColList [private]
 

Definition at line 326 of file colormgr.h.


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