/// <summary/>
		public TopLeftContainerDragHandle()
		{
			ContainerDragHandle rect = new ContainerDragHandle();
			
			rect.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) {
				Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto);
				new DragMoveMouseGesture(this.ExtendedItem, false).Start(this.ExtendedItem.Services.DesignPanel,e);
				e.Handled=true;                                                  
			};
			
			RelativePlacement p = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top);
			p.XOffset = -7;
			p.YOffset = -7;
			
			AddAdorner(p, AdornerOrder.Background, rect);
		}
		/// <summary>
		/// Creates a new SelectedElementRectangleExtension instance.
		/// </summary>
		public SelectedElementRectangleExtension()
		{
			Rectangle selectionRect = new Rectangle();
			selectionRect.SnapsToDevicePixels = true;
			selectionRect.Stroke = new SolidColorBrush(Color.FromRgb(0x47, 0x47, 0x47));
			selectionRect.StrokeThickness = 1.5;
			selectionRect.IsHitTestVisible = false;

			RelativePlacement placement = new RelativePlacement(HorizontalAlignment.Stretch, VerticalAlignment.Stretch);
			placement.XOffset = -1;
			placement.YOffset = -1;
			placement.WidthOffset = 2;
			placement.HeightOffset = 2;

			this.AddAdorners(placement, selectionRect);
		}
		protected override void OnInitialized()
		{
			base.OnInitialized();
			
			ContainerDragHandle rect = new ContainerDragHandle();
			
			rect.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) {
				//Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto);
				new DragMoveMouseGesture(this.ExtendedItem, false).Start(this.ExtendedItem.Services.DesignPanel,e);
				e.Handled=true;
			};
			
			var items = this.ExtendedItem.Services.Selection.SelectedItems;
			
			double minX = 0;
			double minY = 0;
			double maxX = 0;
			double maxY = 0;
			
			foreach (DesignItem di in items) {
				Point relativeLocation = di.View.TranslatePoint(new Point(0, 0), this.ExtendedItem.View);
				
				minX = minX < relativeLocation.X ? minX : relativeLocation.X;
				minY = minY < relativeLocation.Y ? minY : relativeLocation.Y;
				maxX = maxX > relativeLocation.X + ((FrameworkElement)di.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)di.View).ActualWidth;
				maxY = maxY > relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight;
			}
			
			Rectangle rect2 = new Rectangle() {
				Width = (maxX - minX) + 4,
				Height = (maxY - minY) + 4,
				Stroke = Brushes.Black,
				StrokeThickness = 2,
				StrokeDashArray = new DoubleCollection(){ 2, 2 },
			};
			
			RelativePlacement p = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top);
			p.XOffset = minX - 3;
			p.YOffset = minY - 3;
			
			RelativePlacement p2 = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top);
			p2.XOffset = (minX + rect2.Width) - 2;
			p2.YOffset = (minY + rect2.Height) - 2;
						
			AddAdorner(p, AdornerOrder.Background, rect);
			AddAdorner(p2, AdornerOrder.Background, rect2);
		}
		protected override void OnInitialized()
		{
			base.OnInitialized();
			_menu = new QuickOperationMenu();
			_menu.Loaded += OnMenuLoaded;
			var placement = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Top) {XOffset = 7, YOffset = 3.5};
			this.AddAdorners(placement, _menu);
			
			var kbs = this.ExtendedItem.Services.GetService(typeof (IKeyBindingService)) as IKeyBindingService;
			var command = new RelayCommand(delegate
			                                {
			                                	_menu.MainHeader.IsSubmenuOpen = true;
			                                	_menu.MainHeader.Focus();
			                                });
			_keyBinding=new KeyBinding(command, Key.Enter, ModifierKeys.Alt);
			if (kbs != null)
				kbs.RegisterBinding(_keyBinding);
		}
		protected override void OnInitialized()
		{
			base.OnInitialized();
			if (this.ExtendedItem != null)
			{
				RelativePlacement placementHeight = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Stretch);
				placementHeight.XOffset = 10;
				_heightDisplay = new HeightDisplay();
				_heightDisplay.DataContext = this.ExtendedItem.Component;

				RelativePlacement placementWidth = new RelativePlacement(HorizontalAlignment.Stretch, VerticalAlignment.Bottom);
				placementWidth.YOffset = 10;
				_widthDisplay = new WidthDisplay();
				_widthDisplay.DataContext = this.ExtendedItem.Component;

				this.AddAdorners(placementHeight, _heightDisplay);
				this.AddAdorners(placementWidth, _widthDisplay);
				_heightDisplay.Visibility=Visibility.Hidden;
				_widthDisplay.Visibility=Visibility.Hidden;
			}
		}
		protected override void OnInitialized()
		{
			leftBar = new GridRailAdorner(this.ExtendedItem, adornerPanel, Orientation.Vertical);
			topBar = new GridRailAdorner(this.ExtendedItem, adornerPanel, Orientation.Horizontal);
			
			RelativePlacement rp = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Stretch);
			rp.XOffset -= GridRailAdorner.RailDistance;
			AdornerPanel.SetPlacement(leftBar, rp);
			rp = new RelativePlacement(HorizontalAlignment.Stretch, VerticalAlignment.Top);
			rp.YOffset -= GridRailAdorner.RailDistance;
			AdornerPanel.SetPlacement(topBar, rp);
			
			adornerPanel.Children.Add(leftBar);
			adornerPanel.Children.Add(topBar);
			this.Adorners.Add(adornerPanel);
			
			CreateSplitter();
			this.ExtendedItem.PropertyChanged += OnPropertyChanged;
					
			base.OnInitialized();
		}
		protected override void OnInitialized()
		{
			base.OnInitialized();
			element = ExtendedItem.Component as FrameworkElement;
			editor = new InPlaceEditor(ExtendedItem);
			editor.DataContext = element;
			editor.Visibility = Visibility.Hidden; // Hide the editor first, It's visibility is governed by mouse events.
			
			placement = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top);
			adornerPanel.Children.Add(editor);
			Adorners.Add(adornerPanel);
			
			designPanel = ExtendedItem.Services.GetService<IDesignPanel>() as DesignPanel;
			Debug.Assert(designPanel!=null);
			
			/* Add mouse event handlers */
			designPanel.PreviewMouseLeftButtonDown += MouseDown;
			designPanel.PreviewMouseLeftButtonUp += MouseUp;
			designPanel.PreviewMouseMove += MouseMove;
			
			/* To update the position of Editor in case of resize operation */
			ExtendedItem.PropertyChanged += PropertyChanged;
		}
		/// <summary>
		/// Places resize thumbs at their respective positions
		/// and streches out thumbs which are at the center of outline to extend resizability across the whole outline
		/// </summary>
		/// <param name="resizeThumb"></param>
		/// <param name="alignment"></param>
		/// <returns></returns>
		private RelativePlacement Place(ref ResizeThumb resizeThumb,PlacementAlignment alignment)
		{
			RelativePlacement placement = new RelativePlacement(alignment.Horizontal,alignment.Vertical);
			
			if (alignment.Horizontal == HorizontalAlignment.Center)
			{
				placement.WidthRelativeToContentWidth = 1;
				placement.HeightOffset = 6;
				resizeThumb.Opacity = 0;
				return placement;
			}
			if (alignment.Vertical == VerticalAlignment.Center)
			{
				placement.HeightRelativeToContentHeight = 1;
				placement.WidthOffset = 6;
				resizeThumb.Opacity = 0;
				return placement;
			}
			
			placement.WidthOffset = 6;
			placement.HeightOffset = 6;
			return placement;
		}
 private void DrawVerticalRectangle(double offset)
 {
     _rectangle.Width = 2;
     _rectangle.Fill = Brushes.Black;
     var placement = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Stretch) {XOffset = offset};
     AdornerPanel.SetPlacement(_rectangle, placement);
 }
 private void DrawHorizontalRectangle(double offset)
 {
     _rectangle.Height = 2;
     _rectangle.Fill = Brushes.Black;
     var placement = new RelativePlacement(HorizontalAlignment.Stretch, VerticalAlignment.Top) {YOffset = offset};
     AdornerPanel.SetPlacement(_rectangle, placement);
 }
