internal static List <FlowPanelLayoutUtilities.LineInfo> ExtractLines(SceneElement container)
        {
            List <FlowPanelLayoutUtilities.LineInfo> list = new List <FlowPanelLayoutUtilities.LineInfo>();
            IViewPanel  flowPanel   = MoveStrategy.GetContainerHost(container) as IViewPanel;
            Orientation orientation = flowPanel.Orientation;
            double      num         = -1.0;
            Point       startPoint  = new Point(0.0, 0.0);

            FlowPanelLayoutUtilities.InitializeStartPoint(ref startPoint, flowPanel);
            int startElementIndex = 0;
            int endElementIndex   = 0;
            ActualBoundsInParent actualBoundsInParent = new ActualBoundsInParent(container);

            for (int index = 0; index < flowPanel.ChildrenCount; ++index)
            {
                IViewVisual child1 = flowPanel.GetChild(index);
                Rect        rect   = actualBoundsInParent[child1];
                num = FlowPanelLayoutUtilities.UpdateLineLength(num, startPoint, rect, orientation);
                if (endElementIndex + 1 < flowPanel.ChildrenCount)
                {
                    IViewVisual child2 = flowPanel.GetChild(endElementIndex + 1);
                    Rect        nextElementLayoutBounds = actualBoundsInParent[child2];
                    if (FlowPanelLayoutUtilities.IsNextElementStartOfNewLine(rect, nextElementLayoutBounds, orientation))
                    {
                        list.Add(new FlowPanelLayoutUtilities.LineInfo(startPoint, num, startElementIndex, endElementIndex));
                        startElementIndex = endElementIndex + 1;
                        FlowPanelLayoutUtilities.UpdateStartPoint(ref startPoint, num, orientation);
                        num = -1.0;
                    }
                    ++endElementIndex;
                }
                else
                {
                    list.Add(new FlowPanelLayoutUtilities.LineInfo(startPoint, num, startElementIndex, endElementIndex));
                    break;
                }
            }
            return(list);
        }
        protected override bool GetInsertionInfo(SceneElement container, int insertionIndex, bool isCursorAtEnd, out Point position, out double length, out Orientation orientation)
        {
            position    = new Point();
            length      = 0.0;
            orientation = Orientation.Horizontal;
            IViewPanel viewPanel = MoveStrategy.GetContainerHost(container) as IViewPanel;

            if (container == null || viewPanel == null)
            {
                return(false);
            }
            orientation = viewPanel.Orientation;
            if (viewPanel.ChildrenCount == 0)
            {
                position = new Point(0.0, 0.0);
                length   = orientation == Orientation.Horizontal ? viewPanel.RenderSize.Height : viewPanel.RenderSize.Width;
                return(true);
            }
            List <FlowPanelLayoutUtilities.LineInfo> lines = FlowPanelLayoutUtilities.ExtractLines(container);

            if (lines.Count <= 0)
            {
                return(false);
            }
            FlowPanelLayoutUtilities.LineInfo lineInfo1 = (FlowPanelLayoutUtilities.LineInfo)null;
            IViewVisual          index = (IViewVisual)null;
            ActualBoundsInParent actualBoundsInParent = new ActualBoundsInParent(container);

            foreach (FlowPanelLayoutUtilities.LineInfo lineInfo2 in lines)
            {
                if (lineInfo2.EndElementIndex == insertionIndex - 1 && isCursorAtEnd && insertionIndex < viewPanel.ChildrenCount)
                {
                    index     = viewPanel.GetChild(lineInfo2.EndElementIndex);
                    lineInfo1 = lineInfo2;
                    length    = lineInfo2.LineLength;
                    break;
                }
                if (lineInfo2.StartElementIndex <= insertionIndex && insertionIndex <= lineInfo2.EndElementIndex)
                {
                    index     = viewPanel.GetChild(insertionIndex);
                    lineInfo1 = lineInfo2;
                    length    = lineInfo2.LineLength;
                    break;
                }
            }
            Matrix matrixFromTransform = VectorUtilities.GetMatrixFromTransform(this.AdornerSet.ViewModel.DefaultView.ComputeTransformToVisual((IViewObject)viewPanel, this.Element.Visual));
            Point  point = new Point(matrixFromTransform.OffsetX, matrixFromTransform.OffsetY);

            if (index != null && lineInfo1 != null)
            {
                Rect rect = actualBoundsInParent[index];
                switch (orientation)
                {
                case Orientation.Horizontal:
                    double num1 = isCursorAtEnd ? rect.Right : rect.Left;
                    position = new Point(num1 + point.X, lineInfo1.StartPoint.Y + point.Y);
                    break;

                case Orientation.Vertical:
                    double num2 = isCursorAtEnd ? rect.Bottom : rect.Top;
                    position = new Point(lineInfo1.StartPoint.X + point.X, num2 + point.Y);
                    break;

                default:
                    throw new NotImplementedException(ExceptionStringTable.StackPanelUnrecognizedOrientation);
                }
                return(true);
            }
            FlowPanelLayoutUtilities.LineInfo lineInfo3 = lines[lines.Count - 1];
            if (insertionIndex <= lineInfo3.EndElementIndex)
            {
                return(false);
            }
            IViewVisual child = viewPanel.GetChild(lineInfo3.EndElementIndex);
            Rect        rect1 = actualBoundsInParent[child];

            switch (orientation)
            {
            case Orientation.Horizontal:
                position = new Point(rect1.Right + point.X, lineInfo3.StartPoint.Y + point.Y);
                break;

            case Orientation.Vertical:
                position = new Point(lineInfo3.StartPoint.X + point.X, rect1.Bottom + point.Y);
                break;

            default:
                throw new NotImplementedException(ExceptionStringTable.StackPanelUnrecognizedOrientation);
            }
            length = lineInfo3.LineLength;
            return(true);
        }
        public static int GetInsertionIndex(SceneElement container, Point position, out bool isCursorAtEnd)
        {
            isCursorAtEnd = false;
            IViewPanel viewPanel = MoveStrategy.GetContainerHost(container) as IViewPanel;

            if (viewPanel == null)
            {
                return(0);
            }
            Orientation orientation = viewPanel.Orientation;

            if (viewPanel.ChildrenCount == 0)
            {
                return(0);
            }
            bool flag = PlatformTypes.StackPanel.IsAssignableFrom((ITypeId)container.Type) || PlatformTypes.VirtualizingStackPanel.IsAssignableFrom((ITypeId)container.Type);
            ActualBoundsInParent actualBoundsInParent = new ActualBoundsInParent(container);

            foreach (FlowPanelLayoutUtilities.LineInfo line in FlowPanelLayoutUtilities.ExtractLines(container))
            {
                if (flag || FlowPanelLayoutUtilities.IsPointInLine(position, line, orientation))
                {
                    if (line.StartElementIndex == line.EndElementIndex)
                    {
                        IViewVisual child = viewPanel.GetChild(line.StartElementIndex);
                        Rect        elementLayoutBounds = actualBoundsInParent[child];
                        if (FlowPanelLayoutUtilities.DoesPointLieBeforeElement(position, elementLayoutBounds, orientation))
                        {
                            isCursorAtEnd = false;
                            return(line.StartElementIndex);
                        }
                        isCursorAtEnd = true;
                        return(line.StartElementIndex + 1);
                    }
                    IViewVisual child1 = viewPanel.GetChild(line.StartElementIndex);
                    IViewVisual child2 = viewPanel.GetChild(line.EndElementIndex);
                    Rect        elementLayoutBounds1 = actualBoundsInParent[child1];
                    Rect        elementLayoutBounds2 = actualBoundsInParent[child2];
                    if (FlowPanelLayoutUtilities.DoesPointLieBeforeElement(position, elementLayoutBounds1, orientation))
                    {
                        isCursorAtEnd = false;
                        return(line.StartElementIndex);
                    }
                    if (FlowPanelLayoutUtilities.DoesPointLieAfterElement(position, elementLayoutBounds2, orientation))
                    {
                        isCursorAtEnd = true;
                        return(line.EndElementIndex + 1);
                    }
                    for (int startElementIndex = line.StartElementIndex; startElementIndex < line.EndElementIndex; ++startElementIndex)
                    {
                        IViewVisual child3 = viewPanel.GetChild(startElementIndex);
                        IViewVisual child4 = viewPanel.GetChild(startElementIndex + 1);
                        Rect        currentElementLayoutBounds = actualBoundsInParent[child3];
                        Rect        nextElementLayoutBounds    = actualBoundsInParent[child4];
                        if (FlowPanelLayoutUtilities.DoesPointLieBetweenElements(position, currentElementLayoutBounds, nextElementLayoutBounds, orientation))
                        {
                            return(startElementIndex + 1);
                        }
                    }
                    break;
                }
            }
            if (flag)
            {
                return(-1);
            }
            isCursorAtEnd = true;
            return(viewPanel.ChildrenCount);
        }