OpTextCaret Class Reference

OpTextCaret groups together all caret moving ops. More...

#include <textops.h>

Inheritance diagram for OpTextCaret:

Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpTextCaret ()
 OpTextCaret constructor. Sets the member variables.
void DoMoveCaretLeft (BOOL WithSelect, BOOL AWord)
 Cursor left key operation - see movement rules above.
void DoMoveCaretRight (BOOL WithSelect, BOOL AWord)
 Cursor right key operation. If the caret is selected then the caret moves one position to the right. If there is a sub-selection then the caret will move to the right of the last selected character and become selected. The subselection is cleared.
void DoMoveCaretUp (BOOL WithSelect)
 Moves the caret up one line.
void DoMoveCaretDown (BOOL WithSelect)
 Moves the caret down one line, dealing with selection if needed.
void DoMoveCaretHome (BOOL WithSelect, BOOL ToStoryStart)
 Moves the caret to the left of the first character on the line, or to the start of the TextStory.
void DoMoveCaretEnd (BOOL WithSelect, BOOL ToStoryEnd)
 Moves the caret to the right of the last character on the line.
void DoSelectWordAtCaret ()
 Moves the caret to the start of the word that is is currently at, then selects the characters to the end of the word.

Static Public Member Functions

static VisibleTextNodeGetLineStartCharacter (VisibleTextNode *pCharacter)
 This function returns a pointer to the VisibleTextNode at the start of a line.
static VisibleTextNodeGetLineEndCharacter (VisibleTextNode *pCharacter)
 This function returns a pointer to the VisibleTextNode at the end of a line, this should be an EOLNode.
static void SelectStoryCharacters (VisibleTextNode *, VisibleTextNode *, TextStory *, CaretNode *)
 This function selects characters between the two pointers (inclusive), deselecting all other characters in the story.

Protected Member Functions

void MoveCaretToSelectionEnd (BOOL MoveToLeft)
 This function should be called to move the caret to the end of the selected text. It also selectes the caret, deselecting the other characters.
void CompleteOperation ()
 This function performs common things done at the end of all operations It calls the End() method so don't do anything else except return after calling it.
VisibleTextNodeGetCharacterLineChange (VisibleTextNode *pCharacter, BOOL ToLeftOfChar, BOOL *NewToLeft, BOOL MoveUp)
BOOL PreCaretMove ()
 Carries out common pre operation code for caret movement ops.

Protected Attributes

TextStorypStory
CaretNodepCaret
VisibleTextNodepOtherSelEnd
BOOL SelToRightOfCaret
VerticalInsetStore PreviousVerticalInset

Static Protected Attributes

static VerticalInsetStore VertInset

Detailed Description

OpTextCaret groups together all caret moving ops.

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

Definition at line 650 of file textops.h.


Constructor & Destructor Documentation

OpTextCaret::OpTextCaret  ) 
 

OpTextCaret constructor. Sets the member variables.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/7/94

Definition at line 3127 of file textops.cpp.

03128 {
03129     // Get pointers to the focus story.  There should be one!
03130     pStory = TextStory::GetFocusStory();
03131     ERROR3IF(pStory == NULL, "OpTextCaret created without a focus story");
03132 
03133     // Get pointer to caret and other end of selection
03134     if (pStory != NULL)
03135     {
03136         pCaret = pStory->GetCaret();
03137         pOtherSelEnd = pStory->GetSelectionEnd(&SelToRightOfCaret);
03138 
03139         // If no selection then set pointer to the caret
03140         if (pOtherSelEnd == NULL)
03141             pOtherSelEnd = pCaret;
03142     }
03143     else
03144     {
03145         pCaret = NULL;
03146         pOtherSelEnd = NULL;
03147     }
03148 
03149     // Reset the vertical move inset
03150     PreviousVerticalInset = VertInset;
03151     VertInset.LastInset = VERTICALMOVEINSET_NONE;
03152     VertInset.HoldingInset = VERTICALMOVEINSET_NONE;
03153 }


Member Function Documentation

void OpTextCaret::CompleteOperation  )  [protected]
 

This function performs common things done at the end of all operations It calls the End() method so don't do anything else except return after calling it.

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

Definition at line 3202 of file textops.cpp.

03203 {
03204     GetApplication()->UpdateSelection();
03205 
03206     End();
03207 }

void OpTextCaret::DoMoveCaretDown BOOL  WithSelect  ) 
 

Moves the caret down one line, dealing with selection if needed.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/4/95
Parameters:
WithSelect - TRUE if characters should be selected [INPUTS] Scroll - TRUE to scroll the screen

Definition at line 2786 of file textops.cpp.

