PositionCaretAction Class Reference

This action is used to position a caret within a TextStory. Its execute function inserts another PositionCaretAction into the undo record to return the caret to its current position and then moves it to the stored position. More...

#include <textops.h>

Inheritance diagram for PositionCaretAction:

Action ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 PositionCaretAction ()
 Constructor for PositionCaretAction. Initialises the member variables.
 ~PositionCaretAction ()
 Destructor for PositionCaretAction.
virtual ActionCode Execute ()
 This action inserts the opposite PositionCaretAction for redo purposes, then moves the CaretNode within the TextStory.

Static Public Member Functions

static ActionCode Init (Operation *pOp, ActionList *pActionList, TextStory *pStory, BaseTextClass *pAttachNode, AttachNodeDirection Direction)
 Call this function to cause the move of caret a TextStory during an undo/redo set of operations. In your Do function move the caret, then call this function to insert an undo record for that deletion.
static BOOL DoStoreCaretPosition (Operation *pOp, TextStory *pStory)
 Call this function to restore the position of the caret in an undo list.

Static Protected Member Functions

static BOOL GetCaretNeighbour (TextStory *pStory, BaseTextClass **pNeighbour, AttachNodeDirection *pDirection)
 Gets a pointer to the node that execute function should attach the caret to.

Protected Attributes

TextStorypTextStory
BaseTextClasspNearNode
AttachNodeDirection AttachDirection

Detailed Description

This action is used to position a caret within a TextStory. Its execute function inserts another PositionCaretAction into the undo record to return the caret to its current position and then moves it to the stored position.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/04/95

Definition at line 570 of file textops.h.


Constructor & Destructor Documentation

PositionCaretAction::PositionCaretAction  ) 
 

Constructor for PositionCaretAction. Initialises the member variables.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/4/95

Definition at line 1141 of file textops.cpp.

01142 {
01143     pTextStory = NULL;
01144     pNearNode = NULL;
01145     AttachDirection = NEXT;
01146 }

PositionCaretAction::~PositionCaretAction  ) 
 

Destructor for PositionCaretAction.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/4/95

Definition at line 1157 of file textops.cpp.

01158 {
01159 }


Member Function Documentation

BOOL PositionCaretAction::DoStoreCaretPosition Operation pOp,
TextStory pStory
[static]
 

Call this function to restore the position of the caret in an undo list.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com> (originally Peter)
Date:
15/2/96
Parameters:
pOp - operation to which this action belongs (NULL if not undoable) [INPUTS] pStory - pointer to textstory to which this action applies
Returns:
FALSE if fails

Definition at line 1264 of file textops.cpp.

01265 {
01266     ERROR2IF(pStory==NULL,FALSE,"PositionCaretAction::DoStoreCaretPosition() - pStory==NULL");
01267     ERROR2IF(pOp   ==NULL,FALSE,"PositionCaretAction::DoStoreCaretPosition() - pOp==NULL");
01268 
01269     // Get a pointer to the node to reattach the caret to
01270     CaretNode* pCaret = pStory->GetCaret();
01271     ERROR2IF(pCaret==NULL,FALSE,"PositionCaretAction::DoStoreCaretPosition() - pCaret==NULL");
01272 
01273     ActionList* pActionList = pOp->GetUndoActionList();
01274     ERROR2IF(pActionList==NULL,FALSE,"PositionCaretAction::DoStoreCaretPosition() - pActionList==NULL");
01275 
01276     // get a neighbour for the caret, and its direction
01277     BaseTextClass* pReattachNode = NULL;
01278     AttachNodeDirection AttachDir = NEXT;
01279     if (GetCaretNeighbour(pStory, &pReattachNode, &AttachDir)==FALSE)
01280         return FALSE;
01281 
01282     // Create an action for this
01283     if (PositionCaretAction::Init(pOp, pActionList, pStory, pReattachNode, AttachDir)==AC_FAIL)
01284         return FALSE;
01285 
01286     return TRUE;
01287 }

ActionCode PositionCaretAction::Execute  )  [virtual]
 

This action inserts the opposite PositionCaretAction for redo purposes, then moves the CaretNode within the TextStory.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/4/95
Returns:
ActionCode, either AC_OK, AC_NORECORD or AC_FAIL

Reimplemented from Action.

Definition at line 1172 of file textops.cpp.

