Browse Source

Support drag'n'drop from toolbox to designer surface.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2439 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
2010223356
  1. 4
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs
  2. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  3. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
  4. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs
  5. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  6. 40
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
  7. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs
  8. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/PointerTool.cs
  9. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  10. 49
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/PlacementTests.cs
  11. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj
  12. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignPanelHitTestResult.cs
  13. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs

4
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs

@ -38,7 +38,9 @@ namespace StandaloneDesigner @@ -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);
}

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

@ -59,10 +59,10 @@ namespace ICSharpCode.WpfDesign.Designer @@ -59,10 +59,10 @@ namespace ICSharpCode.WpfDesign.Designer
/// <summary>
/// Performs a custom hit testing lookup for the specified mouse event args.
/// </summary>
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 @@ -74,9 +74,8 @@ namespace ICSharpCode.WpfDesign.Designer
/// Performs a hit test on the design surface, raising <paramref name="callback"/> for each match.
/// Hit testing continues while the callback returns true.
/// </summary>
public void HitTest(MouseEventArgs e, bool testAdorners, bool testDesignSurface, Predicate<DesignPanelHitTestResult> callback)
public void HitTest(Point mousePosition, bool testAdorners, bool testDesignSurface, Predicate<DesignPanelHitTestResult> callback)
{
Point mousePosition = e.GetPosition(this);
if (mousePosition.X < 0 || mousePosition.Y < 0 || mousePosition.X > this.RenderSize.Width || mousePosition.Y > this.RenderSize.Height) {
return;
}

24
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasChildResizeSupport.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -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 @@ -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;
}
/// <inherits/>
public void SetPosition(PlacementInformation info)
{
@ -91,10 +73,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -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);
}
}

24
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs

@ -49,25 +49,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -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));
}
/// <inherits/>
@ -75,10 +57,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -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);
}
}

24
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.Windows;
namespace ICSharpCode.WpfDesign.Designer
{
@ -41,5 +42,28 @@ 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;
}
}
}

40
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs

@ -15,7 +15,7 @@ using ICSharpCode.WpfDesign.Designer.Controls; @@ -15,7 +15,7 @@ using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.Services
{
/// <summary>
/// A tool that creates a component when used.
/// A tool that creates a component.
/// </summary>
public class CreateComponentTool : ITool
{
@ -83,7 +83,36 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -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 @@ -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<IPlacementBehavior>();
if (behavior != null) {
@ -165,7 +194,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -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 @@ -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();
}
}

14
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs

@ -56,12 +56,11 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -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 @@ -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 @@ -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;

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/PointerTool.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -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<IHandlePointerToolMouseDown>();
if (b != null) {

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -72,7 +72,7 @@ @@ -72,7 +72,7 @@
<Compile Include="Controls\WindowClone.cs" />
<Compile Include="DesignPanel.cs" />
<Compile Include="ModelTools.cs" />
<Compile Include="Extensions\CanvasChildResizeSupport.cs" />
<Compile Include="Extensions\CanvasPlacementSupport.cs" />
<Compile Include="Extensions\PanelInstanceFactory.cs" />
<Compile Include="Extensions\PanelSelectionHandler.cs" />
<Compile Include="Extensions\SelectedElementRectangleExtension.cs" />

49
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/PlacementTests.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
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("<Button Width='100' Height='200'/>");
Move(new Vector(50, 25), button);
AssertCanvasDesignerOutput(@"<Button Width=""100"" Height=""200"" Canvas.Left=""50"" Canvas.Top=""25"" />", button.Context);
}
[Test]
public void MoveAutoWidthButton()
{
DesignItem button = CreateCanvasContext("<Button/>");
Move(new Vector(50, 25), button);
AssertCanvasDesignerOutput(@"<Button Canvas.Left=""50"" Canvas.Top=""25"" />", button.Context);
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

@ -51,6 +51,7 @@ @@ -51,6 +51,7 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Designer\ModelTestHelper.cs" />
<Compile Include="Designer\ModelTests.cs" />
<Compile Include="Designer\PlacementTests.cs" />
<Compile Include="XamlDom\ExampleClass.cs" />
<Compile Include="XamlDom\ExampleClassContainer.cs" />
<Compile Include="XamlDom\ExampleService.cs" />

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignPanelHitTestResult.cs

@ -6,14 +6,14 @@ @@ -6,14 +6,14 @@
// </file>
using System;
using System.Windows.Input;
using System.Windows;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
namespace ICSharpCode.WpfDesign
{
/// <summary>
/// Describes the result of a <see cref="IDesignPanel.HitTest(MouseEventArgs, bool, bool)"/> call.
/// Describes the result of a <see cref="IDesignPanel.HitTest(Point, bool, bool)"/> call.
/// </summary>
public struct DesignPanelHitTestResult : IEquatable<DesignPanelHitTestResult>
{

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs

@ -88,13 +88,13 @@ namespace ICSharpCode.WpfDesign @@ -88,13 +88,13 @@ namespace ICSharpCode.WpfDesign
/// <summary>
/// Performs a hit test on the design surface.
/// </summary>
DesignPanelHitTestResult HitTest(MouseEventArgs e, bool testAdorners, bool testDesignSurface);
DesignPanelHitTestResult HitTest(Point mousePosition, bool testAdorners, bool testDesignSurface);
/// <summary>
/// Performs a hit test on the design surface, raising <paramref name="callback"/> for each match.
/// Hit testing continues while the callback returns true.
/// </summary>
void HitTest(MouseEventArgs e, bool testAdorners, bool testDesignSurface, Predicate<DesignPanelHitTestResult> callback);
void HitTest(Point mousePosition, bool testAdorners, bool testDesignSurface, Predicate<DesignPanelHitTestResult> callback);
// The following members were missing in <see cref="IInputElement"/>, but
// are supported on the DesignPanel:

Loading…
Cancel
Save