Skip to content

Commit

Permalink
Merge pull request #424 from jizc/feature/enable-more-custom-implemen…
Browse files Browse the repository at this point in the history
…tations

Enable custom IDragInfo & IDropInfo implementations
  • Loading branch information
punker76 authored Dec 5, 2024
2 parents 6c5f2c2 + 57c9116 commit 2e203bc
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/GongSolutions.WPF.DragDrop/DragDrop.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ public static void SetSelectDroppedItems(DependencyObject element, bool value)
}

/// <summary>
/// Gets or sets the <see cref="ScrollViewer"/> that will be used as <see cref="DropInfo.TargetScrollViewer"/>.
/// Gets or sets the <see cref="ScrollViewer"/> that will be used as <see cref="IDropInfo.TargetScrollViewer"/>.
/// </summary>
public static readonly DependencyProperty DropTargetScrollViewerProperty
= DependencyProperty.RegisterAttached("DropTargetScrollViewer",
Expand All @@ -1624,7 +1624,7 @@ public static readonly DependencyProperty DropTargetScrollViewerProperty

/// <summary>Helper for getting <see cref="DropTargetScrollViewerProperty"/> from <paramref name="element"/>.</summary>
/// <param name="element"><see cref="DependencyObject"/> to read <see cref="DropTargetScrollViewerProperty"/> from.</param>
/// <remarks>Gets the <see cref="ScrollViewer"/> that will be used as <see cref="DropInfo.TargetScrollViewer"/>.</remarks>
/// <remarks>Gets the <see cref="ScrollViewer"/> that will be used as <see cref="IDropInfo.TargetScrollViewer"/>.</remarks>
/// <returns>DropTargetScrollViewer property value.</returns>
[AttachedPropertyBrowsableForType(typeof(UIElement))]
public static ScrollViewer GetDropTargetScrollViewer(DependencyObject element)
Expand All @@ -1635,7 +1635,7 @@ public static ScrollViewer GetDropTargetScrollViewer(DependencyObject element)
/// <summary>Helper for setting <see cref="DropTargetScrollViewerProperty"/> on <paramref name="element"/>.</summary>
/// <param name="element"><see cref="DependencyObject"/> to set <see cref="DropTargetScrollViewerProperty"/> on.</param>
/// <param name="value">DropTargetScrollViewer property value.</param>
/// <remarks>Sets the <see cref="ScrollViewer"/> that will be used as <see cref="DropInfo.TargetScrollViewer"/>.</remarks>
/// <remarks>Sets the <see cref="ScrollViewer"/> that will be used as <see cref="IDropInfo.TargetScrollViewer"/>.</remarks>
[AttachedPropertyBrowsableForType(typeof(UIElement))]
public static void SetDropTargetScrollViewer(DependencyObject element, ScrollViewer value)
{
Expand Down
6 changes: 3 additions & 3 deletions src/GongSolutions.WPF.DragDrop/DragDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ private static void DoMouseButtonDown(object sender, MouseButtonEventArgs e)
DragSourceDown(sender, dragInfo, e, elementPosition);
}

private static void DragSourceDown(object sender, DragInfo dragInfo, InputEventArgs e, Point elementPosition)
private static void DragSourceDown(object sender, IDragInfo dragInfo, InputEventArgs e, Point elementPosition)
{
if (dragInfo.VisualSource is ItemsControl control && control.CanSelectMultipleItems())
{
Expand Down Expand Up @@ -619,7 +619,7 @@ private static void DoDragSourceMove(object sender, Func<IInputElement, Point> g
&& (Math.Abs(position.X - dragStart.X) > DragDrop.GetMinimumHorizontalDragDistance(dragInfo.VisualSource) ||
Math.Abs(position.Y - dragStart.Y) > DragDrop.GetMinimumVerticalDragDistance(dragInfo.VisualSource)))
{
dragInfo.RefreshSelectedItems(sender);
dragInfo.RefreshSourceItems(sender);

var dragHandler = TryGetDragHandler(dragInfo, sender as UIElement);
if (dragHandler.CanStartDrag(dragInfo))
Expand Down Expand Up @@ -1040,7 +1040,7 @@ private static DropTargetAdorner DropTargetAdorner
}
}

private static DragInfo _dragInfo;
private static IDragInfo _dragInfo;
private static bool _dragInProgress;
private static object _clickSupressItem;

Expand Down
3 changes: 2 additions & 1 deletion src/GongSolutions.WPF.DragDrop/DragInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public DragInfo(object sender, object originalSource, MouseButton mouseButton, F
this.SourceItems ??= Enumerable.Empty<object>();
}

internal void RefreshSelectedItems(object sender)
/// <inheritdoc />
public virtual void RefreshSourceItems(object sender)
{
if (sender is not ItemsControl itemsControl)
{
Expand Down
8 changes: 2 additions & 6 deletions src/GongSolutions.WPF.DragDrop/DropInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,10 @@ public int UnfilteredInsertIndex
/// <inheritdoc />
public CollectionViewGroup TargetGroup { get; protected set; }

/// <summary>
/// Gets the ScrollViewer control for the visual target.
/// </summary>
/// <inheritdoc />
public ScrollViewer TargetScrollViewer { get; protected set; }

/// <summary>
/// Gets or Sets the ScrollingMode for the drop action.
/// </summary>
/// <inheritdoc />
public ScrollingMode TargetScrollingMode { get; set; }

/// <inheritdoc />
Expand Down
8 changes: 7 additions & 1 deletion src/GongSolutions.WPF.DragDrop/DropTargetAdorner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ internal static DropTargetAdorner Create(Type type, UIElement adornedElement, ID
throw new InvalidOperationException("The requested adorner class does not derive from DropTargetAdorner.");
}

return type.GetConstructor(new[] { typeof(UIElement), typeof(DropInfo) })?.Invoke(new object[] { adornedElement, dropInfo }) as DropTargetAdorner;
var ctor = type.GetConstructor(new[] { typeof(UIElement), typeof(IDropInfo) });
if (ctor is null && dropInfo is DropInfo)
{
ctor = type.GetConstructor(new[] { typeof(UIElement), typeof(DropInfo) });
}

return ctor?.Invoke(new object[] { adornedElement, dropInfo }) as DropTargetAdorner;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace GongSolutions.Wpf.DragDrop
{
public class DropTargetInsertionAdorner : DropTargetAdorner
{
public DropTargetInsertionAdorner(UIElement adornedElement, DropInfo dropInfo)
public DropTargetInsertionAdorner(UIElement adornedElement, IDropInfo dropInfo)
: base(adornedElement, dropInfo)
{
}
Expand Down
6 changes: 6 additions & 0 deletions src/GongSolutions.WPF.DragDrop/IDragInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,11 @@ public interface IDragInfo
/// Gets the drag drop copy key state indicating the effect of the drag drop operation.
/// </summary>
DragDropKeyStates DragDropCopyKeyState { get; }

/// <summary>
/// Refreshes the <see cref="SourceItems" /> property.
/// </summary>
/// <param name="sender">The drag source control.</param>
void RefreshSourceItems(object sender);
}
}
2 changes: 1 addition & 1 deletion src/GongSolutions.WPF.DragDrop/IDragInfoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public interface IDragInfoBuilder
/// <param name="mouseButton">The mouse button which was used for the drag operation.</param>
/// <param name="getPosition">A function of the input event which is used to get drag position points.</param>
[CanBeNull]
DragInfo CreateDragInfo(object sender, object originalSource, MouseButton mouseButton, Func<IInputElement, Point> getPosition);
IDragInfo CreateDragInfo(object sender, object originalSource, MouseButton mouseButton, Func<IInputElement, Point> getPosition);
}
}
2 changes: 1 addition & 1 deletion src/GongSolutions.WPF.DragDrop/IDragSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IDragSource
/// </summary>
/// <param name="dragInfo">Object which contains several drag information.</param>
/// <remarks>
/// To allow a drag to be started, the <see cref="DragInfo.Effects" /> property on <paramref name="dragInfo" />
/// To allow a drag to be started, the <see cref="IDragInfo.Effects" /> property on <paramref name="dragInfo" />
/// should be set to a value other than <see cref="DragDropEffects.None" />.
/// </remarks>
void StartDrag(IDragInfo dragInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/GongSolutions.WPF.DragDrop/IDropInfoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public interface IDropInfoBuilder
/// <param name="dragInfo">Information about the drag source, if the drag came from within the framework.</param>
/// <param name="eventType">The type of the underlying event (tunneled or bubbled).</param>
[CanBeNull]
IDropInfo CreateDropInfo(object sender, DragEventArgs e, [CanBeNull] DragInfo dragInfo, EventType eventType);
IDropInfo CreateDropInfo(object sender, DragEventArgs e, [CanBeNull] IDragInfo dragInfo, EventType eventType);
}
}
4 changes: 2 additions & 2 deletions src/GongSolutions.WPF.DragDrop/IDropTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ void DragEnter(IDropInfo dropInfo)
/// </summary>
/// <param name="dropInfo">Object which contains several drop information.</param>
/// <remarks>
/// To allow a drop at the current drag position, the <see cref="DropInfo.Effects"/> property on
/// To allow a drop at the current drag position, the <see cref="IDropInfo.Effects"/> property on
/// <paramref name="dropInfo"/> should be set to a value other than <see cref="DragDropEffects.None"/>
/// and <see cref="DropInfo.Data"/> should be set to a non-null value.
/// and <see cref="IDropInfo.Data"/> should be set to a non-null value.
/// </remarks>
void DragOver(IDropInfo dropInfo);

Expand Down
2 changes: 1 addition & 1 deletion src/Showcase/Models/TextBoxCustomDropHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class DropTargetHighlightAdorner : DropTargetAdorner
private readonly Pen _pen;
private readonly Brush _brush;

public DropTargetHighlightAdorner(UIElement adornedElement, DropInfo dropInfo)
public DropTargetHighlightAdorner(UIElement adornedElement, IDropInfo dropInfo)
: base(adornedElement, dropInfo)
{
this._pen = new Pen(Brushes.Tomato, 2);
Expand Down

0 comments on commit 2e203bc

Please sign in to comment.