diff --git a/src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs b/src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs
index 8dbeeb06c4..3ee4eb23aa 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs
@@ -38,7 +38,9 @@ namespace StandaloneDesigner
AddTool(typeof(Button));
AddTool(typeof(TextBox));
AddTool(typeof(CheckBox));
-
+ AddTool(typeof(Label));
+ AddTool(typeof(Canvas));
+ AddTool(typeof(Grid));
toolService.CurrentToolChanged += OnCurrentToolChanged;
OnCurrentToolChanged(null, null);
}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
index c93533c0b5..3b2a7845f5 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
@@ -59,10 +59,10 @@ namespace ICSharpCode.WpfDesign.Designer
///
/// Performs a custom hit testing lookup for the specified mouse event args.
///
- public DesignPanelHitTestResult HitTest(MouseEventArgs e, bool testAdorners, bool testDesignSurface)
+ public DesignPanelHitTestResult HitTest(Point mousePosition, bool testAdorners, bool testDesignSurface)
{
DesignPanelHitTestResult result = DesignPanelHitTestResult.NoHit;
- HitTest(e, testAdorners, testDesignSurface,
+ HitTest(mousePosition, testAdorners, testDesignSurface,
delegate(DesignPanelHitTestResult r) {
result = r;
return false;
@@ -74,9 +74,8 @@ namespace ICSharpCode.WpfDesign.Designer
/// Performs a hit test on the design surface, raising for each match.
/// Hit testing continues while the callback returns true.
///
- public void HitTest(MouseEventArgs e, bool testAdorners, bool testDesignSurface, Predicate callback)
+ public void HitTest(Point mousePosition, bool testAdorners, bool testDesignSurface, Predicate callback)
{
- Point mousePosition = e.GetPosition(this);
if (mousePosition.X < 0 || mousePosition.Y < 0 || mousePosition.X > this.RenderSize.Width || mousePosition.Y > this.RenderSize.Height) {
return;
}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasChildResizeSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
similarity index 85%
rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasChildResizeSupport.cs
rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
index 6432ad59a8..8f1d92d98e 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasChildResizeSupport.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
@@ -41,7 +41,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public Rect GetPosition(PlacementOperation operation, DesignItem childItem)
{
UIElement child = childItem.View;
- return new Rect(GetLeft(child), GetTop(child), GetWidth(child), GetHeight(child));
+ return new Rect(GetLeft(child), GetTop(child), ModelTools.GetWidth(child), ModelTools.GetHeight(child));
}
static double GetLeft(UIElement element)
@@ -62,24 +62,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
return v;
}
- static double GetWidth(UIElement element)
- {
- double v = (double)element.GetValue(FrameworkElement.WidthProperty);
- if (double.IsNaN(v))
- return element.RenderSize.Width;
- else
- return v;
- }
-
- static double GetHeight(UIElement element)
- {
- double v = (double)element.GetValue(FrameworkElement.HeightProperty);
- if (double.IsNaN(v))
- return element.RenderSize.Height;
- else
- return v;
- }
-
///
public void SetPosition(PlacementInformation info)
{
@@ -91,10 +73,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (newPosition.Top != GetTop(child)) {
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
}
- if (newPosition.Width != GetWidth(child)) {
+ if (newPosition.Width != ModelTools.GetWidth(child)) {
info.Item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newPosition.Right - newPosition.Left);
}
- if (newPosition.Height != GetHeight(child)) {
+ if (newPosition.Height != ModelTools.GetHeight(child)) {
info.Item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newPosition.Bottom - newPosition.Top);
}
}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs
index 5394c412c5..baeeeae731 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs
@@ -49,25 +49,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public Rect GetPosition(PlacementOperation operation, DesignItem childItem)
{
UIElement child = childItem.View;
- return new Rect(0, 0, GetWidth(child), GetHeight(child));
- }
-
- static double GetWidth(UIElement element)
- {
- double v = (double)element.GetValue(FrameworkElement.WidthProperty);
- if (double.IsNaN(v))
- return element.RenderSize.Width;
- else
- return v;
- }
-
- static double GetHeight(UIElement element)
- {
- double v = (double)element.GetValue(FrameworkElement.HeightProperty);
- if (double.IsNaN(v))
- return element.RenderSize.Height;
- else
- return v;
+ return new Rect(0, 0, ModelTools.GetWidth(child), ModelTools.GetHeight(child));
}
///
@@ -75,10 +57,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
UIElement element = info.Item.View;
Rect newPosition = info.Bounds;
- if (newPosition.Right != GetWidth(element)) {
+ if (newPosition.Right != ModelTools.GetWidth(element)) {
info.Item.Properties[FrameworkElement.WidthProperty].SetValue(newPosition.Right);
}
- if (newPosition.Bottom != GetHeight(element)) {
+ if (newPosition.Bottom != ModelTools.GetHeight(element)) {
info.Item.Properties[FrameworkElement.HeightProperty].SetValue(newPosition.Bottom);
}
}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
index 5644f8efec..b392c88214 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
@@ -6,6 +6,7 @@
//
using System;
+using System.Windows;
namespace ICSharpCode.WpfDesign.Designer
{
@@ -41,5 +42,28 @@ namespace ICSharpCode.WpfDesign.Designer
}
return 0;
}
+
+ internal static Size GetDefaultSize(DesignItem createdItem)
+ {
+ return new Size(GetWidth(createdItem.View), GetHeight(createdItem.View));
+ }
+
+ internal static double GetWidth(UIElement element)
+ {
+ double v = (double)element.GetValue(FrameworkElement.WidthProperty);
+ if (double.IsNaN(v))
+ return element.RenderSize.Width;
+ else
+ return v;
+ }
+
+ internal static double GetHeight(UIElement element)
+ {
+ double v = (double)element.GetValue(FrameworkElement.HeightProperty);
+ if (double.IsNaN(v))
+ return element.RenderSize.Height;
+ else
+ return v;
+ }
}
}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
index 4232da0fad..18035c8d93 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
@@ -15,7 +15,7 @@ using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.Services
{
///
- /// A tool that creates a component when used.
+ /// A tool that creates a component.
///
public class CreateComponentTool : ITool
{
@@ -83,7 +83,36 @@ namespace ICSharpCode.WpfDesign.Designer.Services
if (e.Data.GetData(typeof(CreateComponentTool)) != this)
return;
e.Handled = true;
- MessageBox.Show("Not implemented");
+
+ IDesignPanel designPanel = (IDesignPanel)sender;
+ DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true);
+ if (result.ModelHit != null) {
+ designPanel.Focus();
+
+ DesignItem createdItem = CreateItem(designPanel.Context);
+ AddItemWithDefaultSize(result.ModelHit, createdItem, e.GetPosition(result.ModelHit.View));
+ }
+
+ if (designPanel.Context.Services.Tool.CurrentTool is CreateComponentTool) {
+ designPanel.Context.Services.Tool.CurrentTool = designPanel.Context.Services.Tool.PointerTool;
+ }
+ }
+
+ internal static bool AddItemWithDefaultSize(DesignItem container, DesignItem createdItem, Point position)
+ {
+ PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents(
+ container,
+ new DesignItem[] { createdItem },
+ new Rect[] { new Rect(position, ModelTools.GetDefaultSize(createdItem)) },
+ PlacementType.Move
+ );
+ if (operation != null) {
+ container.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
+ operation.Commit();
+ return true;
+ } else {
+ return false;
+ }
}
void OnMouseDown(object sender, MouseButtonEventArgs e)
@@ -91,7 +120,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) {
e.Handled = true;
IDesignPanel designPanel = (IDesignPanel)sender;
- DesignPanelHitTestResult result = designPanel.HitTest(e, false, true);
+ DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true);
if (result.ModelHit != null) {
IPlacementBehavior behavior = result.ModelHit.GetBehavior();
if (behavior != null) {
@@ -165,7 +194,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
operation = null;
}
} else {
-
+ CreateComponentTool.AddItemWithDefaultSize(container, createdItem, e.GetPosition(positionRelativeTo));
}
base.OnMouseUp(sender, e);
}
@@ -176,6 +205,9 @@ namespace ICSharpCode.WpfDesign.Designer.Services
operation.Abort();
operation = null;
}
+ if (services.Tool.CurrentTool is CreateComponentTool) {
+ services.Tool.CurrentTool = services.Tool.PointerTool;
+ }
base.OnStopped();
}
}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs
index 4276d56c70..244faac7c8 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs
@@ -56,12 +56,11 @@ namespace ICSharpCode.WpfDesign.Designer.Services
if (operation != null) {
UIElement currentContainer = operation.CurrentContainer.View;
Point p = e.GetPosition(currentContainer);
- if (p.X < 0 || p.Y < 0 || p.X > currentContainer.RenderSize.Width || p.Y > currentContainer.RenderSize.Height) {
- // outside the bounds of the current container
- if (operation.CurrentContainerBehavior.CanLeaveContainer(operation)) {
- if (ChangeContainerIfPossible(e)) {
- return;
- }
+
+ // try to switch the container
+ if (operation.CurrentContainerBehavior.CanLeaveContainer(operation)) {
+ if (ChangeContainerIfPossible(e)) {
+ return;
}
}
@@ -82,7 +81,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
DesignPanelHitTestResult result = DesignPanelHitTestResult.NoHit;
ISelectionService selection = services.Selection;
designPanel.HitTest(
- e, false, true,
+ e.GetPosition(designPanel), false, true,
delegate(DesignPanelHitTestResult r) {
if (r.ModelHit == null)
return true; // continue hit testing
@@ -98,6 +97,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
{
DesignPanelHitTestResult result = HitTestUnselectedModel(e);
if (result.ModelHit == null) return false;
+ if (result.ModelHit == operation.CurrentContainer) return false;
// check that we don't move an item into itself:
DesignItem tmp = result.ModelHit;
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/PointerTool.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/PointerTool.cs
index acc13d6fac..618d319d0b 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/PointerTool.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/PointerTool.cs
@@ -33,7 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) {
e.Handled = true;
IDesignPanel designPanel = (IDesignPanel)sender;
- DesignPanelHitTestResult result = designPanel.HitTest(e, false, true);
+ DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true);
if (result.ModelHit != null) {
IHandlePointerToolMouseDown b = result.ModelHit.GetBehavior();
if (b != null) {
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
index e4ba22dc43..967a7c2102 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
@@ -72,7 +72,7 @@
-
+
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/PlacementTests.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/PlacementTests.cs
new file mode 100644
index 0000000000..f5d966c6cd
--- /dev/null
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/PlacementTests.cs
@@ -0,0 +1,49 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+using System.Windows;
+using NUnit.Framework;
+using ICSharpCode.WpfDesign;
+using ICSharpCode.WpfDesign.Designer;
+using ICSharpCode.WpfDesign.Designer.Extensions;
+
+namespace ICSharpCode.WpfDesign.Tests.Designer
+{
+ [TestFixture]
+ public class PlacementTests : ModelTestHelper
+ {
+ void Move(Vector v, params DesignItem[] items)
+ {
+ PlacementOperation operation = PlacementOperation.Start(items, PlacementType.Move);
+ foreach (PlacementInformation info in operation.PlacedItems) {
+ info.Bounds = new Rect(info.OriginalBounds.Left + v.X,
+ info.OriginalBounds.Top + v.Y,
+ info.OriginalBounds.Width,
+ info.OriginalBounds.Height);
+ operation.CurrentContainerBehavior.SetPosition(info);
+ }
+ operation.Commit();
+ }
+
+ [Test]
+ public void MoveFixedWidthButton()
+ {
+ DesignItem button = CreateCanvasContext("");
+ Move(new Vector(50, 25), button);
+ AssertCanvasDesignerOutput(@"", button.Context);
+ }
+
+ [Test]
+ public void MoveAutoWidthButton()
+ {
+ DesignItem button = CreateCanvasContext("");
+ Move(new Vector(50, 25), button);
+ AssertCanvasDesignerOutput(@"", button.Context);
+ }
+ }
+}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj
index 10c625c737..04d6f0d601 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj
@@ -51,6 +51,7 @@
+
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignPanelHitTestResult.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignPanelHitTestResult.cs
index 8f937e7efa..1e0b9ca893 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignPanelHitTestResult.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignPanelHitTestResult.cs
@@ -6,14 +6,14 @@
//
using System;
-using System.Windows.Input;
+using System.Windows;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
namespace ICSharpCode.WpfDesign
{
///
- /// Describes the result of a call.
+ /// Describes the result of a call.
///
public struct DesignPanelHitTestResult : IEquatable
{
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs
index e091c13708..26c9734af2 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs
@@ -88,13 +88,13 @@ namespace ICSharpCode.WpfDesign
///
/// Performs a hit test on the design surface.
///
- DesignPanelHitTestResult HitTest(MouseEventArgs e, bool testAdorners, bool testDesignSurface);
+ DesignPanelHitTestResult HitTest(Point mousePosition, bool testAdorners, bool testDesignSurface);
///
/// Performs a hit test on the design surface, raising for each match.
/// Hit testing continues while the callback returns true.
///
- void HitTest(MouseEventArgs e, bool testAdorners, bool testDesignSurface, Predicate callback);
+ void HitTest(Point mousePosition, bool testAdorners, bool testDesignSurface, Predicate callback);
// The following members were missing in , but
// are supported on the DesignPanel: