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, item.View.RenderSize);
		}
        public override void LeaveContainer(PlacementOperation operation)
        {
            base.LeaveContainer(operation);
            /* Hide the rectangle in case switching to the other container
 			   *  otherwise it will show up intersecting with the container */
            _rectangle.Visibility = Visibility.Hidden; 
        }
		public virtual void EndPlacement(PlacementOperation operation)
		{
			InfoTextEnterArea.Stop(ref infoTextEnterArea);

			this.ExtendedItem.Services.Selection.SetSelectedComponents(null);
			this.ExtendedItem.Services.Selection.SetSelectedComponents(operation.PlacedItems.Select(x => x.Item).ToList());
		}
Exemple #4
0
 public void Cancel()
 {
     if (operation != null) {
         operation.Abort();
         operation = null;
     }
 }
        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 BeforeSetPosition(PlacementOperation operation)
		{
			base.BeforeSetPosition(operation);
			if (surface == null) return;

			DesignPanel designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
			if (designPanel == null || !designPanel.UseRasterPlacement)
				return;

			if (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 LeaveContainer(PlacementOperation operation)
		{
			base.LeaveContainer(operation);
			foreach (PlacementInformation info in operation.PlacedItems) {
				info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
				info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset();
			}
		}
		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();
			}
		}
		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();
			}
		}
		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 (var info in operation.PlacedItems) {
         info.Item.Properties[FrameworkElement.MarginProperty].Reset();
         info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset();
         info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].Reset();
     }
     _rectangle.Visibility = Visibility.Visible;
 }
Exemple #12
0
		public void Start(Point p)
		{
			startPoint = p;
			IPlacementBehavior b = PlacementOperation.GetPlacementBehavior(selectedItems);
			if (b != null && b.CanPlace(selectedItems, PlacementType.Move, PlacementAlignment.TopLeft)) {
				List<DesignItem> sortedSelectedItems = new List<DesignItem>(selectedItems);
				sortedSelectedItems.Sort(ModelTools.ComparePositionInModelFile);
				selectedItems = sortedSelectedItems;
				operation = PlacementOperation.Start(selectedItems, PlacementType.Move);
			}
		}
		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 virtual void LeaveContainer(PlacementOperation operation)
 {
     foreach (var item in operation.PlacedItems)
     {
         if (item.Item.ParentProperty.IsCollection)
         {
             item.Item.ParentProperty.CollectionElements.Remove(item.Item);
         }
         else
         {
             item.Item.ParentProperty.Reset();
         }
     }
 }
Exemple #15
0
        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.View is ContentControl)
            {
                if (!CanContentControlAdd((ContentControl)ExtendedItem.View))
                {
                    return(false);
                }
            }

            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 bool CanEnterContainer(PlacementOperation operation, bool shouldAlwaysEnter)
        {
            var canEnter = internalCanEnterContainer(operation);

            if (canEnter && !shouldAlwaysEnter && !Keyboard.IsKeyDown(Key.LeftAlt) && !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;
        }
Exemple #17
0
        public virtual bool CanEnterContainer(PlacementOperation operation, bool shouldAlwaysEnter)
        {
            var canEnter = internalCanEnterContainer(operation);

            if (canEnter && !shouldAlwaysEnter && !Keyboard.IsKeyDown(Key.LeftAlt) && !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);
        }
Exemple #18
0
 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();
     }
 }
        internal static void Move(Vector v, params DesignItem[] items)
        {
            PlacementOperation operation = PlacementOperation.Start(items, PlacementType.Move);

            foreach (PlacementInformation info in operation.PlacedItems)
            {
                info.Bounds = new Rect(info.OriginalBounds.Left + v.X,
                                       info.OriginalBounds.Top + v.Y,
                                       info.OriginalBounds.Width,
                                       info.OriginalBounds.Height);
                operation.CurrentContainerBehavior.SetPosition(info);
            }
            operation.Commit();
        }
