protected override Point GetCenter(Matrix matrix)
        {
            IViewVisual viewVisual = this.Element.Visual as IViewVisual;
            Rect        rect       = viewVisual != null?viewVisual.GetLayoutSlot() : Rect.Empty;

            Matrix fromVisualParent = this.Element.GetComputedTransformFromVisualParent();
            Rect   childRect        = this.DesignerContext.ActiveSceneViewModel.GetLayoutDesignerForChild((SceneElement)this.Element, true).GetChildRect(this.Element);
            double y = (childRect.Top + childRect.Bottom) / 2.0;
            double x = (childRect.Left + childRect.Right) / 2.0;
            Point  point;

            switch (this.type)
            {
            case ElementLayoutAdornerType.Left:
                point = new Point(rect.Left, y);
                break;

            case ElementLayoutAdornerType.Top:
                point = new Point(x, rect.Top);
                break;

            case ElementLayoutAdornerType.Right:
                point = new Point(rect.Right, y);
                break;

            case ElementLayoutAdornerType.Bottom:
                point = new Point(x, rect.Bottom);
                break;

            default:
                throw new NotSupportedException();
            }
            matrix = fromVisualParent * matrix;
            return(point * matrix);
        }
示例#2
0
        protected void MoveDraggedElementsWithTempTransform()
        {
            Point point1 = this.DragCurrentPosition;

            if (this.IsConstraining)
            {
                point1 = this.ConstrainPointToAxis(this.DragStartPosition, this.DragCurrentPosition);
            }
            for (int index = 0; index < this.DraggedElements.Count; ++index)
            {
                BaseFrameworkElement frameworkElement = this.DraggedElements[index];
                if (this.originalTransforms[index] == null)
                {
                    Transform transform = (Transform)frameworkElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
                    this.originalTransforms[index] = transform == null ? Transform.Identity : transform;
                }
                IViewVisual viewVisual = frameworkElement.Visual as IViewVisual;
                if (viewVisual != null)
                {
                    SceneView activeView = this.ActiveView;
                    Point     point2     = activeView.TransformPoint((IViewObject)activeView.HitTestRoot, viewVisual.VisualParent, this.DragStartPosition);
                    Vector    vector     = activeView.TransformPoint((IViewObject)activeView.HitTestRoot, viewVisual.VisualParent, point1) - point2 - this.Context.DuplicationOffset;
                    Matrix    matrix     = this.originalTransforms[index].Value;
                    matrix.Translate(vector.X, vector.Y);
                    Transform transform = (Transform) new MatrixTransform(matrix);
                    viewVisual.SetValue((ITypeResolver)this.ActiveSceneViewModel.ProjectContext, this.ActiveSceneViewModel.ProjectContext.ResolveProperty(Base2DElement.RenderTransformProperty), this.ActiveView.ConvertFromWpfValue((object)transform));
                }
            }
        }
示例#3
0
        public LayoutConstraintMode GetHeightConstraintMode(BaseFrameworkElement child)
        {
            IViewVisual child1 = child == null ? (IViewVisual)null : child.Visual as IViewVisual;
            IViewVisual parent = child1 == null ? (IViewVisual)null : child1.VisualParent as IViewVisual;
            SceneView   view   = child == null ? (SceneView)null : child.ViewModel.DefaultView;

            return(this.GetHeightConstraintModeCore(parent, child1, view, false));
        }
示例#4
0
 public SceneNodeViewItem(SceneView view, IViewVisual viewVisual)
 {
     if (viewVisual == null)
     {
         throw new ArgumentNullException("viewVisual");
     }
     this.view       = view;
     this.viewVisual = viewVisual;
 }
示例#5
0
        public virtual bool IsInArtboard(IViewVisual visual)
        {
            Visual visual1 = visual.PlatformSpecificObject as Visual;

            if (visual1 != null)
            {
                return(this.IsAncestorOf((DependencyObject)visual1));
            }
            return(false);
        }
示例#6
0
        private bool IsTransformed(SceneElement element)
        {
            IViewVisual viewVisual = element.Visual as IViewVisual;

            if (viewVisual != null)
            {
                return(viewVisual.IsTransformed);
            }
            return(false);
        }
