예제 #1
0
        private PlacementOperation(DesignItem[] items, PlacementType type)
        {
            List <DesignItem> moveableItems;

            this.currentContainerBehavior = GetPlacementBehavior(items, out moveableItems, type);

            PlacementInformation[] information = new PlacementInformation[moveableItems.Count];
            for (int i = 0; i < information.Length; i++)
            {
                information[i] = new PlacementInformation(moveableItems[i], this);
            }
            this.placedItems = new ReadOnlyCollection <PlacementInformation>(information);
            this.type        = type;

            this.currentContainer = moveableItems[0].Parent;

            this.changeGroup = moveableItems[0].Context.OpenGroup(type.ToString(), moveableItems);
        }
        /// <summary>
        /// Make the placed item switch the container.
        /// This method assumes that you already have checked if changing the container is possible.
        /// </summary>
        public void ChangeContainer(DesignItem newContainer)
        {
            if (newContainer == null)
            {
                throw new ArgumentNullException("newContainer");
            }
            if (isAborted || isCommitted)
            {
                throw new PlacementOperationException("The operation is not running anymore.");
            }
            if (currentContainer == newContainer)
            {
                return;
            }

            if (!currentContainerBehavior.CanLeaveContainer(this))
            {
                throw new PlacementOperationException("The items cannot be removed from their parent container.");
            }

            try {
                currentContainerBehavior.LeaveContainer(this);

                GeneralTransform transform = currentContainer.View.TransformToVisual(newContainer.View);

                foreach (PlacementInformation info in placedItems)
                {
                    info.OriginalBounds = TransformRectByMiddlePoint(transform, info.OriginalBounds);
                    info.Bounds         = TransformRectByMiddlePoint(transform, info.Bounds).Round();
                }

                currentContainer         = newContainer;
                currentContainerBehavior = newContainer.GetBehavior <IPlacementBehavior>();

                Debug.Assert(currentContainerBehavior != null);
                currentContainerBehavior.EnterContainer(this);
            } catch (Exception ex) {
                Debug.WriteLine(ex.ToString());
                Abort();
                throw;
            }
        }
        void OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left))
            {
                e.Handled = true;
                IDesignPanel             designPanel = (IDesignPanel)sender;
                DesignPanelHitTestResult result      = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default);
                if (result.ModelHit != null)
                {
                    IPlacementBehavior behavior = result.ModelHit.GetBehavior <IPlacementBehavior>();
                    if (behavior != null)
                    {
                        DesignItem createdItem = CreateItem(designPanel.Context);

                        new CreateComponentMouseGesture(result.ModelHit, createdItem, changeGroup).Start(designPanel, e);
                        // CreateComponentMouseGesture now is responsible for the changeGroup created by CreateItem()
                        changeGroup = null;
                    }
                }
            }
        }
        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;

            if (rotateTransform != null)
            {
                angle = rotateTransform.Angle;
            }
        }
예제 #5
0
		protected override void OnInitialized()
		{
			base.OnInitialized();
			extendedItemArray[0] = this.ExtendedItem;
			this.ExtendedItem.PropertyChanged += OnPropertyChanged;
			this.Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged;
			resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
			UpdateAdornerVisibility();
			OnPrimarySelectionChanged(null, null);
		}
예제 #6
0
		/// <summary>
		/// Make the placed item switch the container.
		/// This method assumes that you already have checked if changing the container is possible.
		/// </summary>
		public void ChangeContainer(DesignItem newContainer)
		{
			if (newContainer == null)
				throw new ArgumentNullException("newContainer");
			if (isAborted || isCommitted)
				throw new InvalidOperationException("The operation is not running anymore.");
			if (currentContainer == newContainer)
				return;
			
			if (!currentContainerBehavior.CanLeaveContainer(this))
				throw new NotSupportedException("The items cannot be removed from their parent container.");
			
			try {
				currentContainerBehavior.LeaveContainer(this);
				
				GeneralTransform transform = currentContainer.View.TransformToVisual(newContainer.View);
				
				foreach (PlacementInformation info in placedItems) {
					info.OriginalBounds = TransformRectByMiddlePoint(transform, info.OriginalBounds);
					info.Bounds = TransformRectByMiddlePoint(transform, info.Bounds).Round();
				}
				
				currentContainer = newContainer;
				currentContainerBehavior = newContainer.GetBehavior<IPlacementBehavior>();
				
				Debug.Assert(currentContainerBehavior != null);
				currentContainerBehavior.EnterContainer(this);
			} catch (Exception ex) {
				Debug.WriteLine(ex.ToString());
				Abort();
				throw;
			}
		}
예제 #7
0
		private PlacementOperation(DesignItem[] items, PlacementType type)
		{
			PlacementInformation[] information = new PlacementInformation[items.Length];
			for (int i = 0; i < information.Length; i++) {
				information[i] = new PlacementInformation(items[i], this);
			}
			this.placedItems = new ReadOnlyCollection<PlacementInformation>(information);
			this.type = type;
			
			this.currentContainer = items[0].Parent;
			this.currentContainerBehavior = GetPlacementBehavior(items);
			
			this.changeGroup = items[0].Context.OpenGroup(type.ToString(), items);
		}
예제 #8
0
		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;
			
			if (rotateTransform != null)
				angle = rotateTransform.Angle;
		}
예제 #9
0
		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;
			if (this.rotateTransform == null) {
				var tg = designerItem.RenderTransform as TransformGroup;
				if (tg != null) {
					this.rotateTransform = tg.Children.FirstOrDefault(x => x is RotateTransform) as RotateTransform;
				}
			}
				
		}