internal void Remove(int lineId)
        {
#if DEBUG
            if (lineId < 0)
            {
                throw new NotSupportedException();
            }
#endif
            if ((layerFlags & FLOWLAYER_HAS_MULTILINE) == 0)
            {
                return;
            }
            List <EditableTextLine> lines = (List <EditableTextLine>)lineCollection;
            if (lines.Count < 2)
            {
                return;
            }

            EditableTextLine tobeRemovedLine = lines[lineId];
            tobeRemovedLine.editableFlowLayer = null;
            int cy = tobeRemovedLine.Top;
            lines.RemoveAt(lineId); int j = lines.Count;
            for (int i = lineId; i < j; ++i)
            {
                EditableTextLine line = lines[i];
                line.SetTop(cy); line.SetLineNumber(i); cy += line.ActualLineHeight;
            }

            if (lines.Count == 1)
            {
                lineCollection         = lines[0];
                FlowLayerHasMultiLines = false;
            }
        }
 void AppendLine(EditableTextLine line)
 {
     if ((layerFlags & FLOWLAYER_HAS_MULTILINE) != 0)
     {
         List <EditableTextLine> lines = (List <EditableTextLine>)lineCollection;
         int lineCount             = lines.Count;
         EditableTextLine lastLine = lines[lineCount - 1];
         line.SetLineNumber(lineCount);
         line.SetTop(lastLine.Top + lastLine.ActualLineHeight);
         lines.Add(line);
     }
     else
     {
         EditableTextLine        onlyLine    = (EditableTextLine)lineCollection;
         List <EditableTextLine> newLineList = new List <EditableTextLine>();
         newLineList.Add(onlyLine);
         line.SetTop(onlyLine.ActualLineHeight);
         line.SetLineNumber(1);
         newLineList.Add(line);
         lineCollection         = newLineList;
         FlowLayerHasMultiLines = true;
     }
 }
        void InsertLine(int insertAt, EditableTextLine textLine)
        {
            if (insertAt < 0)
            {
                throw new NotSupportedException();
            }

            List <EditableTextLine> lines = lineCollection as List <EditableTextLine>;

            if (lines != null)
            {
                int j = lines.Count;
                if (insertAt > j - 1)
                {
                    AppendLine(textLine);
                }
                else
                {
                    EditableTextLine line = lines[insertAt];
                    int cy = line.Top;
                    textLine.SetTop(cy);
                    textLine.SetLineNumber(insertAt);
                    cy += line.ActualLineHeight;
                    for (int i = insertAt; i < j; i++)
                    {
                        line = lines[i];
                        line.SetTop(cy);
                        line.SetLineNumber(i + 1);
                        cy += line.ActualLineHeight;
                    }
                    textLine.editableFlowLayer = this;
                    lines.Insert(insertAt, textLine);
                }
            }
            else
            {
                lines = new List <EditableTextLine>();
                lines.Add((EditableTextLine)lineCollection);
                lineCollection         = lines;
                FlowLayerHasMultiLines = true;
                int j = lines.Count;
                if (insertAt > j - 1)
                {
                    AppendLine(textLine);
                }
                else
                {
                    EditableTextLine line = lines[insertAt];
                    int cy = line.Top;
                    textLine.SetTop(cy);
                    textLine.SetLineNumber(insertAt);
                    cy += line.ActualLineHeight;
                    for (int i = insertAt; i < j; i++)
                    {
                        line = lines[i];
                        line.SetTop(cy);
                        line.SetLineNumber(i + 1);
                        cy += line.ActualLineHeight;
                    }
                    textLine.editableFlowLayer = this;
                    lines.Insert(insertAt, textLine);
                }
            }
        }
        void PerformHorizontalFlowArrangeForMultilineText(
            int ownerClientLeft, int ownerClientWidth,
            int ownerClientTop)
        {
#if DEBUG
            long startTick = DateTime.Now.Ticks;
#endif

            List <EditableTextLine> lines = (List <EditableTextLine>) this.lineCollection;
            int  ownerClientRight         = ownerClientLeft + ownerClientWidth;
            int  curX           = 0;
            int  curY           = 0;
            bool lastestIsBlock = false;
            int  maxWidth       = 0;
            int  curY_fromTop   = ownerClientTop;
            int  maxHeightInRow = EditableTextLine.DEFAULT_LINE_HEIGHT;
            int  lineCount      = lines.Count;
            for (int i = 0; i < lineCount; ++i)
            {
                EditableTextLine line = lines[i];
                curX           = ownerClientLeft;
                lastestIsBlock = false;
                line.SetTop(curY_fromTop);
                if (!line.NeedArrange)
                {
                    maxHeightInRow = line.ActualLineHeight;
                    if (line.ActualLineWidth > maxWidth)
                    {
                        maxWidth = line.ActualLineWidth;
                    }
                }
                else
                {
                    maxHeightInRow = EditableTextLine.DEFAULT_LINE_HEIGHT;
                    EditableTextLine newLine = null;
                    line.ValidateContentArrangement();
                    bool isFirstRunInThisLine = true;
                    foreach (EditableRun currentRun in line)
                    {
#if DEBUG
                        vinv_dbug_BeginSetElementBound(currentRun);
#endif
                        int v_desired_width  = currentRun.Width;
                        int v_desired_height = currentRun.Height;
                        if (isFirstRunInThisLine)
                        {
                            lastestIsBlock = currentRun.IsBlockElement;
                            if (v_desired_height > maxHeightInRow)
                            {
                                maxHeightInRow = v_desired_height;
                            }
                            EditableRun.DirectSetLocation(currentRun, curX, 0);
                            if (v_desired_height > maxHeightInRow)
                            {
                                maxHeightInRow = v_desired_height;
                            }
                            if (lastestIsBlock)
                            {
                                v_desired_width = ownerClientWidth;
                            }

                            EditableRun.DirectSetSize(currentRun,
                                                      v_desired_width, v_desired_height);
                            currentRun.MarkValidContentArrangement();
                            curX += v_desired_width;
                            isFirstRunInThisLine = false;
                        }
                        else
                        {
                            if (lastestIsBlock || currentRun.IsBlockElement ||
                                (curX + v_desired_width > ownerClientRight))
                            {
                                newLine = new EditableTextLine(this);
                                newLine.AddLast(currentRun);
                                curY           = curY_fromTop + maxHeightInRow;
                                curY_fromTop   = curY;
                                maxHeightInRow = EditableTextLine.DEFAULT_LINE_HEIGHT;
                                EditableRun nextR = currentRun.NextTextRun;
                                while (nextR != null)
                                {
                                    line.UnsafeRemoveVisualElement(nextR);
                                    newLine.AddLast(nextR);
                                    nextR = nextR.NextTextRun;
                                }
                                if (i + 1 == lineCount)
                                {
                                    lines.Add(newLine);
                                }
                                else
                                {
                                    lines.Insert(i + 1, newLine);
                                }
                                lineCount++;
                                break;
                            }
                            else
                            {
                                lastestIsBlock = currentRun.IsBlockElement;
                                if (v_desired_height > maxHeightInRow)
                                {
                                    maxHeightInRow = v_desired_height;
                                }
                                EditableRun.DirectSetLocation(currentRun, curX, 0);
                                EditableRun.DirectSetSize(currentRun,
                                                          v_desired_width, v_desired_height);
                                currentRun.MarkValidContentArrangement();
                                curX += v_desired_width;
                            }
                        }

#if DEBUG
                        vinv_dbug_EndSetElementBound(currentRun);
#endif
                    }
                    if (curX > maxWidth)
                    {
                        maxWidth = curX;
                    }
                }
                line.SetPostArrangeLineSize(maxWidth, maxHeightInRow);
                curY         = curY_fromTop + maxHeightInRow;
                curY_fromTop = curY;
            }

            ValidateArrangement();
        }
 public void SetCurrentLineTop(int y)
 {
     currentLine.SetTop(y);
 }
        void InsertLine(int insertAt, EditableTextLine textLine)
        {
            if (insertAt < 0)
            {
                throw new NotSupportedException();
            }

            List<EditableTextLine> lines = lineCollection as List<EditableTextLine>;
            if (lines != null)
            {
                int j = lines.Count;
                if (insertAt > j - 1)
                {
                    AppendLine(textLine);
                }
                else
                {
                    EditableTextLine line = lines[insertAt];
                    int cy = line.Top;
                    textLine.SetTop(cy);
                    textLine.SetLineNumber(insertAt);
                    cy += line.ActualLineHeight;
                    for (int i = insertAt; i < j; i++)
                    {
                        line = lines[i];
                        line.SetTop(cy);
                        line.SetLineNumber(i + 1);
                        cy += line.ActualLineHeight;
                    }
                    textLine.editableFlowLayer = this;
                    lines.Insert(insertAt, textLine);
                }
            }
            else
            {
                lines = new List<EditableTextLine>();
                lines.Add((EditableTextLine)lineCollection);
                lineCollection = lines;
                FlowLayerHasMultiLines = true;
                int j = lines.Count;
                if (insertAt > j - 1)
                {
                    AppendLine(textLine);
                }
                else
                {
                    EditableTextLine line = lines[insertAt];
                    int cy = line.Top;
                    textLine.SetTop(cy);
                    textLine.SetLineNumber(insertAt);
                    cy += line.ActualLineHeight;
                    for (int i = insertAt; i < j; i++)
                    {
                        line = lines[i];
                        line.SetTop(cy);
                        line.SetLineNumber(i + 1);
                        cy += line.ActualLineHeight;
                    }
                    textLine.editableFlowLayer = this;
                    lines.Insert(insertAt, textLine);
                }
            }
        }
 void AppendLine(EditableTextLine line)
 {
     if ((layerFlags & FLOWLAYER_HAS_MULTILINE) != 0)
     {
         List<EditableTextLine> lines = (List<EditableTextLine>)lineCollection;
         int lineCount = lines.Count;
         EditableTextLine lastLine = lines[lineCount - 1];
         line.SetLineNumber(lineCount);
         line.SetTop(lastLine.Top + lastLine.ActualLineHeight);
         lines.Add(line);
     }
     else
     {
         EditableTextLine onlyLine = (EditableTextLine)lineCollection;
         List<EditableTextLine> newLineList = new List<EditableTextLine>();
         newLineList.Add(onlyLine);
         line.SetTop(onlyLine.ActualLineHeight);
         line.SetLineNumber(1);
         newLineList.Add(line);
         lineCollection = newLineList;
         FlowLayerHasMultiLines = true;
     }
 }