示例#7
0
        public override bool IsInArtboard(IViewVisual visual)
        {
            bool flag = false;

            if (this.silverlightImageHost.RenderRoot != null)
            {
                flag = this.platformView.IsAncestorOf(this.ViewObjectFactory.Instantiate(this.silverlightImageHost.RenderRoot), (IViewObject)visual);
            }
            return(flag);
        }
        private static void InvalidateMeasure(IViewObject viewObject)
        {
            IViewVisual viewVisual = viewObject as IViewVisual;

            if (viewVisual == null)
            {
                return;
            }
            viewVisual.InvalidateMeasure();
        }
 public Rect this[IViewVisual childVisual]
 {
     get
     {
         Rect actualBoundsInParent;
         if (!this.layoutBounds.TryGetValue((IViewObject)childVisual, out actualBoundsInParent))
         {
             this.layoutBounds[(IViewObject)childVisual] = actualBoundsInParent = this.parent.ViewModel.DefaultView.GetActualBoundsInParent((IViewObject)childVisual);
         }
         return(actualBoundsInParent);
     }
 }
示例#10
0
        public static Rect RoundUpLayoutRect(BaseFrameworkElement element, Rect rect)
        {
            IPlatformGeometryHelper geometryHelper = element.Platform.GeometryHelper;
            IViewVisual             visual         = element.ViewObject as IViewVisual;

            if (geometryHelper.NeedRoundupLayoutRect(visual))
            {
                IProperty propertyKey = element.ProjectContext.ResolveProperty(Base2DElement.UseLayoutRoundingProperty);
                if (propertyKey != null && (bool)visual.GetCurrentValue(propertyKey))
                {
                    return(geometryHelper.RoundupLayoutRect(rect));
                }
            }
            return(rect);
        }
示例#11
0
        protected override void UpdateLayoutInternal()
        {
            SceneNode sceneNode = this.allowViewScoping ? this.viewModel.ViewRoot : this.viewModel.RootNode;

            if (sceneNode == null)
            {
                return;
            }
            IViewVisual viewVisual = this.GetCorrespondingViewObject(sceneNode.DocumentNodePath) as IViewVisual;

            if (viewVisual == null)
            {
                return;
            }
            viewVisual.UpdateLayout();
        }
示例#12
0
        public static IDisposable TurnOffLayoutRounding(BaseFrameworkElement element)
        {
            IViewVisual viewVisual  = element.ViewObject as IViewVisual;
            IProperty   propertyKey = element.ProjectContext.ResolveProperty(Base2DElement.UseLayoutRoundingProperty);

            if (propertyKey == null || viewVisual == null || !(bool)viewVisual.GetCurrentValue(propertyKey))
            {
                return((IDisposable)null);
            }
            SceneEditTransaction editTransaction = element.ViewModel.CreateEditTransaction("TurnOffLayoutRounding", true);

            element.SetValue((IPropertyId)propertyKey, (object)false);
            editTransaction.Update();
            viewVisual.UpdateLayout();
            return((IDisposable)editTransaction);
        }
示例#13
0
        public virtual void FillChild(BaseFrameworkElement element)
        {
            IViewVisual viewVisual1 = element.Visual as IViewVisual;
            IViewVisual viewVisual2 = viewVisual1 != null ? viewVisual1.VisualParent as IViewVisual : (IViewVisual)null;
            Type        runtimeType = element.ProjectContext.ResolveType(PlatformTypes.UIElement).RuntimeType;

            if (viewVisual2 == null || !runtimeType.IsAssignableFrom(viewVisual2.TargetType))
            {
                viewVisual2 = element.ParentElement.Visual as IViewVisual;
            }
            if (viewVisual2 == null)
            {
                return;
            }
            Rect rect = new Rect(new Point(), viewVisual2.RenderSize);

            this.SetChildRect(element, this.PrepareLayoutRect(rect), LayoutOverrides.None, LayoutOverrides.All, LayoutOverrides.All);
        }
示例#14
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            Size size = base.ArrangeOverride(finalSize);

            this.EnsureValidContentBounds();
            if (this.centerDocument && this.EditableContentObject != null)
            {
                IViewVisual viewVisual = this.EditableContentObject as IViewVisual;
                if (viewVisual != null)
                {
                    Size desiredSize = viewVisual.DesiredSize;
                    this.CenterX        = desiredSize.Width / 2.0;
                    this.CenterY        = desiredSize.Height / 2.0;
                    this.centerDocument = false;
                }
            }
            return(size);
        }
