protected override void CreateAdorners() { BaseFrameworkElement child = this.Element as BaseFrameworkElement; BaseFrameworkElement frameworkElement = this.Element.ParentElement as BaseFrameworkElement; if (child == null || frameworkElement == null || !frameworkElement.IsAttached) { return; } ILayoutDesigner designerForChild = this.ViewModel.GetLayoutDesignerForChild(this.Element, true); if ((designerForChild.GetWidthConstraintMode(child) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike) { this.AddAdorner((Adorner) new ElementLayoutLineAdorner((AdornerSet)this, ElementLayoutAdornerType.Left)); this.AddAdorner((Adorner) new ElementLayoutLineAdorner((AdornerSet)this, ElementLayoutAdornerType.Right)); this.AddAdorner((Adorner) new ElementLayoutLockAdorner((AdornerSet)this, ElementLayoutAdornerType.Left)); this.AddAdorner((Adorner) new ElementLayoutLockAdorner((AdornerSet)this, ElementLayoutAdornerType.Right)); } if ((designerForChild.GetHeightConstraintMode(child) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike) { return; } this.AddAdorner((Adorner) new ElementLayoutLineAdorner((AdornerSet)this, ElementLayoutAdornerType.Top)); this.AddAdorner((Adorner) new ElementLayoutLineAdorner((AdornerSet)this, ElementLayoutAdornerType.Bottom)); this.AddAdorner((Adorner) new ElementLayoutLockAdorner((AdornerSet)this, ElementLayoutAdornerType.Top)); this.AddAdorner((Adorner) new ElementLayoutLockAdorner((AdornerSet)this, ElementLayoutAdornerType.Bottom)); }
public LayoutOperation(ILayoutDesigner designer, BaseFrameworkElement child) { this.Designer = designer; this.Child = child; this.Settings = new LayoutSettings(); this.SettingsFromElement = LayoutUtilities.GetLayoutSettingsFromElement((SceneElement)child); this.ExplicitOverrides = LayoutUtilities.GetLayoutOverrides((SceneElement)child); this.WidthConstraintMode = designer.GetWidthConstraintMode(child); this.HeightConstraintMode = designer.GetHeightConstraintMode(child); }
private static SceneElement ChangeLayoutType(SceneElement sourceElement, ITypeId layoutType, ref SceneElement elementContainingChildren) { IDocumentRoot documentRoot = sourceElement.DocumentNode.DocumentRoot; IDocumentContext documentContext = documentRoot.DocumentContext; SceneViewModel viewModel = sourceElement.ViewModel; Size size = Size.Empty; BaseFrameworkElement frameworkElement = sourceElement as BaseFrameworkElement; if (frameworkElement != null) { size = frameworkElement.GetComputedTightBounds().Size; } using (viewModel.ForceBaseValue()) { SceneElement sceneElement = (SceneElement)viewModel.CreateSceneNode(layoutType); using (viewModel.DisableUpdateChildrenOnAddAndRemove()) { using (viewModel.DisableDrawIntoState()) { viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)sourceElement); Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)sourceElement); Dictionary <IPropertyId, List <SceneNode> > storedChildren = ChangeLayoutTypeCommand.StoreChildren(sourceElement); if (sourceElement.DocumentNode == documentRoot.RootNode) { documentRoot.RootNode = sceneElement.DocumentNode; sceneElement.DocumentNode.NameScope = new DocumentNodeNameScope(); } else { ISceneNodeCollection <SceneNode> collectionContainer = sourceElement.GetCollectionContainer(); int index = collectionContainer.IndexOf((SceneNode)sourceElement); sourceElement.Remove(); collectionContainer.Insert(index, (SceneNode)sceneElement); } SceneElementHelper.ApplyProperties((SceneNode)sceneElement, properties); elementContainingChildren = ChangeLayoutTypeCommand.ApplyChildren(sceneElement, storedChildren, size); } } if (sceneElement is GridElement || sceneElement is CanvasElement) { ILayoutDesigner designerForChild = sceneElement.ViewModel.GetLayoutDesignerForChild(sceneElement, true); if ((designerForChild.GetWidthConstraintMode((BaseFrameworkElement)sceneElement) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike) { sceneElement.SetValue(BaseFrameworkElement.WidthProperty, (object)size.Width); } if ((designerForChild.GetHeightConstraintMode((BaseFrameworkElement)sceneElement) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike) { sceneElement.SetValue(BaseFrameworkElement.HeightProperty, (object)size.Height); } } return(sceneElement); } }
private static MoveStrategy CreateByParentType(MoveStrategyContext context, BaseFrameworkElement parentContainer) { MoveStrategyFactory.MoveStrategyTypeHandlerFactory orCreateCache = DesignSurfacePlatformCaches.GetOrCreateCache <MoveStrategyFactory.MoveStrategyTypeHandlerFactory>(parentContainer.Platform.Metadata, DesignSurfacePlatformCaches.MoveStrategyFactoryCache); ItemsControlElement itemsControlElement = parentContainer as ItemsControlElement; TextBlockElement textBlockElement = parentContainer as TextBlockElement; Type type = (Type)null; if (itemsControlElement != null && itemsControlElement.ItemsHost != null) { type = orCreateCache.GetHandlerType((ITypeResolver)itemsControlElement.ProjectContext, itemsControlElement.ItemsHost.GetIType((ITypeResolver)parentContainer.ProjectContext), true); } if (type == (Type)null) { type = orCreateCache.GetHandlerType((ITypeResolver)parentContainer.ProjectContext, parentContainer.Type, false); } if (type == typeof(GenericMoveStrategy)) { ILayoutDesigner designerForParent = parentContainer.ViewModel.GetLayoutDesignerForParent((SceneElement)parentContainer, true); if ((designerForParent.GetWidthConstraintMode(parentContainer, (BaseFrameworkElement)null) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike && (designerForParent.GetHeightConstraintMode(parentContainer, (BaseFrameworkElement)null) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike) { type = typeof(LayoutMoveStrategy); } } if (textBlockElement != null && !parentContainer.ViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsTextBlockInlineUIContainer)) { type = (Type)null; } if (!(type != (Type)null)) { return((MoveStrategy)null); } MoveStrategy moveStrategy = (MoveStrategy)Activator.CreateInstance(type, new object[1] { (object)context }); moveStrategy.LayoutContainer = parentContainer; return(moveStrategy); }
public void Start(ToolBehaviorContext toolContext, BaseFrameworkElement targetElement, IList <BaseFrameworkElement> ignoredElements) { if (this.IsStarted) { this.Stop(); } this.toolContext = toolContext; if (this.toolContext.View.ViewModel.UsingEffectDesigner) { return; } this.container = (Base2DElement)null; this.targetElement = (SceneElement)targetElement; if (targetElement == null) { ISceneInsertionPoint sceneInsertionPoint = this.toolContext.View.ViewModel.ActiveSceneInsertionPoint; if (sceneInsertionPoint != null) { this.container = sceneInsertionPoint.SceneElement as Base2DElement; } } else if (!this.IsTransformed((SceneElement)targetElement)) { this.container = targetElement.ParentElement as Base2DElement; } ILayoutDesigner layoutDesigner = targetElement == null?this.toolContext.View.ViewModel.GetLayoutDesignerForParent((SceneElement)this.container, true) : this.toolContext.View.ViewModel.GetLayoutDesignerForChild(this.targetElement, true); BaseFrameworkElement parent = this.container as BaseFrameworkElement; bool leftRight = layoutDesigner.GetWidthConstraintMode(parent, targetElement) != LayoutConstraintMode.CanvasLike; bool topBottom = layoutDesigner.GetHeightConstraintMode(parent, targetElement) != LayoutConstraintMode.CanvasLike; if (!leftRight && !topBottom) { this.container = (Base2DElement)null; } if (this.container == null) { return; } this.snapLineRenderer.Attach(toolContext, (SceneElement)this.container); Rect actualBounds = this.toolContext.View.GetActualBounds(this.container.ViewObject); this.AddSnapLines(actualBounds, true, leftRight, topBottom); GridElement gridElement = this.container as GridElement; if (gridElement != null) { double x = 0.0; foreach (ColumnDefinitionNode columnDefinitionNode in (IEnumerable <ColumnDefinitionNode>)gridElement.ColumnDefinitions) { x += columnDefinitionNode.ComputedWidth; Point p1 = new Point(x, actualBounds.Top); Point p2 = new Point(x, actualBounds.Bottom); this.snapLines.Add(new SnapLine(p1, p2, SnapLineOrientation.Vertical, SnapLineLocation.Minimum, true)); this.snapLines.Add(new SnapLine(p1, p2, SnapLineOrientation.Vertical, SnapLineLocation.Maximum, true)); } double y = 0.0; foreach (RowDefinitionNode rowDefinitionNode in (IEnumerable <RowDefinitionNode>)gridElement.RowDefinitions) { y += rowDefinitionNode.ComputedHeight; Point p1 = new Point(actualBounds.Left, y); Point p2 = new Point(actualBounds.Right, y); this.snapLines.Add(new SnapLine(p1, p2, SnapLineOrientation.Horizontal, SnapLineLocation.Minimum, true)); this.snapLines.Add(new SnapLine(p1, p2, SnapLineOrientation.Horizontal, SnapLineLocation.Maximum, true)); } } if (!(this.container is PanelElement)) { return; } foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)((PanelElement)this.container).Children) { BaseFrameworkElement frameworkElement = sceneNode as BaseFrameworkElement; if (frameworkElement != null && frameworkElement != targetElement && frameworkElement.IsViewObjectValid && ((ignoredElements == null || !ignoredElements.Contains(frameworkElement)) && !this.IsTransformed((SceneElement)frameworkElement))) { Rect actualBoundsInParent = this.toolContext.View.GetActualBoundsInParent(frameworkElement.ViewObject); this.AddSnapLines(actualBoundsInParent, false, leftRight, topBottom); double baseline = this.toolContext.View.GetBaseline((SceneNode)frameworkElement); if (!double.IsNaN(baseline)) { this.snapLines.Add(new SnapLine(new Point(actualBoundsInParent.Left, actualBoundsInParent.Top + baseline), new Point(actualBoundsInParent.Right, actualBoundsInParent.Top + baseline), SnapLineOrientation.Horizontal, SnapLineLocation.Baseline, false)); } } } }
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); } }