-
-
Notifications
You must be signed in to change notification settings - Fork 3k
WPF - Implement UpdateDragCursor #2691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
d957e36
9734701
f151f36
b89ca68
fff4f6d
6d7872c
63a14d2
adb755a
32ffab5
b1d222c
3e38388
0ef3fd1
10f32eb
2ce9fdd
9b93a98
1be3f82
8013d2f
120f5fc
252da08
7a6c364
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| using System; | ||
merceyz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using System.Collections.Generic; | ||
| using System.Runtime.InteropServices; | ||
| using System.Windows.Input; | ||
| using System.Windows.Interop; | ||
| using CefSharp.Enums; | ||
| using Microsoft.Win32.SafeHandles; | ||
|
|
||
| namespace CefSharp.Wpf | ||
| { | ||
|
|
||
| internal static class DragCursorProvider | ||
| { | ||
| [DllImport("kernel32.dll")] | ||
| private static extern IntPtr LoadLibrary(string dllToLoad); | ||
|
|
||
| [DllImport("user32.dll")] | ||
| private static extern IntPtr LoadCursor(IntPtr hInstance, ushort lpCursorName); | ||
|
|
||
| private static readonly Dictionary<DragOperationsMask, Cursor> DragCursors; | ||
|
|
||
| static DragCursorProvider() | ||
| { | ||
| var library = LoadLibrary("ole32.dll"); | ||
| DragCursors = new Dictionary<DragOperationsMask, Cursor>() | ||
| { | ||
| { DragOperationsMask.None, GetCursorFromLib(library, 1) }, | ||
|
||
| { DragOperationsMask.Move, GetCursorFromLib(library, 2) }, | ||
|
||
| { DragOperationsMask.Copy, GetCursorFromLib(library, 3) }, | ||
| { DragOperationsMask.Link, GetCursorFromLib(library, 4) } | ||
| // TODO: support black cursors | ||
| }; | ||
| } | ||
|
|
||
| private static Cursor GetCursorFromLib(IntPtr library, ushort cursorIndex) | ||
| { | ||
| var cursorHandle = LoadCursor(library, cursorIndex); | ||
| return CursorInteropHelper.Create(new SafeFileHandle(cursorHandle, false)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get the Windows cursor for the drag effect specified. | ||
| /// </summary> | ||
| /// <param name="operation"></param> | ||
| /// <returns>The drop cursor based on the specified drag operation effect</returns> | ||
| public static Cursor GetCursor(DragOperationsMask operation) | ||
| { | ||
| Cursor cursor; | ||
| if (DragCursors.TryGetValue(operation, out cursor)) | ||
| { | ||
| return cursor; | ||
| } | ||
| return Cursors.Arrow; | ||
| } | ||
| } | ||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this is run
Sync? If so please add a comment as to the reason.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an attempt to reduce the flicker, but it still exists.