Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit f88ae80

Browse files
Merge pull request #692 from jogibear9988/master
Multiple fixes for WpfDesigner
2 parents 1006dfc + 3e1bd35 commit f88ae80

24 files changed

Lines changed: 551 additions & 52 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using ICSharpCode.WpfDesign.UIExtensions;
20+
using System.Windows;
21+
using System.Windows.Controls;
22+
using System.Windows.Controls.Primitives;
23+
24+
namespace ICSharpCode.WpfDesign.Designer.Controls
25+
{
26+
public class UserControlPointsObjectThumb : DesignerThumb
27+
{
28+
public DependencyProperty DependencyProperty { get; set; }
29+
}
30+
}

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ public DesignPanel()
219219

220220
#region Properties
221221

222+
public DesignSurface DesignSurface { get; internal set; }
223+
222224
//Set custom HitTestFilterCallbak
223225
public HitTestFilterCallback CustomHitTestFilterBehavior { get; set; }
224226

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ public DesignSurface()
7676
this.AddCommandHandler(Commands.AlignCenterCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.HorizontalMiddle), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
7777
this.AddCommandHandler(Commands.AlignRightCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.Right), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
7878

79-
//Todo
80-
//this.AddCommandHandler(Commands.RotateLeftCommand, () => , () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
81-
//this.AddCommandHandler(Commands.RotateRightCommand, () => , () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
79+
this.AddCommandHandler(Commands.RotateLeftCommand, () => ModelTools.ApplyTransform(this.DesignContext.Services.Selection.PrimarySelection, new RotateTransform(-90)), () => this.DesignContext.Services.Selection.PrimarySelection != null);
80+
this.AddCommandHandler(Commands.RotateRightCommand, () => ModelTools.ApplyTransform(this.DesignContext.Services.Selection.PrimarySelection, new RotateTransform(90)), () => this.DesignContext.Services.Selection.PrimarySelection != null);
8281

8382
_sceneContainer = new Border() { AllowDrop = false, UseLayoutRounding = true };
8483
_sceneContainer.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal);
8584

86-
_designPanel = new DesignPanel() {Child = _sceneContainer};
85+
_designPanel = new DesignPanel() {Child = _sceneContainer, DesignSurface = this};
8786
}
8887

8988
internal DesignPanel _designPanel;

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ public override void EnterContainer(PlacementOperation operation)
147147
info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset();
148148
info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].Reset();
149149
info.Item.Properties[FrameworkElement.MarginProperty].Reset();
150+
151+
if (operation.Type == PlacementType.PasteItem) {
152+
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(((double)info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance) + PlacementOperation.PasteOffset);
153+
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(((double)info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance) + PlacementOperation.PasteOffset);
154+
}
150155
}
151156
}
152157

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ public virtual void EndPlacement(PlacementOperation operation)
6363
{
6464
InfoTextEnterArea.Stop(ref infoTextEnterArea);
6565

66-
this.ExtendedItem.Services.Selection.SetSelectedComponents(null);
67-
this.ExtendedItem.Services.Selection.SetSelectedComponents(operation.PlacedItems.Select(x => x.Item).ToList());
66+
if (operation.Type != PlacementType.Delete)
67+
{
68+
this.ExtendedItem.Services.Selection.SetSelectedComponents(null);
69+
this.ExtendedItem.Services.Selection.SetSelectedComponents(operation.PlacedItems.Select(x => x.Item).ToList());
70+
}
6871
}
6972

7073
public virtual Rect GetPosition(PlacementOperation operation, DesignItem item)

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,26 @@ public override void EnterContainer(PlacementOperation operation)
162162
enteredIntoNewContainer=true;
163163
grid.UpdateLayout();
164164
base.EnterContainer(operation);
165+
166+
if (operation.Type == PlacementType.PasteItem) {
167+
foreach (PlacementInformation info in operation.PlacedItems) {
168+
var margin = (Thickness)info.Item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
169+
var horizontalAlignment = (HorizontalAlignment)info.Item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance;
170+
var verticalAlignment = (VerticalAlignment)info.Item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance;
171+
172+
if (horizontalAlignment == HorizontalAlignment.Left)
173+
margin.Left += PlacementOperation.PasteOffset;
174+
else if (horizontalAlignment == HorizontalAlignment.Right)
175+
margin.Right -= PlacementOperation.PasteOffset;
176+
177+
if (verticalAlignment == VerticalAlignment.Top)
178+
margin.Top += PlacementOperation.PasteOffset;
179+
else if (verticalAlignment == VerticalAlignment.Bottom)
180+
margin.Bottom -= PlacementOperation.PasteOffset;
181+
182+
info.Item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
183+
}
184+
}
165185
}
166186

