Skip to content

Commit

Permalink
Merge pull request #182 from ivan-danilov/cursors-fix
Browse files Browse the repository at this point in the history
Fix: problem with cursors that are not the same on my OS as hardcoded in the MouseCursor class
  • Loading branch information
JakeGinnivan committed Jan 2, 2014
2 parents 26f8aa8 + bb8b646 commit 70d0104
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions src/TestStack.White/InputDevices/MouseCursor.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace TestStack.White.InputDevices
{
public class MouseCursor
{
public static MouseCursor IShapedCursor = new MouseCursor(65555);
public static MouseCursor Pointer = new MouseCursor(65553);
public static readonly MouseCursor DefaultAndWait = new MouseCursor(65575);
public static readonly MouseCursor Wait = new MouseCursor(65557);
public static readonly MouseCursor SilverlightWait = new MouseCursor(65543);
public static MouseCursor SilverlightPointer = new MouseCursor(65539);
[DllImport("user32.dll")]
static extern IntPtr LoadCursor(IntPtr hInstance, IDC_STANDARD_CURSORS lpCursorName);

enum IDC_STANDARD_CURSORS
{
IDC_ARROW = 32512,
IDC_IBEAM = 32513,
IDC_WAIT = 32514,
IDC_CROSS = 32515,
IDC_UPARROW = 32516,
IDC_SIZE = 32640,
IDC_ICON = 32641,
IDC_SIZENWSE = 32642,
IDC_SIZENESW = 32643,
IDC_SIZEWE = 32644,
IDC_SIZENS = 32645,
IDC_SIZEALL = 32646,
IDC_NO = 32648,
IDC_HAND = 32649,
IDC_APPSTARTING = 32650,
IDC_HELP = 32651
}

public static MouseCursor IShapedCursor = new MouseCursor(IDC_STANDARD_CURSORS.IDC_IBEAM);
public static MouseCursor Pointer = new MouseCursor(IDC_STANDARD_CURSORS.IDC_ARROW);
public static readonly MouseCursor DefaultAndWait = new MouseCursor(IDC_STANDARD_CURSORS.IDC_APPSTARTING);
public static readonly MouseCursor Wait = new MouseCursor(IDC_STANDARD_CURSORS.IDC_WAIT);

private readonly int value;
private static readonly List<MouseCursor> waitCursors = new List<MouseCursor>();
Expand All @@ -19,7 +42,6 @@ static MouseCursor()
{
waitCursors.Add(DefaultAndWait);
waitCursors.Add(Wait);
waitCursors.Add(SilverlightWait);
waitCursors.AddRange(DynamicWaitCursors());
}

Expand All @@ -28,6 +50,12 @@ public MouseCursor(int value)
this.value = value;
}

private MouseCursor(IDC_STANDARD_CURSORS cursor)
{
var c = LoadCursor(IntPtr.Zero, cursor);
this.value = c.ToInt32();
}

public static List<MouseCursor> DynamicWaitCursors()
{
return new List<MouseCursor> {new MouseCursor(Cursors.WaitCursor.Handle.ToInt32())};
Expand Down

0 comments on commit 70d0104

Please sign in to comment.