02787 {
02788     BOOL Success = TRUE;
02789     if (!PreCaretMove())
02790     {
02791         Success = FALSE;
02792         goto DoneMovement;
02793     }
02794         
02795     if (WithSelect)
02796     {
02797         // get the 'other' end of the currect selection (the caret is at non-moving end)
02798         VisibleTextNode* pSelEnd = pCaret;
02799         VisibleTextNode* pSelStart = pOtherSelEnd;
02800         VisibleTextNode* pOldSelStart = pSelStart;
02801         BOOL SelToLeftOfNewEnd = TRUE;
02802         pSelStart = GetCharacterLineChange(pSelStart, SelToRightOfCaret, &SelToLeftOfNewEnd, FALSE);
02803 
02804         if (pSelStart == NULL)
02805         {
02806             DoMoveCaretEnd(TRUE, TRUE);
02807             return; // We have already End()ed
02808         }
02809         else
02810         {
02811             ERROR3IF(pSelEnd == NULL, "Failed to find selection end (where's the caret!)");
02812             if ((pSelStart != NULL) && (pSelEnd != NULL))
02813             {
02814                 if (!SelToLeftOfNewEnd && (pSelStart->FindNextVTNInStory() != NULL))
02815                     pSelStart = pSelStart->FindNextVTNInStory();
02816                 VisibleTextNode* pScrollTo = pSelStart;
02817 
02818                 // Ensure that start is before end.  For down movement see if the character
02819                 // after the new start is selected, swap if it isn't
02820                 VisibleTextNode* pNext = pSelStart->FindNextVTNInStory();
02821                 if ((pNext == NULL) || ((pNext != NULL) && (pSelStart != pSelEnd) && (pNext != pSelEnd) && !pNext->IsSelected()))
02822                 {
02823                     VisibleTextNode* pTemp = pSelEnd;
02824                     pSelEnd = pSelStart;
02825                     pSelStart = pTemp;
02826                     VisibleTextNode *pPrev = pSelEnd->FindPrevVTNInStory();
02827                     if ((pPrev != NULL) && (pPrev != pOldSelStart))
02828                         pSelEnd = pPrev;
02829                     pScrollTo = pSelEnd;
02830                 }
02831 
02832                 if (pScrollTo->IsAnEOLNode() && (pScrollTo->FindNextVTNInStory() != NULL))
02833                     pScrollTo = pScrollTo->FindNextVTNInStory();
02834 
02835                 // Select the characters and scroll to show moving end
02836                 pScrollTo->ScrollToShow();      
02837                 OpTextCaret::SelectStoryCharacters(pSelStart, pSelEnd, pStory, pCaret);
02838             }
02839         }
02840     }
02841     else
02842     {
02843         if (pStory->GetSelectionEnd() != NULL)
02844             MoveCaretToSelectionEnd(FALSE);
02845         else
02846         {
02847             BOOL ToLeft = FALSE;
02848             VisibleTextNode* pNewPos = GetCharacterLineChange(pCaret, TRUE, &ToLeft, FALSE);
02849 
02850             if (pNewPos != NULL)
02851             {
02852                 NodeRenderableInk::DeselectAll(TRUE,FALSE);
02853                 pStory->MoveCaretToCharacter(pNewPos, ToLeft?PREV:NEXT);
02854                 pCaret->ScrollToShow();
02855                 pCaret->Select(TRUE);
02856             }
02857         }
02858     }
02859 
02860 DoneMovement:
02861     if (!Success)
02862     {
02863         FailAndExecute();
02864         InformError();
02865     }
02866     
02867     CompleteOperation();
02868 }

void OpTextCaret::DoMoveCaretEnd BOOL  WithSelect,
BOOL  ToStoryEnd
 

Moves the caret to the right of the last character on the line.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/3/95
Parameters:
WithSelect - true if characters from the current caret position to the end [INPUTS] of the line should be selected

Definition at line 2961 of file textops.cpp.

