private void ExtractItems(int[] itemSerials)
		{
			for(int i=0; i < itemSerials.Length; ++i)
			{
				Item item = World.FindItem(itemSerials[i]);

				if(item != null && !(item is BaseMulti))
				{
					DesignItem designItem = new DesignItem();
					designItem.ItemID = (short)item.ItemID;
					designItem.X = item.X;
					designItem.Y = item.Y;
					designItem.Z = item.Z;
					designItem.Hue = (short)item.Hue;

					_items.Add(designItem);
				}
			}

			ExtractResponse resp = null;

			if(_items.Count > 0)
				resp = new ExtractResponse(_items);
			else
				resp = null;

			SendResponse(resp);
		}
		public void LoadItemsCollection(DesignItem item)
		{
			Debug.Assert(item.View is ItemsControl);
			_item=item;
			_componentService=item.Services.Component;
			item.Services.Selection.SelectionChanged+= delegate { PropertyGridView.SelectedItems=item.Services.Selection.SelectedItems;  };
			var control=item.View as ItemsControl;
			if(control!=null){
				TypeMappings.TryGetValue(control.GetType(), out _type);
				if (_type != null) {
					IOutlineNode node = OutlineNode.Create(item);
					Outline.Root = node;
					PropertyGridView.PropertyGrid.SelectedItems = item.Services.Selection.SelectedItems;
				}
				else{
					PropertyGridView.IsEnabled=false;
					Outline.IsEnabled=false;
					AddItem.IsEnabled=false;
					RemoveItem.IsEnabled=false;
					MoveUpItem.IsEnabled=false;
					MoveDownItem.IsEnabled=false;
				}
			}
			
		}
예제 #3
0
		bool displayUnitSelector; // Indicates whether Grid UnitSeletor should be displayed.
		
		public GridRailAdorner(DesignItem gridItem, AdornerPanel adornerPanel, Orientation orientation)
		{
			Debug.Assert(gridItem != null);
			Debug.Assert(adornerPanel != null);
			
			this.gridItem = gridItem;
			this.grid = (Grid)gridItem.Component;
			this.adornerPanel = adornerPanel;
			this.orientation = orientation;
			this.displayUnitSelector=false;
			this.unitSelector = new GridUnitSelector(this);
			adornerPanel.Children.Add(unitSelector);
			
			if (orientation == Orientation.Horizontal) {
				this.Height = RailSize;
				previewAdorner = new GridColumnSplitterAdorner(this, gridItem, null, null);
			} else { // vertical
				this.Width = RailSize;
				previewAdorner = new GridRowSplitterAdorner(this, gridItem, null, null);
			}
			unitSelector.Orientation = orientation;
			previewAdorner.IsPreview = true;
			previewAdorner.IsHitTestVisible = false;
			unitSelector.Visibility = Visibility.Hidden;
			
		}
		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 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));
        }
예제 #6
0
		public PanelMoveAdorner(DesignItem item)
		{
			this.item = item;
			
			scaleTransform = new ScaleTransform(1.0, 1.0);
			this.LayoutTransform = scaleTransform;
		}
예제 #7
0
		public string GetOutlineNodeName(DesignItem designItem)
		{
			if (string.IsNullOrEmpty(designItem.Name)) {
					return designItem.ComponentType.Name;
				}
				return designItem.ComponentType.Name + " (" + designItem.Name + ")";
		}
예제 #8
0
		public CanvasPositionHandle(DesignItem adornedControlItem, AdornerPanel adornerPanel, HandleOrientation orientation)
		{
			Debug.Assert(adornedControlItem != null);
			this.adornedControlItem = adornedControlItem;
			this.adornerPanel = adornerPanel;
			this.orientation = orientation;

			Angle = (double) orientation;
			
			canvas = (Canvas) adornedControlItem.Parent.Component;
			adornedControl = (FrameworkElement) adornedControlItem.Component;
			Stub = new MarginStub(this);
			ShouldBeVisible = true;

			leftDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.LeftProperty,
			                                                           adornedControlItem.Component.GetType());
			leftDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
			rightDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.RightProperty,
			                                                            adornedControlItem.Component.GetType());
			rightDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
			topDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.TopProperty,
			                                                          adornedControlItem.Component.GetType());
			topDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
			bottomDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.BottomProperty,
			                                                             adornedControlItem.Component.GetType());
			bottomDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
			widthDescriptor = DependencyPropertyDescriptor.FromProperty(Control.WidthProperty,
			                                                            adornedControlItem.Component.GetType());
			widthDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
			heightDescriptor = DependencyPropertyDescriptor.FromProperty(Control.WidthProperty,
			                                                             adornedControlItem.Component.GetType());
			heightDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
			BindAndPlaceHandle();
		}
예제 #9
0
		/// <summary>
		/// Compares the positions of a and b in the model file.
		/// </summary>
		public static int ComparePositionInModelFile(DesignItem a, DesignItem b)
		{
			// first remember all parent properties of a
			HashSet<DesignItemProperty> aProps = new HashSet<DesignItemProperty>();
			DesignItem tmp = a;
			while (tmp != null) {
				aProps.Add(tmp.ParentProperty);
				tmp = tmp.Parent;
			}
			
			// now walk up b's parent tree until a matching property is found
			tmp = b;
			while (tmp != null) {
				DesignItemProperty prop = tmp.ParentProperty;
				if (aProps.Contains(prop)) {
					if (prop.IsCollection) {
						return prop.CollectionElements.IndexOf(a).CompareTo(prop.CollectionElements.IndexOf(b));
					} else {
						return 0;
					}
				}
				tmp = tmp.Parent;
			}
			return 0;
		}
예제 #10
0
		private void drag_Rotate_Started(DragListener drag)
		{
			var designerItem = this.ExtendedItem.Component as FrameworkElement;
			this.parent = VisualTreeHelper.GetParent(designerItem) as UIElement;
			this.centerPoint = designerItem.TranslatePoint(
				new Point(designerItem.ActualWidth*designerItem.RenderTransformOrigin.X,
				          designerItem.ActualHeight*designerItem.RenderTransformOrigin.Y),
				this.parent);

			Point startPoint = Mouse.GetPosition(this.parent);
			this.startVector = Point.Subtract(startPoint, this.centerPoint);

			if (this.rotateTransform == null)
			{
				this.initialAngle = 0;
			}
			else
			{
				this.initialAngle = this.rotateTransform.Angle;
			}

			rtTransform = this.ExtendedItem.Properties[FrameworkElement.RenderTransformProperty].Value;

			operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
		}
