Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ namespace UITests.Windows_UI_Xaml.DragAndDrop
{
[Sample(
Description =
"This test showcases the common scenario of dragging files and/or folders from another window (usually a file explorer) into a specific rectangle that accepts the drop. The files that were dragged and dropped should be seen as a list.",
"""
- This test showcases the common scenario of dragging files and/or folders from another window (usually a file explorer) into a specific rectangle that accepts the drop. The files that were dragged and dropped should be seen as a list.
- If you have non-100% scaling of your screen, the drag indicator should always render above your mouse cursor, irrespective of where in the app's window you move it.
""",
IsManualTest = true,
IgnoreInSnapshotTests = true)]
public sealed partial class DragDrop_Files : UserControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public unsafe Win32DragDropExtension(DragDropManager manager)
_dropTarget.Dispose();
}

private Point GetScaledPosition(float x, float y)
{
var xamlRoot = _manager.ContentRoot.GetOrCreateXamlRoot();
return new Point(x / xamlRoot.RasterizationScale, y / xamlRoot.RasterizationScale);
}

unsafe HRESULT IDropTarget.Interface.DragEnter(IDataObject* dataObject, MODIFIERKEYS_FLAGS grfKeyState, POINTL pt, DROPEFFECT* pdwEffect)
{
Debug.Assert(_manager is not null && _coreDragDropManager is not null);
Expand All @@ -87,9 +93,12 @@ unsafe HRESULT IDropTarget.Interface.DragEnter(IDataObject* dataObject, MODIFIER
}

var position = new System.Drawing.Point(pt.x, pt.y);

var success = PInvoke.ScreenToClient(_hwnd, ref position);
if (!success) { this.LogError()?.Error($"{nameof(PInvoke.ScreenToClient)} failed: {Win32Helper.GetErrorMessage()}"); }
var src = new DragEventSource(position.X, position.Y, grfKeyState);
var scaledPosition = GetScaledPosition(position.X, position.Y);

var src = new DragEventSource(scaledPosition, grfKeyState);

var formats = new Span<FORMATETC>(formatBuffer, (int)fetchedFormatCount);
if (this.Log().IsEnabled(LogLevel.Trace))
Expand Down Expand Up @@ -154,7 +163,8 @@ unsafe HRESULT IDropTarget.Interface.DragOver(MODIFIERKEYS_FLAGS grfKeyState, PO
var position = new System.Drawing.Point(pt.x, pt.y);
var success = PInvoke.ScreenToClient(_hwnd, ref position);
if (!success) { this.LogError()?.Error($"{nameof(PInvoke.ScreenToClient)} failed: {Win32Helper.GetErrorMessage()}"); }
var src = new DragEventSource(position.X, position.Y, grfKeyState);
var scaledPosition = GetScaledPosition(position.X, position.Y);
var src = new DragEventSource(scaledPosition, grfKeyState);

this.LogTrace()?.Trace($"{nameof(IDropTarget.Interface.DragOver)} @ {position}");

Expand All @@ -177,7 +187,8 @@ unsafe HRESULT IDropTarget.Interface.Drop(IDataObject* dataObject, MODIFIERKEYS_
var position = new System.Drawing.Point(pt.x, pt.y);
var success = PInvoke.ScreenToClient(_hwnd, ref position);
if (!success) { this.LogError()?.Error($"{nameof(PInvoke.ScreenToClient)} failed: {Win32Helper.GetErrorMessage()}"); }
var src = new DragEventSource(position.X, position.Y, grfKeyState);
var scaledPosition = GetScaledPosition(position.X, position.Y);
var src = new DragEventSource(scaledPosition, grfKeyState);

this.LogTrace()?.Trace($"{nameof(IDropTarget.Interface.Drop)} @ {position}");

Expand All @@ -188,10 +199,10 @@ unsafe HRESULT IDropTarget.Interface.Drop(IDataObject* dataObject, MODIFIERKEYS_

public void StartNativeDrag(CoreDragInfo info, Action<DataPackageOperation> action) => throw new System.NotImplementedException();

private readonly struct DragEventSource(int x, int y, MODIFIERKEYS_FLAGS modifierFlags) : IDragEventSource
private readonly struct DragEventSource(Point point, MODIFIERKEYS_FLAGS modifierFlags) : IDragEventSource
{
private static long _nextFrameId;
private readonly Point _location = new(x, y);
private readonly Point _location = point;

public long Id => _fakePointerId;

Expand Down
Loading