01173 {
01174     ERROR2IF(pTextStory==NULL,AC_FAIL,"PositionCaretAction::Execute() - pTextStory==NULL");
01175     ERROR2IF( pNearNode==NULL,AC_FAIL,"PositionCaretAction::Execute() - pNearNode==NULL");
01176     CaretNode* pCaret = pTextStory->GetCaret();
01177     ERROR2IF(    pCaret==NULL,AC_FAIL,"PositionCaretAction::Execute() - pCaret==NULL");
01178     
01179     // create redo action to position caret where it is currently
01180     BaseTextClass*      pReDoAttachNode = NULL;
01181     AttachNodeDirection ReDoAttachDir   = NEXT;
01182     if (!GetCaretNeighbour(pTextStory, &pReDoAttachNode, &ReDoAttachDir))
01183         return AC_FAIL;
01184     if (PositionCaretAction::Init(pOperation,pOppositeActLst,pTextStory,pReDoAttachNode,ReDoAttachDir)==AC_FAIL)
01185         return AC_FAIL;
01186 
01187     // ensure FIRSTCHILD actually means first child object
01188     Node*               pAttachNode = pNearNode;
01189     AttachNodeDirection  AttachDir  = AttachDirection;
01190     if (AttachDirection==FIRSTCHILD)
01191         pNearNode->GetAttachNodeAndDirectionToAttachFirstChildObject(&pAttachNode,&AttachDir);
01192 
01193     // Move caret, deselect in old pos and reselect in new pos to maintain ParentOfSelected
01194     BOOL CaretWasSelected = pCaret->IsSelected();
01195     if (CaretWasSelected)
01196         pCaret->SetSelected(FALSE);
01197     pCaret->MoveNode(pAttachNode, AttachDir);
01198     if (CaretWasSelected)
01199         pCaret->SetSelected(TRUE);
01200 
01201     pTextStory->AttachCaretAttributes();            // ensure caret has attrs of its context
01202     pCaret->ScrollToShow();                         // ensure caret on screen
01203 
01204     return AC_OK;
01205 }

BOOL PositionCaretAction::GetCaretNeighbour TextStory pStory,
BaseTextClass **  ppNeighbour,
AttachNodeDirection pDirection
[static, protected]
 

Gets a pointer to the node that execute function should attach the caret to.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/4/95
Parameters:
pStory - points the TextStory with the caret [INPUTS]
ppNeighbour - ptr to node the caret should be attached to [OUTPUTS] pDirection - direction of the attachment
Returns:
FALSE if fails

Definition at line 1303 of file textops.cpp.

01305 {
01306     ERROR2IF(     pStory== NULL,FALSE,"PositionCaretAction::GetCaretNeighbour() - pStory==NULL");
01307     ERROR2IF(ppNeighbour== NULL,FALSE,"PositionCaretAction::GetCaretNeighbour() - ppNeighbour==NULL");
01308     ERROR2IF( pDirection== NULL,FALSE,"PositionCaretAction::GetCaretNeighbour() - pDirection==NULL");
01309 
01310     // Get a pointer to the node to reattach the caret to
01311     CaretNode* pCaret = pStory->GetCaret();
01312     ERROR2IF(pCaret==NULL,FALSE,"PositionCaretAction::GetCaretNeighbour() - story has no caret");
01313     *ppNeighbour = pCaret->FindPrevVTNInLine();
01314     *pDirection  = NEXT;
01315     if (*ppNeighbour==NULL)
01316     {
01317         *ppNeighbour = pCaret->FindNextVTNInLine();
01318         *pDirection  = PREV;
01319     }
01320     if (*ppNeighbour==NULL)
01321     {
01322         *ppNeighbour = pCaret->FindParentLine();
01323         ERROR2IF(*ppNeighbour==NULL,FALSE,"PositionCaretAction::GetCaretNeighbour() - caret has no parent TExtLine");
01324         *pDirection  = FIRSTCHILD;
01325     }
01326 
01327     return TRUE;
01328 }

ActionCode PositionCaretAction::Init Operation pOp,
ActionList pActionList,
TextStory pStory,
BaseTextClass pAttachNode,
AttachNodeDirection  Direction
[static]
 

Call this function to cause the move of caret a TextStory during an undo/redo set of operations. In your Do function move the caret, then call this function to insert an undo record for that deletion.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/4/95
Parameters:
pOp is the pointer to the operation to which this action belongs [INPUTS] pActionList is the action list to which this action should be added pStory - pointer to the text story to apply this action to pAttachNode is the node the caret should be attached to Direction is the direction of the attachment (either NEXT or PREV)
Returns:
ActionCode, one of AC_OK, AC_NO_RECORD or AC_FAIL
See also:
Action::Init(), PositionCaretAction::Execute()

Definition at line 1229 of file textops.cpp.

01234 {
01235     UINT32 ActSize = sizeof(PositionCaretAction);
01236 
01237     PositionCaretAction* pNewAction = NULL;
01238 
01239     ActionCode Ac = Action::Init( pOp, pActionList, ActSize, CC_RUNTIME_CLASS(PositionCaretAction), (Action**)&pNewAction);
01240     if ((Ac == AC_OK) && (pNewAction != NULL))
01241     {
01242         ERROR2IF(pStory == NULL, AC_FAIL, "TextStory pointer was NULL");
01243         ERROR2IF(pAttachNode == NULL, AC_FAIL, "Attachment node pointer was NULL");
01244         pNewAction->pTextStory = pStory;
01245         pNewAction->pNearNode = pAttachNode;
01246         pNewAction->AttachDirection = Direction;
01247     }
01248 
01249     return Ac;
01250 }


Member Data Documentation

AttachNodeDirection PositionCaretAction::AttachDirection [protected]
 

Definition at line 592 of file textops.h.

BaseTextClass* PositionCaretAction::pNearNode [protected]
 

Definition at line 591 of file textops.h.

TextStory* PositionCaretAction::pTextStory [protected]
 

Definition at line 590 of file textops.h.


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