Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit cfa59ea

Browse files
Merge pull request #521 from gumme/WpfDesignerPartialPanelSelectionHandler
changed implementation of PanelSelectionHandler so that custom panelsele...
2 parents 672e65a + d690ae5 commit cfa59ea

File tree

3 files changed

+116
-8
lines changed

3 files changed

+116
-8
lines changed

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelSelectionHandler.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public void HandleSelectionMouseDown(IDesignPanel designPanel, MouseButtonEventA
5252
}
5353
}
5454

55-
sealed class RangeSelectionGesture : ClickOrDragMouseGesture
55+
internal class RangeSelectionGesture : ClickOrDragMouseGesture
5656
{
57-
DesignItem container;
58-
AdornerPanel adornerPanel;
59-
SelectionFrame selectionFrame;
57+
protected DesignItem container;
58+
protected AdornerPanel adornerPanel;
59+
protected SelectionFrame selectionFrame;
6060

61-
GrayOutDesignerExceptActiveArea grayOut;
61+
protected GrayOutDesignerExceptActiveArea grayOut;
6262

6363
public RangeSelectionGesture(DesignItem container)
6464
{
@@ -100,7 +100,7 @@ protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
100100
Math.Abs(startPoint.Y - endPoint.Y)
101101
);
102102

103-
ICollection<DesignItem> items = GetChildDesignItemsInContainer(container, new RectangleGeometry(frameRect));
103+
ICollection<DesignItem> items = GetChildDesignItemsInContainer(new RectangleGeometry(frameRect));
104104
if (items.Count == 0) {
105105
items.Add(container);
106106
}
@@ -109,8 +109,7 @@ protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
109109
Stop();
110110
}
111111

112-
static ICollection<DesignItem> GetChildDesignItemsInContainer(
113-
DesignItem container, Geometry geometry)
112+
protected virtual ICollection<DesignItem> GetChildDesignItemsInContainer(Geometry geometry)
114113
{
115114
HashSet<DesignItem> resultItems = new HashSet<DesignItem>();
116115
ViewService viewService = container.Services.View;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
8585
</Compile>
8686
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
87+
<Compile Include="Extensions\PartialPanelSelectionHandler.cs" />
8788
<Compile Include="Extensions\RightClickContextMenu.xaml.cs">
8889
<DependentUpon>RightClickContextMenu.xaml</DependentUpon>
8990
<SubType>Code</SubType>

0 commit comments

Comments
 (0)