Example #11
0
		protected override void OnMouseMove(MouseEventArgs e)
		{
			base.OnMouseMove(e);
			RelativePlacement rp = new RelativePlacement();
			RelativePlacement rpUnitSelector = new RelativePlacement();
			if (orientation == Orientation.Vertical)
			{
				double insertionPosition = e.GetPosition(this).Y;
				RowDefinition current = grid.RowDefinitions
					.FirstOrDefault(r => insertionPosition >= r.Offset &&
					                insertionPosition <= (r.Offset + r.ActualHeight));

				rp.XOffset = -(RailSize + RailDistance);
				rp.WidthOffset = RailSize + RailDistance;
				rp.WidthRelativeToContentWidth = 1;
				rp.HeightOffset = SplitterWidth;
				rp.YOffset = e.GetPosition(this).Y - SplitterWidth / 2;
				if (current != null)
				{
					DesignItem component = this.gridItem.Services.Component.GetDesignItem(current);
					rpUnitSelector.XOffset = -(RailSize + RailDistance) * 2.75;
					rpUnitSelector.WidthOffset = RailSize + RailDistance;
					rpUnitSelector.WidthRelativeToContentWidth = 1;
					rpUnitSelector.HeightOffset = 55;
					rpUnitSelector.YOffset = current.Offset + current.ActualHeight / 2 - 25;
					unitSelector.SelectedItem = component;
					unitSelector.Unit = ((GridLength)component.Properties[RowDefinition.HeightProperty].ValueOnInstance).GridUnitType;
					displayUnitSelector = true;
				}
				else
				{
					displayUnitSelector = false;
				}
			}
			else
			{
				double insertionPosition = e.GetPosition(this).X;
				ColumnDefinition current = grid.ColumnDefinitions
					.FirstOrDefault(r => insertionPosition >= r.Offset &&
					                insertionPosition <= (r.Offset + r.ActualWidth));

				rp.YOffset = -(RailSize + RailDistance);
				rp.HeightOffset = RailSize + RailDistance;
				rp.HeightRelativeToContentHeight = 1;
				rp.WidthOffset = SplitterWidth;
				rp.XOffset = e.GetPosition(this).X - SplitterWidth / 2;

				if (current != null)
				{
					DesignItem component = this.gridItem.Services.Component.GetDesignItem(current);
					Debug.Assert(component != null);
					rpUnitSelector.YOffset = -(RailSize + RailDistance) * 2.20;
					rpUnitSelector.HeightOffset = RailSize + RailDistance;
					rpUnitSelector.HeightRelativeToContentHeight = 1;
					rpUnitSelector.WidthOffset = 75;
					rpUnitSelector.XOffset = current.Offset + current.ActualWidth / 2 - 35;
					unitSelector.SelectedItem = component;
					unitSelector.Unit = ((GridLength)component.Properties[ColumnDefinition.WidthProperty].ValueOnInstance).GridUnitType;
					displayUnitSelector = true;
				}
				else
				{
					displayUnitSelector = false;
				}
			}
			AdornerPanel.SetPlacement(previewAdorner, rp);
			if (displayUnitSelector)
				AdornerPanel.SetPlacement(unitSelector, rpUnitSelector);
		}