02962 {
02963     if (!PreCaretMove())
02964     {
02965         FailAndExecute();
02966         InformError();
02967         End();
02968         return;
02969     }
02970 
02971     VisibleTextNode* pMoveChar = pStory->GetSelectionEnd();
02972     if (ToStoryEnd)
02973         pMoveChar = pStory->FindLastVTN();
02974     else
02975     {
02976         if (pMoveChar == NULL)
02977             pMoveChar = GetLineEndCharacter(pCaret);
02978         else
02979             pMoveChar = GetLineEndCharacter(pMoveChar);
02980     }
02981 
02982     if (pMoveChar == NULL)
02983         return ;
02984 
02985     if (WithSelect)
02986     {
02987         // Get a pointer to the first and last selectable chars
02988         VisibleTextNode* pSelStartChar = pCaret;
02989         VisibleTextNode* pSelEndChar = pMoveChar->FindPrevVTNInStory();
02990         if (pSelEndChar == NULL)
02991             pSelEndChar = pMoveChar;
02992 
02993         if (pSelStartChar != pSelEndChar)
02994         {
02995             // Its possible that the end character is in front of the start
02996             VisibleTextNode* pChar = pSelEndChar;
02997             while (pChar != NULL)
02998             {
02999                 if (pChar == pSelStartChar)
03000                 {
03001                     pSelStartChar = pSelEndChar->FindNextVTNInStory();
03002                     pSelEndChar = pCaret->FindPrevVTNInStory();
03003                     break;
03004                 }
03005 
03006                 pChar = pChar->FindNextVTNInStory();
03007             }
03008             if (pChar == NULL)
03009                 pSelStartChar = pCaret->FindNextVTNInStory();
03010         }
03011 
03012         if (pSelEndChar != NULL)
03013             pSelEndChar->ScrollToShow();
03014 
03015         SelectStoryCharacters(pSelStartChar, pSelEndChar, pStory, pCaret);
03016     }
03017     else
03018     {
03019         NodeRenderableInk::DeselectAll(TRUE,FALSE);
03020         if (pMoveChar != pCaret)
03021         {
03022             if (pMoveChar->IsAnEOLNode())
03023                 pStory->MoveCaretToCharacter(pMoveChar, PREV);
03024             else
03025                 pStory->MoveCaretToCharacter(pMoveChar, NEXT);
03026         }
03027         pCaret->ScrollToShow();
03028         pCaret->Select(TRUE);
03029     }
03030 
03031     CompleteOperation();
03032 }

void OpTextCaret::DoMoveCaretHome BOOL  WithSelect,
BOOL  ToStoryStart
 

Moves the caret to the left of the first character on the line, or to the start of the TextStory.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/3/95
Parameters:
WithSelect - true if characters from the current caret position to the home [INPUTS] position should be selected

Definition at line 2882 of file textops.cpp.

02883 {
02884     if (!PreCaretMove())
02885     {
02886         FailAndExecute();
02887         InformError();
02888         End();
02889         return;
02890     }
02891 
02892     VisibleTextNode* pMoveChar = pStory->GetSelectionEnd();
02893     if (ToStoryStart)
02894         pMoveChar = pStory->FindFirstVTN();
02895     else
02896     {
02897         if (pMoveChar == NULL)
02898             pMoveChar = GetLineStartCharacter(pCaret);
02899         else
02900             pMoveChar = GetLineStartCharacter(pMoveChar);
02901     }
02902 
02903     if (pMoveChar == NULL)
02904         return ;
02905 
02906     if (WithSelect)
02907     {
02908         // Get a pointer to the first and last selectable chars
02909         VisibleTextNode* pSelEndChar = pCaret;
02910         VisibleTextNode* pSelStartChar = (VisibleTextNode*)pMoveChar;
02911         if ((pSelEndChar != NULL) && (pSelStartChar != NULL))
02912         {
02913             // Its possible that the end character is in front of the start
02914             if (pSelStartChar != pSelEndChar)
02915             {
02916                 VisibleTextNode* pChar = pSelEndChar;
02917                 while (pChar != NULL)
02918                 {
02919                     if (pChar == pSelStartChar)
02920                     {
02921                         pSelStartChar = pCaret->FindNextVTNInStory();
02922                         pSelEndChar = pChar->FindPrevVTNInStory();
02923                         break;
02924                     }
02925 
02926                     pChar = pChar->FindNextVTNInStory();
02927                 }
02928 
02929                 if (pChar==NULL)
02930                     pSelEndChar = pCaret->FindPrevVTNInStory();
02931             }               
02932 
02933             if (pSelStartChar != NULL)
02934                 pSelStartChar->ScrollToShow();
02935             SelectStoryCharacters(pSelStartChar, pSelEndChar, pStory, pCaret);
02936         }
02937     }
02938     else
02939     {
02940         NodeRenderableInk::DeselectAll(TRUE,FALSE);
02941         if (pMoveChar != pCaret)
02942             pStory->MoveCaretToCharacter(pMoveChar, PREV);
02943         pCaret->ScrollToShow();
02944         pCaret->Select(TRUE);
02945     }
02946 
02947     CompleteOperation();
02948 }

void OpTextCaret::DoMoveCaretLeft BOOL  WithSelect,
BOOL  AWord
 

Cursor left key operation - see movement rules above.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/3/95 - rewritten 29/8/95
Parameters:
WithSelect - movement should select words [INPUTS] AWord - move the caret a word at a time
Returns:
Errors: Story and caret pointers are checked for NULL

Definition at line 2502 of file textops.cpp.

02503 {
02504     // Initialise
02505     BOOL Success = TRUE;
02506     if (!PreCaretMove())
02507     {
02508         Success = FALSE;
02509         goto DoneMovement;
02510     }
02511 
02512     if (WithSelect)
02513     {
02514         BOOL MoveSelection = TRUE;
02515         VisibleTextNode* pSelEnd = pCaret;
02516         VisibleTextNode* pSelStart = pOtherSelEnd;
02517 
02518         // Get the new selection end.  Move the current end to the left, either by one word or one character
02519         if (AWord)                         
02520         {
02521             // Special case so we skip back over selected EOLs like Word
02522             if (SelToRightOfCaret && pSelStart->IsAnEOLNode())
02523             {
02524                 pSelStart = pSelStart->FindPrevVTNInStory();
02525                 MoveSelection = FALSE;
02526             }
02527             else
02528                 pSelStart = pStory->GetPrevWordChar(pSelStart);
02529         }
02530         else
02531         {
02532             VisibleTextNode* pTemp = pSelStart->FindPrevVTNInStory();
02533             if (pTemp != NULL)
02534                 pSelStart = pTemp;
02535         }
02536 
02537         ERROR3IF(pSelStart == NULL, "Failed to find selection start");
02538         ERROR3IF(pSelEnd == NULL, "Failed to find selection end (where's the caret!)");
02539         VisibleTextNode* pScrollTo = pSelStart;
02540         if ((pSelStart != NULL) && (pSelEnd != NULL))
02541         {
02542             // Ensure that start is before end.  For left movement see if the character
02543             // before the new start is selected and swap if it is
02544             VisibleTextNode* pPrev = pSelStart->FindPrevVTNInStory();
02545             if ((pPrev != NULL) && (pSelStart != pSelEnd) && (pPrev->IsSelected() || pPrev->IsACaret()))
02546             {
02547                 VisibleTextNode* pTemp = pSelEnd;
02548                 pSelEnd = pSelStart;
02549                 pSelStart = pTemp;
02550                 pTemp = pSelEnd->FindPrevVTNInStory();
02551                 if (AWord && MoveSelection && (pTemp != NULL) && !pSelEnd->IsAnEOLNode())
02552                     pSelEnd = pTemp;
02553                 pScrollTo = pSelEnd;
02554             }
02555 
02556             // Select the characters and scroll to show moving end
02557             pScrollTo->ScrollToShow();      
02558             OpTextCaret::SelectStoryCharacters(pSelStart, pSelEnd, pStory, pCaret);
02559         }
02560     }
02561     else
02562     {
02563         // If there is a selected region move caret to its end, else move caret
02564         if (pStory->GetSelectionEnd() != NULL)
02565             MoveCaretToSelectionEnd(TRUE);
02566         else
02567         {
02568             if (pCaret->FindPrevVTNInStory() != NULL)
02569             {
02570                 NodeRenderableInk::DeselectAll(TRUE, FALSE);
02571                 if (AWord)
02572                     Success = pStory->MoveCaretLeftAWord();
02573                 else
02574                     Success = pStory->MoveCaretLeftAChar();
02575                 pCaret->ScrollToShow();
02576                 pCaret->Select(TRUE);
02577             }
02578         }
02579     }
02580 
02581 DoneMovement:
02582     if (!Success)
02583     {
02584         FailAndExecute();
02585         InformError();
02586     }
02587     
02588     CompleteOperation();
02589 }

void OpTextCaret::DoMoveCaretRight BOOL  WithSelect,
BOOL  AWord
 

Cursor right key operation. If the caret is selected then the caret moves one position to the right. If there is a sub-selection then the caret will move to the right of the last selected character and become selected. The subselection is cleared.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/3/95
Parameters:
pTextStory,: The TextStory to perform the operation on [INPUTS] AWord: Move the caret a word at a time

Definition at line 2605 of file textops.cpp.

