public void AddAfter(EditableRun afterVisualElement, EditableRun visualElement)
        {
            EditableTextLine targetLine = afterVisualElement.OwnerEditableLine;

            if (targetLine != null)
            {
                targetLine.AddAfter(afterVisualElement, visualElement);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
        public void AddBefore(EditableRun beforeVisualElement, EditableRun visualElement)
        {
            EditableTextLine targetLine = beforeVisualElement.OwnerEditableLine;

            if (targetLine != null)
            {
                targetLine.AddBefore(beforeVisualElement, visualElement);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
        public void LocalResumeLineReArrange()
        {
            _lineFlags &= ~LOCAL_SUSPEND_LINE_REARRANGE;
            LinkedListNode <EditableRun> curNode = this.First;
            int cx = 0;

            while (curNode != null)
            {
                EditableRun ve = curNode.Value;
                EditableRun.DirectSetLocation(ve, cx, 0);
                cx     += ve.Width;
                curNode = curNode.Next;
            }
        }
        LinkedList <EditableRun> CollectRightRuns(EditableRun t)
        {
            if (t.IsLineBreak)
            {
                throw new NotSupportedException();
            }
            LinkedList <EditableRun> colllectRun = new LinkedList <EditableRun>();

            foreach (EditableRun r in EditableFlowLayer.TextRunForward(t, this.LastRun))
            {
                colllectRun.AddLast(r);
            }
            return(colllectRun);
        }
        LinkedList <EditableRun> CollectLeftRuns(EditableRun t)
        {
            if (t.IsLineBreak)
            {
                throw new NotSupportedException();
            }

            LinkedList <EditableRun> colllectRun = new LinkedList <EditableRun>();

            foreach (EditableRun r in GetVisualElementForward(this.FirstRun, t))
            {
                colllectRun.AddLast(r);
            }
            return(colllectRun);
        }
Ejemplo n.º 6
0
        public TextLineReader(EditableTextFlowLayer flowlayer)
        {
#if DEBUG
            this.dbug_MyId = dbugTotalId;
            dbugTotalId++;
#endif

            _textFlowLayer    = flowlayer;
            flowlayer.Reflow += new EventHandler(flowlayer_Reflow);
            _currentLine      = flowlayer.GetTextLine(0);
            if (_currentLine.FirstRun != null)
            {
                _currentTextRun = _currentLine.FirstRun;
            }
        }
Ejemplo n.º 7
0
        public void MoveToLine(int lineNumber)
        {
            _currentLine  = _textFlowLayer.GetTextLine(lineNumber);
            _currentLineY = _currentLine.Top;

            //if current line is a blank line
            //not first run => currentTextRun= null
            _currentTextRun = (EditableRun)_currentLine.FirstRun;

            _rCharOffset  = 0;
            _rPixelOffset = 0;

            caret_char_index = 0;
            _caretXPos       = 0;
        }
Ejemplo n.º 8
0
        //
        internal IEnumerable <EditableRun> GetVisualElementForward(EditableRun startVisualElement)
        {
            if (startVisualElement != null)
            {
                yield return(startVisualElement);

                var curRun = startVisualElement.NextTextRun;
                while (curRun != null)
                {
                    yield return(curRun);

                    curRun = curRun.NextTextRun;
                }
            }
        }
        public void RefreshInlineArrange()
        {
            EditableRun r        = this.FirstRun;
            int         lastestX = 0;

            while (r != null)
            {
                RenderElement.DirectSetLocation(
                    r,
                    lastestX,
                    r.Y);
                lastestX += r.Width;
                r         = r.NextTextRun;
            }
        }
Ejemplo n.º 10
0
        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)
                    {
                        if (newPointInfo.TextRun == null)
                        {
                            CurrentLine.AddFirst(textRun);
                        }
                        else
                        {
                            CurrentLine.AddBefore((EditableRun)newPointInfo.TextRun, textRun);
                        }
                    }
                    else
                    {
                        if (newPointInfo.TextRun == null)
                        {
                            CurrentLine.AddFirst(textRun);
                        }
                        else
                        {
                            CurrentLine.AddAfter((EditableRun)newPointInfo.TextRun, textRun);
                        }
                    }
                    CurrentLine.TextLineReCalculateActualLineSize();
                    CurrentLine.RefreshInlineArrange();
                    EnsureCurrentTextRun(CharIndex + textRun.CharacterCount);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
        }
Ejemplo n.º 11
0
        internal IEnumerable <EditableRun> GetVisualElementForward(EditableRun startVisualElement, EditableRun stopVisualElement)
        {
            if (startVisualElement != null)
            {
                LinkedListNode <EditableRun> lexnode = GetLineLinkedNode(startVisualElement);
                while (lexnode != null)
                {
                    yield return(lexnode.Value);

                    if (lexnode.Value == stopVisualElement)
                    {
                        break;
                    }
                    lexnode = lexnode.Next;
                }
            }
        }
Ejemplo n.º 12
0
 EditableRun MakeTextRun(int sourceIndex, int length)
 {
     if (length > 0)
     {
         EditableRun newTextRun = null;
         char[]      newContent = new char[length];
         Array.Copy(_mybuffer, sourceIndex, newContent, 0, length);
         newTextRun             = new EditableTextRun(this.Root, newContent, this.SpanStyle);
         newTextRun.IsLineBreak = this.IsLineBreak;
         newTextRun.UpdateRunWidth();
         return(newTextRun);
     }
     else
     {
         throw new Exception("string must be null or zero length");
     }
 }
Ejemplo n.º 13
0
        public void AddCharacter(char c)
        {
            if (CurrentLine.IsBlankLine)
            {
                //TODO: review here, enable this feature or not
                //some char can't be a start char on blank line

                if (!InternalTextLayerController.CanCaretStopOnThisChar(c))
                {
                    return;
                }
                //

                //1. new
                EditableRun t = new EditableTextRun(this.RootGfx,
                                                    c,
                                                    this.CurrentSpanStyle);
                var owner = this.FlowLayer.OwnerRenderElement;
                CurrentLine.AddLast(t);
                SetCurrentTextRun(t);
            }
            else
            {
                EditableRun cRun = CurrentTextRun;
                if (cRun != null)
                {
                    if (cRun.IsInsertable)
                    {
                        cRun.InsertAfter(CurrentTextRunCharIndex, c);
                    }
                    else
                    {
                        AddTextSpan(new EditableTextRun(this.RootGfx, c, this.CurrentSpanStyle));
                        return;
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }
            }

            CurrentLine.TextLineReCalculateActualLineSize();
            CurrentLine.RefreshInlineArrange();
            SetCurrentCharStepRight();
        }
        void RemoveRight(EditableRun t)
        {
            if (t.IsLineBreak)
            {
                throw new NotSupportedException();
            }

            LinkedList <EditableRun>     tobeRemoveTextRuns = CollectRightRuns(t);
            LinkedListNode <EditableRun> curNode            = tobeRemoveTextRuns.First;

            LocalSuspendLineReArrange();
            while (curNode != null)
            {
                Remove(curNode.Value);
                curNode = curNode.Next;
            }
            LocalResumeLineReArrange();
        }
Ejemplo n.º 15
0
        bool MoveToPreviousTextRun()
        {
#if DEBUG
            if (_currentTextRun.IsLineBreak)
            {
                throw new NotSupportedException();
            }
#endif
            if (_currentTextRun.PrevTextRun != null)
            {
                _currentTextRun  = _currentTextRun.PrevTextRun;
                _rCharOffset    -= _currentTextRun.CharacterCount;
                _rPixelOffset   -= _currentTextRun.Width;
                caret_char_index = _rCharOffset + _currentTextRun.CharacterCount;
                _caretXPos       = _rPixelOffset + _currentTextRun.Width;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 16
0
        bool MoveToNextTextRun()
        {
#if DEBUG
            if (_currentTextRun.IsLineBreak)
            {
                throw new NotSupportedException();
            }
#endif


            EditableRun nextTextRun = _currentTextRun.NextTextRun;
            if (nextTextRun != null && !nextTextRun.IsLineBreak)
            {
                _rCharOffset    += _currentTextRun.CharacterCount;
                _rPixelOffset   += _currentTextRun.Width;
                _currentTextRun  = nextTextRun;
                caret_char_index = _rCharOffset;
                _caretXPos       = _rPixelOffset + _currentTextRun.GetRunWidth(0);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 17
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);

            if (postCutTextRun != null)
            {
                output.Add(postCutTextRun);
            }
            foreach (EditableRun t in GetVisualElementForward(tobeCutRun.NextTextRun, this.LastRun))
            {
                output.Add(t.Clone());
            }
        }
Ejemplo n.º 18
0
        internal EditableTextLine SplitToNewLine(EditableRun startVisualElement)
        {
            LinkedListNode <EditableRun> curNode        = GetLineLinkedNode(startVisualElement);
            EditableTextLine             newSplitedLine = EditableFlowLayer.InsertNewLine(_currentLineNumber + 1);

            newSplitedLine.LocalSuspendLineReArrange();
            while (curNode != null)
            {
                LinkedListNode <EditableRun> tobeRemovedNode = curNode;
                curNode = curNode.Next;
                if (tobeRemovedNode.List != null)
                {
                    EditableRun tmpv = tobeRemovedNode.Value;
                    _runs.Remove(tobeRemovedNode);
                    newSplitedLine.AddLast(tmpv);
                }
                else
                {
                }
            }
            newSplitedLine.LocalResumeLineReArrange();
            return(newSplitedLine);
        }
Ejemplo n.º 19
0
        public void Remove(EditableRun v)
        {
#if DEBUG
            if (v.IsLineBreak)
            {
                throw new NotSupportedException("not support line break");
            }
#endif


            _runs.Remove(GetLineLinkedNode(v));
            EditableRun.RemoveParentLink(v);
            if ((_lineFlags & LOCAL_SUSPEND_LINE_REARRANGE) != 0)
            {
                return;
            }

            if (!this.EndWithLineBreak && this.RunCount == 0 && _currentLineNumber > 0)
            {
                if (!EditableFlowLayer.GetTextLine(_currentLineNumber - 1).EndWithLineBreak)
                {
                    EditableFlowLayer.Remove(_currentLineNumber);
                }
            }
            else
            {
                //var ownerVe = editableFlowLayer.OwnerRenderElement;
                //if (ownerVe != null)
                //{
                //    RenderElement.InnerInvalidateLayoutAndStartBubbleUp(ownerVe);
                //}
                //else
                //{
                //    throw new NotSupportedException();
                //}
            }
        }
Ejemplo n.º 20
0
        public void TextLineReCalculateActualLineSize()
        {
            EditableRun r          = this.FirstRun;
            int         maxHeight  = 2;
            int         accumWidth = 0;

            while (r != null)
            {
                if (r.Height > maxHeight)
                {
                    maxHeight = r.Height;
                }
                accumWidth += r.Width;
                r           = r.NextTextRun;
            }
            _actualLineWidth  = accumWidth;
            _actualLineHeight = maxHeight;

            if (this.RunCount == 0)
            {
                //no span
                _actualLineHeight = OwnerFlowLayer.DefaultLineHeight;
            }
        }
Ejemplo n.º 21
0
        void JoinWithNextLine()
        {
            if (!IsLastLine)
            {
                EditableTextLine lowerLine = EditableFlowLayer.GetTextLine(_currentLineNumber + 1);
                this.LocalSuspendLineReArrange();
                int         cx          = 0;
                EditableRun lastTextRun = (EditableRun)this.LastRun;
                if (lastTextRun != null)
                {
                    cx = lastTextRun.Right;
                }

                foreach (EditableRun r in lowerLine._runs)
                {
                    this.AddLast(r);
                    EditableRun.DirectSetLocation(r, cx, 0);
                    cx += r.Width;
                }
                this.LocalResumeLineReArrange();
                this.EndWithLineBreak = lowerLine.EndWithLineBreak;
                EditableFlowLayer.Remove(lowerLine._currentLineNumber);
            }
        }
Ejemplo n.º 22
0
        public void SplitToNewLine()
        {
            EditableRun lineBreakRun = new EditableTextRun(this.RootGfx, '\n', this.CurrentSpanStyle);
            EditableRun currentRun   = CurrentTextRun;

            if (CurrentLine.IsBlankLine)
            {
                CurrentLine.AddLast(lineBreakRun);
            }
            else
            {
                if (CharIndex == -1)
                {
                    CurrentLine.AddFirst(lineBreakRun);
                    SetCurrentTextRun(null);
                }
                else
                {
                    EditableRun rightSplitedPart = EditableRun.InnerRemove(currentRun,
                                                                           CurrentTextRunCharIndex + 1, true);
                    if (rightSplitedPart != null)
                    {
                        CurrentLine.AddAfter(currentRun, rightSplitedPart);
                    }
                    CurrentLine.AddAfter(currentRun, lineBreakRun);
                    if (currentRun.CharacterCount == 0)
                    {
                        CurrentLine.Remove(currentRun);
                    }
                }
            }


            this.TextLayer.TopDownReCalculateContentSize();
            EnsureCurrentTextRun();
        }
Ejemplo n.º 23
0
        public EditableVisualPointInfo GetTextPointInfoFromCharIndex(int charIndex)
        {
            int limit = CharCount - 1;

            if (charIndex > limit)
            {
                charIndex = limit;
            }

            EditableVisualPointInfo textPointInfo = new EditableVisualPointInfo(this, charIndex);
            int         rCharOffset  = 0;
            int         rPixelOffset = 0;
            EditableRun lastestRun   = null;

            foreach (EditableRun r in _runs)
            {
                lastestRun = r;
                int thisCharCount = lastestRun.CharacterCount;
                if (thisCharCount + rCharOffset > charIndex)
                {
                    int localCharOffset = charIndex - rCharOffset;
                    int pixelOffset     = lastestRun.GetRunWidth(localCharOffset);
                    textPointInfo.SetAdditionVisualInfo(lastestRun,
                                                        localCharOffset, rPixelOffset + pixelOffset
                                                        , rPixelOffset);
                    return(textPointInfo);
                }
                else
                {
                    rCharOffset  += thisCharCount;
                    rPixelOffset += r.Width;
                }
            }
            textPointInfo.SetAdditionVisualInfo(lastestRun, rCharOffset - lastestRun.CharacterCount, rPixelOffset, rPixelOffset - lastestRun.Width);
            return(textPointInfo);
        }
Ejemplo n.º 24
0
 public virtual void VisitEditableRun(EditableRun run)
 {
 }
Ejemplo n.º 25
0
 void AddNormalRunToLast(EditableRun v)
 {
     v.SetInternalLinkedNode(_runs.AddLast(v), this);
 }
Ejemplo n.º 26
0
 void AddNormalRunAfter(EditableRun afterVisualElement, EditableRun v)
 {
     v.SetInternalLinkedNode(_runs.AddAfter(GetLineLinkedNode(afterVisualElement), v), this);
 }
Ejemplo n.º 27
0
 void AddNormalRunBefore(EditableRun beforeVisualElement, EditableRun v)
 {
     v.SetInternalLinkedNode(_runs.AddBefore(GetLineLinkedNode(beforeVisualElement), v), this);
 }
Ejemplo n.º 28
0
 static LinkedListNode <EditableRun> GetLineLinkedNode(EditableRun ve)
 {
     return(ve.LinkedNodeForEditableRun);
 }
Ejemplo n.º 29
0
 internal static EditableRunCharLocation InnerGetCharacterFromPixelOffset(EditableRun tt, int pixelOffset)
 {
     return(tt.GetCharacterFromPixelOffset(pixelOffset));
 }
Ejemplo n.º 30
0
 internal static EditableRun InnerRemove(EditableRun tt, int startIndex, bool withFreeRun)
 {
     return(tt.Remove(startIndex, tt.CharacterCount - (startIndex), withFreeRun));
 }