From fb3be549138dd3f0b4bbd4ea23148bbb5700e383 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 27 Aug 2009 09:47:34 +0000 Subject: [PATCH] DragMoveMouseGesture bugfix: use coordinates relative to design panel because MoveLogic expects those. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4774 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Controls/WindowClone.cs | 20 ++-- .../Extensions/DefaultPlacementBehavior.cs | 2 + .../Project/Services/DragMoveMouseGesture.cs | 14 +-- .../Project/Services/MoveLogic.cs | 92 +++++++++---------- .../Project/WpfDesign.Designer.csproj | 1 - .../Project/Xaml/XamlDesignContext.cs | 4 +- .../WpfDesign/Project/ServiceContainer.cs | 20 ++-- .../Project/ServiceRequiredException.cs | 62 +++++++++++++ .../WpfDesign/Project/WpfDesign.csproj | 1 + 9 files changed, 137 insertions(+), 79 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceRequiredException.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs index 13d6b52c4f..520d1e1c44 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs @@ -164,49 +164,45 @@ namespace ICSharpCode.WpfDesign.Designer.Controls set { SetValue(Window.WindowStyleProperty, value); } } - #pragma warning disable 0067 - // disable "event is never used" warning - /// /// This event is never raised. (for compatibility with only). /// - public event EventHandler Activated; + public event EventHandler Activated { add {} remove {} } /// /// This event is never raised. (for compatibility with only). /// - public event EventHandler Closed; + public event EventHandler Closed { add {} remove {} } /// /// This event is never raised. (for compatibility with only). /// - public event EventHandler Closing; + public event EventHandler Closing { add {} remove {} } /// /// This event is never raised. (for compatibility with only). /// - public event EventHandler ContentRendered; + public event EventHandler ContentRendered { add {} remove {} } /// /// This event is never raised. (for compatibility with only). /// - public event EventHandler Deactivated; + public event EventHandler Deactivated { add {} remove {} } /// /// This event is never raised. (for compatibility with only). /// - public event EventHandler LocationChanged; + public event EventHandler LocationChanged { add {} remove {} } /// /// This event is never raised. (for compatibility with only). /// - public event EventHandler SourceInitialized; + public event EventHandler SourceInitialized { add {} remove {} } /// /// This event is never raised. (for compatibility with only). /// - public event EventHandler StateChanged; - #pragma warning restore + public event EventHandler StateChanged { add {} remove {} } } /// diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs index 90edbbaac9..5898c7aeca 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs @@ -39,6 +39,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions 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); } 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 df58dbdf1b..41c2889e57 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs @@ -20,31 +20,27 @@ namespace ICSharpCode.WpfDesign.Designer.Services sealed class DragMoveMouseGesture : ClickOrDragMouseGesture { bool isDoubleClick; - MoveLogic moveLogic; + MoveLogic moveLogic; internal DragMoveMouseGesture(DesignItem clickedOn, bool isDoubleClick) { Debug.Assert(clickedOn != null); this.isDoubleClick = isDoubleClick; - - if (clickedOn.Parent != null) - this.positionRelativeTo = clickedOn.Parent.View; - else - this.positionRelativeTo = clickedOn.View; + this.positionRelativeTo = clickedOn.Services.DesignPanel; - moveLogic = new MoveLogic(clickedOn); + moveLogic = new MoveLogic(clickedOn); } protected override void OnDragStarted(MouseEventArgs e) { - moveLogic.Start(startPoint); + moveLogic.Start(startPoint); } protected override void OnMouseMove(object sender, MouseEventArgs e) { base.OnMouseMove(sender, e); // call OnDragStarted if min. drag distace is reached - moveLogic.Move(e.GetPosition(positionRelativeTo)); + moveLogic.Move(e.GetPosition(positionRelativeTo)); } protected override void OnMouseUp(object sender, MouseButtonEventArgs e) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs index fc82bfbe34..4742ac0d67 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs @@ -6,49 +6,49 @@ using System.Windows; namespace ICSharpCode.WpfDesign.Designer.Services { - class MoveLogic - { - public MoveLogic(DesignItem clickedOn) - { - this.clickedOn = clickedOn; + class MoveLogic + { + public MoveLogic(DesignItem clickedOn) + { + this.clickedOn = clickedOn; selectedItems = clickedOn.Services.Selection.SelectedItems; if (!selectedItems.Contains(clickedOn)) selectedItems = SharedInstances.EmptyDesignItemArray; - } + } - DesignItem clickedOn; - PlacementOperation operation; - ICollection selectedItems; - Point startPoint; + DesignItem clickedOn; + PlacementOperation operation; + ICollection selectedItems; + Point startPoint; - public DesignItem ClickedOn { - get { return clickedOn; } - } + public DesignItem ClickedOn { + get { return clickedOn; } + } - public PlacementOperation Operation { - get { return operation; } - } + public PlacementOperation Operation { + get { return operation; } + } - public IDesignPanel DesignPanel { - get { return clickedOn.Services.DesignPanel; } - } + public IDesignPanel DesignPanel { + get { return clickedOn.Services.DesignPanel; } + } - public void Start(Point p) - { - startPoint = p; - IPlacementBehavior b = PlacementOperation.GetPlacementBehavior(selectedItems); + public void Start(Point p) + { + startPoint = p; + IPlacementBehavior b = PlacementOperation.GetPlacementBehavior(selectedItems); if (b != null && b.CanPlace(selectedItems, PlacementType.Move, PlacementAlignment.TopLeft)) { List sortedSelectedItems = new List(selectedItems); sortedSelectedItems.Sort(ModelTools.ComparePositionInModelFile); selectedItems = sortedSelectedItems; operation = PlacementOperation.Start(selectedItems, PlacementType.Move); } - } + } - public void Move(Point p) - { - if (operation != null) { + public void Move(Point p) + { + if (operation != null) { // try to switch the container if (operation.CurrentContainerBehavior.CanLeaveContainer(operation)) { @@ -60,45 +60,45 @@ namespace ICSharpCode.WpfDesign.Designer.Services info.Bounds = new Rect(info.OriginalBounds.Left + v.X, info.OriginalBounds.Top + v.Y, info.OriginalBounds.Width, - info.OriginalBounds.Height); + info.OriginalBounds.Height); } operation.CurrentContainerBehavior.BeforeSetPosition(operation); foreach (PlacementInformation info in operation.PlacedItems) { operation.CurrentContainerBehavior.SetPosition(info); } } - } + } - public void Stop() - { - if (operation != null) { + public void Stop() + { + if (operation != null) { operation.Commit(); operation = null; } - } + } - public void Cancel() - { - if (operation != null) { + public void Cancel() + { + if (operation != null) { operation.Abort(); operation = null; } - } + } - // Perform hit testing on the design panel and return the first model that is not selected + // Perform hit testing on the design panel and return the first model that is not selected DesignPanelHitTestResult HitTestUnselectedModel(Point p) { DesignPanelHitTestResult result = DesignPanelHitTestResult.NoHit; ISelectionService selection = clickedOn.Services.Selection; DesignPanel.HitTest(p, false, true, delegate(DesignPanelHitTestResult r) { - if (r.ModelHit == null) - return true; // continue hit testing - if (selection.IsComponentSelected(r.ModelHit)) - return true; // continue hit testing - result = r; - return false; // finish hit testing - }); + if (r.ModelHit == null) + return true; // continue hit testing + if (selection.IsComponentSelected(r.ModelHit)) + return true; // continue hit testing + result = r; + return false; // finish hit testing + }); return result; } @@ -136,5 +136,5 @@ namespace ICSharpCode.WpfDesign.Designer.Services } } } - } + } } 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 678fcfb295..b0cd6e4d39 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -169,7 +169,6 @@ PropertyGridView.xaml - ChooseClassDialog.xaml diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs index 96d29de519..b272638c7d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs @@ -116,9 +116,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml if (affectedItems == null) throw new ArgumentNullException("affectedItems"); - UndoService undoService = this.Services.GetService(); - if (undoService == null) - throw new ServiceRequiredException(typeof(UndoService)); + UndoService undoService = this.Services.GetRequiredService(); UndoTransaction g = undoService.StartTransaction(affectedItems); g.Title = changeGroupTitle; return g; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs index 6e758bb2c4..7b2747e0fa 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs @@ -96,11 +96,15 @@ namespace ICSharpCode.WpfDesign } } - T GetServiceOrThrowException() where T : class + /// + /// Gets a required service. + /// Never returns null; instead a ServiceRequiredException is thrown when the service cannot be found. + /// + public T GetRequiredService() where T : class { T service = (T)GetService(typeof(T)); if (service == null) { - throw new DesignerException("Could not find guaranteed service " + typeof(T).FullName); + throw new ServiceRequiredException(typeof(T)); } return service; } @@ -111,7 +115,7 @@ namespace ICSharpCode.WpfDesign /// public ISelectionService Selection { get { - return GetServiceOrThrowException(); + return GetRequiredService(); } } @@ -121,7 +125,7 @@ namespace ICSharpCode.WpfDesign /// public IToolService Tool { get { - return GetServiceOrThrowException(); + return GetRequiredService(); } } @@ -131,7 +135,7 @@ namespace ICSharpCode.WpfDesign /// public IComponentService Component { get { - return GetServiceOrThrowException(); + return GetRequiredService(); } } @@ -141,7 +145,7 @@ namespace ICSharpCode.WpfDesign /// public ViewService View { get { - return GetServiceOrThrowException(); + return GetRequiredService(); } } @@ -151,7 +155,7 @@ namespace ICSharpCode.WpfDesign /// public Extensions.ExtensionManager ExtensionManager { get { - return GetServiceOrThrowException(); + return GetRequiredService(); } } @@ -161,7 +165,7 @@ namespace ICSharpCode.WpfDesign /// public IDesignPanel DesignPanel { get { - return GetServiceOrThrowException(); + return GetRequiredService(); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceRequiredException.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceRequiredException.cs new file mode 100644 index 0000000000..e6b1458072 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceRequiredException.cs @@ -0,0 +1,62 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Runtime.Serialization; + +namespace ICSharpCode.WpfDesign +{ + /// + /// Exception class used for designer failures. + /// + [Serializable] + public class ServiceRequiredException : DesignerException + { + /// + /// Gets the missing sevice. + /// + public Type ServiceType { get; private set; } + + /// + /// Create a new ServiceRequiredException instance. + /// + public ServiceRequiredException(Type serviceType) + : this("Service " + serviceType.FullName + " is required.") + { + this.ServiceType = serviceType; + } + + /// + /// Create a new ServiceRequiredException instance. + /// + public ServiceRequiredException() + { + } + + /// + /// Create a new ServiceRequiredException instance. + /// + public ServiceRequiredException(string message) : base(message) + { + } + + /// + /// Create a new ServiceRequiredException instance. + /// + public ServiceRequiredException(string message, Exception innerException) : base(message, innerException) + { + } + + /// + /// Create a new ServiceRequiredException instance. + /// + protected ServiceRequiredException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj index 441627854f..12333da561 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj @@ -109,6 +109,7 @@ +