예제 #11
0
 public void Intialize()
 {
     _button = CreateGridContext("<Button Margin=\"21,21,21,21\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\"/>");
     var gridItem = _button.Parent;
     gridItem.Properties[FrameworkElement.HeightProperty].SetValue("200");
     gridItem.Properties[FrameworkElement.WidthProperty].SetValue("200");
 }
예제 #12
0
		public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e)
		{
			var createdItem = CreateItem(panel.Context, createItemType);

			var startPoint = e.GetPosition(clickedOn.View);
			var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn,
			                                                               new DesignItem[] { createdItem },
			                                                               new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) },
			                                                               PlacementType.AddItem);
			if (operation != null) {
				createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
				operation.Commit();
			}
			
			createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black);
			createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d);
			createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None);
			
			var figure = new PathFigure();
			var geometry = new PathGeometry();
			var geometryDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(geometry);
			var figureDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(figure);
			createdItem.Properties[Path.DataProperty].SetValue(geometry);
			//geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem);
			figureDesignItem.Properties[PathFigure.StartPointProperty].SetValue(new Point(0,0));
			
			new DrawPathMouseGesture(figure, createdItem, clickedOn.View, changeGroup, this.ExtendedItem.GetCompleteAppliedTransformationToView()).Start(panel, (MouseButtonEventArgs) e);
		}
예제 #13
0
		public override void InitializeDefaults(DesignItem item)
		{
			DesignItemProperty fillProperty = item.Properties["Fill"];
			if (fillProperty.ValueOnInstance == null) {
				fillProperty.SetValue(Brushes.YellowGreen);
			}
		}
예제 #14
0
		public override void InitializeDefaults(DesignItem item)
		{
			DesignItemProperty contentProperty = item.Properties["Content"];
			if (contentProperty.ValueOnInstance == null) {
				contentProperty.SetValue(item.ComponentType.Name);
			}
		}
        public override void SetBindings(DesignItem item, FrameworkElement view)
        {
            base.SetBindings(item, view);

            view.SetBinding(FrameworkElement.VerticalAlignmentProperty, new Binding("Component.VerticalOptions") { Source = item, Converter = LayoutOptionsToVerticalAlignmentConverter.Instance });
            view.SetBinding(FrameworkElement.HorizontalAlignmentProperty, new Binding("Component.HorizontalOptions") { Source = item, Converter = LayoutOptionsToHorizontalAlignmentConverter.Instance });
        }
예제 #16
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;
			}
		}
        public override FrameworkElement CreateView(DesignItem item)
        {
            var tabcontrol = new System.Windows.Controls.TabControl();
            tabcontrol.Background = TransparentBrush.GetTransparentBrush();

            foreach (var collectionElement in item.ContentProperty.CollectionElements)
            {
                tabcontrol.Items.Add(collectionElement.View);
            }

            item.ContentProperty.CollectionElements.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach (DesignItem newItem in args.NewItems)
                    {
                        tabcontrol.Items.Add(newItem.View);
                    }
                }
                else if (args.Action == NotifyCollectionChangedAction.Remove)
                {
                    foreach (DesignItem oldItem in args.OldItems)
                    {
                        tabcontrol.Items.Remove(oldItem.View);
                    }
                }
            };

            return tabcontrol;
        }
예제 #18
0
		protected OutlineNodeBase(DesignItem designItem)
		{
			DesignItem = designItem;

			bool hidden = false;
			try
			{
				hidden = (bool)designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).ValueOnInstance;
			}
			catch (Exception)
			{ }
			if (hidden) {
				_isDesignTimeVisible = false;
			}

			bool locked = false;
			try
			{
				locked = (bool)designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).ValueOnInstance;
			}
			catch (Exception)
			{ }
			if (locked) {
				_isDesignTimeLocked = true;
			}

			//TODO

			DesignItem.NameChanged += new EventHandler(DesignItem_NameChanged);
			DesignItem.PropertyChanged += new PropertyChangedEventHandler(DesignItem_PropertyChanged);
		}
		public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e)
		{
			var createdItem = CreateItem(panel.Context, createItemType);

			var startPoint = e.GetPosition(clickedOn.View);
			var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn,
			                                                               new DesignItem[] { createdItem },
			                                                               new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) },
			                                                               PlacementType.AddItem);
			if (operation != null) {
				createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
				operation.Commit();
			}
			
			createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black);
			createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d);
			createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None);
			
			if (createItemType == typeof(Polyline))
				createdItem.Properties[Polyline.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0)));
			else
				createdItem.Properties[Polygon.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0)));
			
			new DrawPolylineMouseGesture(createdItem, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e);
		}
        public override void InitializeDesignItem(DesignItem item)
        {
            var view = new ContentPageView();

            view.SetBinding(ContentPageView.ContentProperty, new Binding("ContentProperty.ValueOnInstanceOrView") { Source = item });

            item.SetView(view);
        }
        public IEnumerable<MemberDescriptor> GetAvailableProperties(DesignItem designItem)
        {
            IEnumerable<PropertyDescriptor> retVal = TypeHelper.GetAvailableProperties(designItem.Component);

            retVal = retVal.Where(c => c.Name == "Foreground");

            return retVal;
        }
예제 #22
0
		internal void InitializeDefaultExtension(DesignItem extendedItem)
		{
			Debug.Assert(this._extendedItem == null);
			Debug.Assert(extendedItem != null);
			
			this._extendedItem = extendedItem;
			OnInitialized();
		}
예제 #23
0
		public void Intialize()
		{
			_buttonInGridWithAutoSize=CreateGridContext("<Button/>");
			Move(new Vector(50,25),_buttonInGridWithAutoSize);
			
			_buttonIsGridWithFixedSize=CreateGridContext("<Button HorizontalAlignment=\"Left\" VerticalAlignment=\"Top\" Width=\"50\" Height=\"50\"/>");
			Move(new Vector(50,25),_buttonIsGridWithFixedSize);
		}
예제 #24
0
		public MoveLogic(DesignItem clickedOn)
		{
			this.clickedOn = clickedOn;
			
			selectedItems = clickedOn.Services.Selection.SelectedItems;
			if (!selectedItems.Contains(clickedOn))
				selectedItems = SharedInstances.EmptyDesignItemArray;
		}
예제 #25
0
		private void BoundingBox_Callback( Mobile from, Map map, Point3D start, Point3D end, object state )
		{
			Utility.FixPoints( ref start, ref end );
			Rectangle2D rect = new Rectangle2D(start, end);

			#region MobileSaver
			from.SendMessage( "Extracting Mobiles" );

			foreach ( Mobile m in map.GetMobilesInBounds( rect ) )
			{
				if ( m != null && m is BaseCreature )
				{
					int saveflag = MobileSaver.GetSaveFlag( m );

					if ( saveflag > 0 )
					{
						DesignItem designItem = new DesignItem();
						designItem.ItemID = (short)0x1;
						designItem.X = m.X;
						designItem.Y = m.Y;
						designItem.Z = m.Z + saveflag;
						designItem.Hue = (short)m.Hue;
					}
				}
			}
			#endregion

			for ( int x = 0; x <= rect.Width; ++x )
			{
				for ( int y = 0; y <= rect.Height; ++y )
				{
					int tileX = rect.Start.X + x;
					int tileY = rect.Start.Y + y;

					Sector sector = map.GetSector( tileX, tileY );

					for ( int i = 0; i < sector.Items.Count; ++i )
					{
						Item item = (Item)sector.Items[i];

						if(_args.UseMinZ && item.Z < _args.MinZ)
							continue;
						else if(_args.UseMaxZ && item.Z > _args.MaxZ)
							continue;

						if ( item.Visible && item.X == tileX && item.Y == tileY && !((item is BaseMulti) || (item is HouseSign)) )
						{
							_itemSerials.Add(item.Serial.Value);
						}
					}
				}
			}

			if(_itemSerials.Count > 0)
				SendResponse(new SelectItemsResponse((int[])_itemSerials.ToArray(typeof(int))));
			else
				SendResponse(null);
		}
        public override void SetBindings(DesignItem item, FrameworkElement view)
        {
            base.SetBindings(item, view);

            view.SetBinding(EntryView.TextProperty, new Binding("Component.Text") { Source = item });
            view.SetBinding(EntryView.VisibilityProperty, new Binding("Component.IsVisible") { Source = item, Converter = IsVisibleToVisibilityConverter.Instance });
            view.SetBinding(EntryView.FontSizeProperty, new Binding("Component.FontSize") { Source = item });
            view.SetBinding(EntryView.ForegroundProperty, new Binding("Component.TextColor") { Source = item, Converter = ColorToBrushConverter.Instance });
        }
        public override IEnumerable<MemberDescriptor> GetAvailableProperties(DesignItem designItem)
        {
            if (designItem.Component is BindableObject)
            {
                return TypeHelper.GetAvailableProperties(designItem.ComponentType);
            }

            return base.GetAvailableProperties(designItem);
        }
		internal DragMoveMouseGesture(DesignItem clickedOn, bool isDoubleClick)
		{
			Debug.Assert(clickedOn != null);
			
			this.isDoubleClick = isDoubleClick;
			this.positionRelativeTo = clickedOn.Services.DesignPanel;

			moveLogic = new MoveLogic(clickedOn);
		}
예제 #29
0
		public static OutlineNode Create(DesignItem designItem)
		{
			OutlineNode node;
			if (!outlineNodes.TryGetValue(designItem, out node)) {
				node = new OutlineNode(designItem);
				outlineNodes[designItem] = node;
			}
			return node;
		}
예제 #30
0
		/// <summary>
		/// Gets if the specified design item is in the document it belongs to.
		/// </summary>
		/// <returns>True for live objects, false for deleted objects.</returns>
		public static bool IsInDocument(DesignItem item)
		{
			DesignItem rootItem = item.Context.RootItem;
			while (item != null) {
				if (item == rootItem) return true;
				item = item.Parent;
			}
			return false;
		}
예제 #31
0
 internal GridColumnSplitterAdorner(GridRailAdorner rail, DesignItem gridItem, DesignItem firstRow, DesignItem secondRow)
     : base(rail, gridItem, firstRow, secondRow)
 {
 }