示例#15
0
        public static Rect GetRoundedUpChildRect(ILayoutDesigner designer, BaseFrameworkElement element)
        {
            IPlatformGeometryHelper geometryHelper = element.Platform.GeometryHelper;
            IViewVisual             visual         = element.ViewObject as IViewVisual;

            if (geometryHelper.NeedRoundupLayoutRect(visual))
            {
                using (IDisposable disposable = LayoutRoundingHelper.TurnOffLayoutRounding(element))
                {
                    if (disposable != null)
                    {
                        Rect childRect = designer.GetChildRect(element);
                        return(geometryHelper.RoundupLayoutRect(childRect));
                    }
                }
            }
            return(designer.GetChildRect(element));
        }
        public static bool CanEditInPlace(SceneElement targetElement, ReferenceStep targetProperty, DocumentNodePath template)
        {
            DocumentNodePath documentNodePath = targetElement.DocumentNodePath;
            SceneViewModel   viewModel        = targetElement.ViewModel.GetViewModel(template.Node.DocumentRoot, true);

            if (targetElement.IsViewObjectValid && (targetElement.IsInstantiatedElementVisible || PlatformTypes.Style.IsAssignableFrom((ITypeId)template.Node.Type) && (targetProperty.Equals((object)BaseFrameworkElement.StyleProperty) || targetProperty == StyleNode.BasedOnProperty)) && (viewModel == targetElement.ViewModel && documentNodePath.IsAncestorOf(template)))
            {
                if (viewModel.DefaultView.GetInstantiatedElements(template).Count > 0)
                {
                    return(true);
                }
                if (!viewModel.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf) && PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)template.Node.Type))
                {
                    SceneNode valueAsSceneNode = viewModel.GetSceneNode(template.Node).GetLocalValueAsSceneNode(viewModel.ProjectContext.PlatformMetadata.KnownProperties.FrameworkTemplateVisualTree);
                    if (valueAsSceneNode != null)
                    {
                        IViewVisual viewVisual = targetElement.ViewTargetElement as IViewVisual;
                        if (viewVisual == null && ProjectNeutralTypes.DataGridColumn.IsAssignableFrom((ITypeId)targetElement.Type))
                        {
                            DataGridElement dataGridElement = targetElement.Parent as DataGridElement;
                            if (dataGridElement != null && targetElement.DocumentNode.IsChild && (targetElement.DocumentNode.Parent.IsProperty && DataGridElement.ColumnsProperty.Equals((object)targetElement.DocumentNode.Parent.SitePropertyKey)))
                            {
                                viewVisual = dataGridElement.ViewTargetElement as IViewVisual;
                            }
                        }
                        if (viewVisual != null)
                        {
                            DocumentNodePath pathInContainer = template.GetPathInContainer(valueAsSceneNode.DocumentNode);
                            foreach (IViewObject viewObject in (IEnumerable <IViewObject>)viewModel.DefaultView.GetInstantiatedElements(pathInContainer))
                            {
                                IViewVisual visual = viewObject as IViewVisual;
                                if (visual != null && viewVisual.IsAncestorOf(visual))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
        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);
        }
示例#18
0
        protected virtual void DoUpdateElementPosition(Point pointBegin, Point pointEnd)
        {
            IViewVisual viewVisual1 = this.ActiveSceneInsertionPoint.SceneElement.Visual as IViewVisual;
            IViewVisual viewVisual2 = this.LayoutTargetElement.Visual as IViewVisual;
            IViewVisual visual      = viewVisual2 != null ? viewVisual2.VisualParent as IViewVisual : (IViewVisual)null;

            if (visual != null && viewVisual1 != visual && (viewVisual1 != null && this.ActiveSceneViewModel.ProjectContext.ResolveType(PlatformTypes.UIElement).RuntimeType.IsAssignableFrom(visual.TargetType)))
            {
                GeneralTransform generalTransform = viewVisual1.TransformToVisual(visual);
                pointBegin = generalTransform.Transform(pointBegin);
                pointEnd   = generalTransform.Transform(pointEnd);
            }
            double width  = Math.Abs(pointEnd.X - pointBegin.X);
            double height = Math.Abs(pointEnd.Y - pointBegin.Y);

            this.ReplaceSubTransaction();
            ILayoutDesigner designerForChild = this.ActiveSceneViewModel.GetLayoutDesignerForChild((SceneElement)this.LayoutTargetElement, true);
            Vector          vector           = new Vector(Math.Min(pointBegin.X, pointEnd.X), Math.Min(pointBegin.Y, pointEnd.Y));
            Rect            rect             = new Rect(vector.X, vector.Y, width, height);

            designerForChild.SetChildRect(this.LayoutTargetElement, rect, LayoutOverrides.None, LayoutOverrides.Width | LayoutOverrides.Height, LayoutOverrides.None, SetRectMode.CreateAtPosition);
        }
        private void GetPoints(out Point pointBegin, out Point pointEnd)
        {
            IViewVisual viewVisual = this.Element.Visual as IViewVisual;
            Rect        rect       = viewVisual != null?viewVisual.GetLayoutSlot() : Rect.Empty;

            Matrix fromVisualParent = this.Element.GetComputedTransformFromVisualParent();
            Rect   childRect        = this.DesignerContext.ActiveSceneViewModel.GetLayoutDesignerForChild((SceneElement)this.Element, true).GetChildRect(this.Element);
            double y = (childRect.Top + childRect.Bottom) / 2.0;
            double x = (childRect.Left + childRect.Right) / 2.0;

            switch (this.type)
            {
            case ElementLayoutAdornerType.Left:
                pointBegin = new Point(childRect.Left, y);
                pointEnd   = new Point(rect.Left, y);
                break;

            case ElementLayoutAdornerType.Top:
                pointBegin = new Point(x, childRect.Top);
                pointEnd   = new Point(x, rect.Top);
                break;

            case ElementLayoutAdornerType.Right:
                pointBegin = new Point(childRect.Right, y);
                pointEnd   = new Point(rect.Right, y);
                break;

            case ElementLayoutAdornerType.Bottom:
                pointBegin = new Point(x, childRect.Bottom);
                pointEnd   = new Point(x, rect.Bottom);
                break;

            default:
                throw new NotSupportedException();
            }
            pointBegin *= fromVisualParent;
            pointEnd   *= fromVisualParent;
        }
        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);
        }
示例#21
0
        private LayoutConstraintMode GetHeightConstraintModeCore(IViewVisual parent, IViewVisual child, SceneView view, bool allowGridAutoChecks)
        {
            if (parent == null)
            {
                return(LayoutConstraintMode.CanvasLike);
            }
            LayoutConstraintMode layoutConstraintMode = LayoutConstraintMode.NonOverlappingGridlike;
            IType itype = parent.GetIType((ITypeResolver)view.ProjectContext);

            if (PlatformTypes.Grid.IsAssignableFrom((ITypeId)itype) || PlatformTypes.Canvas.IsAssignableFrom((ITypeId)itype))
            {
                layoutConstraintMode |= LayoutConstraintMode.Overlapping;
            }
            IViewVisual viewVisual = parent.VisualParent as IViewVisual;

            if (viewVisual != null && PlatformTypes.IsInstance(viewVisual.PlatformSpecificObject, ProjectNeutralTypes.Viewbox, (ITypeResolver)view.ProjectContext))
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if (PlatformTypes.Canvas.IsAssignableFrom((ITypeId)itype) || PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)itype) || (PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)itype) || PlatformTypes.FlowDocumentScrollViewer.IsAssignableFrom((ITypeId)itype)) || (PlatformTypes.ScrollContentPresenter.IsAssignableFrom((ITypeId)itype) || ProjectNeutralTypes.Viewbox.IsAssignableFrom((ITypeId)itype) || (PlatformTypes.Popup.IsAssignableFrom((ITypeId)itype) || ProjectNeutralTypes.PathPanel.IsAssignableFrom((ITypeId)itype))))
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if (PlatformTypes.StackPanel.IsAssignableFrom((ITypeId)itype) && ((IViewPanel)parent).Orientation == Orientation.Vertical)
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if (ProjectNeutralTypes.DockPanel.IsAssignableFrom((ITypeId)itype) && child != null)
            {
                switch ((Dock)view.ConvertToWpfValue(child.GetCurrentValue(view.ProjectContext.ResolveProperty(DockPanelElement.DockProperty))))
                {
                case Dock.Top:
                case Dock.Bottom:
                    layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                    break;
                }
            }
            if (ProjectNeutralTypes.WrapPanel.IsAssignableFrom((ITypeId)itype) && double.IsNaN((double)parent.GetCurrentValue(view.ProjectContext.ResolveProperty(WrapPanelElement.ItemHeightProperty))))
            {
                layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
            }
            if ((layoutConstraintMode & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike && double.IsNaN((double)parent.GetCurrentValue(view.ProjectContext.ResolveProperty(BaseFrameworkElement.HeightProperty))) && double.IsNaN((double)parent.GetCurrentValue(view.ProjectContext.ResolveProperty(DesignTimeProperties.DesignHeightProperty))))
            {
                IViewGrid viewGrid = parent as IViewGrid;
                if (viewGrid != null)
                {
                    if (!allowGridAutoChecks)
                    {
                        return(layoutConstraintMode);
                    }
                    IType type = child == null ? (IType)null : child.GetIType((ITypeResolver)view.ProjectContext);
                    if (child != null && (!PlatformTypes.Path.IsAssignableFrom((ITypeId)type) || !double.IsNaN((double)child.GetCurrentValue(view.ProjectContext.ResolveProperty(BaseFrameworkElement.HeightProperty)))))
                    {
                        int    val2_1 = (int)child.GetCurrentValue(view.ProjectContext.ResolveProperty(GridElement.RowProperty));
                        int    val2_2 = val2_1 + (int)child.GetCurrentValue(view.ProjectContext.ResolveProperty(GridElement.RowSpanProperty));
                        int    num1   = Math.Max(0, Math.Min(viewGrid.RowDefinitionsCount - 1, val2_1));
                        int    num2   = Math.Max(0, Math.Min(viewGrid.RowDefinitionsCount, val2_2));
                        double num3   = 0.0;
                        bool   flag1  = true;
                        bool   flag2  = true;
                        if (num2 == 0)
                        {
                            flag1 = false;
                            flag2 = false;
                            num3  = viewGrid.RenderSize.Height;
                        }
                        else
                        {
                            for (int index = num1; index < num2; ++index)
                            {
                                IViewRowDefinition rowDefinition = viewGrid.GetRowDefinition(index);
                                flag1 &= rowDefinition.Height.IsAuto;
                                flag2 &= rowDefinition.Height.IsAbsolute;
                                num3  += rowDefinition.ActualHeight;
                            }
                        }
                        double    height      = child.DesiredSize.Height;
                        IProperty propertyKey = view.Platform.Metadata.ResolveProperty(Base2DElement.UseLayoutRoundingProperty);
                        if (propertyKey != null && child.GetCurrentValue(propertyKey) != parent.GetCurrentValue(propertyKey))
                        {
                            height += 0.999;
                        }
                        if (Tolerances.LessThan(height, num3) || flag2)
                        {
                            return(layoutConstraintMode);
                        }
                        if (flag1)
                        {
                            layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                        }
                    }
                }
                if ((VerticalAlignment)view.ConvertToWpfValue(parent.GetCurrentValue(view.ProjectContext.ResolveProperty(BaseFrameworkElement.VerticalAlignmentProperty))) != VerticalAlignment.Stretch)
                {
                    layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                }
                else
                {
                    if (PlatformTypes.Control.IsAssignableFrom((ITypeId)itype) || PlatformTypes.ContentPresenter.IsAssignableFrom((ITypeId)itype))
                    {
                        allowGridAutoChecks = true;
                    }
                    if ((this.GetHeightConstraintModeCore(parent.VisualParent as IViewVisual, parent, view, allowGridAutoChecks) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike)
                    {
                        layoutConstraintMode |= LayoutConstraintMode.CanvasLike;
                    }
                }
            }
            return(layoutConstraintMode);
        }
        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);
        }
