From 767cdc1f6f6a63ce997fc9476911e2c361f9d402 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Wed, 20 Feb 2013 20:33:05 -0500 Subject: Pushing missing changes --- MediaBrowser.UI.Controls/ExtendedButton.cs | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 MediaBrowser.UI.Controls/ExtendedButton.cs (limited to 'MediaBrowser.UI.Controls/ExtendedButton.cs') diff --git a/MediaBrowser.UI.Controls/ExtendedButton.cs b/MediaBrowser.UI.Controls/ExtendedButton.cs new file mode 100644 index 0000000000..1b8e9039d4 --- /dev/null +++ b/MediaBrowser.UI.Controls/ExtendedButton.cs @@ -0,0 +1,49 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +namespace MediaBrowser.UI.Controls +{ + /// + /// This subclass simply autofocuses itself when the mouse moves over it + /// + public class ExtendedButton : Button + { + private Point? _lastMouseMovePoint; + + /// + /// Handles OnMouseMove to auto-select the item that's being moused over + /// + protected override void OnMouseMove(MouseEventArgs e) + { + base.OnMouseMove(e); + + var window = this.GetWindow(); + + // If the cursor is currently hidden, don't bother reacting to it + if (Cursor == Cursors.None || window.Cursor == Cursors.None) + { + return; + } + + // Store the last position for comparison purposes + // Even if the mouse is not moving this event will fire as elements are showing and hiding + var pos = e.GetPosition(window); + + if (!_lastMouseMovePoint.HasValue) + { + _lastMouseMovePoint = pos; + return; + } + + if (pos == _lastMouseMovePoint) + { + return; + } + + _lastMouseMovePoint = pos; + + Focus(); + } + } +} -- cgit v1.2.3