|
|
@ -1,7 +1,10 @@ |
|
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
|
using Avalonia.Controls; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Input; |
|
|
|
|
|
using Avalonia.VisualTree; |
|
|
using Avalonia.Win32.Interop; |
|
|
using Avalonia.Win32.Interop; |
|
|
|
|
|
|
|
|
namespace Avalonia.Win32.Input |
|
|
namespace Avalonia.Win32.Input |
|
|
@ -10,23 +13,32 @@ namespace Avalonia.Win32.Input |
|
|
{ |
|
|
{ |
|
|
public static WindowsMouseDevice Instance { get; } = new WindowsMouseDevice(); |
|
|
public static WindowsMouseDevice Instance { get; } = new WindowsMouseDevice(); |
|
|
|
|
|
|
|
|
|
|
|
public WindowsMouseDevice() : base(new WindowsMousePointer()) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public WindowImpl CurrentWindow |
|
|
public WindowImpl CurrentWindow |
|
|
{ |
|
|
{ |
|
|
get; |
|
|
get; |
|
|
set; |
|
|
set; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override void Capture(IInputElement control) |
|
|
class WindowsMousePointer : Pointer |
|
|
{ |
|
|
{ |
|
|
base.Capture(control); |
|
|
public WindowsMousePointer() : base(Pointer.GetNextFreeId(),PointerType.Mouse, true) |
|
|
|
|
|
|
|
|
if (control != null) |
|
|
|
|
|
{ |
|
|
{ |
|
|
UnmanagedMethods.SetCapture(CurrentWindow.Handle.Handle); |
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
|
|
|
protected override void PlatformCapture(IInputElement element) |
|
|
{ |
|
|
{ |
|
|
UnmanagedMethods.ReleaseCapture(); |
|
|
var hwnd = ((element?.GetVisualRoot() as TopLevel)?.PlatformImpl as WindowImpl) |
|
|
|
|
|
?.Handle.Handle; |
|
|
|
|
|
|
|
|
|
|
|
if (hwnd.HasValue && hwnd != IntPtr.Zero) |
|
|
|
|
|
UnmanagedMethods.SetCapture(hwnd.Value); |
|
|
|
|
|
else |
|
|
|
|
|
UnmanagedMethods.ReleaseCapture(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|