Example #12
0
		/// <summary>
		/// Binds the <see cref="HandleLength"/> to the margin and place the handles.
		/// </summary>
		void BindAndPlaceHandle()
		{
			if (!adornerPanel.Children.Contains(this))
				adornerPanel.Children.Add(this);
			if (!adornerPanel.Children.Contains(Stub))
				adornerPanel.Children.Add(Stub);
			RelativePlacement placement=new RelativePlacement();
			Binding binding = new Binding();
			binding.Source = adornedControl;
			switch (orientation)
			{
				case HandleOrientation.Left:
					binding.Path = new PropertyPath("Margin.Left");
					placement = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Center);
					placement.XOffset=-HandleLengthOffset;
					break;
				case HandleOrientation.Top:
					binding.Path = new PropertyPath("Margin.Top");
					placement = new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top);
					placement.YOffset=-HandleLengthOffset;
					break;
				case HandleOrientation.Right:
					binding.Path = new PropertyPath("Margin.Right");
					placement = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Center);
					placement.XOffset=HandleLengthOffset;
					break;
				case HandleOrientation.Bottom:
					binding.Path = new PropertyPath("Margin.Bottom");
					placement = new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Bottom);
					placement.YOffset=HandleLengthOffset;
					break;
			}

			binding.Mode = BindingMode.TwoWay;
			SetBinding(HandleLengthProperty, binding);

			AdornerPanel.SetPlacement(this, placement);
			AdornerPanel.SetPlacement(Stub, placement);
			
			DecideVisiblity(this.HandleLength);
		}
		/// <summary>
		/// Binds the <see cref="MarginHandle.HandleLength"/> to the margin and place the handles.
		/// </summary>
		void BindAndPlaceHandle()
		{
			if (!adornerPanel.Children.Contains(this))
				adornerPanel.Children.Add(this);
			if (!adornerPanel.Children.Contains(Stub))
				adornerPanel.Children.Add(Stub);
			RelativePlacement placement=new RelativePlacement();
			switch (orientation)
			{
				case HandleOrientation.Left:
					{
						var wr = (double) leftDescriptor.GetValue(adornedControl);
						if (double.IsNaN(wr))
						{
							wr = (double) rightDescriptor.GetValue(adornedControl);
							wr = canvas.ActualWidth - (adornedControl.ActualWidth + wr);
						}
						else
						{
							if (line1 != null)
							{
								line1.StrokeDashArray.Clear();
								line2.StrokeDashArray.Clear();
							}
						}
						this.HandleLength = wr;
						placement = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Center);
						placement.XOffset = -HandleLengthOffset;
						break;
					}
				case HandleOrientation.Top:
					{
						var wr = (double)topDescriptor.GetValue(adornedControl);
						if (double.IsNaN(wr))
						{
							wr = (double)bottomDescriptor.GetValue(adornedControl);
							wr = canvas.ActualHeight - (adornedControl.ActualHeight + wr);
						}
						else
						{
							if (line1 != null)
							{
								line1.StrokeDashArray.Clear();
								line2.StrokeDashArray.Clear();
							}
						}
						this.HandleLength = wr;
						placement = new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top);
						placement.YOffset = -HandleLengthOffset;
						break;
					}
				case HandleOrientation.Right:
					{
						var wr = (double) rightDescriptor.GetValue(adornedControl);
						if (double.IsNaN(wr))
						{
							wr = (double) leftDescriptor.GetValue(adornedControl);
							wr = canvas.ActualWidth - (adornedControl.ActualWidth + wr);
						}
						else
						{
							if (line1 != null)
							{
								line1.StrokeDashArray.Clear();
								line2.StrokeDashArray.Clear();
							}
						}
						this.HandleLength = wr;
						placement = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Center);
						placement.XOffset = HandleLengthOffset;
						break;
					}
				case HandleOrientation.Bottom:
					{
						var wr = (double)bottomDescriptor.GetValue(adornedControl);
						if (double.IsNaN(wr))
						{
							wr = (double)topDescriptor.GetValue(adornedControl);
							wr = canvas.ActualHeight - (adornedControl.ActualHeight + wr);
						}
						else
						{
							if (line1 != null)
							{
								line1.StrokeDashArray.Clear();
								line2.StrokeDashArray.Clear();
							}
						}
						this.HandleLength = wr;
						placement = new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Bottom);
						placement.YOffset = HandleLengthOffset;
						break;
					}
			}

			AdornerPanel.SetPlacement(this, placement);
			this.Visibility = Visibility.Visible;
		}
		void SetPlacement(Point endPoint)
		{
			RelativePlacement p = new RelativePlacement();
			p.XOffset = Math.Min(startPoint.X, endPoint.X);
			p.YOffset = Math.Min(startPoint.Y, endPoint.Y);
			p.WidthOffset = Math.Max(startPoint.X, endPoint.X) - p.XOffset;
			p.HeightOffset = Math.Max(startPoint.Y, endPoint.Y) - p.YOffset;
			AdornerPanel.SetPlacement(selectionFrame, p);
		}