Exemple #20
0
        /// <summary>
        /// Deletes the specified components from their parent containers.
        /// If the deleted components are currently selected, they are deselected before they are deleted.
        /// </summary>
        public static void DeleteComponents(ICollection <DesignItem> deleteItems)
        {
            if (deleteItems.Count > 0)
            {
                var changeGroup = deleteItems.First().OpenGroup("Delete Items");
                try
                {
                    var itemsGrpParent = deleteItems.GroupBy(x => x.Parent);
                    foreach (var itemsList in itemsGrpParent)
                    {
                        var                items     = itemsList.ToList();
                        DesignItem         parent    = items.First().Parent;
                        PlacementOperation operation = PlacementOperation.Start(items, PlacementType.Delete);
                        try
                        {
                            ISelectionService selectionService = items.First().Services.Selection;
                            selectionService.SetSelectedComponents(items, SelectionTypes.Remove);
                            // if the selection is empty after deleting some components, select the parent of the deleted component
                            if (selectionService.SelectionCount == 0 && !items.Contains(parent))
                            {
                                selectionService.SetSelectedComponents(new[] { parent });
                            }
                            foreach (var designItem in items)
                            {
                                designItem.Name = null;
                            }

                            var service = parent.Services.Component as XamlComponentService;
                            foreach (var item in items)
                            {
                                service.RaiseComponentRemoved(item);
                            }

                            operation.DeleteItemsAndCommit();
                        }
                        catch
                        {
                            operation.Abort();
                            throw;
                        }
                    }
                    changeGroup.Commit();
                }
                catch
                {
                    changeGroup.Abort();
                    throw;
                }
            }
        }
Exemple #21
0
 public virtual void LeaveContainer(PlacementOperation operation)
 {
     foreach (var info in operation.PlacedItems)
     {
         var parentProperty = info.Item.ParentProperty;
         if (parentProperty.IsCollection)
         {
             parentProperty.CollectionElements.Remove(info.Item);
         }
         else
         {
             parentProperty.Reset();
         }
     }
 }
Exemple #22
0
        /// <summary>
        /// Adds Items under a parent given that the content property is collection and can add types of <paramref name="pastedItems"/>
        /// </summary>
        /// <param name="parent">The Parent element</param>
        /// <param name="pastedItems">The list of elements to be added</param>
        void AddInParent(DesignItem parent, IList <DesignItem> pastedItems)
        {
            IEnumerable <Rect> rects = pastedItems.Select(i => new Rect(new Point(0, 0),
                                                                        new Point((double)i.Properties["Width"].ValueOnInstance,
                                                                                  (double)i.Properties["Height"].ValueOnInstance)));
            var operation =
                PlacementOperation.TryStartInsertNewComponents(parent, pastedItems, rects.ToList(),
                                                               PlacementType.PasteItem);
            ISelectionService selection = _context.Services.Selection;

            selection.SetSelectedComponents(pastedItems);
            if (operation != null)
            {
                operation.Commit();
            }
        }
Exemple #23
0
        void SetOperation()
        {
            var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;

            _zoom = designPanel.TryFindParent <ZoomControl>();

            if (resizeBehavior != null)
            {
                operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
            }
            else
            {
                changeGroup = ExtendedItem.Context.OpenGroup("Resize", extendedItemArray);
            }
            _isResizing = true;
        }
        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);
                }
            }
        }
Exemple #25
0
        private static ItemPos GetItemPos(PlacementOperation operation, DesignItem designItem)
        {
            var itemPos = new ItemPos()
            {
                DesignItem = designItem
            };

            var pos = operation.CurrentContainerBehavior.GetPosition(operation, designItem);

            itemPos.Xmin = pos.X;
            itemPos.Xmax = pos.X + pos.Width;
            itemPos.Ymin = pos.Y;
            itemPos.Ymax = pos.Y + pos.Height;

            return(itemPos);
        }