02606 {
02607     BOOL Success = TRUE;
02608     if (!PreCaretMove())
02609     {
02610         Success = FALSE;
02611         goto DoneMovement;
02612     }
02613 
02614     if (WithSelect)
02615     {
02616         VisibleTextNode* pSelEnd = pCaret;
02617         VisibleTextNode* pSelStart = pOtherSelEnd;
02618 
02619         // Get the new selection end.  Move the current end to the right, either by one word or one character
02620         if (AWord)
02621         {
02622             // If the sel end is at the end of a line then skip to the start of the new line
02623             // then to the end of the first word on the line
02624             if (pSelStart->IsAnEOLNode() && SelToRightOfCaret)
02625                 pSelStart = pStory->GetNextWordChar(pSelStart);
02626             pSelStart = pSelStart->FindNextVTNInStory();
02627             pSelStart = pStory->GetNextWordChar(pSelStart);
02628         }
02629         else
02630             pSelStart = pSelStart->FindNextVTNInStory();
02631 
02632         ERROR3IF(pSelStart == NULL, "Failed to find slection start");
02633         ERROR3IF(pSelEnd == NULL, "Failed to find slection end (where's the caret!)");
02634         VisibleTextNode* pScrollTo = pSelStart;
02635         if ((pSelStart != NULL) && (pSelEnd != NULL))
02636         {
02637             // Ensure that start is before end.  For right movement see if the character
02638             // after the new start is selected, swap if it isn't
02639             VisibleTextNode* pNext = pSelStart->FindNextVTNInStory();
02640             if ((pNext == NULL) || (pNext != NULL) && (pSelStart != pSelEnd) && (pNext != pSelEnd) && !pNext->IsSelected())
02641             {
02642                 VisibleTextNode* pTemp = pSelEnd;
02643                 pSelEnd = pSelStart;
02644                 pSelStart = pTemp;
02645                 if (AWord && (pSelEnd->FindPrevVTNInStory() != NULL) && (pSelEnd->FindNext() != pStory->FindLastVTN()))
02646                     pSelEnd = pSelEnd->FindPrevVTNInStory();
02647                 pScrollTo = pSelEnd;
02648             }
02649 
02650             // Select the characters and scroll to show moving end
02651             pScrollTo->ScrollToShow();      
02652             OpTextCaret::SelectStoryCharacters(pSelStart, pSelEnd, pStory, pCaret);
02653         }
02654     }
02655     else
02656     {
02657         // If there is a selected region move caret to its end, else move caret
02658         if (pStory->GetSelectionEnd() != NULL)
02659             MoveCaretToSelectionEnd(FALSE);
02660         else
02661         {
02662             // Do simple caret moving
02663             if (pCaret->FindNextVTNInStory() != pStory->FindLastVTN())
02664             {
02665                 NodeRenderableInk::DeselectAll(TRUE,FALSE);
02666                 if (AWord)
02667                     pStory->MoveCaretRightAWord();
02668                 else
02669                     pStory->MoveCaretRightAChar();
02670                 pCaret->ScrollToShow();
02671                 pCaret->Select(TRUE);
02672             }
02673         }
02674     }
02675 
02676 DoneMovement:
02677     if (!Success)
02678     {
02679         FailAndExecute();
02680         InformError();
02681     }
02682     
02683     CompleteOperation();
02684 }

void OpTextCaret::DoMoveCaretUp BOOL  WithSelect  ) 
 

Moves the caret up one line.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/4/95
Parameters:
WithSelect - TRUE if characters should be selected [INPUTS]

Definition at line 2696 of file textops.cpp.

02697 {
02698     BOOL Success = TRUE;
02699     if (!PreCaretMove())
02700     {
02701         Success = FALSE;
02702         goto DoneMovement;
02703     }
02704         
02705     if (WithSelect)
02706     {
02707         VisibleTextNode* pSelEnd = pCaret;
02708         VisibleTextNode* pSelStart = pOtherSelEnd;
02709 
02710         // Move the current selection end up a line
02711         BOOL SelToLeftOfNewEnd = TRUE;
02712         pSelStart = GetCharacterLineChange(pSelStart, SelToRightOfCaret, &SelToLeftOfNewEnd, TRUE);
02713 
02714         if (pSelStart == NULL)
02715         {
02716             DoMoveCaretHome(TRUE, TRUE);
02717             return; // We have already End()ed
02718         }
02719         else
02720         {
02721             ERROR3IF(pSelEnd == NULL, "Failed to find slection end (where's the caret!)");
02722             if ((pSelStart != NULL) && (pSelEnd != NULL))
02723             {
02724                 if (!SelToLeftOfNewEnd && (pSelStart->FindNextVTNInStory() != NULL))
02725                     pSelStart = pSelStart->FindNextVTNInStory();
02726                 VisibleTextNode* pScrollTo = pSelStart;
02727                 // Ensure that start is before end.  For up movement see if the character
02728                 // before the new start is selected and swap if it is
02729                 VisibleTextNode* pPrev = pSelStart->FindPrevVTNInStory();
02730                 if ((pPrev != NULL) && (pSelStart != pSelEnd) && (pPrev->IsSelected() || pPrev->IsACaret()))
02731                 {
02732                     VisibleTextNode* pTemp = pSelEnd;
02733                     pSelEnd = pSelStart;
02734                     pSelStart = pTemp;
02735                     if (pSelEnd->FindPrevVTNInStory() != NULL)
02736                         pSelEnd = pSelEnd->FindPrevVTNInStory();
02737                     pScrollTo = pSelEnd;
02738                 }
02739 
02740                 // Select the characters and scroll to show moving end
02741                 pScrollTo->ScrollToShow();      
02742                 OpTextCaret::SelectStoryCharacters(pSelStart, pSelEnd, pStory, pCaret);
02743             }
02744         }
02745     }
02746     else
02747     {
02748         if (pStory->GetSelectionEnd() != NULL)
02749             MoveCaretToSelectionEnd(TRUE);
02750         else
02751         {
02752             BOOL ToLeft = FALSE;
02753             VisibleTextNode* pNewPos = GetCharacterLineChange(pCaret, TRUE, &ToLeft, TRUE);
02754 
02755             if (pNewPos != NULL)
02756             {
02757                 NodeRenderableInk::DeselectAll(TRUE,FALSE);
02758                 pStory->MoveCaretToCharacter(pNewPos, ToLeft?PREV:NEXT);
02759                 pCaret->ScrollToShow();
02760                 pCaret->Select(TRUE);
02761             }
02762         }
02763     }
02764 
02765 DoneMovement:
02766     if (!Success)
02767     {
02768         FailAndExecute();
02769         InformError();
02770     }
02771     
02772     CompleteOperation();
02773 }