예제 #32
0
        public ArrangeItemsContextMenu(DesignItem designItem)
        {
            this.designItem = designItem;

            SpecialInitializeComponent();
        }
 public override bool ShouldApplyExtensions(DesignItem extendedItem)
 {
     return(false);
 }
        /// <summary>
        /// Paste items from clipboard into the designer.
        /// </summary>
        public void Paste()
        {
            bool   pasted              = false;
            string combinedXaml        = Clipboard.GetText(TextDataFormat.Xaml);
            IEnumerable <string> xamls = combinedXaml.Split(_delimeter);

            xamls = xamls.Where(xaml => xaml != "");

            DesignItem parent = _context.Services.Selection.PrimarySelection;
            DesignItem child  = _context.Services.Selection.PrimarySelection;

            XamlDesignItem rootItem    = _context.RootItem as XamlDesignItem;
            var            pastedItems = new Collection <DesignItem>();

            foreach (var xaml in xamls)
            {
                var obj = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, _settings);
                if (obj != null)
                {
                    DesignItem item = _context._componentService.RegisterXamlComponentRecursive(obj);
                    if (item != null)
                    {
                        pastedItems.Add(item);
                    }
                }
            }

            if (pastedItems.Count != 0)
            {
                var changeGroup = _context.OpenGroup("Paste " + pastedItems.Count + " elements", pastedItems);
                while (parent != null && pasted == false)
                {
                    if (parent.ContentProperty != null)
                    {
                        if (parent.ContentProperty.IsCollection)
                        {
                            if (CollectionSupport.CanCollectionAdd(parent.ContentProperty.ReturnType, pastedItems.Select(item => item.Component)) && parent.GetBehavior <IPlacementBehavior>() != null)
                            {
                                AddInParent(parent, pastedItems);
                                pasted = true;
                            }
                        }
                        else if (pastedItems.Count == 1 && parent.ContentProperty.Value == null && parent.ContentProperty.ValueOnInstance == null && DefaultPlacementBehavior.CanContentControlAdd((ContentControl)parent.View))
                        {
                            AddInParent(parent, pastedItems);
                            pasted = true;
                        }
                        if (!pasted)
                        {
                            parent = parent.Parent;
                        }
                    }
                    else
                    {
                        parent = parent.Parent;
                    }
                }

                while (pasted == false)
                {
                    if (child.ContentProperty != null)
                    {
                        if (child.ContentProperty.IsCollection)
                        {
                            foreach (var col in child.ContentProperty.CollectionElements)
                            {
                                if (col.ContentProperty != null && col.ContentProperty.IsCollection)
                                {
                                    if (CollectionSupport.CanCollectionAdd(col.ContentProperty.ReturnType, pastedItems.Select(item => item.Component)))
                                    {
                                        pasted = true;
                                    }
                                }
                            }
                            break;
                        }
                        else if (child.ContentProperty.Value != null)
                        {
                            child = child.ContentProperty.Value;
                        }
                        else if (pastedItems.Count == 1)
                        {
                            child.ContentProperty.SetValue(pastedItems.First().Component);
                            pasted = true;
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                changeGroup.Commit();
            }
        }
        public static void ApplyTransform(DesignItem designItem, Transform transform, bool relative = true)
        {
            var changeGroup = designItem.OpenGroup("Apply Transform");

            Transform oldTransform = null;

            if (designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).IsSet)
            {
                oldTransform = designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).ValueOnInstance as Transform;
            }

            if (oldTransform is MatrixTransform)
            {
                var mt = oldTransform as MatrixTransform;
                var tg = new TransformGroup();
                if (mt.Matrix.OffsetX != 0 && mt.Matrix.OffsetY != 0)
                {
                    tg.Children.Add(new TranslateTransform()
                    {
                        X = mt.Matrix.OffsetX, Y = mt.Matrix.OffsetY
                    });
                }
                if (mt.Matrix.M11 != 0 && mt.Matrix.M22 != 0)
                {
                    tg.Children.Add(new ScaleTransform()
                    {
                        ScaleX = mt.Matrix.M11, ScaleY = mt.Matrix.M22
                    });
                }

                var angle = Math.Atan2(mt.Matrix.M21, mt.Matrix.M11) * 180 / Math.PI;
                if (angle != 0)
                {
                    tg.Children.Add(new RotateTransform()
                    {
                        Angle = angle
                    });
                }
                //if (mt.Matrix.M11 != 0 && mt.Matrix.M22 != 0)
                //	tg.Children.Add(new SkewTransform(){ ScaleX = mt.Matrix.M11, ScaleY = mt.Matrix.M22 });
            }
            else if (oldTransform != null && oldTransform.GetType() != transform.GetType())
            {
                var tg    = new TransformGroup();
                var tgDes = designItem.Services.Component.RegisterComponentForDesigner(tg);
                tgDes.ContentProperty.CollectionElements.Add(designItem.Services.Component.GetDesignItem(oldTransform));
                designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(tg);
                oldTransform = tg;
            }



            if (transform is RotateTransform)
            {
                var rotateTransform = transform as RotateTransform;

                if (oldTransform is RotateTransform || oldTransform == null)
                {
                    if (rotateTransform.Angle != 0)
                    {
                        designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(transform);
                        var angle = rotateTransform.Angle;
                        if (relative && oldTransform != null)
                        {
                            angle = rotateTransform.Angle + ((RotateTransform)oldTransform).Angle;
                        }
                        designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.AngleProperty).SetValue(angle);
                        if (rotateTransform.CenterX != 0.0)
                        {
                            designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterXProperty).SetValue(rotateTransform.CenterX);
                        }
                        if (rotateTransform.CenterY != 0.0)
                        {
                            designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterYProperty).SetValue(rotateTransform.CenterY);
                        }

                        if (oldTransform == null)
                        {
                            designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
                        }
                    }
                    else
                    {
                        designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Reset();
                        designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).Reset();
                    }
                }
                else if (oldTransform is TransformGroup)
                {
                    var tg  = oldTransform as TransformGroup;
                    var rot = tg.Children.FirstOrDefault(x => x is RotateTransform);
                    if (rot != null)
                    {
                        designItem.Services.Component.GetDesignItem(tg).ContentProperty.CollectionElements.Remove(designItem.Services.Component.GetDesignItem(rot));
                    }
                    if (rotateTransform.Angle != 0)
                    {
                        var des = designItem.Services.Component.GetDesignItem(transform);
                        if (des == null)
                        {
                            des = designItem.Services.Component.RegisterComponentForDesigner(transform);
                        }
                        designItem.Services.Component.GetDesignItem(tg).ContentProperty.CollectionElements.Add(des);
                        if (oldTransform == null)
                        {
                            designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
                        }
                    }
                }
                else
                {
                    if (rotateTransform.Angle != 0)
                    {
                        designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(transform);
                        if (oldTransform == null)
                        {
                            designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
                        }
                    }
                }
            }

            ((DesignPanel)designItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(designItem.View, true);

            changeGroup.Commit();
        }
예제 #36
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);
            }
        }
예제 #37
0
 public bool IsComponentSelected(DesignItem component)
 {
     return(_selectedComponents.Contains(component));
 }