Exemple #26
0
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            AdornerPanel parent = this.Parent as AdornerPanel;

            if (parent != null && parent.AdornedElement != null)
            {
                if (checkWidth)
                {
                    this.ThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Width > 14;
                }
                else if (checkHeight)
                {
                    this.ThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Height > 14;
                }
            }
            return(base.ArrangeOverride(arrangeBounds));
        }
        private bool AddItemsWithCustomSize(DesignItem container, DesignItem[] createdItems, IList <Rect> positions)
        {
            PlacementOperation operation = null;

            while (operation == null && container != null)
            {
                operation = PlacementOperation.TryStartInsertNewComponents(
                    container,
                    createdItems,
                    positions,
                    PlacementType.AddItem
                    );

                if (operation != null)
                {
                    break;
                }

                try
                {
                    if (container.Parent != null)
                    {
                        var rel = container.View.TranslatePoint(new Point(0, 0), container.Parent.View);
                        for (var index = 0; index < positions.Count; index++)
                        {
                            positions[index] = new Rect(new Point(positions[index].X + rel.X, positions[index].Y + rel.Y), positions[index].Size);
                        }
                    }
                }
                catch (Exception)
                { }

                container = container.Parent;
            }

            if (operation != null)
            {
                container.Services.Selection.SetSelectedComponents(createdItems);
                operation.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
        protected override void OnInitialized()
        {
            if (this.ExtendedItem.Component is WindowClone)
            {
                return;
            }
            base.OnInitialized();
            extendedItemArray[0] = this.ExtendedItem;
            this.ExtendedItem.PropertyChanged += OnPropertyChanged;
            this.Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged;
            resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
            OnPrimarySelectionChanged(null, null);

            var designerItem = this.ExtendedItem.Component as FrameworkElement;

            this.rotateTransform = designerItem.RenderTransform as RotateTransform;
        }
        void SetOperation()
        {
            var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;

            _zoom = designPanel.TryFindParent <ZoomControl>();

            CommitOrAbortKeyboardOperation();

            //Move a Virtual Design Item arround... (for Snaplines, raster, ...)
            //And Resfresh the Points after Positioning that Item!
            //if (resizeBehavior != null)
            operation = PlacementOperation.Start(extendedItemArray, PlacementType.MovePoint);
//			else
//			{
//				changeGroup = ExtendedItem.Context.OpenGroup("Resize", extendedItemArray);
//			}
            _isResizing = true;
        }
Exemple #30
0
        /// <summary>
        /// is invoked whenever a line is selected on the canvas, remember that the adorners are created for each line object and never destroyed
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            resizeThumbs = new DesignerThumb[]
            {
                CreateThumb(PlacementAlignment.TopLeft, Cursors.Cross),
                CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross)
            };

            extendedItemArray[0] = this.ExtendedItem;

            Invalidate();

            this.ExtendedItem.PropertyChanged += OnPropertyChanged;
            resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
            UpdateAdornerVisibility();
        }
Exemple #31
0
        public bool CanInsert(IEnumerable <IOutlineNode> nodes, IOutlineNode after, bool copy)
        {
            var placementBehavior = DesignItem.GetBehavior <IPlacementBehavior>();

            if (placementBehavior == null)
            {
                return(false);
            }
            var operation = PlacementOperation.Start(nodes.Select(node => node.DesignItem).ToArray(), DummyPlacementType);

            if (operation != null)
            {
                bool canEnter = placementBehavior.CanEnterContainer(operation, true);
                operation.Abort();
                return(canEnter);
            }
            return(false);
        }
 protected override void OnStopped()
 {
     if (operation != null)
     {
         operation.Abort();
         operation = null;
     }
     if (changeGroup != null)
     {
         changeGroup.Abort();
         changeGroup = null;
     }
     if (services.Tool.CurrentTool is CreateComponentTool)
     {
         services.Tool.CurrentTool = services.Tool.PointerTool;
     }
     base.OnStopped();
 }