167187
GrayOutDesignerExceptActiveArea grayOut;

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected void UpdateAdornerVisibility()
107107
/// <param name="alignment"></param>
108108
/// <param name="index">if using a polygon or multipoint adorner this is the index of the point in the Points array</param>
109109
/// <returns></returns>
110-
protected PointTrackerPlacementSupport Place(ref DesignerThumb designerThumb, PlacementAlignment alignment, int index = -1)
110+
protected PointTrackerPlacementSupport Place(DesignerThumb designerThumb, PlacementAlignment alignment, int index = -1)
111111
{
112112
PointTrackerPlacementSupport placement = new PointTrackerPlacementSupport(ExtendedItem.View as Shape, alignment, index);
113113
return placement;

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Bounds
5656
protected DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor)
5757
{
5858
DesignerThumb designerThumb = new DesignerThumb { Alignment = alignment, Cursor = cursor, IsPrimarySelection = true};
59-
AdornerPanel.SetPlacement(designerThumb, Place(ref designerThumb, alignment));
59+
AdornerPanel.SetPlacement(designerThumb, Place(designerThumb, alignment));
6060

6161
adornerPanel.Children.Add(designerThumb);
6262

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class PolyLineHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp
4949
protected DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index)
5050
{
5151
DesignerThumb designerThumb = new MultiPointThumb { Index = index, Alignment = alignment, Cursor = cursor, IsPrimarySelection = true };
52-
AdornerPlacement ap = Place(ref designerThumb, alignment, index);
52+
AdornerPlacement ap = Place(designerThumb, alignment, index);
5353
(designerThumb as MultiPointThumb).AdornerPlacement = ap;
5454

5555
AdornerPanel.SetPlacement(designerThumb, ap);

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using System.Diagnostics;
21+
using System.Linq;
2122
using System.Windows;
2223
using System.Windows.Controls.Primitives;
2324
using System.Windows.Input;
@@ -116,29 +117,7 @@ private void drag_Rotate_Changed(DragListener drag)
116117
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
117118
destAngle = ((int)destAngle / 15) * 15;
118119

119-
if (destAngle == 0)
120-
{
121-
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Reset();
122-
rtTransform = null;
123-
rotateTransform = null;
124-
}
125-
else
126-
{
127-
if ((rtTransform == null) || !(rtTransform.Component is RotateTransform))
128-
{
129-
if (!this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).IsSet) {
130-
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5,0.5));
131-
}
132-
133-
if (this.rotateTransform == null)
134-
this.rotateTransform = new RotateTransform(0);
135-
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(rotateTransform);
136-
rtTransform = this.ExtendedItem.Properties[FrameworkElement.RenderTransformProperty].Value;
137-
}
138-
rtTransform.Properties["Angle"].SetValue(destAngle);
139-
140-
((DesignPanel) this.ExtendedItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true);
141-
}
120+
ModelTools.ApplyTransform(this.ExtendedItem, new RotateTransform() { Angle = destAngle });
142121
}
143122

144123
void drag_Rotate_Completed(ICSharpCode.WpfDesign.Designer.Controls.DragListener drag)
@@ -161,6 +140,13 @@ protected override void OnInitialized()
161140

162141
var designerItem = this.ExtendedItem.Component as FrameworkElement;
163142
this.rotateTransform = designerItem.RenderTransform as RotateTransform;
143+
if (this.rotateTransform == null) {
144+
var tg = designerItem.RenderTransform as TransformGroup;
145+
if (tg != null) {
146+
this.rotateTransform = tg.Children.FirstOrDefault(x => x is RotateTransform) as RotateTransform;
147+
}
148+
}
149+
164150
}
165151

166152
void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)

0 commit comments

Comments
 (0)