Browse Source

Fix mouse capture.

Fixes #15.
pull/16/head
Steven Kirk 12 years ago
parent
commit
3a09abe30b
  1. 4
      Perspex.Input/IPointerDevice.cs
  2. 15
      Perspex.Input/MouseDevice.cs
  3. 15
      Windows/Perspex.Win32/Input/WindowsMouseDevice.cs

4
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);
}

15
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<IInteractive>().FirstOrDefault();
}
private IInputElement HitTest(IInputElement root, Point p)
{
return this.Captured ?? root.InputHitTest(p);
}
}
}

15
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;

Loading…
Cancel
Save