using System;
using System.Windows;
using System.Windows.Input;

namespace Valg.EVA.Skanning.UserInterfaceElements.LightBox
{
    public static class EnsureArrowCursorForWindowExtension
    {
        public static Window EnsureArrowCursorForWindow(this Window window)
        {
            var hasBeenActivated = false;

            window.Activated += (sender, args) =>
            {
                if (!hasBeenActivated)
                {
                    hasBeenActivated = true;

                    var previousCursor = Mouse.OverrideCursor;
                    Mouse.OverrideCursor = null;

                    window.Closed += (sender2, args2) => Mouse.OverrideCursor = previousCursor;
                }
            };

            return window;
        }
    }
}
