|
| 1 | +/* |
| 2 | + * Created by SharpDevelop. |
| 3 | + * User: trubra |
| 4 | + * Date: 2014-08-06 |
| 5 | + * Time: 14:13 |
| 6 | + * |
| 7 | + * To change this template use Tools | Options | Coding | Edit Standard Headers. |
| 8 | + */ |
| 9 | +using System; |
| 10 | +using System.Collections.Generic; |
| 11 | +using System.Diagnostics; |
| 12 | +using System.Windows; |
| 13 | +using System.Windows.Controls; |
| 14 | +using System.Windows.Input; |
| 15 | +using System.Windows.Media; |
| 16 | + |
| 17 | +using ICSharpCode.WpfDesign.Adorners; |
| 18 | +using ICSharpCode.WpfDesign.Designer.Controls; |
| 19 | +using ICSharpCode.WpfDesign.Designer.Services; |
| 20 | +using ICSharpCode.WpfDesign.Extensions; |
| 21 | + |
| 22 | +namespace ICSharpCode.WpfDesign.Designer.Extensions |
| 23 | +{ |
| 24 | + public class PartialPanelSelectionHandler : BehaviorExtension, IHandlePointerToolMouseDown |
| 25 | + { |
| 26 | + protected override void OnInitialized() |
| 27 | + { |
| 28 | + base.OnInitialized(); |
| 29 | + this.ExtendedItem.AddBehavior(typeof(IHandlePointerToolMouseDown), this); |
| 30 | + } |
| 31 | + |
| 32 | + public new void HandleSelectionMouseDown(IDesignPanel designPanel, MouseButtonEventArgs e, DesignPanelHitTestResult result) |
| 33 | + { |
| 34 | + if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) |
| 35 | + { |
| 36 | + e.Handled = true; |
| 37 | + new PartialRangeSelectionGesture(result.ModelHit).Start(designPanel, e); |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// |
| 44 | + /// </summary> |
| 45 | + internal class PartialRangeSelectionGesture : RangeSelectionGesture |
| 46 | + { |
| 47 | + public PartialRangeSelectionGesture(DesignItem container) |
| 48 | + : base(container) |
| 49 | + { |
| 50 | + } |
| 51 | + |
| 52 | + protected override ICollection<DesignItem> GetChildDesignItemsInContainer(Geometry geometry) |
| 53 | + { |
| 54 | + HashSet<DesignItem> resultItems = new HashSet<DesignItem>(); |
| 55 | + ViewService viewService = container.Services.View; |
| 56 | + |
| 57 | + HitTestFilterCallback filterCallback = delegate(DependencyObject potentialHitTestTarget) |
| 58 | + { |
| 59 | + FrameworkElement element = potentialHitTestTarget as FrameworkElement; |
| 60 | + if (element != null) |
| 61 | + { |
| 62 | + // ensure we are able to select elements with width/height=0 |
| 63 | + if (element.ActualWidth == 0 || element.ActualHeight == 0) |
| 64 | + { |
| 65 | + DependencyObject tmp = element; |
| 66 | + DesignItem model = null; |
| 67 | + while (tmp != null) |
| 68 | + { |
| 69 | + model = viewService.GetModel(tmp); |
| 70 | + if (model != null) break; |
| 71 | + tmp = VisualTreeHelper.GetParent(tmp); |
| 72 | + } |
| 73 | + if (model != container) |
| 74 | + { |
| 75 | + resultItems.Add(model); |
| 76 | + return HitTestFilterBehavior.ContinueSkipChildren; |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + return HitTestFilterBehavior.Continue; |
| 81 | + }; |
| 82 | + |
| 83 | + HitTestResultCallback resultCallback = delegate(HitTestResult result) |
| 84 | + { |
| 85 | + if (((GeometryHitTestResult)result).IntersectionDetail == IntersectionDetail.FullyInside || (Mouse.RightButton== MouseButtonState.Pressed && ((GeometryHitTestResult)result).IntersectionDetail == IntersectionDetail.Intersects)) |
| 86 | + { |
| 87 | + // find the model for the visual contained in the selection area |
| 88 | + DependencyObject tmp = result.VisualHit; |
| 89 | + DesignItem model = null; |
| 90 | + while (tmp != null) |
| 91 | + { |
| 92 | + model = viewService.GetModel(tmp); |
| 93 | + if (model != null) break; |
| 94 | + tmp = VisualTreeHelper.GetParent(tmp); |
| 95 | + } |
| 96 | + if (model != container) |
| 97 | + { |
| 98 | + resultItems.Add(model); |
| 99 | + } |
| 100 | + } |
| 101 | + return HitTestResultBehavior.Continue; |
| 102 | + }; |
| 103 | + |
| 104 | + VisualTreeHelper.HitTest(container.View, filterCallback, resultCallback, new GeometryHitTestParameters(geometry)); |
| 105 | + return resultItems; |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments