OpMakeColourLocalToFrame Class Reference

Operation to create copy of a colour (and its descendants) for the current frame. More...

#include <coldlog.h>

Inheritance diagram for OpMakeColourLocalToFrame:

UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpMakeColourLocalToFrame ()
 OpMakeColourLocalToFrame constructor (Creates an undoable operation).
 ~OpMakeColourLocalToFrame ()
 OpMakeColourLocalToFrame destructor.
void Do (OpDescriptor *)
 OpMakeColourLocalToFrame has a special overloaded DoWithParam operator which takes parameters describing what is to be done - that version of Do must be used.
void DoWithParam (OpDescriptor *, OpParam *)
 Performs the Make colour local to frame operation, which makes copies of Target and all the children of it and replaces the references to them with references to the copies, but only on the active frame.
virtual void PerformMergeProcessing ()
 Called during EndOp to perform merging with the previous operation.
virtual BOOL Undo ()
 Undoes whatever Do() or Redo() did.
virtual BOOL Redo ()
 Redoes whatever Undo() undid.

Static Public Member Functions

static BOOL Init ()
 Declares a preference that allows you to clear memory in delete().
static OpState GetState (String_256 *, OpDescriptor *)
 For finding the OpMakeColourLocalToFrame's state.

Protected Member Functions

BOOL ReplaceColourOnActiveLayer (IndexedColour *pOld, IndexedColour *pNew)
 Replaces all the references to pOld with references to pNew on the active frame.
BOOL IsColourLocalToFrame (Layer *pTheLayer, IndexedColour *pCol)
IndexedColourMakeColourLocalToFrame (IndexedColour *pCol)
 Creates a new colour, which is a copy of the pCol. The name of the new colour is <FrameName> (<ColourName>), where FrameName is the name of the active frame, and ColurName is the name of pCol. ReplaceColourOnActiveLayer is called to replace pCol with the new copy on the active frame. Afterthat the colour list for the current document is to find all the children of this colour and this function is recursivelly called for them.

Protected Attributes

ColourListParentList
DocumentpOurDoc
LayerpActiveLayer
ColourListComponentColComp
Operationm_pPreviousOp

Detailed Description

Operation to create copy of a colour (and its descendants) for the current frame.

Author:
Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/7/97

Definition at line 652 of file coldlog.h.


Constructor & Destructor Documentation

OpMakeColourLocalToFrame::OpMakeColourLocalToFrame  ) 
 

OpMakeColourLocalToFrame constructor (Creates an undoable operation).

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

Errors: -

See also:
-

Definition at line 11069 of file coldlog.cpp.

11069                                                    : UndoableOperation()
11070 {
11071 }

OpMakeColourLocalToFrame::~OpMakeColourLocalToFrame  ) 
 

OpMakeColourLocalToFrame destructor.

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

Errors: -

See also:
-

Definition at line 11090 of file coldlog.cpp.

11091 {
11092 }


Member Function Documentation

void OpMakeColourLocalToFrame::Do OpDescriptor NotUsed  )  [virtual]
 

OpMakeColourLocalToFrame has a special overloaded DoWithParam operator which takes parameters describing what is to be done - that version of Do must be used.

Author:
Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/7/97
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 11226 of file coldlog.cpp.

11227 {
11228     ENSURE(FALSE, "OpMakeColourLocalToFrame does not provide a Do() function - Use DoWithParam");
11229     End();
11230 }

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

Performs the Make colour local to frame operation, which makes copies of Target and all the children of it and replaces the references to them with references to the copies, but only on the active frame.

Author:
Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/7/97
Parameters:
pOp - OpDescriptor as for all Do() functions [INPUTS] Param - points to a ColourChangeInfo structure with parameters: ParentList - The List in which the colours reside Target - The colour to be changed NewDefn - The returned copy of Target InvisibleChange - unused colour - unused
- [OUTPUTS]
Returns:
-