void OpTextCaret::DoSelectWordAtCaret  ) 
 

Moves the caret to the start of the word that is is currently at, then selects the characters to the end of the word.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
05/04/95
Returns:
Errors: Checks story and caret pointers for NULL

Definition at line 3067 of file textops.cpp.

03068 {
03069     // Validate the pointers
03070     if (!PreCaretMove())
03071     {
03072         InformError();
03073         FailAndExecute();
03074         End();
03075         return;
03076     }
03077     
03078     NodeRenderableInk::DeselectAll(TRUE,FALSE);
03079     DialogManager::DefaultKeyboardFocus();
03080 
03081     // find the start of the previous word and move the caret there
03082     VisibleTextNode* pPrevWordStart = pStory->GetPrevWordChar(pCaret);
03083     if (pPrevWordStart==NULL)
03084     {
03085         ERROR3("OpTextCaret::DoSelectWordAtCaret() - failed to find start of previous word!");
03086         return;
03087     }
03088     if (pPrevWordStart!=pCaret)
03089         pStory->MoveCaretToCharacter(pPrevWordStart, PREV);
03090 
03091     // find the start of the next word
03092     VisibleTextNode* pNextWordStart = pStory->GetNextWordChar(pPrevWordStart);
03093     if (pNextWordStart==NULL)
03094     {
03095         ERROR3("OpTextCaret::DoSelectWordAtCaret() - failed to find start of next word!");
03096         return;
03097     }
03098 
03099 #ifdef SELECT_CARET_AND_CHARS
03100     // Select the caret
03101     pCaret->Select(TRUE);
03102 #endif
03103 
03104     // select all chars between the start of the last word to the start of the next word
03105     VisibleTextNode* pVTN = pPrevWordStart;
03106     while (pVTN!=NULL && pVTN!=pNextWordStart)
03107     {
03108         if (!pVTN->IsAnEOLNode())
03109             pVTN->Select(TRUE);
03110         pVTN = pVTN->FindNextVTNInStory();
03111         ERROR3IF(pVTN==NULL,"OpTextCaret::DoSelectWordAtCaret() - never found pNextWordStart");
03112     }
03113 
03114     GetApplication()->FindSelection()->SetGag(FALSE);
03115     CompleteOperation();
03116 }

VisibleTextNode * OpTextCaret::GetCharacterLineChange VisibleTextNode pCharacter,
BOOL  ToLeftOfChar,
BOOL *  NewToLeft,
BOOL  MoveUp
[protected]
 

Definition at line 3358 of file textops.cpp.

03360 {
03361     ERROR2IF(pCharacter == NULL, NULL, "NULL entry param");
03362 
03363     // Get a pointer to the current and next TextLine
03364     TextLine* pCurrentLine = pCharacter->FindParentLine();
03365     ERROR2IF(pCurrentLine == NULL, NULL, "Character didn't have a parent text line");
03366     TextLine* pNewLine = NULL;
03367     if (MoveUp)
03368         pNewLine = pCurrentLine->FindPrevLine();
03369     else
03370         pNewLine = pCurrentLine->FindNextLine();
03371 
03372     // If there is a new line then find the character on it
03373     VisibleTextNode* pResult = NULL;
03374     if (pNewLine != NULL)
03375     {
03376         // Get the current distance along the line, using the previous vertical move if there was one
03377         MILLIPOINT CurrentDistance = pCharacter->CalcCharDistAlongLine(ToLeftOfChar);
03378         if (PreviousVerticalInset.HoldingInset != VERTICALMOVEINSET_NONE &&
03379             PreviousVerticalInset.LastInset == CurrentDistance &&
03380             CurrentDistance != -1)
03381         {
03382             CurrentDistance = PreviousVerticalInset.HoldingInset;
03383         }
03384         else
03385         {
03386             PreviousVerticalInset.HoldingInset = VERTICALMOVEINSET_NONE;
03387         }
03388 
03389         // Get the character that distance along the new line
03390         if (CurrentDistance != -1)
03391             pResult = pNewLine->FindCharAtDistAlongLine(CurrentDistance, NewToLeft);
03392 
03393         // Update the vertical move memory
03394         if (pResult != NULL)
03395         {
03396             if (PreviousVerticalInset.HoldingInset != VERTICALMOVEINSET_NONE)
03397                 VertInset.HoldingInset = PreviousVerticalInset.HoldingInset;
03398             else
03399                 VertInset.HoldingInset = CurrentDistance;
03400             VertInset.LastInset = pResult->CalcCharDistAlongLine(!*NewToLeft);
03401         }
03402     }
03403 
03404     return pResult;
03405 }

