OpTextKern Class Reference

This Operation applies a kern to the FocusStory. More...

#include <textops.h>

Inheritance diagram for OpTextKern:

OpTextUndoable SelOperation UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpTextKern ()
 OpTextKern constructor.
virtual void DoWithParam (OpDescriptor *, OpParam *pParam)
 If the Caret is selected in the focus story then the kern is inserted to the right of the caret. If there is a sub-selection then a kern is inserted before the first selected character and a negative kern after the last selected character.
virtual void PerformMergeProcessing ()
 This virtual function gets called to allow for the merging of text kern ops.

Static Public Member Functions

static BOOL Init ()
 OpTextKern initialiser method.
static OpState GetState (String_256 *, OpDescriptor *)
 For finding OpTextKern's state. The Op is greyed if there is no selected caret in the focus story.

Private Member Functions

BOOL DoInsertKernWithMerge (VisibleTextNode *TTContextNode, DocCoord &Value)
 This Do function inserts a Kern before TTContextNode and merges adjacent kerns.

Detailed Description

This Operation applies a kern to the FocusStory.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/03/95

Definition at line 290 of file textops.h.


Constructor & Destructor Documentation

OpTextKern::OpTextKern  ) 
 

OpTextKern constructor.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/03/95

Definition at line 1342 of file textops.cpp.

01342                       : OpTextUndoable()                                
01343 {                              
01344 }


Member Function Documentation

BOOL OpTextKern::DoInsertKernWithMerge VisibleTextNode TTContextNode,
DocCoord Value
[private]
 

This Do function inserts a Kern before TTContextNode and merges adjacent kerns.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/3/95
Parameters:
TTContextNode,: A kern will be Inserted before this node [INPUTS] Value: The kern's X,Y offset value
Returns:
TRUE if it worked FALSE otherwise, Call End()
See also:
OpTextKern::DoWithParam

Definition at line 1479 of file textops.cpp.

01480 {
01481     ERROR2IF(TTContextNode == NULL, FALSE, "TTContextNode is NULL");
01482     DocCoord KernValue = Value;
01483     AbstractTextChar* pPrevATC = (AbstractTextChar*)TTContextNode->FindPrevious(CC_RUNTIME_CLASS(AbstractTextChar));
01484     AbstractTextChar* pNextATC = (AbstractTextChar*)TTContextNode->FindNext(CC_RUNTIME_CLASS(AbstractTextChar));
01485     BOOL ok = TRUE;
01486 
01487     // if there is a kern to the right hide it and merge its value into the new one
01488     ObjChangeParam ObjDelete(OBJCHANGE_STARTING,ObjChangeFlags(TRUE),NULL,this);
01489     if (ok && (pNextATC!=NULL) && IS_A(pNextATC, KernCode))
01490     {
01491         KernValue = KernValue + ((KernCode*)pNextATC)->GetValue();
01492         ok = pNextATC->AllowOp(&ObjDelete);
01493         if (ok)
01494             ok = DoHideNode(pNextATC, TRUE);
01495     }
01496 
01497     // Hide the old kern code if the new values are zero
01498     if (ok && (pPrevATC!=NULL) && IS_A(pPrevATC, KernCode) && (KernValue.x==0) && (KernValue.y==0))
01499     {
01500         ok = pPrevATC->AllowOp(&ObjDelete);
01501         if (ok)
01502             ok = DoHideNode(pPrevATC, TRUE);
01503         pPrevATC = NULL;
01504     }
01505 
01506     // if the new kern will have an effect, set its value and insert it into the tree
01507     if (ok && (KernValue.x!=0 || KernValue.y!=0))
01508     {
01509         // Create a new kern if required, otherwise update the existing one
01510         if ((pPrevATC == NULL) || !IS_A(pPrevATC,KernCode) )
01511         {
01512             // Create the new Kern code
01513             KernCode* pKernCode = NULL;
01514             ALLOC_WITH_FAIL(pKernCode, (new KernCode()), this);
01515             ok = (pKernCode != NULL);
01516 
01517             // Now copy the attributes from the previous character to the kern
01518             if (ok)
01519             {
01520                 AbstractTextChar* pAttrChar = pPrevATC;
01521                 if (pAttrChar == NULL)
01522                     pAttrChar = pNextATC;
01523                 if (pAttrChar != NULL)
01524                     ok = pAttrChar->CopyChildrenTo(pKernCode);
01525                 // BODGE TEXT - should only copy children attributes
01526             }
01527 
01528             // Insert it in the tree
01529             if (ok)
01530             {
01531                 pKernCode->SetValue(KernValue);
01532                 ObjChangeParam ObjInsert(OBJCHANGE_STARTING,ObjChangeFlags(),NULL,this);
01533                 ok = TTContextNode->AllowOp(&ObjInsert);
01534                 if (ok)
01535                     ok = pKernCode->DoInsertNewNode(this,TTContextNode,PREV);
01536             }
01537         }
01538         else
01539         {
01540             // Call AllowOp to mark the kern code as changed
01541             ObjChangeParam ObjEdit(OBJCHANGE_STARTING,ObjChangeFlags(),NULL,this);
01542             if (pPrevATC->AllowOp(&ObjEdit))
01543             {
01544                 // Store the current code value
01545                 ok = StoreKernCodeAction::DoStoreKernValue(this, &UndoActions, (KernCode*)pPrevATC);
01546 
01547                 // set it to the new value
01548                 if (ok)
01549                     ((KernCode*)pPrevATC)->SetValue(KernValue);
01550             }
01551         }
01552     }
01553 
01554     return ok;
01555 }   

