Browse Source

Avoid deprecated input API in win32 backend

pull/8577/head
Max Katz 4 years ago
parent
commit
5d836f88ef
  1. 21
      src/Windows/Avalonia.Win32/Input/WindowsMouseDevice.cs
  2. 7
      src/Windows/Avalonia.Win32/WindowImpl.cs

21
src/Windows/Avalonia.Win32/Input/WindowsMouseDevice.cs

@ -8,15 +8,28 @@ namespace Avalonia.Win32.Input
{ {
class WindowsMouseDevice : MouseDevice class WindowsMouseDevice : MouseDevice
{ {
public WindowsMouseDevice() : base(new WindowsMousePointer()) private readonly IPointer _pointer;
public WindowsMouseDevice() : base(WindowsMousePointer.CreatePointer(out var pointer))
{ {
_pointer = pointer;
}
// Normally user should use IPointer.Capture instead of MouseDevice.Capture,
// But on Windows we need to handle WM_MOUSE capture manually without having access to the Pointer.
internal void Capture(IInputElement control)
{
_pointer.Capture(control);
} }
class WindowsMousePointer : Pointer internal class WindowsMousePointer : Pointer
{ {
public WindowsMousePointer() : base(Pointer.GetNextFreeId(),PointerType.Mouse, true) private WindowsMousePointer() : base(Pointer.GetNextFreeId(),PointerType.Mouse, true)
{
}
public static WindowsMousePointer CreatePointer(out WindowsMousePointer pointer)
{ {
return pointer = new WindowsMousePointer();
} }
protected override void PlatformCapture(IInputElement element) protected override void PlatformCapture(IInputElement element)

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

@ -72,7 +72,7 @@ namespace Avalonia.Win32
private const WindowStyles WindowStateMask = (WindowStyles.WS_MAXIMIZE | WindowStyles.WS_MINIMIZE); private const WindowStyles WindowStateMask = (WindowStyles.WS_MAXIMIZE | WindowStyles.WS_MINIMIZE);
private readonly TouchDevice _touchDevice; private readonly TouchDevice _touchDevice;
private readonly MouseDevice _mouseDevice; private readonly WindowsMouseDevice _mouseDevice;
private readonly PenDevice _penDevice; private readonly PenDevice _penDevice;
private readonly ManagedDeferredRendererLock _rendererLock; private readonly ManagedDeferredRendererLock _rendererLock;
private readonly FramebufferManager _framebuffer; private readonly FramebufferManager _framebuffer;
@ -689,10 +689,9 @@ namespace Avalonia.Win32
public void BeginMoveDrag(PointerPressedEventArgs e) public void BeginMoveDrag(PointerPressedEventArgs e)
{ {
_mouseDevice.Capture(null); e.Pointer.Capture(null);
DefWindowProc(_hwnd, (int)WindowsMessage.WM_NCLBUTTONDOWN, DefWindowProc(_hwnd, (int)WindowsMessage.WM_NCLBUTTONDOWN,
new IntPtr((int)HitTestValues.HTCAPTION), IntPtr.Zero); new IntPtr((int)HitTestValues.HTCAPTION), IntPtr.Zero);
e.Pointer.Capture(null);
} }
public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e) public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)
@ -702,7 +701,7 @@ namespace Avalonia.Win32
#if USE_MANAGED_DRAG #if USE_MANAGED_DRAG
_managedDrag.BeginResizeDrag(edge, ScreenToClient(MouseDevice.Position.ToPoint(_scaling))); _managedDrag.BeginResizeDrag(edge, ScreenToClient(MouseDevice.Position.ToPoint(_scaling)));
#else #else
_mouseDevice.Capture(null); e.Pointer.Capture(null);
DefWindowProc(_hwnd, (int)WindowsMessage.WM_NCLBUTTONDOWN, DefWindowProc(_hwnd, (int)WindowsMessage.WM_NCLBUTTONDOWN,
new IntPtr((int)s_edgeLookup[edge]), IntPtr.Zero); new IntPtr((int)s_edgeLookup[edge]), IntPtr.Zero);
#endif #endif

Loading…
Cancel
Save