示例#23
0
        private void SetLayout(ISceneInsertionPoint insertionPoint, Rect rect, SceneNode node, SceneNode layoutTarget, SceneEditTransaction undo)
        {
            if (!PlatformTypes.UIElement.IsAssignableFrom((ITypeId)node.Type))
            {
                return;
            }
            bool flag1 = false;
            bool flag2 = false;

            if (node.IsSet(BaseFrameworkElement.WidthProperty) == PropertyState.Set && double.IsNaN(rect.Width))
            {
                rect.Width = (double)node.GetLocalOrDefaultValueAsWpf(BaseFrameworkElement.WidthProperty);
                flag1      = true;
            }
            if (node.IsSet(BaseFrameworkElement.HeightProperty) == PropertyState.Set && double.IsNaN(rect.Height))
            {
                rect.Height = (double)node.GetLocalOrDefaultValueAsWpf(BaseFrameworkElement.HeightProperty);
                flag2       = true;
            }
            using (this.ViewModel.ForceBaseValue())
            {
                BaseFrameworkElement child = layoutTarget as BaseFrameworkElement;
                if (child == null)
                {
                    return;
                }
                SetRectMode     setRectMode      = SetRectMode.Default;
                ILayoutDesigner designerForChild = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true);
                if (double.IsNaN(rect.Width) || double.IsNaN(rect.Height))
                {
                    setRectMode = SetRectMode.CreateDefault;
                    bool flag3 = PlatformTypes.Control.IsAssignableFrom((ITypeId)node.Type) || PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)node.Type);
                    for (int index = 0; index < DefaultTypeInstantiator.SizeNonExceptions.Length; ++index)
                    {
                        if (DefaultTypeInstantiator.SizeNonExceptions[index].Equals((object)node.Type))
                        {
                            flag3 = false;
                        }
                    }
                    if (!flag3)
                    {
                        BaseFrameworkElement frameworkElement = insertionPoint.SceneNode as BaseFrameworkElement;
                        if (frameworkElement != null)
                        {
                            Rect   computedTightBounds = frameworkElement.GetComputedTightBounds();
                            double val1_1 = 100.0;
                            double val1_2 = 100.0;
                            if (ProjectNeutralTypes.GridSplitter.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_1 = 5.0;
                            }
                            else if (PlatformTypes.Button.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_1 = 75.0;
                            }
                            else if (PlatformTypes.ComboBox.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_1 = 120.0;
                            }
                            if (PlatformTypes.ProgressBar.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_2 = 10.0;
                            }
                            else if (PlatformTypes.Button.IsAssignableFrom((ITypeId)node.Type) || PlatformTypes.ComboBox.IsAssignableFrom((ITypeId)node.Type))
                            {
                                val1_2 = double.NaN;
                            }
                            if ((designerForChild.GetWidthConstraintMode(child) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike)
                            {
                                val1_1 = Math.Min(val1_1, computedTightBounds.Width);
                            }
                            if ((designerForChild.GetHeightConstraintMode(child) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike)
                            {
                                val1_2 = Math.Min(val1_2, computedTightBounds.Height);
                            }
                            rect = new Rect(rect.Left, rect.Top, double.IsNaN(rect.Width) ? val1_1 : rect.Width, double.IsNaN(rect.Height) ? val1_2 : rect.Height);
                        }
                    }
                }
                LayoutOverrides layoutOverrides   = LayoutOverrides.None;
                LayoutOverrides overridesToIgnore = LayoutOverrides.None;
                Rect            rect1             = rect;
                if (double.IsNaN(rect.Width))
                {
                    layoutOverrides |= LayoutOverrides.Width;
                    rect1.Width      = 0.0;
                }
                else
                {
                    overridesToIgnore |= LayoutOverrides.Width;
                }
                if (double.IsNaN(rect.Height))
                {
                    layoutOverrides |= LayoutOverrides.Height;
                    rect1.Height     = 0.0;
                }
                else
                {
                    overridesToIgnore |= LayoutOverrides.Height;
                }
                designerForChild.SetChildRect(child, rect1, layoutOverrides, overridesToIgnore, LayoutOverrides.None, setRectMode);
                undo.Update();
                IViewVisual viewVisual = child.ViewObject as IViewVisual;
                if (viewVisual == null || !double.IsNaN(rect.Width) && !double.IsNaN(rect.Height))
                {
                    return;
                }
                viewVisual.UpdateLayout();
                Rect childRect = designerForChild.GetChildRect(child);
                if (double.IsNaN(rect.Width) && !flag1)
                {
                    if (viewVisual.RenderSize.Width < 5.0)
                    {
                        rect1.Width        = 100.0;
                        layoutOverrides   &= ~LayoutOverrides.Width;
                        overridesToIgnore |= LayoutOverrides.Width;
                    }
                    else
                    {
                        rect1.Width = childRect.Width;
                    }
                }
                if (double.IsNaN(rect.Height) && !flag2)
                {
                    if (viewVisual.RenderSize.Height < 5.0)
                    {
                        rect1.Height       = 100.0;
                        layoutOverrides   &= ~LayoutOverrides.Height;
                        overridesToIgnore |= LayoutOverrides.Height;
                    }
                    else
                    {
                        rect1.Height = childRect.Height;
                    }
                }
                LayoutOverrides nonExplicitOverrides = LayoutOverrides.None;
                if (PlatformTypes.FlowDocumentScrollViewer.IsAssignableFrom((ITypeId)child.Type) || PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)child.Type))
                {
                    nonExplicitOverrides = LayoutOverrides.Width;
                }
                designerForChild.SetChildRect(child, rect1, layoutOverrides, overridesToIgnore, nonExplicitOverrides, setRectMode);
            }
        }