public void CopySelectedTextToPlainText(StringBuilder stBuilder)
 {
     if (selectionRange == null)
     {
     }
     else
     {
         selectionRange.SwapIfUnOrder();
         if (selectionRange.IsOnTheSameLine)
         {
             LinkedList <EditableRun> runs = textLineWriter.CopySelectedTextRuns(selectionRange);
             foreach (EditableRun t in runs)
             {
                 t.CopyContentToStringBuilder(stBuilder);
             }
         }
         else
         {
             VisualPointInfo startPoint = selectionRange.StartPoint;
             CurrentLineNumber        = startPoint.LineId;
             textLineWriter.CharIndex = startPoint.LineCharIndex;
             LinkedList <EditableRun> runs = textLineWriter.CopySelectedTextRuns(selectionRange);
             foreach (EditableRun t in runs)
             {
                 t.CopyContentToStringBuilder(stBuilder);
             }
         }
     }
 }
Beispiel #2
0
        void LeftCopy(VisualPointInfo pointInfo, List <EditableRun> output)
        {
            if (pointInfo.LineId != currentLineNumber)
            {
                throw new NotSupportedException();
            }
            EditableRun tobeCutRun = pointInfo.TextRun;

            if (tobeCutRun == null)
            {
                return;
            }

            foreach (EditableRun t in _runs)
            {
                if (t != tobeCutRun)
                {
                    output.Add(t.Clone());
                }
                else
                {
                    break;
                }
            }
            EditableRun preCutTextRun = tobeCutRun.LeftCopy(pointInfo.RunLocalSelectedIndex);

            if (preCutTextRun != null)
            {
                output.Add(preCutTextRun);
            }
        }
        public void AddTextSpan(EditableRun textRun)
        {
            if (CurrentLine.IsBlankLine)
            {
                CurrentLine.AddLast(textRun);
                SetCurrentTextRun(textRun);
                CurrentLine.TextLineReCalculateActualLineSize();
                CurrentLine.RefreshInlineArrange();

                SetCurrentCharIndex(CharIndex + textRun.CharacterCount);
            }
            else
            {
                if (CurrentTextRun != null)
                {
                    VisualPointInfo newPointInfo = CurrentLine.Split(GetCurrentPointInfo());
                    if (newPointInfo.IsOnTheBeginOfLine)
                    {
                        CurrentLine.AddBefore((EditableRun)newPointInfo.TextRun, textRun);
                    }
                    else
                    {
                        CurrentLine.AddAfter((EditableRun)newPointInfo.TextRun, textRun);
                    }
                    CurrentLine.TextLineReCalculateActualLineSize();
                    CurrentLine.RefreshInlineArrange();
                    EnsureCurrentTextRun(CharIndex + textRun.CharacterCount);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
        }
Beispiel #4
0
        public void HandleDoubleClick(UIMouseEventArgs e)
        {
            internalTextLayerController.CancelSelect();
            EditableRun textRun = this.CurrentTextRun;

            if (textRun != null)
            {
                VisualPointInfo pointInfo          = internalTextLayerController.GetCurrentPointInfo();
                int             lineCharacterIndex = pointInfo.LineCharIndex;
                int             local_sel_Index    = pointInfo.RunLocalSelectedIndex;
                //default behaviour is select only a hit word under the caret
                //so ask the text layer to find a hit word
                int startAt, len;
                internalTextLayerController.FindUnderlyingWord(out startAt, out len);
                if (len > 0)
                {
                    InvalidateGraphicOfCurrentLineArea();
                    internalTextLayerController.TryMoveCaretTo(startAt, true);
                    internalTextLayerController.StartSelect();
                    internalTextLayerController.TryMoveCaretTo(startAt + len);
                    internalTextLayerController.EndSelect();


                    //internalTextLayerController.TryMoveCaretTo(lineCharacterIndex - local_sel_Index, true);
                    //internalTextLayerController.StartSelect();
                    //internalTextLayerController.TryMoveCaretTo(internalTextLayerController.CharIndex + textRun.CharacterCount);
                    //internalTextLayerController.EndSelect();

                    InvalidateGraphicOfCurrentLineArea();
                }
            }
        }
        public void OnDoubleClick(UIMouseEventArgs e)
        {
            internalTextLayerController.CancelSelect();
            EditableRun textRun = this.CurrentTextRun;

            if (textRun != null)
            {
                VisualPointInfo pointInfo          = internalTextLayerController.GetCurrentPointInfo();
                int             lineCharacterIndex = pointInfo.LineCharIndex;
                int             localselIndex      = pointInfo.LocalSelectedIndex;
                internalTextLayerController.CharIndex = lineCharacterIndex - localselIndex - 1;
                internalTextLayerController.StartSelect();
                internalTextLayerController.CharIndex += textRun.CharacterCount;
                internalTextLayerController.EndSelect();
            }
        }
Beispiel #6
0
        public void FindCurrentUnderlyingWord(out int startAt, out int len)
        {
            EditableRun textRun = this.CurrentTextRun;

            if (textRun != null)
            {
                VisualPointInfo pointInfo          = internalTextLayerController.GetCurrentPointInfo();
                int             lineCharacterIndex = pointInfo.LineCharIndex;
                int             local_sel_Index    = pointInfo.RunLocalSelectedIndex;
                //default behaviour is select only a hit word under the caret
                //so ask the text layer to find a hit word
                internalTextLayerController.FindUnderlyingWord(out startAt, out len);
            }
            else
            {
                startAt = len = 0;
            }
        }
Beispiel #7
0
        public void Draw(Canvas destPage, Rectangle updateArea)
        {
            if (IsOnTheSameLine)
            {
                VisualPointInfo topEndPoint    = TopEnd;
                VisualPointInfo bottomEndPoint = BottomEnd;

                int linetop = topEndPoint.LineTop;

                destPage.FillRectangle(Color.LightGray, topEndPoint.X, linetop,
                                       bottomEndPoint.X - topEndPoint.X, topEndPoint.ActualLineHeight);
            }
            else
            {
                EditableVisualPointInfo topEndPoint = TopEnd;
                int lineYPos = topEndPoint.LineTop;

                destPage.FillRectangle(Color.LightGray, topEndPoint.X, lineYPos,
                                       topEndPoint.CurrentWidth - topEndPoint.X,
                                       topEndPoint.ActualLineHeight);

                int topLineId    = topEndPoint.LineId;
                int bottomLineId = BottomEnd.LineId;
                if (bottomLineId - topLineId > 1)
                {
                    EditableTextLine adjacentStartLine = topEndPoint.EditableLine.Next;
                    while (adjacentStartLine != BottomEnd.Line)
                    {
                        destPage.FillRectangle(Color.LightGray, 0,
                                               adjacentStartLine.LineTop,
                                               adjacentStartLine.CurrentWidth,
                                               adjacentStartLine.ActualLineHeight);
                        adjacentStartLine = adjacentStartLine.Next;
                    }
                    EditableTextLine adjacentStopLine = BottomEnd.Line.Prev;
                }
                VisualPointInfo bottomEndPoint = BottomEnd;
                lineYPos = bottomEndPoint.LineTop;

                destPage.FillRectangle(Color.LightGray, 0, lineYPos, bottomEndPoint.X,
                                       bottomEndPoint.ActualLineHeight);
            }
        }
Beispiel #8
0
        void RightCopy(VisualPointInfo pointInfo, List <EditableRun> output)
        {
            if (pointInfo.LineId != currentLineNumber)
            {
                throw new NotSupportedException();
            }
            EditableRun tobeCutRun = pointInfo.TextRun;

            if (tobeCutRun == null)
            {
                return;
            }
            EditableRun postCutTextRun = (EditableRun)tobeCutRun.Copy(pointInfo.RunLocalSelectedIndex + 1);

            if (postCutTextRun != null)
            {
                output.Add(postCutTextRun);
            }
            foreach (EditableRun t in GetVisualElementForward(tobeCutRun.NextTextRun, this.LastRun))
            {
                output.Add(t.Clone());
            }
        }
        public Rectangle GetRectAreaOf(int beginlineNum, int beginColumnNum, int endLineNum, int endColumnNum)
        {
            EditableTextFlowLayer flowLayer = this.textLayer;
            EditableTextLine      beginLine = flowLayer.GetTextLineAtPos(beginlineNum);

            if (beginLine == null)
            {
                return(Rectangle.Empty);
            }
            if (beginlineNum == endLineNum)
            {
                VisualPointInfo beginPoint = beginLine.GetTextPointInfoFromCharIndex(beginColumnNum);
                VisualPointInfo endPoint   = beginLine.GetTextPointInfoFromCharIndex(endColumnNum);
                return(new Rectangle(beginPoint.X, beginLine.Top, endPoint.X, beginLine.ActualLineHeight));
            }
            else
            {
                VisualPointInfo  beginPoint = beginLine.GetTextPointInfoFromCharIndex(beginColumnNum);
                EditableTextLine endLine    = flowLayer.GetTextLineAtPos(endLineNum);
                VisualPointInfo  endPoint   = endLine.GetTextPointInfoFromCharIndex(endColumnNum);
                return(new Rectangle(beginPoint.X, beginLine.Top, endPoint.X, beginLine.ActualLineHeight));
            }
        }
Beispiel #10
0
        VisualSelectionRangeSnapShot RemoveSelectedText()
        {
#if DEBUG
            if (dbugEnableTextManRecorder)
            {
                dbugTextManRecorder.WriteInfo("TxLMan::RemoveSelectedText");
                dbugTextManRecorder.BeginContext();
            }
#endif

            if (selectionRange == null)
            {
#if DEBUG
                if (dbugEnableTextManRecorder)
                {
                    dbugTextManRecorder.WriteInfo("NO_SEL_RANGE");
                    dbugTextManRecorder.EndContext();
                }
#endif
                return(VisualSelectionRangeSnapShot.Empty);
            }
            else if (!selectionRange.IsValid)
            {
#if DEBUG
                if (dbugEnableTextManRecorder)
                {
                    dbugTextManRecorder.WriteInfo("!RANGE_ON_SAME_POINT");
                }
#endif
                CancelSelect();
#if DEBUG
                if (dbugEnableTextManRecorder)
                {
                    dbugTextManRecorder.EndContext();
                }
#endif
                return(VisualSelectionRangeSnapShot.Empty);
            }
            selectionRange.SwapIfUnOrder();
            VisualSelectionRangeSnapShot selSnapshot = selectionRange.GetSelectionRangeSnapshot();
            VisualPointInfo startPoint = selectionRange.StartPoint;
            CurrentLineNumber = startPoint.LineId;
            int preCutIndex = startPoint.LineCharIndex;
            textLineWriter.CharIndex = startPoint.LineCharIndex;
            if (selectionRange.IsOnTheSameLine)
            {
                LinkedList <EditableRun> tobeDeleteTextRun = textLineWriter.CopySelectedTextRuns(selectionRange);
                if (tobeDeleteTextRun != null)
                {
                    commandHistory.AddDocAction(
                        new DocActionDeleteRange(tobeDeleteTextRun,
                                                 selSnapshot.startLineNum,
                                                 selSnapshot.startColumnNum,
                                                 selSnapshot.endLineNum,
                                                 selSnapshot.endColumnNum));
                    textLineWriter.RemoveSelectedTextRuns(selectionRange);
                    updateJustCurrentLine = true;
                }
            }
            else
            {
                int startPointLindId    = startPoint.LineId;
                int startPointCharIndex = startPoint.LineCharIndex;
                LinkedList <EditableRun> tobeDeleteTextRun = textLineWriter.CopySelectedTextRuns(selectionRange);
                if (tobeDeleteTextRun != null)
                {
                    commandHistory.AddDocAction(
                        new DocActionDeleteRange(tobeDeleteTextRun,
                                                 selSnapshot.startLineNum,
                                                 selSnapshot.startColumnNum,
                                                 selSnapshot.endLineNum,
                                                 selSnapshot.endColumnNum));
                    textLineWriter.RemoveSelectedTextRuns(selectionRange);
                    updateJustCurrentLine = false;
                    textLineWriter.MoveToLine(startPointLindId);
                    textLineWriter.CharIndex = startPointCharIndex;
                }
            }
            CancelSelect();
            TextEditRenderBox.NotifyTextContentSizeChanged(visualTextSurface);
#if DEBUG
            if (dbugEnableTextManRecorder)
            {
                dbugTextManRecorder.EndContext();
            }
#endif
            return(selSnapshot);
        }
Beispiel #11
0
        internal void Remove(VisualSelectionRange selectionRange)
        {
            EditableVisualPointInfo startPoint = selectionRange.StartPoint;
            EditableVisualPointInfo endPoint   = selectionRange.EndPoint;

            if (startPoint.TextRun != null)
            {
                if (startPoint.TextRun == endPoint.TextRun)
                {
                    EditableRun removedRun = (EditableRun)startPoint.TextRun;
                    EditableRun.InnerRemove(removedRun,
                                            startPoint.RunLocalSelectedIndex,
                                            endPoint.LineCharIndex - startPoint.LineCharIndex, false);
                    if (removedRun.CharacterCount == 0)
                    {
                        if (startPoint.LineId == this.currentLineNumber)
                        {
                            this.Remove(removedRun);
                        }
                        else
                        {
                            EditableTextLine line = editableFlowLayer.GetTextLine(startPoint.LineId);
                            line.Remove(removedRun);
                        }
                    }
                }
                else
                {
                    EditableVisualPointInfo newStartPoint = null;
                    EditableVisualPointInfo newStopPoint  = null;
                    EditableTextLine        startLine     = null;
                    EditableTextLine        stopLine      = null;
                    if (startPoint.LineId == currentLineNumber)
                    {
                        startLine = this;
                    }
                    else
                    {
                        startLine = editableFlowLayer.GetTextLine(startPoint.LineId);
                    }
                    newStartPoint = startLine.Split(startPoint);
                    if (endPoint.LineId == currentLineNumber)
                    {
                        stopLine = this;
                    }
                    else
                    {
                        stopLine = editableFlowLayer.GetTextLine(endPoint.LineId);
                    }

                    newStopPoint = stopLine.Split(endPoint);
                    if (startLine == stopLine)
                    {
                        if (newStartPoint.TextRun != null)
                        {
                            LinkedList <EditableRun> tobeRemoveRuns = new LinkedList <EditableRun>();
                            if (newStartPoint.LineCharIndex == 0)
                            {
                                foreach (EditableRun t in editableFlowLayer.TextRunForward(
                                             (EditableRun)newStartPoint.TextRun,
                                             (EditableRun)newStopPoint.TextRun))
                                {
                                    tobeRemoveRuns.AddLast(t);
                                }
                            }
                            else
                            {
                                foreach (EditableRun t in editableFlowLayer.TextRunForward(
                                             newStartPoint.TextRun.NextTextRun,
                                             (EditableRun)newStopPoint.TextRun))
                                {
                                    tobeRemoveRuns.AddLast(t);
                                }
                            }
                            startLine.LocalSuspendLineReArrange();
                            foreach (EditableRun t in tobeRemoveRuns)
                            {
                                startLine.Remove(t);
                            }
                            startLine.LocalResumeLineReArrange();
                        }
                        else
                        {
                            throw new NotSupportedException();
                        }
                    }
                    else
                    {
                        int startLineId = newStartPoint.LineId;
                        int stopLineId  = newStopPoint.LineId;
                        if (newStopPoint.LineCharIndex > 0)
                        {
                            stopLine.RemoveLeft((EditableRun)newStopPoint.TextRun);
                        }
                        for (int i = stopLineId - 1; i > startLineId; i--)
                        {
                            EditableTextLine line = editableFlowLayer.GetTextLine(i);
                            line.Clear();
                            line.JoinWithNextLine();
                        }
                        if (newStartPoint.LineCharIndex == 0)
                        {
                            startLine.RemoveRight((EditableRun)newStartPoint.TextRun);
                        }
                        else
                        {
                            EditableRun nextRun = ((EditableRun)newStartPoint.TextRun).NextTextRun;
                            if (nextRun != null && !nextRun.IsLineBreak)
                            {
                                startLine.RemoveRight(nextRun);
                            }
                        }
                        startLine.JoinWithNextLine();
                    }
                }
            }
            else
            {
                VisualPointInfo  newStartPoint = null;
                VisualPointInfo  newStopPoint  = null;
                EditableTextLine startLine     = null;
                EditableTextLine stopLine      = null;
                if (startPoint.LineId == this.currentLineNumber)
                {
                    startLine = this;
                }
                else
                {
                    startLine = editableFlowLayer.GetTextLine(startPoint.LineId);
                }
                newStartPoint = startLine.Split(startPoint);
                if (endPoint.LineId == currentLineNumber)
                {
                    stopLine = this;
                }
                else
                {
                    stopLine = editableFlowLayer.GetTextLine(endPoint.LineId);
                }
                newStopPoint = stopLine.Split(endPoint);
                if (startLine == stopLine)
                {
                    if (newStartPoint.TextRun != null)
                    {
                        LinkedList <EditableRun> tobeRemoveRuns = new LinkedList <EditableRun>();
                        if (newStartPoint.LineCharIndex == -1)
                        {
                            foreach (EditableRun t in editableFlowLayer.TextRunForward(
                                         (EditableRun)newStartPoint.TextRun,
                                         (EditableRun)newStopPoint.TextRun))
                            {
                                tobeRemoveRuns.AddLast(t);
                            }
                        }
                        else
                        {
                            foreach (EditableRun t in editableFlowLayer.TextRunForward(
                                         newStartPoint.TextRun.NextTextRun,
                                         (EditableRun)newStopPoint.TextRun))
                            {
                                tobeRemoveRuns.AddLast(t);
                            }
                        }
                        foreach (EditableRun t in tobeRemoveRuns)
                        {
                            startLine.Remove(t);
                        }
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
                else
                {
                    int startLineId = newStartPoint.LineId;
                    int stopLineId  = newStopPoint.LineId;
                    if (newStopPoint.LineCharIndex > -1)
                    {
                        stopLine.RemoveLeft((EditableRun)newStopPoint.TextRun);
                    }
                    for (int i = stopLineId - 1; i > startLineId; i--)
                    {
                        EditableTextLine line = editableFlowLayer.GetTextLine(i);
                        line.Clear();
                        line.JoinWithNextLine();
                    }
                    if (newStartPoint.LineCharIndex == -1)
                    {
                        if (newStartPoint.TextRun != null)
                        {
                            startLine.RemoveRight((EditableRun)newStartPoint.TextRun);
                        }
                    }
                    else
                    {
                        EditableRun nextRun = newStartPoint.TextRun.NextTextRun;
                        if (nextRun != null && !nextRun.IsLineBreak)
                        {
                            startLine.RemoveRight(nextRun);
                        }
                    }
                    startLine.JoinWithNextLine();
                }
            }
        }
        void LeftCopy(VisualPointInfo pointInfo, LinkedList<EditableRun> output)
        {
            if (pointInfo.LineId != currentLineNumber)
            {
                throw new NotSupportedException();
            }
            EditableRun tobeCutRun = pointInfo.TextRun;
            if (tobeCutRun == null)
            {
                return;
            }

            foreach (EditableRun t in this)
            {
                if (t != tobeCutRun)
                {
                    output.AddLast(t.Clone());
                }
                else
                {
                    break;
                }
            }
            EditableRun preCutTextRun = tobeCutRun.LeftCopy(pointInfo.LocalSelectedIndex);
            if (preCutTextRun != null)
            {
                output.AddLast(preCutTextRun);
            }
        }
 void RightCopy(VisualPointInfo pointInfo, LinkedList<EditableRun> output)
 {
     if (pointInfo.LineId != currentLineNumber)
     {
         throw new NotSupportedException();
     }
     EditableRun tobeCutRun = pointInfo.TextRun;
     if (tobeCutRun == null)
     {
         return;
     }
     EditableRun postCutTextRun = (EditableRun)tobeCutRun.Copy(pointInfo.LocalSelectedIndex + 1);
     if (postCutTextRun != null)
     {
         output.AddLast(postCutTextRun);
     }
     foreach (EditableRun t in GetVisualElementForward(tobeCutRun.NextTextRun, this.LastRun))
     {
         output.AddLast(t.Clone());
     }
 }