public override void LeaveContainer(PlacementOperation operation) { GrayOutDesignerExceptActiveArea.Stop(ref grayOut); base.LeaveContainer(operation); foreach (PlacementInformation info in operation.PlacedItems) { if (info.Item.ComponentType == typeof(System.Windows.Controls.ColumnDefinition)) { // TODO: combine the width of the deleted column with the previous column this.ExtendedItem.Properties["ColumnDefinitions"].CollectionElements.Remove(info.Item); } else if (info.Item.ComponentType == typeof(System.Windows.Controls.RowDefinition)) { this.ExtendedItem.Properties["RowDefinitions"].CollectionElements.Remove(info.Item); } else { info.Item.Properties.GetAttachedProperty(System.Windows.Controls.Grid.RowProperty).Reset(); info.Item.Properties.GetAttachedProperty(System.Windows.Controls.Grid.ColumnProperty).Reset(); info.Item.Properties.GetAttachedProperty(System.Windows.Controls.Grid.RowSpanProperty).Reset(); info.Item.Properties.GetAttachedProperty(System.Windows.Controls.Grid.ColumnSpanProperty).Reset(); HorizontalAlignment ha = (HorizontalAlignment)info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance; VerticalAlignment va = (VerticalAlignment)info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance; if (ha == HorizontalAlignment.Stretch) info.Item.Properties[FrameworkElement.WidthProperty].SetValue(info.Bounds.Width); if (va == VerticalAlignment.Stretch) info.Item.Properties[FrameworkElement.HeightProperty].SetValue(info.Bounds.Height); } } }
public override Rect GetPosition(PlacementOperation operation, DesignItem item) { UIElement child = item.View; if (child == null) return Rect.Empty; double x, y; if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty)) { x = GetCanvasProperty(child, Canvas.LeftProperty); } else { x = extendedComponent.ActualWidth - GetCanvasProperty(child, Canvas.RightProperty) - PlacementOperation.GetRealElementSize(child).Width; } if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty)) { y = GetCanvasProperty(child, Canvas.TopProperty); } else { y = extendedComponent.ActualHeight - GetCanvasProperty(child, Canvas.BottomProperty) - PlacementOperation.GetRealElementSize(child).Height; } var p = new Point(x, y); //Fixes, Empty Image Resized to 0 //return new Rect(p, child.RenderSize); return new Rect(p, PlacementOperation.GetRealElementSize(item.View)); }
public override void EnterContainer(PlacementOperation operation) { enteredIntoNewContainer=true; grid.UpdateLayout(); base.EnterContainer(operation); if (operation.Type == PlacementType.PasteItem) { foreach (PlacementInformation info in operation.PlacedItems) { var margin = (Thickness)info.Item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance; var horizontalAlignment = (HorizontalAlignment)info.Item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance; var verticalAlignment = (VerticalAlignment)info.Item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance; if (horizontalAlignment == HorizontalAlignment.Left) margin.Left += PlacementOperation.PasteOffset; else if (horizontalAlignment == HorizontalAlignment.Right) margin.Right -= PlacementOperation.PasteOffset; if (verticalAlignment == VerticalAlignment.Top) margin.Top += PlacementOperation.PasteOffset; else if (verticalAlignment == VerticalAlignment.Bottom) margin.Bottom -= PlacementOperation.PasteOffset; info.Item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin); } } }
public override void BeforeSetPosition(PlacementOperation operation) { base.BeforeSetPosition(operation); if (surface == null) return; DesignPanel designPanel = ExtendedItem.Services.DesignPanel as DesignPanel; if (designPanel == null || !designPanel.UseRasterPlacement) return; if (System.Windows.Input.Keyboard.IsKeyDown(Key.LeftCtrl)) { surface.Children.Clear(); rasterDrawn = false; return; } drawRaster(); var bounds = operation.PlacedItems[0].Bounds; bounds.Y = ((int)bounds.Y/raster)*raster; bounds.X = ((int)bounds.X/raster)*raster; bounds.Width = Convert.ToInt32((bounds.Width/raster))*raster; bounds.Height = Convert.ToInt32((bounds.Height/raster))*raster; operation.PlacedItems[0].Bounds = bounds; }
public override void BeginPlacement(PlacementOperation operation) { base.BeginPlacement(operation); DesignPanel designPanel = ExtendedItem.Services.DesignPanel as DesignPanel; if (designPanel != null) raster = designPanel.RasterWidth; CreateSurface(operation); }
public override void EnterContainer(PlacementOperation operation) { base.EnterContainer(operation); foreach (PlacementInformation info in operation.PlacedItems) { info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset(); info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].Reset(); info.Item.Properties[FrameworkElement.MarginProperty].Reset(); if (operation.Type == PlacementType.PasteItem) { info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(((double)info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance) + PlacementOperation.PasteOffset); info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(((double)info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance) + PlacementOperation.PasteOffset); } } }
public virtual bool CanEnterContainer(PlacementOperation operation, bool shouldAlwaysEnter) { var canEnter = internalCanEnterContainer(operation); if (canEnter && !shouldAlwaysEnter && !System.Windows.Input.Keyboard.IsKeyDown(Key.LeftAlt) && !System.Windows.Input.Keyboard.IsKeyDown(Key.RightAlt)) { var b = new Rect(0, 0, ((FrameworkElement)this.ExtendedItem.View).ActualWidth, ((FrameworkElement)this.ExtendedItem.View).ActualHeight); InfoTextEnterArea.Start(ref infoTextEnterArea, this.Services, this.ExtendedItem.View, b, Translations.Instance.PressAltText); return false; } return canEnter; }
public override void BeginPlacement(PlacementOperation operation) { base.BeginPlacement(operation); if (_rects.Count > 0) _rects.Clear(); /* Add Rect of all children to _rects */ var children = this.ExtendedItem.ContentProperty.CollectionElements; foreach (var child in children) { Point p = child.View.TranslatePoint(new Point(0, 0), this.ExtendedItem.View); _rects.Add(new Rect(p, child.View.RenderSize)); } if (_adornerPanel != null && this.ExtendedItem.Services.DesignPanel.Adorners.Contains(_adornerPanel)) this.ExtendedItem.Services.DesignPanel.Adorners.Remove(_adornerPanel); /* Place the Rectangle */ _adornerPanel = new AdornerPanel(); _rectangle = new Rectangle(); _adornerPanel.SetAdornedElement(this.ExtendedItem.View, this.ExtendedItem); _adornerPanel.Children.Add(_rectangle); this.ExtendedItem.Services.DesignPanel.Adorners.Add(_adornerPanel); }
/// <summary> /// Starts a new placement operation that changes the placement of <paramref name="placedItems"/>. /// </summary> /// <param name="placedItems">The items to be placed.</param> /// <param name="type">The type of the placement.</param> /// <returns>A PlacementOperation object.</returns> /// <remarks> /// You MUST call either <see cref="Abort"/> or <see cref="Commit"/> on the returned PlacementOperation /// once you are done with it, otherwise a ChangeGroup will be left open and Undo/Redo will fail to work! /// </remarks> public static PlacementOperation Start(ICollection <DesignItem> placedItems, PlacementType type) { if (placedItems == null) { throw new ArgumentNullException("placedItems"); } if (type == null) { throw new ArgumentNullException("type"); } DesignItem[] items = placedItems.ToArray(); if (items.Length == 0) { throw new ArgumentException("placedItems.Length must be > 0"); } PlacementOperation op = new PlacementOperation(items, type); try { if (op.currentContainerBehavior == null) { throw new PlacementOperationException("Starting the operation is not supported"); } op.currentContainerBehavior.BeginPlacement(op); foreach (PlacementInformation info in op.placedItems) { info.OriginalBounds = op.currentContainerBehavior.GetPosition(op, info.Item); info.Bounds = info.OriginalBounds; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); op.changeGroup.Abort(); throw; } return(op); }
public override void EnterContainer(PlacementOperation operation) { base.EnterContainer(operation); CreateSurface(operation); }
public override void EndPlacement(PlacementOperation operation) { base.EndPlacement(operation); DeleteSurface(); }
public override void BeginPlacement(PlacementOperation operation) { base.BeginPlacement(operation); CreateSurface(operation); }
public override void EndPlacement(PlacementOperation operation) { GrayOutDesignerExceptActiveArea.Stop(ref grayOut); base.EndPlacement(operation); }
public virtual void EnterContainer(PlacementOperation operation) { if (ExtendedItem.ContentProperty.IsCollection) { foreach (var info in operation.PlacedItems) { ExtendedItem.ContentProperty.CollectionElements.Add(info.Item); } } else { ExtendedItem.ContentProperty.SetValue(operation.PlacedItems[0].Item); } if (operation.Type == PlacementType.AddItem) { foreach (var info in operation.PlacedItems) { SetPosition(info); } } }
void CreateSurface(PlacementOperation operation) { if (ExtendedItem.Services.GetService<IDesignPanel>() != null) { surface = new Canvas(); adornerPanel = new AdornerPanel(); adornerPanel.SetAdornedElement(ExtendedItem.View, ExtendedItem); AdornerPanel.SetPlacement(surface, AdornerPlacement.FillContent); adornerPanel.Children.Add(surface); ExtendedItem.Services.DesignPanel.Adorners.Add(adornerPanel); BuildMaps(operation); if (operation.Type != PlacementType.Resize && operation.PlacedItems.Count == 1) { baseline = GetBaseline(operation.PlacedItems[0].Item.View); } } }
/// <summary> /// Starts a new placement operation that changes the placement of <paramref name="placedItems"/>. /// </summary> /// <param name="placedItems">The items to be placed.</param> /// <param name="type">The type of the placement.</param> /// <returns>A PlacementOperation object.</returns> /// <remarks> /// You MUST call either <see cref="Abort"/> or <see cref="Commit"/> on the returned PlacementOperation /// once you are done with it, otherwise a ChangeGroup will be left open and Undo/Redo will fail to work! /// </remarks> public static PlacementOperation Start(ICollection<DesignItem> placedItems, PlacementType type) { if (placedItems == null) throw new ArgumentNullException("placedItems"); if (type == null) throw new ArgumentNullException("type"); DesignItem[] items = placedItems.ToArray(); if (items.Length == 0) throw new ArgumentException("placedItems.Length must be > 0"); PlacementOperation op = new PlacementOperation(items, type); try { if (op.currentContainerBehavior == null) throw new InvalidOperationException("Starting the operation is not supported"); op.currentContainerBehavior.BeginPlacement(op); foreach (PlacementInformation info in op.placedItems) { info.OriginalBounds = op.currentContainerBehavior.GetPosition(op, info.Item); info.Bounds = info.OriginalBounds; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); op.changeGroup.Abort(); throw; } return op; }
public override void EndPlacement(PlacementOperation operation) { GrayOutDesignerExceptActiveArea.Stop(ref grayOut); enteredIntoNewContainer=false; base.EndPlacement(operation); }
public virtual void BeforeSetPosition(PlacementOperation operation) { }
public virtual void BeginPlacement(PlacementOperation operation) { }
private bool internalCanEnterContainer(PlacementOperation operation) { InfoTextEnterArea.Stop(ref infoTextEnterArea); if (ExtendedItem.Component is Expander) { if (!((Expander) ExtendedItem.Component).IsExpanded) { ((Expander) ExtendedItem.Component).IsExpanded = true; } } if (ExtendedItem.Component is UserControl && ExtendedItem.ComponentType != typeof(UserControl)) return false; if (ExtendedItem.Component is Decorator) return ((Decorator)ExtendedItem.Component).Child == null; if (ExtendedItem.ContentProperty.IsCollection) return CollectionSupport.CanCollectionAdd(ExtendedItem.ContentProperty.ReturnType, operation.PlacedItems.Select(p => p.Item.Component)); if (ExtendedItem.ContentProperty.ReturnType == typeof(string)) return false; if (!ExtendedItem.ContentProperty.IsSet) return true; object value = ExtendedItem.ContentProperty.ValueOnInstance; // don't overwrite non-primitive values like bindings return ExtendedItem.ContentProperty.Value == null && (value is string && string.IsNullOrEmpty(value as string)); }
public virtual void LeaveContainer(PlacementOperation operation) { if (ExtendedItem.ContentProperty.IsCollection) { foreach (var info in operation.PlacedItems) { ExtendedItem.ContentProperty.CollectionElements.Remove(info.Item); } } else { ExtendedItem.ContentProperty.Reset(); } }
public virtual Rect GetPosition(PlacementOperation operation, DesignItem item) { if (item.View == null) return Rect.Empty; var p = item.View.TranslatePoint(new Point(), operation.CurrentContainer.View); return new Rect(p, PlacementOperation.GetRealElementSize(item.View)); }
public override void LeaveContainer(PlacementOperation operation) { base.LeaveContainer(operation); DeleteSurface(); }
public virtual void EndPlacement(PlacementOperation operation) { InfoTextEnterArea.Stop(ref infoTextEnterArea); if (operation.Type != PlacementType.Delete) { this.ExtendedItem.Services.Selection.SetSelectedComponents(null); this.ExtendedItem.Services.Selection.SetSelectedComponents(operation.PlacedItems.Select(x => x.Item).ToList()); } }
void BuildMaps(PlacementOperation operation) { horizontalMap = new List<Snapline>(); verticalMap = new List<Snapline>(); var containerRect = new Rect(0, 0, ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View)); AddLines(containerRect, -Margin, false); AddLines(containerRect, 0, false); AddContainerSnaplines(containerRect, horizontalMap, verticalMap); if (!CanPlace(operation.PlacedItems.Select(x => x.Item), operation.Type, PlacementAlignment.Center)) return; foreach (var item in AllDesignItems() /* ExtendedItem.ContentProperty.CollectionElements */ .Except(operation.PlacedItems.Select(f => f.Item)) .Where(x=> x.View != null && !GetDisableSnaplines(x.View))) { if (item != null) { var bounds = GetPosition(operation, item); AddLines(bounds, 0, false); AddLines(bounds, Margin, true); AddBaseline(item, bounds, horizontalMap); } } }
void CreateSurface(PlacementOperation operation) { if (ExtendedItem.Services.GetService<IDesignPanel>() != null) { surface = new Canvas(); adornerPanel = new AdornerPanel(); adornerPanel.SetAdornedElement(ExtendedItem.View, ExtendedItem); AdornerPanel.SetPlacement(surface, AdornerPlacement.FillContent); adornerPanel.Children.Add(surface); ExtendedItem.Services.DesignPanel.Adorners.Add(adornerPanel); } }
public override void BeforeSetPosition(PlacementOperation operation) { base.BeforeSetPosition(operation); if (surface == null) return; DesignPanel designPanel = ExtendedItem.Services.DesignPanel as DesignPanel; if (designPanel == null || !designPanel.UseSnaplinePlacement) return; surface.Children.Clear(); if (System.Windows.Input.Keyboard.IsKeyDown(Key.LeftCtrl)) return; Rect bounds = Rect.Empty; foreach (var item in operation.PlacedItems) { bounds.Union(item.Bounds); } var horizontalInput = new List<Snapline>(); var verticalInput = new List<Snapline>(); var info = operation.PlacedItems[0]; if (operation.Type == PlacementType.Resize) { AddLines(bounds, 0, false, horizontalInput, verticalInput, info.ResizeThumbAlignment); } else { AddLines(bounds, 0, false, horizontalInput, verticalInput, null); if (baseline.HasValue) { var textOffset = bounds.Top + baseline.Value; horizontalInput.Add(new Snapline() { Group = 1, Offset = textOffset, Start = bounds.Left, End = bounds.Right }); } } // debug //foreach (var t in horizontalMap.Concat(horizontalInput)) { // surface.Children.Add(new Line() { X1 = t.Start, X2 = t.End, Y1 = t.Offset, Y2 = t.Offset, Stroke = Brushes.Black }); //} //foreach (var t in verticalMap.Concat(verticalInput)) { // surface.Children.Add(new Line() { X1 = t.Offset, X2 = t.Offset, Y1 = t.Start , Y2 = t.End, Stroke = Brushes.Black }); //} //return; List<Snapline> drawLines; double delta; if (Snap(horizontalInput, horizontalMap, Accuracy, out drawLines, out delta)) { if (operation.Type == PlacementType.Resize) { if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Vertical == VerticalAlignment.Top) { bounds.Y += delta; bounds.Height = Math.Max(0, bounds.Height - delta); } else { bounds.Height = Math.Max(0, bounds.Height + delta); } info.Bounds = bounds; } else { foreach (var item in operation.PlacedItems) { var r = item.Bounds; r.Y += delta; item.Bounds = r; } } foreach (var d in drawLines) { DrawLine(d.Start, d.Offset + d.DrawOffset, d.End, d.Offset + d.DrawOffset); } } if (Snap(verticalInput, verticalMap, Accuracy, out drawLines, out delta)) { if (operation.Type == PlacementType.Resize) { if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Horizontal == HorizontalAlignment.Left) { bounds.X += delta; bounds.Width = Math.Max(0, bounds.Width - delta); } else { bounds.Width = Math.Max(0, bounds.Width + delta); } info.Bounds = bounds; } else { foreach (var item in operation.PlacedItems) { var r = item.Bounds; r.X += delta; item.Bounds = r; } } foreach (var d in drawLines) { DrawLine(d.Offset + d.DrawOffset, d.Start, d.Offset + d.DrawOffset, d.End); } } }
public override void LeaveContainer(PlacementOperation operation) { GrayOutDesignerExceptActiveArea.Stop(ref grayOut); base.LeaveContainer(operation); foreach (PlacementInformation info in operation.PlacedItems) { info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset(); info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset(); } }
internal PlacementInformation(DesignItem item, PlacementOperation operation) { this.item = item; this.operation = operation; }
/// <summary> /// Try to insert new components into the container. /// </summary> /// <param name="container">The container that should become the parent of the components.</param> /// <param name="placedItems">The components to add to the container.</param> /// <param name="positions">The rectangle specifying the position the element should get.</param> /// <param name="type">The type </param> /// <returns>The operation that inserts the new components, or null if inserting is not possible.</returns> public static PlacementOperation TryStartInsertNewComponents(DesignItem container, IList<DesignItem> placedItems, IList<Rect> positions, PlacementType type) { if (container == null) throw new ArgumentNullException("container"); if (placedItems == null) throw new ArgumentNullException("placedItems"); if (positions == null) throw new ArgumentNullException("positions"); if (type == null) throw new ArgumentNullException("type"); if (placedItems.Count == 0) throw new ArgumentException("placedItems.Count must be > 0"); if (placedItems.Count != positions.Count) throw new ArgumentException("positions.Count must be = placedItems.Count"); DesignItem[] items = placedItems.ToArray(); PlacementOperation op = new PlacementOperation(items, type); try { for (int i = 0; i < items.Length; i++) { op.placedItems[i].OriginalBounds = op.placedItems[i].Bounds = positions[i]; } op.currentContainer = container; op.currentContainerBehavior = container.GetBehavior<IPlacementBehavior>(); if (op.currentContainerBehavior == null || !op.currentContainerBehavior.CanEnterContainer(op, true)) { op.changeGroup.Abort(); return null; } op.currentContainerBehavior.EnterContainer(op); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); op.changeGroup.Abort(); throw; } return op; }
public virtual bool CanLeaveContainer(PlacementOperation operation) { return true; }