예제 #38
0
        public virtual void SetSelectedComponents(ICollection <DesignItem> components, SelectionTypes selectionType)
        {
            if (components == null)
            {
                components = SharedInstances.EmptyDesignItemArray;
            }

            if (components.Contains(null))
            {
                throw new ArgumentException("Cannot select 'null'.");
            }

            var prevSelectedItems = _selectedComponents.ToArray();

            if (SelectionChanging != null)
            {
                SelectionChanging(this, EventArgs.Empty);
            }

            DesignItem newPrimarySelection = _primarySelection;

            if (selectionType == SelectionTypes.Auto)
            {
                if (Keyboard.Modifiers == ModifierKeys.Control)
                {
                    selectionType = SelectionTypes.Toggle;                     // Ctrl pressed: toggle selection
                }
                else if ((Keyboard.Modifiers & ~ModifierKeys.Control) == ModifierKeys.Shift)
                {
                    selectionType = SelectionTypes.Add;                     // Shift or Ctrl+Shift pressed: add to selection
                }
                else
                {
                    selectionType = SelectionTypes.Primary;                     // otherwise: change primary selection
                }
            }

            if ((selectionType & SelectionTypes.Primary) == SelectionTypes.Primary)
            {
                // change primary selection to first new component
                newPrimarySelection = null;
                foreach (DesignItem obj in components)
                {
                    newPrimarySelection = obj;
                    break;
                }

                selectionType &= ~SelectionTypes.Primary;
                if (selectionType == 0)
                {
                    // if selectionType was only Primary, and components has only one item that
                    // changes the primary selection was changed to an already-selected item,
                    // then we keep the current selection.
                    // otherwise, we replace it
                    if (components.Count == 1 && IsComponentSelected(newPrimarySelection) && prevSelectedItems.Length == 1)
                    {
                        // keep selectionType = 0 -> don't change the selection
                    }
                    else
                    {
                        selectionType = SelectionTypes.Replace;
                    }
                }
            }

            HashSet <DesignItem> componentsToNotifyOfSelectionChange = new HashSet <DesignItem>();

            switch (selectionType)
            {
            case SelectionTypes.Add:
                // add to selection and notify if required
                foreach (DesignItem obj in components)
                {
                    if (_selectedComponents.Add(obj))
                    {
                        componentsToNotifyOfSelectionChange.Add(obj);
                    }
                }
                break;

            case SelectionTypes.Remove:
                // remove from selection and notify if required
                foreach (DesignItem obj in components)
                {
                    if (_selectedComponents.Remove(obj))
                    {
                        componentsToNotifyOfSelectionChange.Add(obj);
                    }
                }
                break;

            case SelectionTypes.Replace:
                // notify all old components:
                componentsToNotifyOfSelectionChange.AddRange(_selectedComponents);
                // set _selectedCompontents to new components
                _selectedComponents.Clear();
                foreach (DesignItem obj in components)
                {
                    _selectedComponents.Add(obj);
                    // notify the new components
                    componentsToNotifyOfSelectionChange.Add(obj);
                }
                break;

            case SelectionTypes.Toggle:
                // toggle selection and notify
                foreach (DesignItem obj in components)
                {
                    if (_selectedComponents.Contains(obj))
                    {
                        _selectedComponents.Remove(obj);
                    }
                    else
                    {
                        _selectedComponents.Add(obj);
                    }
                    componentsToNotifyOfSelectionChange.Add(obj);
                }
                break;

            case 0:
                // do nothing
                break;

            default:
                throw new NotSupportedException("The selection type " + selectionType + " is not supported");
            }

            if (!IsComponentSelected(newPrimarySelection))
            {
                // primary selection is not selected anymore - change primary selection to any other selected component
                newPrimarySelection = null;
                foreach (DesignItem obj in _selectedComponents)
                {
                    newPrimarySelection = obj;
                    break;
                }
            }

            // Primary selection has changed:
            if (newPrimarySelection != _primarySelection)
            {
                componentsToNotifyOfSelectionChange.Add(_primarySelection);
                componentsToNotifyOfSelectionChange.Add(newPrimarySelection);
                if (PrimarySelectionChanging != null)
                {
                    PrimarySelectionChanging(this, EventArgs.Empty);
                }
                _primarySelection = newPrimarySelection;
                if (PrimarySelectionChanged != null)
                {
                    PrimarySelectionChanged(this, EventArgs.Empty);
                }
                RaisePropertyChanged("PrimarySelection");
            }

            if (!_selectedComponents.SequenceEqual(prevSelectedItems))
            {
                if (SelectionChanged != null)
                {
                    SelectionChanged(this, new DesignItemCollectionEventArgs(componentsToNotifyOfSelectionChange));
                }
                RaisePropertyChanged("SelectedItems");
            }
        }
예제 #39
0
 public PartialRangeSelectionGesture(DesignItem container)
     : base(container)
 {
 }
예제 #40
0
        protected override ICollection <DesignItem> GetChildDesignItemsInContainer(Geometry geometry)
        {
            HashSet <DesignItem> resultItems = new HashSet <DesignItem>();
            ViewService          viewService = container.Services.View;

            HitTestFilterCallback filterCallback = delegate(DependencyObject potentialHitTestTarget)
            {
                FrameworkElement element = potentialHitTestTarget as FrameworkElement;
                if (element != null)
                {
                    // ensure we are able to select elements with width/height=0
                    if (element.ActualWidth == 0 || element.ActualHeight == 0)
                    {
                        DependencyObject tmp   = element;
                        DesignItem       model = null;
                        while (tmp != null)
                        {
                            model = viewService.GetModel(tmp);
                            if (model != null)
                            {
                                break;
                            }
                            tmp = VisualTreeHelper.GetParent(tmp);
                        }
                        if (model != container)
                        {
                            resultItems.Add(model);
                            return(HitTestFilterBehavior.ContinueSkipChildren);
                        }
                    }
                }
                return(HitTestFilterBehavior.Continue);
            };

            HitTestResultCallback resultCallback = delegate(HitTestResult result)
            {
                if (((GeometryHitTestResult)result).IntersectionDetail == IntersectionDetail.FullyInside || (Mouse.RightButton == MouseButtonState.Pressed && ((GeometryHitTestResult)result).IntersectionDetail == IntersectionDetail.Intersects))
                {
                    // find the model for the visual contained in the selection area
                    DependencyObject tmp   = result.VisualHit;
                    DesignItem       model = null;
                    while (tmp != null)
                    {
                        model = viewService.GetModel(tmp);
                        if (model != null)
                        {
                            break;
                        }
                        tmp = VisualTreeHelper.GetParent(tmp);
                    }
                    if (model != container)
                    {
                        resultItems.Add(model);
                    }
                }
                return(HitTestResultBehavior.Continue);
            };

            VisualTreeHelper.HitTest(container.View, filterCallback, resultCallback, new GeometryHitTestParameters(geometry));
            return(resultItems);
        }
예제 #41
0
        public TextBlockRightClickContextMenu(DesignItem designItem)
        {
            this.designItem = designItem;

            SpecialInitializeComponent();
        }
예제 #42
0
 /// <summary>
 /// Gets if the item is the primary selection.
 /// </summary>
 public override bool ShouldApplyExtensions(DesignItem extendedItem)
 {
     return(Services.Selection.PrimarySelection == extendedItem);
 }