VisibleTextNode * OpTextCaret::GetLineEndCharacter VisibleTextNode pCharacter  )  [static]
 

This function returns a pointer to the VisibleTextNode at the end of a line, this should be an EOLNode.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/04/95
Parameters:
pCharacter - points to the character to look from [INPUTS]
Returns:
A pointer to the last VisibleTextNode character on the line pCharacter is on, NULL if there is isn't one (this is BAD!)

Definition at line 3446 of file textops.cpp.

03447 {
03448     ERROR2IF(pCharacter == NULL, NULL, "pCharacter was NULL");
03449     VisibleTextNode* pResult = NULL;
03450     
03451     TextLine* pParent = pCharacter->FindParentLine();
03452     ERROR2IF(pParent == NULL, NULL, "Character didn't have a parent TextLine");
03453     pResult = pParent->FindLastVTN();
03454 
03455     ERROR2IF(pResult == NULL, NULL, "Line didn't have a VTN");
03456 
03457     return pResult;
03458 }

VisibleTextNode * OpTextCaret::GetLineStartCharacter VisibleTextNode pCharacter  )  [static]
 

This function returns a pointer to the VisibleTextNode at the start of a line.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/04/95
Parameters:
pCharacter - points to the character to look from [INPUTS]
Returns:
A pointer to the first VisibleTextNode character on the line pCharacter is on, NULL if there is isn't one (this is BAD!)

Definition at line 3419 of file textops.cpp.

03420 {
03421     ERROR2IF(pCharacter == NULL, NULL, "pCharacter was NULL");
03422     VisibleTextNode* pResult = NULL;
03423     
03424     TextLine* pParent = pCharacter->FindParentLine();
03425     ERROR2IF(pParent == NULL, NULL, "Character didn't have a parent TextLine");
03426     pResult = pParent->FindFirstVTN();
03427 
03428     ERROR2IF(pResult == NULL, NULL, "Line didn't have a VTN");
03429 
03430     return pResult;
03431 }

void OpTextCaret::MoveCaretToSelectionEnd BOOL  MoveToLeft  )  [protected]
 

This function should be called to move the caret to the end of the selected text. It also selectes the caret, deselecting the other characters.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/03/95
Parameters:
MoveToLeft,TRUE if caret should go to left side of selection, FALSE for right side [INPUTS]

Definition at line 3166 of file textops.cpp.

03167 {
03168     ERROR3IF(pStory == NULL, "pStory was NULL");
03169     ERROR3IF(pCaret == NULL, "pCaret was NULL");
03170 
03171     if ((pStory != NULL) && (pCaret != NULL) )
03172     {
03173         BOOL SelToRightOfCaret = TRUE;
03174         VisibleTextNode* pSelEnd = pStory->GetSelectionEnd(&SelToRightOfCaret);
03175         ERROR3IF(pSelEnd == NULL, "Who cleared the selection before calling MoveCaretToSelectionEnd?");
03176 
03177         // Reposition the caret at right end of the selected region
03178         NodeRenderableInk::DeselectAll(TRUE,FALSE);
03179         if ((pSelEnd != NULL) && (MoveToLeft != SelToRightOfCaret))
03180         {
03181             if (pSelEnd->IsAnEOLNode())
03182                 pStory->MoveCaretToCharacter(pSelEnd, PREV);
03183             else
03184                 pStory->MoveCaretToCharacter(pSelEnd, MoveToLeft?PREV:NEXT);
03185         }
03186         pCaret->ScrollToShow();
03187         pCaret->Select(TRUE);
03188     }
03189 }

BOOL OpTextCaret::PreCaretMove  )  [protected]
 

Carries out common pre operation code for caret movement ops.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/08/95
Returns:
TRUE for success, FALSE if op should not continue

Errors: Checks story and caret pointers for NULL

Definition at line 3045 of file textops.cpp.

03046 {
03047     // Pointer checks on the ops member variables
03048     ERROR2IF(pStory == NULL, FALSE, "(OpTextCaret::DoMoveCaretLeft) pStory was NULL");
03049     ERROR2IF(pCaret == NULL, FALSE, "(OpTextCaret::DoMoveCaretLeft) pCaret was NULL");
03050 
03051     GetApplication()->FindSelection()->SetGag(TRUE);
03052 
03053     return TRUE;
03054 }

void OpTextCaret::SelectStoryCharacters VisibleTextNode pFirstToSel,
VisibleTextNode pLastToSel,
TextStory pStory,
CaretNode pCaret
[static]
 

This function selects characters between the two pointers (inclusive), deselecting all other characters in the story.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/03/95
Parameters:
pFirstToSel - points to the first character to select [INPUTS] pLastToSel - points to the last character to select pStory - points to the story to operate in pCaret - points to the caret in the TextStory, pass in NULL if you don't have it

Definition at line 3225 of file textops.cpp.

03227 {
03228     ERROR3IF(pStory == NULL, "Story pointer was NULL");
03229     if ((pFirstToSel == NULL) || (pLastToSel == NULL) || (pStory == NULL))
03230         return;
03231 
03232     // Get required pointers
03233     if (pCaret == NULL)
03234         pCaret = pStory->GetCaret();
03235 
03236     BlobManager* pBlobMgr = GetApplication()->GetBlobManager();
03237     if (pBlobMgr == NULL)
03238         return;
03239 
03240     // Adjust the selection bounds so caret is not included.
03241     if (pFirstToSel != pLastToSel)
03242     {
03243         if (pFirstToSel->IsACaret())
03244             pFirstToSel = pFirstToSel->FindNextVTNInStory();
03245         else if (pLastToSel->IsACaret())
03246             pLastToSel = pLastToSel->FindPrevVTNInStory();
03247     }
03248 
03249     // Check that we haven't just swapped the start and end
03250     if (pLastToSel == pFirstToSel->FindPrevVTNInStory())
03251     {
03252         VisibleTextNode* pTemp = pFirstToSel;
03253         pFirstToSel = pLastToSel;
03254         pLastToSel = pTemp;
03255     }
03256 
03257     Spread* pSpread = pStory->FindParentSpread();
03258 
03259     // We only need to use the Blob manager, if there are some pending render regions
03260     RenderRegionList* pRegionList = GetApplication()->GetRegionList();
03261     BOOL UseBlobMgr = !pRegionList->IsEmpty();
03262 
03263     RenderRegion* pRegion = NULL;
03264 
03265     // Select characters using just one render region
03266     if (!UseBlobMgr)
03267         pRegion = DocView::RenderOnTop(NULL, pSpread, ClippedEOR );
03268 
03269     while ( UseBlobMgr || pRegion != NULL )
03270     {
03271         // Loop through all the characters in the story
03272         BOOL Select = FALSE;
03273         VisibleTextNode* pChar = pStory->FindFirstVTN();
03274         VisibleTextNode* pNextChar;
03275         while (pChar != NULL)
03276         {
03277             if (pChar == pFirstToSel)
03278                 Select = TRUE;
03279 
03280             // We don't want the very last character to be selectable
03281             pNextChar = pChar->FindNextVTNInStory();
03282             if (pNextChar == NULL)
03283                 Select = FALSE;
03284 
03285             if (Select)
03286             {
03287                 if (!pChar->IsSelected())
03288                 {
03289                     pChar->SetSelected(TRUE);
03290 
03291                     if (UseBlobMgr)
03292                         pBlobMgr->RenderObjectBlobsOn(NULL, pSpread, pChar);
03293                     else
03294                         pChar->RenderObjectBlobs(pRegion);
03295                 }
03296             }
03297             else
03298             {
03299                 if (pChar->IsSelected())
03300                 {
03301                     if (UseBlobMgr)
03302                         pBlobMgr->RenderObjectBlobsOff(NULL, pSpread, pChar);
03303                     else
03304                         pChar->RenderObjectBlobs(pRegion);
03305 
03306                     pChar->SetSelected(FALSE);
03307                 }
03308             }
03309 
03310             if (pChar == pLastToSel)
03311                 Select = FALSE;
03312 
03313             pChar = pNextChar;
03314 
03315         }
03316 
03317         // Get the Next render region
03318         if (UseBlobMgr)
03319             UseBlobMgr = FALSE;
03320         else
03321             pRegion = DocView::GetNextOnTop(NULL);
03322     }
03323 
03324     GetApplication()->UpdateSelection();
03325 
03326 #ifdef SELECT_CARET_AND_CHARS
03327     // Ensure the caret is always selected
03328     pCaret->Select(TRUE);
03329 #else
03330     // Now that we have finished selecting characters, select the caret if there is no selected chars
03331     if (pStory->GetSelectionEnd() == NULL)
03332         pCaret->Select(TRUE);
03333 #endif
03334 
03335 }


Member Data Documentation

CaretNode* OpTextCaret::pCaret [protected]
 

Definition at line 682 of file textops.h.

VisibleTextNode* OpTextCaret::pOtherSelEnd [protected]
 

Definition at line 683 of file textops.h.

VerticalInsetStore OpTextCaret::PreviousVerticalInset [protected]
 

Definition at line 687 of file textops.h.

TextStory* OpTextCaret::pStory [protected]
 

Definition at line 681 of file textops.h.

BOOL OpTextCaret::SelToRightOfCaret [protected]
 

Definition at line 684 of file textops.h.

VerticalInsetStore OpTextCaret::VertInset [static, protected]
 

Definition at line 686 of file textops.h.


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