Exemple #33
0
        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);

            foreach (var item in ExtendedItem.ContentProperty.CollectionElements
                     .Except(operation.PlacedItems.Select(f => f.Item)))
            {
                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);

                BuildMaps(operation);

                if (operation.Type != PlacementType.Resize && operation.PlacedItems.Count == 1)
                {
                    baseline = GetBaseline(operation.PlacedItems[0].Item.View);
                }
            }
        }
        /// <summary>
        /// is invoked whenever a line is selected on the canvas, remember that the adorners are created for each line object and never destroyed
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            FillThumbProperties();

            foreach (var prp in _thumbProperties)
            {
                CreateThumb(PlacementAlignment.Center, Cursors.Cross, prp);
            }

            extendedItemArray[0] = this.ExtendedItem;

            Invalidate();

            this.ExtendedItem.PropertyChanged += OnPropertyChanged;
            resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
            UpdateAdornerVisibility();
        }
        void DesignPanel_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
            {
                e.Handled = true;

                if (placementOp == null)
                {
                    dx          = 0;
                    dy          = 0;
                    placementOp = PlacementOperation.Start(Context.Services.Selection.SelectedItems, PlacementType.Move);
                }


                dx = (e.Key == Key.Left) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0;
                dy = (e.Key == Key.Up) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0;
                dx = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : (dx != 0 ? dx : 0);
                dy = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : (dy != 0 ? dy : 0);
                double left, top;
                foreach (PlacementInformation info in placementOp.PlacedItems)
                {
                    //Let canvas position preceed bounds definition since there can be a discrepancy between them.
                    left = IsPropertySet(info.Item.View, Canvas.LeftProperty)?(double)info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance: info.OriginalBounds.Left;

                    top = IsPropertySet(info.Item.View, Canvas.TopProperty) ? (double)info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance : info.OriginalBounds.Top;
                    if (!Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        info.Bounds = new Rect(left + dx,
                                               top + dy,
                                               info.OriginalBounds.Width,
                                               info.OriginalBounds.Height);
                    }
                    else
                    {
                        info.Bounds = new Rect(left,
                                               top,
                                               info.OriginalBounds.Width + dx,
                                               info.OriginalBounds.Height + dy);
                    }
                    placementOp.CurrentContainerBehavior.SetPosition(info);
                }
            }
        }
Exemple #37
0
        /// <summary>
        /// Deletes the specified components from their parent containers.
        /// If the deleted components are currently selected, they are deselected before they are deleted.
        /// </summary>
        public static void DeleteComponents(ICollection <DesignItem> items)
        {
            DesignItem         parent    = items.First().Parent;
            PlacementOperation operation = PlacementOperation.Start(items, PlacementType.Delete);

            try {
                ISelectionService selectionService = items.First().Services.Selection;
                selectionService.SetSelectedComponents(items, SelectionTypes.Remove);
                // if the selection is empty after deleting some components, select the parent of the deleted component
                if (selectionService.SelectionCount == 0 && !items.Contains(parent))
                {
                    selectionService.SetSelectedComponents(new DesignItem[] { parent });
                }
                operation.DeleteItemsAndCommit();
            } catch {
                operation.Abort();
                throw;
            }
        }
        internal static bool AddItemWithCustomSize(DesignItem container, DesignItem createdItem, Point position, Size size)
        {
            PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents(
                container,
                new DesignItem[] { createdItem },
                new Rect[] { new Rect(position, size).Round() },
                PlacementType.AddItem
                );

            if (operation != null)
            {
                container.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
                operation.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #39
0
        /// <summary/>
        protected override Size MeasureOverride(Size availableSize)
        {
            if (this.AdornedElement != null)
            {
                foreach (DependencyObject v in base.InternalChildren)
                {
                    UIElement e = v as UIElement;
                    if (e != null)
                    {
                        e.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    }
                }

                return(PlacementOperation.GetRealElementSize(this.AdornedElement));
            }
            else
            {
                return(base.MeasureOverride(availableSize));
            }
        }
        internal static bool AddItemsWithCustomSize(DesignItem container, DesignItem[] createdItems, IList <Rect> positions)
        {
            PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents(
                container,
                createdItems,
                positions,
                PlacementType.AddItem
                );

            if (operation != null)
            {
                container.Services.Selection.SetSelectedComponents(createdItems);
                operation.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #41
0
        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);
                }
            }
        }
Exemple #42
0
 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);
         }
     }
 }
 protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
 {
     if (hasDragStarted)
     {
         if (operation != null)
         {
             operation.Commit();
             operation = null;
         }
     }
     else
     {
         CreateComponentTool.AddItemWithDefaultSize(container, createdItem, e.GetPosition(positionRelativeTo));
     }
     if (changeGroup != null)
     {
         changeGroup.Commit();
         changeGroup = null;
     }
     base.OnMouseUp(sender, e);
 }
