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

Commit

Permalink
Merge pull request #521 from gumme/WpfDesignerPartialPanelSelectionHa…
Browse files Browse the repository at this point in the history
…ndler

changed implementation of PanelSelectionHandler so that custom panelsele...
  • Loading branch information
siegfriedpammer committed Aug 23, 2014
2 parents 672e65a + d690ae5 commit cfa59ea
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 8 deletions.
Expand Up @@ -52,13 +52,13 @@ public void HandleSelectionMouseDown(IDesignPanel designPanel, MouseButtonEventA
}
}

sealed class RangeSelectionGesture : ClickOrDragMouseGesture
internal class RangeSelectionGesture : ClickOrDragMouseGesture
{
DesignItem container;
AdornerPanel adornerPanel;
SelectionFrame selectionFrame;
protected DesignItem container;
protected AdornerPanel adornerPanel;
protected SelectionFrame selectionFrame;

GrayOutDesignerExceptActiveArea grayOut;
protected GrayOutDesignerExceptActiveArea grayOut;

public RangeSelectionGesture(DesignItem container)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
Math.Abs(startPoint.Y - endPoint.Y)
);

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

static ICollection<DesignItem> GetChildDesignItemsInContainer(
DesignItem container, Geometry geometry)
protected virtual ICollection<DesignItem> GetChildDesignItemsInContainer(Geometry geometry)
{
HashSet<DesignItem> resultItems = new HashSet<DesignItem>();
ViewService viewService = container.Services.View;
Expand Down
@@ -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;
}
}
}
Expand Up @@ -84,6 +84,7 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Extensions\PartialPanelSelectionHandler.cs" />
<Compile Include="Extensions\RightClickContextMenu.xaml.cs">
<DependentUpon>RightClickContextMenu.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down

0 comments on commit cfa59ea

Please sign in to comment.