void OpTextKern::DoWithParam OpDescriptor ,
OpParam pOpParam
[virtual]
 

If the Caret is selected in the focus story then the kern is inserted to the right of the caret. If there is a sub-selection then a kern is inserted before the first selected character and a negative kern after the last selected character.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/03/95
Parameters:
OpDescriptor (unused) [INPUTS] pOpParam->Param1 = XKernValue pOpParam->Param2 = YKernValue
See also:
OpTextKern::DoInsertKernWithMerge

Reimplemented from Operation.

Definition at line 1425 of file textops.cpp.

01426 {   
01427     // Extract the parameter
01428     DocCoord KernValue(pOpParam->Param1, pOpParam->Param2);
01429 
01430     // get the focus story and caret
01431     TextStory* pFocusStory=TextStory::GetFocusStory();
01432     CaretNode* pCaret = NULL;
01433     ERROR3IF(pFocusStory==NULL,"OpTextKern::DoWithParam() - The focus story is missing");
01434     if (pFocusStory != NULL)
01435         pCaret = pFocusStory->GetCaret();
01436     ERROR3IF(pCaret==NULL,"OpTextKern::DoWithParam() - The text story's caret is missing");
01437     BOOL ok = ((pFocusStory != NULL) && (pCaret != NULL));
01438 
01439     // Start the TextOp - removes blobs and restores them at the end for us
01440     if (ok)
01441         ok = DoStartTextOp(pFocusStory);
01442     
01443     // if no selection insert kern before caret (else insert one at start and reverse at end of selection)
01444     if ( ok && (pFocusStory->GetSelectionEnd() == NULL))
01445     {
01446         ok = DoInsertKernWithMerge(pCaret, KernValue);
01447     }
01448 
01449     // Update all the changed nodes, i.e tell all the parents of the children that have been effected
01450     if (ok)
01451     {
01452         ObjChangeParam ObjChange(OBJCHANGE_FINISHED,ObjChangeFlags(),NULL,this);
01453         ok = UpdateChangedNodes(&ObjChange);
01454     }
01455 
01456     GetApplication()->UpdateSelection();
01457 
01458     if (!ok)
01459         FailAndExecute();
01460 
01461     End(); 
01462 }           

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

For finding OpTextKern's state. The Op is greyed if there is no selected caret in the focus story.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/03/95
Returns:
The state of the OpTextKern

Definition at line 1390 of file textops.cpp.

01391 {
01392     OpState OpSt;
01393     OpSt.Greyed = TRUE;
01394 
01395     TextStory* pStory = TextStory::GetFocusStory();
01396     if (pStory != NULL)
01397     {
01398         CaretNode* pCaret = pStory->GetCaret();
01399         if (pCaret != NULL) 
01400         {
01401             if (pCaret->IsSelected() && pStory->GetSelectionEnd() == NULL)
01402                 OpSt.Greyed = FALSE;
01403         }
01404     }
01405 
01406     return OpSt;   
01407 }

BOOL OpTextKern::Init void   )  [static]
 

OpTextKern initialiser method.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/03/95
Returns:
TRUE if the operation could be successfully initialised FALSE if no more memory could be allocated

Errors: ERROR will be called if there was insufficient memory to allocate the operation.

Reimplemented from SimpleCCObject.

Definition at line 1359 of file textops.cpp.

01360 {
01361     return (RegisterOpDescriptor(0,
01362                             _R(IDS_KERNOP),
01363                             CC_RUNTIME_CLASS(OpTextKern),
01364                             OPTOKEN_KERNTEXT,
01365                             OpTextKern::GetState,
01366                             0,                          // help ID 
01367                             0,                          // Bubble help
01368                             0,
01369                             0,
01370                             SYSTEMBAR_ILLEGAL,          // For now !
01371                             TRUE,                       // Receive messages
01372                             FALSE,
01373                             FALSE,
01374                             0,
01375                             GREY_WHEN_NO_CURRENT_DOC | GREY_WHEN_NO_SELECTION | DONT_GREY_WHEN_SELECT_INSIDE
01376            )); 
01377 }               

void OpTextKern::PerformMergeProcessing void   )  [virtual]
 

This virtual function gets called to allow for the merging of text kern ops.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/8/95
Returns:
Errors: [Not allowed to fail!]
See also:
UndoableOperation::PerformMergeProcessing

Reimplemented from UndoableOperation.

Definition at line 1568 of file textops.cpp.

01569 {    
01570     // Obtain a pointer to the operation history for the current document
01571     OperationHistory* pOpHist = &pOurDoc->GetOpHistory();
01572     ERROR3IF(pOpHist->FindLastOp() != this, "Last Op should be this op"); 
01573     
01574     // Is operation performed before this a OpTextKern?
01575     Operation* pPrevOp = pOpHist->FindPrevToLastOp();
01576 
01577     if ((pPrevOp != NULL) && IS_A(pPrevOp, OpTextKern))
01578     {
01579         // We can merge with the previous kern if the two ops both have a StoreKernCodeAction
01580         // And they both reference the same (document) kern code
01581         // We also need to access the invalid rectangles within the action list
01582         StoreKernCodeAction* pThisStoreKern = (StoreKernCodeAction*)GetUndoActionList()->FindActionOfClass(CC_RUNTIME_CLASS(StoreKernCodeAction));  
01583         StoreKernCodeAction* pPrevStoreKern = (StoreKernCodeAction*)pPrevOp->GetUndoActionList()->FindActionOfClass(CC_RUNTIME_CLASS(StoreKernCodeAction));
01584         InvalidateArbitaryAction* pThisInvalidRect = (InvalidateArbitaryAction*)GetUndoActionList()->FindActionOfClass(CC_RUNTIME_CLASS(InvalidateArbitaryAction));
01585         InvalidateArbitaryAction* pPrevInvalidRect = (InvalidateArbitaryAction*)pPrevOp->GetUndoActionList()->FindActionOfClass(CC_RUNTIME_CLASS(InvalidateArbitaryAction));
01586     
01587         if ((pThisStoreKern != NULL) && (pPrevStoreKern != NULL) && 
01588                 (pThisInvalidRect != NULL) && (pPrevInvalidRect != NULL) && 
01589                 (pThisStoreKern->GetKernCode() == pPrevStoreKern->GetKernCode()) &&
01590                 (pThisInvalidRect->GetSpread() == pPrevInvalidRect->GetSpread()))
01591         {
01592             // In order to merge these two ops just throw away this op!
01593             // The kern code already has the new value, on undo the (correct) stored value is restored
01594             // However, we must merge the two redraw rectangles
01595             DocRect AllInvalid = pThisInvalidRect->GetRect().Union(pPrevInvalidRect->GetRect());
01596             pPrevInvalidRect->SetRect(AllInvalid);
01597 
01598             // This op is no longer required, so let's vape it
01599             pOpHist->DeleteLastOp(); 
01600         }
01601     }
01602 }


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