Exemple #44
0
        public override void LeaveContainer(PlacementOperation operation)
        {
            GrayOutDesignerExceptActiveArea.Stop(ref grayOut);
            base.LeaveContainer(operation);
            foreach (PlacementInformation info in operation.PlacedItems)
            {
                if (info.Item.ComponentType == typeof(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(RowDefinition))
                {
                    this.ExtendedItem.Properties["RowDefinitions"].CollectionElements.Remove(info.Item);
                }
                else
                {
                    info.Item.Properties.GetAttachedProperty(Grid.RowProperty).Reset();
                    info.Item.Properties.GetAttachedProperty(Grid.ColumnProperty).Reset();
                    info.Item.Properties.GetAttachedProperty(Grid.RowSpanProperty).Reset();
                    info.Item.Properties.GetAttachedProperty(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 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);
 }
        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) {
                    if (!double.IsNaN((double)info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance)) {
                        info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty)
                            .SetValue(((double) info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance) +
                                      PlacementOperation.PasteOffset);
                    }

                    if (!double.IsNaN((double)info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance)) {
                        info.Item.Properties.GetAttachedProperty(Canvas.TopProperty)
                            .SetValue(((double) info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance) +
                                      PlacementOperation.PasteOffset);
                    }
                }
            }
        }
		private void dragX_Started(DragListener drag)
		{
			_adornerLayer = this.adornerPanel.TryFindParent<AdornerLayer>();
			
			var designerItem = this.ExtendedItem.Component as FrameworkElement;
			this.parent = VisualTreeHelper.GetParent(designerItem) as UIElement;
			
			startPoint = Mouse.GetPosition(this.parent);
			
			if (this.skewTransform == null)
			{
				this.skewX = 0;
				this.skewY = 0;
			}
			else
			{
				this.skewX = this.skewTransform.AngleX;
				this.skewY = this.skewTransform.AngleY;
			}
			
			rtTransform = this.ExtendedItem.Properties[FrameworkElement.RenderTransformProperty].Value;
			
			operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
		}
		protected override void OnStopped()
		{
			if (operation != null) {
				operation.Abort();
				operation = null;
			}
			if (changeGroup != null) {
				changeGroup.Abort();
				changeGroup = null;
			}
			if (services.Tool.CurrentTool is CreateComponentTool) {
				services.Tool.CurrentTool = services.Tool.PointerTool;
			}
			base.OnStopped();
		}
		public override void LeaveContainer(PlacementOperation operation)
		{
			base.LeaveContainer(operation);
			DeleteSurface();
		}
		public override void EndPlacement(PlacementOperation operation)
		{
			base.EndPlacement(operation);
			DeleteSurface();
		}
 public override void EndPlacement(PlacementOperation operation)
 {
     base.EndPlacement(operation);
     if (_adornerPanel != null && this.ExtendedItem.Services.DesignPanel.Adorners.Contains(_adornerPanel))
         this.ExtendedItem.Services.DesignPanel.Adorners.Remove(_adornerPanel);
 }
		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 override void EnterContainer(PlacementOperation operation)
		{
			base.EnterContainer(operation);
			CreateSurface(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);
				}
			}
		}
		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));
		}
		void drag_Completed(DragListener drag)
		{
			if (operation != null) {
				if (drag.IsCanceled) operation.Abort();
				else operation.Commit();
				operation = null;
			} else {
				if (drag.IsCanceled) changeGroup.Abort();
				else changeGroup.Commit();
				changeGroup = null;
			}
			_isResizing=false;
			HideSizeAndShowHandles();
		}
		// TODO : Remove all hide/show extensions from here.
		void drag_Started(DragListener drag)
		{
			var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
			if (designPanel != null)
			{
				var p = VisualTreeHelper.GetParent(designPanel);
				while (p != null && !(p is ZoomControl))
				{
					p = VisualTreeHelper.GetParent(p);
				}
				zoom = p as ZoomControl;
			}
			
			/* Abort editing Text if it was editing, because it interferes with the undo stack. */
			foreach(var extension in this.ExtendedItem.Extensions){
				if(extension is InPlaceEditorExtension){
					((InPlaceEditorExtension)extension).AbortEdit();
				}
			}
			
			oldSize = new Size(ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));
			if (resizeBehavior != null)
				operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
			else {
				changeGroup = this.ExtendedItem.Context.OpenGroup("Resize", extendedItemArray);
			}
			_isResizing=true;
			ShowSizeAndHideHandles();
		}
		public virtual void BeginPlacement(PlacementOperation operation)
		{
		}
		public virtual void BeforeSetPosition(PlacementOperation operation)
		{
		}
		public virtual bool CanLeaveContainer(PlacementOperation operation)
		{
			return true;
		}