Browse Source

Port DragMove logic from WPF (#14186)

* Port DragMove logic from WPF to fix missing PointerReleased event on drag out.

* remove WindowState.Normal check
pull/14190/head
Jumar Macato 2 years ago
committed by GitHub
parent
commit
97084260d3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  2. 18
      src/Windows/Avalonia.Win32/WindowImpl.cs

7
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -1183,7 +1183,12 @@ namespace Avalonia.Win32.Interop
[DllImport("user32.dll", EntryPoint = "DefWindowProcW")]
public static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
public const int SC_MOUSEMOVE = 0xf012;
[DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "SendMessageW")]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", EntryPoint = "DispatchMessageW")]
public static extern IntPtr DispatchMessage(ref MSG lpmsg);

18
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -667,8 +667,22 @@ namespace Avalonia.Win32
public void BeginMoveDrag(PointerPressedEventArgs e)
{
e.Pointer.Capture(null);
DefWindowProc(_hwnd, (int)WindowsMessage.WM_NCLBUTTONDOWN,
new IntPtr((int)HitTestValues.HTCAPTION), IntPtr.Zero);
// Mouse.LeftButton actually reflects the primary button user is using.
// So we don't need to check whether the button has been swapped here.
if (e.Pointer.IsPrimary)
{
// SendMessage's return value is dependent on the message send. WM_SYSCOMMAND
// and WM_LBUTTONUP return value just signify whether the WndProc handled the
// message or not, so they are not interesting
SendMessage(_hwnd, (int)WindowsMessage.WM_SYSCOMMAND, (IntPtr)SC_MOUSEMOVE, IntPtr.Zero);
SendMessage(_hwnd, (int)WindowsMessage.WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
}
else
{
throw new InvalidOperationException("BeginMoveDrag Failed");
}
}
public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)

Loading…
Cancel
Save