Reimplemented from Operation.

Definition at line 11255 of file coldlog.cpp.

11256 {
11257     // get our info from the operation parameter
11258     ColourChangeInfo *Info = (ColourChangeInfo *) Param;
11259 
11260     // Set our scope variables
11261     pOurDoc = (Document *)Info->ParentList->GetParentDocument();
11262     pOurView = NULL;
11263     if (!pOurDoc->IsKindOf(CC_RUNTIME_CLASS(Document)))
11264     {
11265         pOurDoc = NULL;     // Arrrgh! It must be a basedoc or something!
11266         End();
11267         return;
11268     }
11269     
11270     // remember the previous operation
11271     OperationHistory* pOpHist = &GetWorkingDoc()->GetOpHistory();
11272     if (pOpHist == NULL)
11273         m_pPreviousOp = NULL;
11274     else
11275         m_pPreviousOp = pOpHist->FindLastOp();
11276     
11277     // Get the colour list component
11278     ColComp = (ColourListComponent *)
11279                 pOurDoc->GetDocComponent(CC_RUNTIME_CLASS(ColourListComponent));
11280 
11281     // Start the copy
11282     if (ColComp != NULL && ColComp->StartComponentCopy())
11283     {
11284     
11285         // get the parent list
11286         ParentList = Info->ParentList;
11287 
11288         // get the spread
11289         Spread *pSpread = pOurDoc->GetSelectedSpread();
11290         if (pSpread != NULL)
11291         {
11292             // find the active layer
11293             pActiveLayer = pSpread->FindActiveLayer();
11294             if (pActiveLayer != NULL)
11295             {
11296                 // do the work
11297                 Info->NewDefn = MakeColourLocalToFrame(Info->Target);
11298             }
11299         }
11300 
11301         // And clean up, merging the new colours into the document's colour list
11302         ColComp->EndComponentCopy(NULL, FALSE);
11303     }
11304 
11305     End();
11306 }

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

For finding the OpMakeColourLocalToFrame's state.

Author:
Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/7/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The state of the OpMakeColourLocalToFrame operation

Definition at line 11141 of file coldlog.cpp.

11142 {
11143     OpState OpSt;
11144     return(OpSt);
11145 }

BOOL OpMakeColourLocalToFrame::Init void   )  [static]
 

Declares a preference that allows you to clear memory in delete().

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/4/94
Returns:
TRUE if it worked OK, FALSE if not

Reimplemented from SimpleCCObject.

Definition at line 11112 of file coldlog.cpp.

11113 {
11114     return (RegisterOpDescriptor(
11115                                     0,
11116                                     _R(IDS_MAKECOLOURLOCALTOFRAMEOP),
11117                                     CC_RUNTIME_CLASS(OpMakeColourLocalToFrame),
11118                                     OPTOKEN_MAKECOLOURLOCALTOFRAME,
11119                                     OpMakeColourLocalToFrame::GetState,
11120                                     0,  /* help ID */
11121                                     0,  /* Bubble help ID */
11122                                     0   /* bitmap ID */
11123                                 ));
11124 }

BOOL OpMakeColourLocalToFrame::IsColourLocalToFrame Layer pTheLayer,
IndexedColour pCol
[protected]
 

IndexedColour * OpMakeColourLocalToFrame::MakeColourLocalToFrame IndexedColour pCol  )  [protected]
 

Creates a new colour, which is a copy of the pCol. The name of the new colour is <FrameName> (<ColourName>), where FrameName is the name of the active frame, and ColurName is the name of pCol. ReplaceColourOnActiveLayer is called to replace pCol with the new copy on the active frame. Afterthat the colour list for the current document is to find all the children of this colour and this function is recursivelly called for them.

Author:
Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/7/97
Parameters:
pCol - pointer to an indexed colour [INPUTS]
- [OUTPUTS]
Returns:
The created copy of pCol, local to the active frame

Definition at line 11524 of file coldlog.cpp.

11525 {
11526     // sanity check
11527     if ((pActiveLayer == NULL) || (pCol == NULL))
11528         return NULL;
11529 
11530     // generate the name for the new colour
11531     String_256 DefName;
11532 
11533     // get the layer name
11534     DefName = pActiveLayer->GetLayerID();
11535 
11536     // add the name of the colour
11537     DefName += _T(" (");
11538     DefName += (TCHAR *)(*(pCol->GetName()));
11539     DefName += _T(")");
11540 
11541     String_64 OrigName;
11542     String_64 NewName;
11543 
11544     // use the first 63 chars only
11545     DefName.Left(&OrigName, 63);
11546 
11547     // ask for a unique name
11548     ParentList->GenerateUniqueColourName(&OrigName, &NewName);
11549 
11550     // create a copy of the original colour
11551     IndexedColour *Copy = new IndexedColour(*pCol); // make a copy of current
11552     if (Copy == NULL)
11553         return NULL;
11554 
11555     // set the new name
11556     Copy->SetName(NewName);
11557 
11558     //Add the colour to the document
11559     // Copy the colour into the destination document (merging it with existing
11560     // colours so we won't keep creating new copies of the same colour as it's applied)
11561     DocColour ColourToApply;
11562     ColourToApply.MakeRefToIndexedColour(Copy);
11563     ColComp->CopyColourAcross(&ColourToApply, TRUE);
11564 
11565     delete Copy; // delete the temp copy
11566     
11567     // get the new colour (now part of the document colours)
11568     Copy = ColourToApply.FindParentIndexedColour();
11569 
11570     // Replace the references of the original colour with the new colour in the active layer
11571     ReplaceColourOnActiveLayer(pCol, Copy);
11572 
11573     // now create local copies for all the children
11574 
11575     // scan the listto find all the children
11576     IndexedColour *C = ParentList->GetUndeletedHead();
11577     while (C != NULL)
11578     {
11579         // a child found
11580         if ((C->FindLinkedParent() == pCol) && (C->IsDeleted() == FALSE))
11581         {
11582             // make local copy (recursive call)
11583             IndexedColour *pResult = MakeColourLocalToFrame(C);
11584 
11585             // set the new parent to it
11586             if (pResult != NULL)
11587                 pResult->SetLinkedParent(Copy, C->GetType());
11588         }
11589 
11590         // go to the next colour in the list
11591         C = ParentList->GetUndeletedNext(C);
11592     }
11593 
11594     return Copy;
11595 }

void OpMakeColourLocalToFrame::PerformMergeProcessing void   )  [virtual]
 

Called during EndOp to perform merging with the previous operation.

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

Reimplemented from UndoableOperation.

Definition at line 11162 of file coldlog.cpp.

11163 {
11164     // Obtain a pointer to the operation history for the operation's document
11165     OperationHistory* pOpHist = &GetWorkingDoc()->GetOpHistory();
11166     if (pOpHist == NULL)
11167     {
11168         ERROR3("There's no OpHistory!?");
11169         return;
11170     }
11171 
11172     // Ensure that we are the last operation added to the operation history
11173     if (pOpHist->FindLastOp() != this)
11174     {
11175         ERROR3("Last Op should be this op");
11176         return;
11177     }
11178     
11179     // obtain a pointer to the previous operation
11180     Operation* pPrevOp = pOpHist->FindPrevToLastOp();
11181 
11182     // do the merging only if we have a previous op, different then the operation before 
11183     // us in the history list at the start of this operation, and that operation
11184     // is a OpHideColours operation
11185     if ((pPrevOp != NULL) && (pPrevOp != m_pPreviousOp) && IS_A(pPrevOp, OpHideColours))
11186     {   
11187         // Copy all the actions from us to the end of the action list in the previous op.
11188         ActionList* pPrevActions = pPrevOp->GetUndoActionList();
11189         ActionList* pPrevOtherActions = pPrevOp->GetRedoActionList();
11190         if ((pPrevActions == NULL) || (pPrevOtherActions == NULL))
11191         {
11192             ERROR3("Previous actions list pointer was NULL");
11193             return;
11194         }
11195 
11196         // Copy actions across
11197         Action* pCurrentAction = (Action*)pPrevActions->RemoveHead();
11198         while (pCurrentAction != NULL)
11199         {
11200             pCurrentAction->TransferToOtherOp(this, &UndoActions, &RedoActions);
11201             pCurrentAction = (Action*)pPrevActions->RemoveHead();
11202         }
11203 
11204         // And remove the previous operation
11205         pOpHist->DeletePrevToLastOp(); 
11206     }
11207 
11208 }

