diff --git a/Perspex.Windows/Input/MouseDevice.cs b/Perspex.Windows/Input/MouseDevice.cs index f1e7ba5f7c..6f6dee6fd3 100644 --- a/Perspex.Windows/Input/MouseDevice.cs +++ b/Perspex.Windows/Input/MouseDevice.cs @@ -9,18 +9,48 @@ namespace Perspex.Windows.Input using System; using System.Reactive.Disposables; using Perspex.Input; + using Perspex.Input.Raw; + using Splat; public class MouseDevice : IMouseDevice { + private static MouseDevice instance = new MouseDevice(); + + public static MouseDevice Instance + { + get { return instance; } + } + public Interactive Captured { get; private set; } + public Window CurrentWindow + { + get; + set; + } + + public Point Position + { + get; + set; + } + public void Capture(Interactive visual) { this.Captured = visual; + + RawMouseEventArgs e = new RawMouseEventArgs( + this, + this.CurrentWindow, + RawMouseEventType.Move, + this.Position); + + IInputManager inputManager = Locator.Current.GetService(); + inputManager.Process(e); } } } diff --git a/Perspex.Windows/Window.cs b/Perspex.Windows/Window.cs index 6ddbd227d0..96c26c9038 100644 --- a/Perspex.Windows/Window.cs +++ b/Perspex.Windows/Window.cs @@ -25,8 +25,6 @@ namespace Perspex.Windows public static readonly PerspexProperty FontSizeProperty = TextBlock.FontSizeProperty.AddOwner(); - private static readonly IInputDevice MouseDevice = new MouseDevice(); - private UnmanagedMethods.WndProc wndProcDelegate; private string className; @@ -149,7 +147,9 @@ namespace Perspex.Windows [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Using Win32 naming for consistency.")] private IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { - RawInputEventArgs e = null; + RawMouseEventArgs e = null; + + MouseDevice.Instance.CurrentWindow = this; switch ((UnmanagedMethods.WindowsMessage)msg) { @@ -167,7 +167,7 @@ namespace Perspex.Windows case UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN: e = new RawMouseEventArgs( - MouseDevice, + MouseDevice.Instance, this, RawMouseEventType.LeftButtonDown, new Point((uint)lParam & 0xffff, (uint)lParam >> 16)); @@ -175,7 +175,7 @@ namespace Perspex.Windows case UnmanagedMethods.WindowsMessage.WM_LBUTTONUP: e = new RawMouseEventArgs( - MouseDevice, + MouseDevice.Instance, this, RawMouseEventType.LeftButtonUp, new Point((uint)lParam & 0xffff, (uint)lParam >> 16)); @@ -183,7 +183,7 @@ namespace Perspex.Windows case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE: e = new RawMouseEventArgs( - MouseDevice, + MouseDevice.Instance, this, RawMouseEventType.Move, new Point((uint)lParam & 0xffff, (uint)lParam >> 16)); @@ -197,6 +197,7 @@ namespace Perspex.Windows if (e != null) { + MouseDevice.Instance.Position = e.Position; this.inputManager.Process(e); }