This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #521 from gumme/WpfDesignerPartialPanelSelectionHa…
…ndler changed implementation of PanelSelectionHandler so that custom panelsele...
- Loading branch information
Showing
3 changed files
with
116 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...yBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Created by SharpDevelop. | ||
* User: trubra | ||
* Date: 2014-08-06 | ||
* Time: 14:13 | ||
* | ||
* To change this template use Tools | Options | Coding | Edit Standard Headers. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
|
||
using ICSharpCode.WpfDesign.Adorners; | ||
using ICSharpCode.WpfDesign.Designer.Controls; | ||
using ICSharpCode.WpfDesign.Designer.Services; | ||
using ICSharpCode.WpfDesign.Extensions; | ||
|
||
namespace ICSharpCode.WpfDesign.Designer.Extensions | ||
{ | ||
public class PartialPanelSelectionHandler : BehaviorExtension, IHandlePointerToolMouseDown | ||
{ | ||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
this.ExtendedItem.AddBehavior(typeof(IHandlePointerToolMouseDown), this); | ||
} | ||
|
||
public new void HandleSelectionMouseDown(IDesignPanel designPanel, MouseButtonEventArgs e, DesignPanelHitTestResult result) | ||
{ | ||
if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) | ||
{ | ||
e.Handled = true; | ||
new PartialRangeSelectionGesture(result.ModelHit).Start(designPanel, e); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
internal class PartialRangeSelectionGesture : RangeSelectionGesture | ||
{ | ||
public PartialRangeSelectionGesture(DesignItem container) | ||
: base(container) | ||
{ | ||
} | ||
|
||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters