#include <textops.h>
Inheritance diagram for OpTextSelection:
Public Types | |
enum | SelectionPos { TO_LEFT, TO_RIGHT, NOT_NEAR } |
Public Member Functions | |
OpTextSelection () | |
Constructor. Initialises members. | |
BOOL | DoDrag (DocCoord Anchor, Spread *pSpread, ClickModifiers ClickMods, Node *ClickNode) |
Initially inserts the caret into the TextStory at the position of the click. | |
virtual BOOL | SnappingDrag () |
virtual void | DragPointerMove (DocCoord PointerPos, ClickModifiers ClickMods, Spread *pSpread, BOOL bSolidDrag) |
Adds or removes characters from the text story selection. | |
virtual void | DragFinished (DocCoord PointerPos, ClickModifiers ClickMods, Spread *pSpread, BOOL Success, BOOL bSolidDrag) |
Handles the drag finishing. Clears the selection if ESCAPE was pressed. | |
BOOL | DoSelectAllText (TextStory *pStory) |
Selects all characters in the given story. | |
BOOL | DoSelectLineText () |
Selects all VTN's in the given text line, clearing all other selections. | |
Static Public Member Functions | |
static BOOL | Declare () |
static OpState | GetState (String_256 *Description, OpDescriptor *) |
Find out the state of the operation at the specific time. | |
static BOOL | Init () |
Adds the operation to the list of all known operations. | |
Protected Member Functions | |
BOOL | InitialCaretPosition (VisibleTextNode *) |
The caret is positioned either to the left or right of the character clicked upon. | |
BOOL | ExtendSelection (VisibleTextNode *, DocCoord ClickPoint) |
If the story clicked on was not the focus story the the caret is positioned at the click point If the story clicked on was the focus story, but there was no text selection then a selection is created between the caret and the click point If the story clicked on was the focus story and there was no text selection the selection is extended, using the caret as the anchor point. | |
BOOL | SelectLine () |
The caret is positioned at the start of the line and all AbstractCharacters on the line are selected. | |
SelectionPos | IsClickToLeftHalfOfChar (AbstractTextChar *pClickChar, DocCoord ClickPoint, BOOL MustChoose) |
To see if a click is to the left or right of the middle of a character. | |
BOOL | GetNewSelEndsOnPath (DocCoord Point, VisibleTextNode **pSelStart, VisibleTextNode **pSelEnd, BOOL *) |
For finding the bounds of the selection when the TextStory is on a path. | |
BOOL | GetNewSelEndsInStory (DocCoord Point, VisibleTextNode **pSelStart, VisibleTextNode **pSelEnd) |
For finding the bounds of the selection when the TextStory is not on a path. | |
BOOL | GetNewSelBoundsChars (BOOL, BOOL, VisibleTextNode *, VisibleTextNode **, VisibleTextNode **) |
Protected Attributes | |
Spread * | StartSpread |
DocCoord | StartPoint |
TextStory * | pSelectionStory |
CaretNode * | pCaret |
Private Member Functions | |
CC_DECLARE_DYNCREATE (OpTextSelection) |
Definition at line 701 of file textops.h.
|
Definition at line 707 of file textops.h.
|
|
Constructor. Initialises members.
Definition at line 3472 of file textops.cpp. 03473 { 03474 StartSpread = NULL; 03475 pSelectionStory = NULL; 03476 }
|
|
|
|
|
|
Initially inserts the caret into the TextStory at the position of the click.
Definition at line 3542 of file textops.cpp. 03544 { 03545 // Validate clicked character and story 03546 ERROR2IF(pClickNode == NULL, FALSE, "Pointer to clicked node was NULL!"); 03547 ERROR2IF(!pClickNode->IsAVisibleTextNode(), FALSE, "Clicked node was not a text character"); 03548 VisibleTextNode* pClickChar = (VisibleTextNode*)pClickNode; 03549 pSelectionStory = (TextStory*)(pClickNode->FindParent(CC_RUNTIME_CLASS(TextStory))); 03550 ERROR2IF(pSelectionStory == NULL, FALSE, "Clicked character didn't have a parent TextStory"); 03551 pCaret = pSelectionStory->GetCaret(); 03552 ERROR2IF(pCaret == NULL, FALSE, "TextStory didn't have a caret"); 03553 03554 // Record the initial parameters for later use 03555 StartPoint = Anchor; 03556 StartSpread = pSpread; 03557 03558 BOOL Success = TRUE; 03559 03560 // Give the mainframe input focus 03561 DialogManager::DefaultKeyboardFocus(); 03562 03563 if (ClickMods.Adjust && !ClickMods.Constrain) 03564 { 03565 // SHIFT click to extend selection 03566 Success = ExtendSelection(pClickChar, Anchor); 03567 End(); 03568 return Success; 03569 } 03570 else 03571 { 03572 if (ClickMods.Constrain) 03573 { 03574 // CTRL click to select line 03575 Success = InitialCaretPosition(pClickChar) && SelectLine(); 03576 End(); 03577 return Success; 03578 } 03579 else 03580 { 03581 // Normal click to position caret and then drag selection 03582 Success = InitialCaretPosition(pClickChar); 03583 } 03584 } 03585 03586 if (Success) 03587 Success = StartDrag( DRAGTYPE_AUTOSCROLL ); 03588 03589 return Success; 03590 }
|
|
Selects all characters in the given story.
Definition at line 4106 of file textops.cpp. 04107 { 04108 ERROR2IF(pStory == NULL, FALSE, "Story pointer was NULL"); 04109 CaretNode* pCaret = pStory->GetCaret(); 04110 ERROR2IF(pCaret == NULL, FALSE, "Story didn't have a caret"); 04111 BOOL ok = TRUE; 04112 04113 NodeRenderableInk::DeselectAll(TRUE, FALSE); 04114 04115 // Move the caret to the start of the text story 04116 VisibleTextNode* pStartChar = pStory->FindFirstVTN(); 04117 if (ok && (pStartChar != pCaret)) 04118 ok = pStory->MoveCaretToCharacter(pStartChar, PREV); 04119 04120 // Get the first and last char in story 04121 pStartChar = pStory->FindFirstVTN(); 04122 VisibleTextNode* pEndChar = pStory->FindLastVTN(); 04123 if ((pStartChar == NULL) || (pEndChar == NULL)) 04124 ok = FALSE; 04125 04126 if (ok) 04127 { 04128 OpTextCaret::SelectStoryCharacters(pStartChar, pEndChar, pStory, pCaret); 04129 } 04130 else 04131 { 04132 FailAndExecute(); 04133 InformError(); 04134 } 04135 04136 End(); 04137 04138 return ok; 04139 }
|
|
Selects all VTN's in the given text line, clearing all other selections.
Definition at line 4154 of file textops.cpp. 04155 { 04156 // Set pointers 04157 pSelectionStory = TextStory::GetFocusStory();; 04158 ERROR2IF(pSelectionStory == NULL, FALSE, "No focus text story"); 04159 pCaret = pSelectionStory->GetCaret(); 04160 ERROR2IF(pCaret == NULL, FALSE, "TextStory didn't have a caret"); 04161 04162 BOOL ok = SelectLine(); 04163 04164 if (!ok) 04165 { 04166 FailAndExecute(); 04167 InformError(); 04168 } 04169 04170 End(); 04171 04172 return ok; 04173 }
|
|
Handles the drag finishing. Clears the selection if ESCAPE was pressed.
Reimplemented from Operation. Definition at line 3663 of file textops.cpp. 03665 { 03666 BOOL Worked = TRUE; 03667 03668 // End the Drag 03669 if (Worked) 03670 Worked = EndDrag(); 03671 03672 // Select the caret if they pressed ESCAPE to end the drag, or there is no remaing selection 03673 BOOL Direction; 03674 if ((!Success) || (pSelectionStory->GetSelectionEnd(&Direction) == NULL) ) 03675 { 03676 if ((pSelectionStory->GetCaret() != NULL) && !pSelectionStory->GetCaret()->IsSelected()) 03677 { 03678 NodeRenderableInk::DeselectAll(TRUE,FALSE); 03679 pSelectionStory->GetCaret()->Select(TRUE); 03680 } 03681 } 03682 03683 GetApplication()->FindSelection()->Update(); 03684 03685 End(); 03686 }
|
|
Adds or removes characters from the text story selection.
Reimplemented from Operation. Definition at line 3605 of file textops.cpp. 03607 { 03608 ERROR3IF(((pSelectionStory == NULL) || (pCaret == NULL)), "A pointer was NULL"); 03609 BOOL Success = TRUE; 03610 03611 // If drag has moved onto a different spread, convert the coord to be relative to the 03612 // original spread. 03613 if (pSpread != StartSpread) 03614 PointerPos = MakeRelativeToSpread(StartSpread, pSpread, PointerPos); 03615 03616 // Do different things depending wether you are on a path or not 03617 VisibleTextNode* pFirstToSel = NULL; 03618 VisibleTextNode* pLastToSel = NULL; 03619 BOOL Ignore = FALSE; 03620 if (pSelectionStory->GetTextPath() != NULL) 03621 Success = GetNewSelEndsOnPath(PointerPos, &pFirstToSel, &pLastToSel, &Ignore); 03622 else 03623 Success = GetNewSelEndsInStory(PointerPos, &pFirstToSel, &pLastToSel); 03624 03625 // Run through all the characters, selecting and deselecting 03626 if (!Success || (pFirstToSel == NULL) || (pLastToSel == NULL)) 03627 { 03628 if ((!pCaret->IsSelected() || (pSelectionStory->GetSelectionEnd() != NULL)) && !Ignore) 03629 { 03630 NodeRenderableInk::DeselectAll(TRUE,FALSE); 03631 pCaret->Select(TRUE); 03632 } 03633 } 03634 else 03635 { 03636 OpTextCaret::SelectStoryCharacters(pFirstToSel, pLastToSel, pSelectionStory, pCaret); 03637 } 03638 03639 if (!Success) 03640 { 03641 InformError(); 03642 FailAndExecute(); 03643 EndDrag(); 03644 End(); 03645 } 03646 }
|
|
If the story clicked on was not the focus story the the caret is positioned at the click point If the story clicked on was the focus story, but there was no text selection then a selection is created between the caret and the click point If the story clicked on was the focus story and there was no text selection the selection is extended, using the caret as the anchor point.
Definition at line 4019 of file textops.cpp. 04020 { 04021 BOOL Success = TRUE; 04022 04023 // Is the selection story the one with the input focus? 04024 if (pSelectionStory != TextStory::GetFocusStory()) 04025 { 04026 Success = InitialCaretPosition(pClickChar); 04027 } 04028 else 04029 { 04030 // BOOL CurrentForwardsDirection = TRUE; 04031 BOOL NewForwardsDirection = TRUE; 04032 // VisibleTextNode* pSelEnd = pSelectionStory->GetSelectionEnd(&CurrentForwardsDirection); 04033 CaretNode* pCaret = pSelectionStory->GetCaret(); 04034 ERROR2IF(pCaret == NULL, FALSE, "Caret not found"); 04035 04036 // Scan from the caret to the right to find the direction of pClickChar 04037 // BODGE TEXT - should be a formatty thing, rather than scanning chars 04038 VisibleTextNode* pChar = pCaret->FindNextVTNInStory(); 04039 while ((pChar != NULL) && (pChar != pClickChar)) 04040 { 04041 pChar = pChar->FindNextVTNInStory(); 04042 } 04043 if (pChar != NULL) 04044 NewForwardsDirection = TRUE; // The clicked char is to the right of the caret 04045 else 04046 NewForwardsDirection = FALSE; // The clicked char is to the left of the caret 04047 04048 // Get the selection end char 04049 VisibleTextNode* pNewSelEndChar = pClickChar; 04050 SelectionPos ClickPos = TO_LEFT; 04051 if (pClickChar->IsAnAbstractTextChar()) 04052 ClickPos = IsClickToLeftHalfOfChar((AbstractTextChar*)pClickChar, ClickPoint, TRUE); 04053 if (NewForwardsDirection && (ClickPos==TO_LEFT)) 04054 { 04055 // The selection goes from the caret to the left of the click char 04056 pNewSelEndChar = pClickChar->FindPrevVTNInStory(); 04057 } 04058 if (!NewForwardsDirection && (ClickPos==TO_RIGHT)) 04059 { 04060 // The selection goes from the caret to the right of the click char 04061 pNewSelEndChar = pClickChar->FindNextVTNInStory(); 04062 } 04063 if (pNewSelEndChar->IsACaret()) 04064 pNewSelEndChar = NULL; 04065 04066 // Get the selection start character 04067 VisibleTextNode* pSelStartChar = NULL; 04068 if (NewForwardsDirection) 04069 pSelStartChar = pCaret->FindNextVTNInStory(); 04070 else 04071 { 04072 pSelStartChar = pNewSelEndChar; 04073 pNewSelEndChar = pCaret->FindPrevVTNInStory(); 04074 } 04075 04076 // Do the selection 04077 if ((pSelStartChar == NULL) || (pNewSelEndChar == NULL)) 04078 { 04079 NodeRenderableInk::DeselectAll(TRUE,FALSE); 04080 pCaret->Select(TRUE); 04081 } 04082 else 04083 { 04084 OpTextCaret::SelectStoryCharacters(pSelStartChar, pNewSelEndChar, pSelectionStory, pCaret); 04085 pNewSelEndChar->ScrollToShow(); 04086 } 04087 } 04088 04089 GetApplication()->UpdateSelection(); 04090 return Success; 04091 }
|
|
Definition at line 3833 of file textops.cpp. 03835 { 03836 ERROR2IF(((pFoundChar == NULL) || (pCaret == NULL)), FALSE, "NULL Pointer found"); 03837 *pSelStart = NULL; 03838 *pSelEnd = NULL; 03839 03840 // Work out wether to include the character in the selection 03841 if (ToLeftOfCaret) 03842 { 03843 // Selection goes from the left/right of pFoundChar to left of caret 03844 if (ToLeftOfChar) 03845 *pSelStart = pFoundChar; 03846 else 03847 { 03848 *pSelStart = pFoundChar->FindNextVTNInStory(); 03849 if (*pSelStart == pCaret) 03850 *pSelStart = NULL; 03851 } 03852 03853 *pSelEnd = pCaret->FindPrevVTNInStory(); 03854 } 03855 else 03856 { 03857 // Selection goes from right of caret to left/right of pChar 03858 if (!ToLeftOfChar) 03859 *pSelEnd = pFoundChar; 03860 else 03861 { 03862 *pSelEnd = pFoundChar->FindPrevVTNInStory(); 03863 if (*pSelEnd == pCaret) 03864 *pSelEnd = NULL; 03865 } 03866 03867 *pSelStart = pCaret->FindNextVTNInStory(); 03868 } 03869 03870 return TRUE; 03871 }
|
|
For finding the bounds of the selection when the TextStory is not on a path.
Definition at line 3777 of file textops.cpp. 03778 { 03779 // Check members 03780 ERROR2IF(((pSelectionStory == NULL) || (pCaret == NULL)), FALSE, "Story or caret pointer was NULL"); 03781 03782 BOOL ToLeftPosChar = TRUE; 03783 VisibleTextNode* pPointerChar = NULL; 03784 if (!pSelectionStory->GetCharacterAtPoint(FALSE, Point, &pPointerChar, &ToLeftPosChar)) 03785 return FALSE; 03786 ERROR2IF(pPointerChar == NULL, FALSE, "GetCharacterAtPoint failed to find a character"); 03787 03788 // Now scan through the Story to see wether the char is to the left or right of the caret 03789 VisibleTextNode* pChar = pSelectionStory->FindFirstVTN(); 03790 ERROR2IF(pChar == NULL, FALSE, "Selection Story had no characters"); 03791 BOOL ToLeftOfCaret = TRUE; 03792 while (pChar != NULL) 03793 { 03794 if (pChar == pCaret) 03795 { 03796 ToLeftOfCaret = FALSE; 03797 break; 03798 } 03799 03800 if (pChar == pPointerChar) 03801 { 03802 break; 03803 } 03804 03805 pChar = pChar->FindNextVTNInStory(); 03806 } 03807 03808 // Generate first and last selection characters 03809 return GetNewSelBoundsChars(ToLeftPosChar, ToLeftOfCaret, pPointerChar, pSelStart, pSelEnd); 03810 }
|
|
For finding the bounds of the selection when the TextStory is on a path.
Definition at line 3705 of file textops.cpp. 03706 { 03707 // Find the first character in the story 03708 ERROR2IF(((pSelectionStory == NULL) || (pCaret == NULL)), FALSE, "Story or caret pointer was NULL"); 03709 VisibleTextNode* pFirstChar = pSelectionStory->FindFirstVTN(); 03710 ERROR2IF(pFirstChar == NULL, FALSE, "Selection Story had no characters"); 03711 03712 // Find the character the pointer is currently over 03713 BOOL Success = TRUE; 03714 DocRect CharBoundsInDoc; 03715 DocRect CharBoundsInChar; 03716 BOOL ToLeftOfCaret = TRUE; 03717 OpTextSelection::SelectionPos CharSelPos = NOT_NEAR; 03718 VisibleTextNode* pCurrent = pFirstChar; 03719 VisibleTextNode* pChar = NULL; 03720 while ((pCurrent != NULL) && Success) 03721 { 03722 if (pCurrent->IsAnAbstractTextChar()) 03723 { 03724 // Do a test on the bounds of the character matrix 03725 Success = ((AbstractTextChar*)pCurrent)->GetMetricsRectBounds(&CharBoundsInDoc); 03726 03727 // Now test the metric rect of the character 03728 if (Success) 03729 { 03730 CharSelPos = IsClickToLeftHalfOfChar((AbstractTextChar*)pCurrent, Point, FALSE); 03731 03732 if (CharSelPos != NOT_NEAR) 03733 { 03734 pChar = (AbstractTextChar*)pCurrent; 03735 break; 03736 } 03737 } 03738 } 03739 03740 if (pCurrent == (VisibleTextNode*)pCaret) 03741 ToLeftOfCaret = FALSE; 03742 03743 pCurrent = pCurrent->FindNextVTNInStory(); 03744 } 03745 03746 // Generate first and last selection characters 03747 if (Success && (pChar != NULL)) 03748 { 03749 *pIgnore = FALSE; 03750 Success = GetNewSelBoundsChars((CharSelPos == TO_LEFT), ToLeftOfCaret, pChar, pSelStart, pSelEnd); 03751 } 03752 else 03753 { 03754 *pIgnore = TRUE; 03755 pSelStart = NULL; 03756 pSelEnd = NULL; 03757 } 03758 03759 return Success; 03760 }
|
|
Find out the state of the operation at the specific time.
Definition at line 3521 of file textops.cpp. 03522 { 03523 OpState Blobby; 03524 03525 return Blobby; 03526 }
|
|
Adds the operation to the list of all known operations.
Reimplemented from SimpleCCObject. Definition at line 3488 of file textops.cpp. 03489 { 03490 return (RegisterOpDescriptor(0, 03491 _R(IDS_OPTEXTSELECTION), 03492 CC_RUNTIME_CLASS(OpTextSelection), 03493 OPTOKEN_TEXTSELECTION, 03494 OpTextSelection::GetState, 03495 0, // help ID 03496 0, // Bubble help 03497 0, 03498 0, 03499 SYSTEMBAR_ILLEGAL, // For now ! 03500 TRUE, // Receive messages 03501 FALSE, 03502 FALSE, 03503 0, 03504 GREY_WHEN_NO_CURRENT_DOC 03505 )); 03506 }
|
|
The caret is positioned either to the left or right of the character clicked upon.
Definition at line 3886 of file textops.cpp. 03887 { 03888 BOOL Success = TRUE; 03889 03890 // Deselect ALL objects in the tree 03891 NodeRenderableInk::DeselectAll(TRUE,FALSE); 03892 if (pSelectionStory!=TextStory::GetFocusStory()) 03893 if (!OpDeleteTextStory::RemoveEmptyFocusStory()) 03894 return FALSE; 03895 03896 // Position the caret to the left or right of the character, depending on the click 03897 OpTextSelection::SelectionPos ClickPos = TO_LEFT; 03898 if (pSelectChar->IsAnAbstractTextChar()) 03899 ClickPos = IsClickToLeftHalfOfChar((AbstractTextChar*)pSelectChar, StartPoint, TRUE); 03900 ERROR3IF(ClickPos == NOT_NEAR,"Selection point was not near the character claimed"); 03901 if (ClickPos == TO_LEFT) 03902 pSelectionStory->MoveCaretToCharacter(pSelectChar, PREV); 03903 if (ClickPos == TO_RIGHT) 03904 pSelectionStory->MoveCaretToCharacter(pSelectChar, NEXT); 03905 03906 // Select the new Caret 03907 TextStory::SetFocusStory(pSelectionStory); 03908 pSelectionStory->GetCaret()->HasMoved(); 03909 pSelectionStory->GetCaret()->ScrollToShow(); 03910 pSelectionStory->GetCaret()->Select(TRUE); 03911 03912 return Success; 03913 }
|
|
To see if a click is to the left or right of the middle of a character.
Definition at line 3930 of file textops.cpp. 03932 { 03933 ERROR3IF(pSelectionStory == NULL, "pSelectionStory is NULL"); 03934 ERROR3IF(pClickChar == NULL, "pClickChar is NULL"); 03935 03936 SelectionPos Result = NOT_NEAR; 03937 03938 if ((pSelectionStory != NULL) && (pClickChar != NULL)) 03939 { 03940 // Transform the mouse position through the two matrices so it is character relative 03941 Matrix CharMat(0,0); 03942 if (pClickChar->GetStoryAndCharMatrix(&CharMat)!=FALSE) 03943 CharMat=CharMat.Inverse(); 03944 else 03945 ERROR3("GetStoryAndCharMatrix() failed"); 03946 03947 // Transform the mouse click position into character space 03948 CharMat.transform(&ClickPoint); 03949 03950 // Get the character rectangle 03951 DocRect CharRect; 03952 if (pClickChar->GetMetricsRect(&CharRect)) 03953 { 03954 if (CharRect.ContainsCoord(ClickPoint) || MustChoose) 03955 { 03956 if (ClickPoint.x > ((CharRect.lo.x+CharRect.hi.x)/2)) 03957 Result = TO_RIGHT; 03958 else 03959 Result = TO_LEFT; 03960 } 03961 } 03962 else 03963 ERROR3("GetMetricsRectInStory failed"); 03964 } 03965 03966 return Result; 03967 }
|
|
The caret is positioned at the start of the line and all AbstractCharacters on the line are selected.
Definition at line 3981 of file textops.cpp. 03982 { 03983 ERROR2IF(pSelectionStory == NULL, FALSE, "Selection story was NULL"); 03984 CaretNode* pCaret = pSelectionStory->GetCaret(); 03985 ERROR2IF(pCaret == NULL, FALSE, "Selection story didn't have a caret"); 03986 TextLine* pLine = pCaret->FindParentLine(); 03987 ERROR2IF(pLine == NULL, FALSE, "Caret didn't have a parent TextLine"); 03988 03989 // Move the caret to the start of the line 03990 NodeRenderableInk::DeselectAll(TRUE,FALSE); 03991 pSelectionStory->MoveCaretToStartOfLine(); 03992 03993 // Get pointer to first and last char in line 03994 VisibleTextNode* pFirstChar = pCaret->FindNextVTNInStory(); 03995 VisibleTextNode* pLastChar = pLine->FindLastVTN(); 03996 03997 // Select the characters 03998 OpTextCaret::SelectStoryCharacters(pFirstChar, pLastChar, pSelectionStory, pCaret); 03999 04000 return TRUE; 04001 }
|
|
Reimplemented from Operation. Definition at line 714 of file textops.h. 00714 { return FALSE; }
|
|
|
|
|
|
|
|
|