diff --git a/Perspex.Input/IPointerDevice.cs b/Perspex.Input/IPointerDevice.cs index a130814e41..2d8667b30d 100644 --- a/Perspex.Input/IPointerDevice.cs +++ b/Perspex.Input/IPointerDevice.cs @@ -11,9 +11,9 @@ namespace Perspex.Input public interface IPointerDevice : IInputDevice { - IInteractive Captured { get; } + IInputElement Captured { get; } - void Capture(IInteractive control); + void Capture(IInputElement control); Point GetPosition(IVisual relativeTo); } diff --git a/Perspex.Input/MouseDevice.cs b/Perspex.Input/MouseDevice.cs index 969f1efe6b..bf3c56e9d9 100644 --- a/Perspex.Input/MouseDevice.cs +++ b/Perspex.Input/MouseDevice.cs @@ -30,7 +30,7 @@ namespace Perspex.Input .Subscribe(this.ProcessRawEvent); } - public IInteractive Captured + public IInputElement Captured { get; protected set; @@ -47,7 +47,7 @@ namespace Perspex.Input protected set; } - public virtual void Capture(IInteractive control) + public virtual void Capture(IInputElement control) { this.Captured = control; } @@ -127,7 +127,7 @@ namespace Perspex.Input private void MouseDown(IMouseDevice device, uint timestamp, IInputElement root, Point p) { - IVisual hit = root.InputHitTest(p); + var hit = this.HitTest(root, p); if (hit != null) { @@ -169,7 +169,7 @@ namespace Perspex.Input private void MouseUp(IMouseDevice device, IInputElement root, Point p) { - IVisual hit = root.InputHitTest(p); + var hit = this.HitTest(root, p); if (hit != null) { @@ -190,7 +190,7 @@ namespace Perspex.Input private void MouseWheel(IMouseDevice device, IInputElement root, Point p, Vector delta) { - IVisual hit = root.InputHitTest(p); + var hit = this.HitTest(root, p); if (hit != null) { @@ -222,5 +222,10 @@ namespace Perspex.Input (hit as IInteractive) ?? hit.GetSelfAndVisualAncestors().OfType().FirstOrDefault(); } + + private IInputElement HitTest(IInputElement root, Point p) + { + return this.Captured ?? root.InputHitTest(p); + } } } diff --git a/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs b/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs index 094d06ed33..94bd703658 100644 --- a/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs +++ b/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs @@ -8,6 +8,7 @@ namespace Perspex.Win32.Input { using System; using Perspex.Input; + using Perspex.Interactivity; using Perspex.Win32.Interop; public class WindowsMouseDevice : MouseDevice @@ -31,6 +32,20 @@ namespace Perspex.Win32.Input internal set { base.Position = value; } } + public override void Capture(IInputElement control) + { + base.Capture(control); + + if (control != null) + { + UnmanagedMethods.SetCapture(this.CurrentWindow.Handle.Handle); + } + else + { + UnmanagedMethods.ReleaseCapture(); + } + } + protected override Point GetClientPosition() { UnmanagedMethods.POINT p;