예제 #43
0
        void UndoRedoDictionaryInternal(bool useExplicitDictionary)
        {
            DesignItem         button    = CreateCanvasContext("<Button/>");
            UndoService        s         = button.Context.Services.GetService <UndoService>();
            IComponentService  component = button.Context.Services.Component;
            string             expectedXamlWithDictionary;
            DesignItemProperty dictionaryProp;

            Assert.IsFalse(s.CanUndo);
            Assert.IsFalse(s.CanRedo);

            using (ChangeGroup g = button.OpenGroup("UndoRedoDictionaryInternal test")) {
                DesignItem containerItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());

                dictionaryProp = containerItem.Properties["Dictionary"];

                if (useExplicitDictionary)
                {
                    dictionaryProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary());

                    expectedXamlWithDictionary = @"<Button>
  <Button.Tag>
    <Controls0:ExampleClassContainer>
      <Controls0:ExampleClassContainer.Dictionary>
        <Controls0:ExampleClassDictionary>
          <Controls0:ExampleClass x:Key=""testKey"" StringProp=""String value"" />
        </Controls0:ExampleClassDictionary>
      </Controls0:ExampleClassContainer.Dictionary>
    </Controls0:ExampleClassContainer>
  </Button.Tag>
</Button>";
                }
                else
                {
                    expectedXamlWithDictionary = @"<Button>
  <Button.Tag>
    <Controls0:ExampleClassContainer>
      <Controls0:ExampleClassContainer.Dictionary>
        <Controls0:ExampleClass x:Key=""testKey"" StringProp=""String value"" />
      </Controls0:ExampleClassContainer.Dictionary>
    </Controls0:ExampleClassContainer>
  </Button.Tag>
</Button>";
                }

                DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
                exampleClassItem.Key = "testKey";
                exampleClassItem.Properties["StringProp"].SetValue("String value");
                dictionaryProp.CollectionElements.Add(exampleClassItem);

                button.Properties["Tag"].SetValue(containerItem);
                g.Commit();
            }

            Assert.IsTrue(s.CanUndo);
            Assert.IsFalse(s.CanRedo);
            AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");

            dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"];
            Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count);

            s.Undo();
            Assert.IsFalse(s.CanUndo);
            Assert.IsTrue(s.CanRedo);
            AssertCanvasDesignerOutput("<Button>\n</Button>", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");

            s.Redo();
            Assert.IsTrue(s.CanUndo);
            Assert.IsFalse(s.CanRedo);
            AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");

            dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"];
            Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count);

            AssertLog("");
        }
예제 #44
0
 internal GridSplitterAdorner(GridRailAdorner rail, DesignItem gridItem, DesignItem firstRow, DesignItem secondRow)
 {
     Debug.Assert(gridItem != null);
     this.grid      = (Grid)gridItem.Component;
     this.gridItem  = gridItem;
     this.firstRow  = firstRow;
     this.secondRow = secondRow;
     this.rail      = rail;
 }
예제 #45
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            e.Handled = true;
            Focus();
            adornerPanel.Children.Remove(previewAdorner);
            if (orientation == Orientation.Vertical)
            {
                double             insertionPosition = e.GetPosition(this).Y;
                DesignItemProperty rowCollection     = gridItem.Properties["RowDefinitions"];

                DesignItem currentRow = null;

                using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid row")) {
                    if (rowCollection.CollectionElements.Count == 0)
                    {
                        DesignItem firstRow = gridItem.Services.Component.RegisterComponentForDesigner(new RowDefinition());
                        rowCollection.CollectionElements.Add(firstRow);
                        grid.UpdateLayout();                         // let WPF assign firstRow.ActualHeight

                        currentRow = firstRow;
                    }
                    else
                    {
                        RowDefinition current = grid.RowDefinitions
                                                .FirstOrDefault(r => insertionPosition >= r.Offset &&
                                                                insertionPosition <= (r.Offset + r.ActualHeight));
                        if (current != null)
                        {
                            currentRow = gridItem.Services.Component.GetDesignItem(current);
                        }
                    }

                    if (currentRow == null)
                    {
                        currentRow = gridItem.Services.Component.GetDesignItem(grid.RowDefinitions.Last());
                    }

                    unitSelector.SelectedItem = currentRow;
                    for (int i = 0; i < grid.RowDefinitions.Count; i++)
                    {
                        RowDefinition row = grid.RowDefinitions[i];
                        if (row.Offset > insertionPosition)
                        {
                            continue;
                        }
                        if (row.Offset + row.ActualHeight < insertionPosition)
                        {
                            continue;
                        }

                        // split row
                        GridLength oldLength = (GridLength)row.GetValue(RowDefinition.HeightProperty);
                        GridLength newLength1, newLength2;
                        SplitLength(oldLength, insertionPosition - row.Offset, row.ActualHeight, out newLength1, out newLength2);
                        DesignItem newRowDefinition = gridItem.Services.Component.RegisterComponentForDesigner(new RowDefinition());
                        rowCollection.CollectionElements.Insert(i + 1, newRowDefinition);
                        rowCollection.CollectionElements[i].Properties[RowDefinition.HeightProperty].SetValue(newLength1);
                        newRowDefinition.Properties[RowDefinition.HeightProperty].SetValue(newLength2);
                        grid.UpdateLayout();
                        FixIndicesAfterSplit(i, Grid.RowProperty, Grid.RowSpanProperty, insertionPosition);
                        grid.UpdateLayout();
                        changeGroup.Commit();
                        break;
                    }
                }
            }
            else
            {
                double             insertionPosition = e.GetPosition(this).X;
                DesignItemProperty columnCollection  = gridItem.Properties["ColumnDefinitions"];

                DesignItem currentColumn = null;

                using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid column")) {
                    if (columnCollection.CollectionElements.Count == 0)
                    {
                        DesignItem firstColumn = gridItem.Services.Component.RegisterComponentForDesigner(new ColumnDefinition());
                        columnCollection.CollectionElements.Add(firstColumn);
                        grid.UpdateLayout();                         // let WPF assign firstColumn.ActualWidth

                        currentColumn = firstColumn;
                    }
                    else
                    {
                        ColumnDefinition current = grid.ColumnDefinitions
                                                   .FirstOrDefault(r => insertionPosition >= r.Offset &&
                                                                   insertionPosition <= (r.Offset + r.ActualWidth));
                        if (current != null)
                        {
                            currentColumn = gridItem.Services.Component.GetDesignItem(current);
                        }
                    }

                    if (currentColumn == null)
                    {
                        currentColumn = gridItem.Services.Component.GetDesignItem(grid.ColumnDefinitions.Last());
                    }

                    unitSelector.SelectedItem = currentColumn;
                    for (int i = 0; i < grid.ColumnDefinitions.Count; i++)
                    {
                        ColumnDefinition column = grid.ColumnDefinitions[i];
                        if (column.Offset > insertionPosition)
                        {
                            continue;
                        }
                        if (column.Offset + column.ActualWidth < insertionPosition)
                        {
                            continue;
                        }

                        // split column
                        GridLength oldLength = (GridLength)column.GetValue(ColumnDefinition.WidthProperty);
                        GridLength newLength1, newLength2;
                        SplitLength(oldLength, insertionPosition - column.Offset, column.ActualWidth, out newLength1, out newLength2);
                        DesignItem newColumnDefinition = gridItem.Services.Component.RegisterComponentForDesigner(new ColumnDefinition());
                        columnCollection.CollectionElements.Insert(i + 1, newColumnDefinition);
                        columnCollection.CollectionElements[i].Properties[ColumnDefinition.WidthProperty].SetValue(newLength1);
                        newColumnDefinition.Properties[ColumnDefinition.WidthProperty].SetValue(newLength2);
                        grid.UpdateLayout();
                        FixIndicesAfterSplit(i, Grid.ColumnProperty, Grid.ColumnSpanProperty, insertionPosition);
                        changeGroup.Commit();
                        grid.UpdateLayout();
                        break;
                    }
                }
            }
            InvalidateVisual();
        }