BOOL OpMakeColourLocalToFrame::Redo  )  [virtual]
 

Redoes whatever Undo() undid.

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

Reimplemented from Operation.

Definition at line 11349 of file coldlog.cpp.

11350 {
11351     if (!Operation::Redo())
11352         return FALSE;
11353 
11354     // send the colour changing message
11355     ColourManager::ColourListHasChanged(ParentList);
11356 
11357     return TRUE;
11358 }

BOOL OpMakeColourLocalToFrame::ReplaceColourOnActiveLayer IndexedColour pOld,
IndexedColour pNew
[protected]
 

Replaces all the references to pOld with references to pNew on the active frame.

Author:
Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/7/97
Parameters:
pOld - the old indexed colour [INPUTS] pNew - the new indexed colour
- [OUTPUTS]
Returns:
-

Definition at line 11378 of file coldlog.cpp.

11379 {
11380     // sanity checks
11381     if ((pOld == NULL) || (pNew == NULL)) 
11382         return FALSE;
11383 
11384     ERROR3IF(pOurDoc == NULL, "No doc");
11385     if (pOurDoc == NULL)
11386         return FALSE;
11387 
11388     // start the attribute changing
11389     ObjChangeFlags ChangeFlags;
11390     ChangeFlags.Attribute = TRUE;
11391 
11392     ObjChangeParam ChangeParam(OBJCHANGE_STARTING, ChangeFlags, NULL, NULL);
11393 
11394     // get the first child of the active layer
11395     Node *CurNode = pActiveLayer->FindFirstDepthFirst();
11396 
11397     while (CurNode != NULL) // for all the nodes on the active layer
11398     {
11399         if (CurNode->IsAnAttribute()) // check only attribute nodes
11400         {
11401             // Have found a NodeAttribute. Scan it to see if it contains colours matching the old colour.
11402 
11403             NodeAttribute *pNodeAttr = (NodeAttribute *) CurNode;
11404             DocColour *pColour;
11405             DocColour *pColourCopy;
11406             UINT32 Context = 0;
11407 
11408             BOOL Found = FALSE; // whether our colour was referenced on this node
11409 
11410             // scan the attribute for the colour
11411             do
11412             {
11413                 // scan all the colour fields
11414                 pColour = pNodeAttr->EnumerateColourFields(Context++);
11415         
11416                 // get to the indexed colour
11417                 IndexedColour *pColourIx = (pColour == NULL) ? NULL : pColour->FindParentIndexedColour();
11418 
11419                 // Check if this colour matches our colour
11420                 if (pColourIx == pOld)
11421                 {
11422                     Found = TRUE; // found it
11423                     break;
11424                 }
11425             } while (pColour != NULL);  // Check the next colour attribute
11426 
11427             
11428             if (Found) // we have found a our colour in this attribute
11429             {
11430                 // make a copy of the attribute
11431                 NodeAttribute *Clone = NULL;
11432                 NodeAttribute *NodeToClone = (NodeAttribute *) CurNode;
11433                 ALLOC_WITH_FAIL(Clone, ((NodeAttribute *)NodeToClone->SimpleCopy()), this);
11434                 if (Clone == NULL) // failed
11435                     break;
11436 
11437                 Context = 0;
11438 
11439                 // for all the colour fields which match our old colour, 
11440                 // replace them with references to the new colour
11441                 do
11442                 {
11443                     // Get the next colour field from the attribute, and find the
11444                     // IndexedColour (if any) to which it refers
11445                     pColour = pNodeAttr->EnumerateColourFields(Context);
11446                     pColourCopy = Clone->EnumerateColourFields(Context);
11447                     Context++;
11448         
11449                     // get the indexed colour
11450                     IndexedColour *pColourIx = (pColour == NULL) ? NULL : pColour->FindParentIndexedColour();
11451 
11452                     // Check if this colour matches our colour
11453                     if (pColourIx == pOld)
11454                     {
11455                         // set the new indexed colour
11456                         pColourCopy->MakeRefToIndexedColour(pNew);
11457                     }
11458                 } while (pColour != NULL);  // Check the next colour attribute
11459 
11460 
11461                 // we need to hide the current attribute node and add the coped node to the tree
11462 
11463                 // find the parent of the node
11464                 Node *Parent = CurNode->FindParent();  
11465                 if (Parent != NULL && Parent->IsBounded())
11466                 {
11467                     // Invoke AllowOp on the node to tag it so that parents such as blends
11468                     // and moulds will also redraw if necessary. 
11469                     if (CurNode->AllowOp(&ChangeParam))
11470                     {
11471                         // Hide the original Attribute
11472                         DoHideNode(CurNode, TRUE);
11473 
11474                         // Add the clone into the tree
11475                         Clone->AttachNode(Parent, FIRSTCHILD);
11476                         HideNodeAction* TheUndoAction; 
11477 
11478                         // Create an action to hide the attribute when we undo
11479                         if (HideNodeAction::Init(this, &UndoActions, Clone, TRUE,
11480                                                  (Action**)(&TheUndoAction)) == AC_FAIL)
11481                         {   
11482                             Clone->CascadeDelete();     // Delink the node/subtree from the
11483                             delete Clone;               // document tree and delete it
11484                         }
11485 
11486                         // make the clone the current node so we can carry on walking the tree
11487                         CurNode = Clone;
11488                     }
11489                 }
11490             }
11491         }
11492 
11493         // go to the next node in the layer
11494         CurNode = CurNode->FindNextDepthFirst(pActiveLayer);
11495     }
11496     
11497     // finished changing the tree
11498     ChangeParam.Define(OBJCHANGE_FINISHED, ChangeParam.GetChangeFlags(), NULL, NULL);
11499     UpdateAllChangedNodes(&ChangeParam);
11500 
11501     return TRUE;
11502 }

BOOL OpMakeColourLocalToFrame::Undo  )  [virtual]
 

Undoes whatever Do() or Redo() did.

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

Reimplemented from Operation.

Definition at line 11323 of file coldlog.cpp.

11324 {
11325     if (Operation::Undo() == FALSE) 
11326         return FALSE;
11327 
11328     // send the colour changing message
11329     ColourManager::ColourListHasChanged(ParentList);
11330 
11331     return TRUE;
11332 }       


Member Data Documentation

ColourListComponent* OpMakeColourLocalToFrame::ColComp [protected]
 

Definition at line 678 of file coldlog.h.

Operation* OpMakeColourLocalToFrame::m_pPreviousOp [protected]
 

Definition at line 679 of file coldlog.h.

Layer* OpMakeColourLocalToFrame::pActiveLayer [protected]
 

Definition at line 677 of file coldlog.h.

ColourList* OpMakeColourLocalToFrame::ParentList [protected]
 

Definition at line 675 of file coldlog.h.

Document* OpMakeColourLocalToFrame::pOurDoc [protected]
 

Reimplemented from Operation.

Definition at line 676 of file coldlog.h.


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