예제 #46
0
        private void ExtractItems()
        {
            foreach (Rect2D rect in _rects)
            {
                #region MobileSaver
                Rectangle2D realrectangle = new Rectangle2D(rect.TopX, rect.TopY, rect.Width, rect.Height);

                foreach (Mobile m in _map.GetMobilesInBounds(realrectangle))
                {
                    if (m != null && m is BaseCreature)
                    {
                        int saveflag = MobileSaver.GetSaveFlag(m);

                        if (saveflag > 0)
                        {
                            DesignItem designItem = new DesignItem();
                            designItem.ItemID = (short)0x1;
                            designItem.X      = m.X;
                            designItem.Y      = m.Y;
                            designItem.Z      = m.Z + saveflag;
                            designItem.Hue    = (short)m.Hue;
                        }
                    }
                }
                #endregion

                for (int x = 0; x <= rect.Width; ++x)
                {
                    for (int y = 0; y <= rect.Height; ++y)
                    {
                        int tileX = rect.TopX + x;
                        int tileY = rect.TopY + y;

                        Sector sector = _map.GetSector(tileX, tileY);

                        if (_args.NonStatic || _args.Static)
                        {
                            for (int i = 0; i < sector.Items.Count; ++i)
                            {
                                Item item = (Item)sector.Items[i];

                                if (!item.Visible)
                                {
                                    continue;
                                }
                                else if ((!_args.NonStatic) && !(item is Static))
                                {
                                    continue;
                                }
                                else if ((!_args.Static) && (item is Static))
                                {
                                    continue;
                                }
                                else if (_args.MinZSet && item.Z < _args.MinZ)
                                {
                                    continue;
                                }
                                else if (_args.MaxZSet && item.Z > _args.MaxZ)
                                {
                                    continue;
                                }

                                int hue = 0;

                                if (_args.ExtractHues)
                                {
                                    hue = item.Hue;
                                }

                                if (item.X == tileX && item.Y == tileY && !((item is BaseMulti) || (item is HouseSign)))
                                {
                                    DesignItem designItem = new DesignItem();
                                    designItem.ItemID = (short)item.ItemID;
                                    designItem.X      = item.X;
                                    designItem.Y      = item.Y;
                                    designItem.Z      = item.Z;
                                    designItem.Hue    = (short)hue;

                                    _items.Add(designItem);
                                }

                                // extract multi
                                if (item is HouseFoundation)
                                {
                                    HouseFoundation house = (HouseFoundation)item;

                                    if (_extractedMultiIds.IndexOf(house.Serial.Value) == -1)
                                    {
                                        ExtractCustomMulti(house);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            ExtractResponse response = new ExtractResponse(_items);

            if (_args.Frozen)
            {
                response.Rects = _rects;
                response.Map   = _map.Name;
            }

            // send response back to the UOAR tool
            SendResponse(response);
        }
예제 #47
0
        public InPlaceEditor(DesignItem designItem)
        {
            this.designItem = designItem;

            this.InputBindings.Add(new KeyBinding(EditingCommands.ToggleBold, Key.B, ModifierKeys.Control));
        }
예제 #48
0
 public void ScrollIntoView(DesignItem designItem)
 {
     enableBringIntoView = true;
     LogicalTreeHelper.BringIntoView(designItem.View);
     enableBringIntoView = false;
 }
        public static Tuple <DesignItem, Rect> WrapItemsNewContainer(IEnumerable <DesignItem> items, Type containerType, bool doInsert = true)
        {
            var collection = items;

            var _context = collection.First().Context as XamlDesignContext;

            var container = collection.First().Parent;

            if (collection.Any(x => x.Parent != container))
            {
                return(null);
            }

            //Change Code to use the Placment Operation!
            var placement = container.Extensions.OfType <IPlacementBehavior>().FirstOrDefault();

            if (placement == null)
            {
                return(null);
            }

            var operation = PlacementOperation.Start(items.ToList(), PlacementType.Move);

            var        newInstance = _context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(containerType, null);
            DesignItem newPanel    = _context.Services.Component.RegisterComponentForDesigner(newInstance);

            List <ItemPos> itemList = new List <ItemPos>();

            foreach (var item in collection)
            {
                itemList.Add(GetItemPos(operation, item));
                //var pos = placement.GetPosition(null, item);
                if (container.Component is Canvas)
                {
                    item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset();
                    item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
                    item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset();
                    item.Properties.GetAttachedProperty(Canvas.BottomProperty).Reset();
                }
                else if (container.Component is Grid)
                {
                    item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).Reset();
                    item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).Reset();
                    item.Properties.GetProperty(FrameworkElement.MarginProperty).Reset();
                }

                var parCol = item.ParentProperty.CollectionElements;
                parCol.Remove(item);
            }

            var xmin = itemList.Min(x => x.Xmin);
            var xmax = itemList.Max(x => x.Xmax);
            var ymin = itemList.Min(x => x.Ymin);
            var ymax = itemList.Max(x => x.Ymax);

            foreach (var item in itemList)
            {
                if (newPanel.Component is Canvas)
                {
                    if (item.HorizontalAlignment == HorizontalAlignment.Right)
                    {
                        item.DesignItem.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(xmax - item.Xmax);
                    }
                    else
                    {
                        item.DesignItem.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(item.Xmin - xmin);
                    }

                    if (item.VerticalAlignment == VerticalAlignment.Bottom)
                    {
                        item.DesignItem.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(ymax - item.Ymax);
                    }
                    else
                    {
                        item.DesignItem.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(item.Ymin - ymin);
                    }

                    newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
                }
                else if (newPanel.Component is Grid)
                {
                    Thickness thickness = new Thickness(0);
                    if (item.HorizontalAlignment == HorizontalAlignment.Right)
                    {
                        item.DesignItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Right);
                        thickness.Right = xmax - item.Xmax;
                    }
                    else
                    {
                        item.DesignItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Left);
                        thickness.Left = item.Xmin - xmin;
                    }

                    if (item.VerticalAlignment == VerticalAlignment.Bottom)
                    {
                        item.DesignItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Bottom);
                        thickness.Bottom = ymax - item.Ymax;
                    }
                    else
                    {
                        item.DesignItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Top);
                        thickness.Top = item.Ymin - ymin;
                    }

                    item.DesignItem.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(thickness);

                    newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
                }
                else if (newPanel.Component is Viewbox)
                {
                    newPanel.ContentProperty.SetValue(item.DesignItem);
                }
            }

            if (doInsert)
            {
                PlacementOperation operation2 = PlacementOperation.TryStartInsertNewComponents(
                    container,
                    new[] { newPanel },
                    new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() },
                    PlacementType.AddItem
                    );

                operation2.Commit();

                _context.Services.Selection.SetSelectedComponents(new[] { newPanel });
            }

            operation.Commit();

            return(new Tuple <DesignItem, Rect>(newPanel, new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round()));
        }
        void targetObject_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var dcontext = ((FrameworkElement)sender).DataContext;

            DesignContext    context    = null;
            FrameworkElement fe         = null;
            DesignItem       designItem = null;

            if (dcontext is DesignItem)
            {
                designItem = (DesignItem)dcontext;
                context    = designItem.Context;
                fe         = designItem.View as FrameworkElement;
            }
            else if (dcontext is FrameworkElement)
            {
                fe = ((FrameworkElement)dcontext);
                var srv = fe.TryFindParent <DesignSurface>();
                if (srv != null)
                {
                    context    = srv.DesignContext;
                    designItem = context.Services.Component.GetDesignItem(fe);
                }
            }

            if (context != null)
            {
                if (_property != null)
                {
                    _binding        = new Binding();
                    _binding.Path   = new PropertyPath(_property);
                    _binding.Source = fe;
                    _binding.UpdateSourceTrigger = UpdateSourceTrigger;

                    if (designItem.Services.Selection.SelectedItems.Count > 1 && UpdateSourceTriggerMultipleSelected != null)
                    {
                        _binding.UpdateSourceTrigger = UpdateSourceTriggerMultipleSelected.Value;
                    }

                    _binding.Mode = BindingMode.TwoWay;
                    _binding.ConverterParameter = ConverterParameter;

                    _converter = new DesignItemSetConverter(designItem, _property, SingleItemProperty, AskWhenMultipleItemsSelected,
                                                            Converter);
                    _binding.Converter = _converter;

                    _targetObject.SetBinding(_targetProperty, _binding);
                }
                else
                {
                    _binding        = new Binding(_propertyName);
                    _binding.Source = fe;
                    _binding.UpdateSourceTrigger = UpdateSourceTrigger;

                    if (designItem.Services.Selection.SelectedItems.Count > 1 && UpdateSourceTriggerMultipleSelected != null)
                    {
                        _binding.UpdateSourceTrigger = UpdateSourceTriggerMultipleSelected.Value;
                    }

                    _binding.Mode = BindingMode.TwoWay;
                    _binding.ConverterParameter = ConverterParameter;

                    _converter = new DesignItemSetConverter(designItem, _propertyName, SingleItemProperty, AskWhenMultipleItemsSelected,
                                                            Converter);
                    _binding.Converter = _converter;

                    _targetObject.SetBinding(_targetProperty, _binding);
                }
            }
            else
            {
                _targetObject.ClearValue(_targetProperty);
            }
        }
 public static bool CanSelectComponent(DesignItem item)
 {
     return(item.View != null);
 }
예제 #52
0
        public DefaultCommandsContextMenu(DesignItem designItem)
        {
            this.designItem = designItem;

            SpecialInitializeComponent();
        }
 public override Extension CreateExtension(Type extensionType, DesignItem extendedItem)
 {
     throw new NotImplementedException();
 }
        public static bool AddItemWithCustomSizePosition(DesignItem container, Type createdItem, Size size, Point position)
        {
            CreateComponentTool cct = new CreateComponentTool(createdItem);

            return(AddItemWithCustomSize(container, cct.CreateItem(container.Context), position, size));
        }
예제 #55
0
 /// <summary>
 /// Gets if the item is the primary selection.
 /// </summary>
 public override bool ShouldApplyExtensions(DesignItem extendedItem)
 {
     return(primarySelectionParent == extendedItem);
 }
예제 #56
0
 /// <summary>
 /// Gets if the item is selected.
 /// </summary>
 public override bool ShouldApplyExtensions(DesignItem extendedItem)
 {
     return(Services.Selection.IsComponentSelected(extendedItem));
 }
        public static bool AddItemWithDefaultSize(DesignItem container, Type createdItem, Size size)
        {
            CreateComponentTool cct = new CreateComponentTool(createdItem);

            return(AddItemWithCustomSize(container, cct.CreateItem(container.Context), new Point(0, 0), size));
        }
예제 #58
0
 public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, MouseEventArgs e,
                           Action <DesignItem> drawItemCallback)
 {
     throw new NotImplementedException();
 }
 internal static bool AddItemWithDefaultSize(DesignItem container, DesignItem createdItem, Point position)
 {
     return(AddItemWithCustomSize(container, createdItem, position, ModelTools.GetDefaultSize(createdItem)));
 }
예제 #60
0
        private void OnAddItemClicked(object sender, RoutedEventArgs e)
        {
            DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance(_type));

            _itemProperty.CollectionElements.Add(newItem);
        }