Skip to content

Commit b4df88f

Browse files
authored
Merge 63a14d2 into 8ffd29f
2 parents 8ffd29f + 63a14d2 commit b4df88f

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

CefSharp.Wpf/CefSharp.Wpf.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
</ItemGroup>
8080
<ItemGroup>
8181
<Compile Include="CefSettings.cs" />
82+
<Compile Include="DragCursorProvider.cs" />
8283
<Compile Include="Internals\MonitorInfo.cs" />
8384
<Compile Include="Internals\MonitorInfoEx.cs" />
8485
<Compile Include="Internals\RectStruct.cs" />

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,8 @@ void IRenderWebBrowser.UpdateDragCursor(DragOperationsMask operation)
787787
/// <param name="operation">describes the allowed operation (none, move, copy, link). </param>
788788
protected virtual void UpdateDragCursor(DragOperationsMask operation)
789789
{
790-
//TODO: Someone should implement this
790+
var dragCursor = DragCursorProvider.GetCursor(operation);
791+
UiThreadRunSync(() => Mouse.SetCursor(dragCursor));
791792
}
792793

793794
/// <summary>

CefSharp.Wpf/DragCursorProvider.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.InteropServices;
4+
using System.Windows.Input;
5+
using System.Windows.Interop;
6+
using CefSharp.Enums;
7+
using Microsoft.Win32.SafeHandles;
8+
9+
namespace CefSharp.Wpf
10+
{
11+
12+
internal static class DragCursorProvider
13+
{
14+
[DllImport("kernel32.dll")]
15+
private static extern IntPtr LoadLibrary(string dllToLoad);
16+
17+
[DllImport("user32.dll")]
18+
private static extern IntPtr LoadCursor(IntPtr hInstance, ushort lpCursorName);
19+
20+
private static readonly Dictionary<DragOperationsMask, Cursor> DragCursors;
21+
22+
static DragCursorProvider()
23+
{
24+
var library = LoadLibrary("ole32.dll");
25+
DragCursors = new Dictionary<DragOperationsMask, Cursor>()
26+
{
27+
{ DragOperationsMask.None, GetCursorFromLib(library, 1) },
28+
{ DragOperationsMask.Move, GetCursorFromLib(library, 2) },
29+
{ DragOperationsMask.Copy, GetCursorFromLib(library, 3) },
30+
{ DragOperationsMask.Link, GetCursorFromLib(library, 4) }
31+
// TODO: support black cursors
32+
};
33+
}
34+
35+
private static Cursor GetCursorFromLib(IntPtr library, ushort cursorIndex)
36+
{
37+
var cursorHandle = LoadCursor(library, cursorIndex);
38+
return CursorInteropHelper.Create(new SafeFileHandle(cursorHandle, false));
39+
}
40+
41+
/// <summary>
42+
/// Get the Windows cursor for the drag effect specified.
43+
/// </summary>
44+
/// <param name="operation"></param>
45+
/// <returns>The drop cursor based on the specified drag operation effect</returns>
46+
public static Cursor GetCursor(DragOperationsMask operation)
47+
{
48+
Cursor cursor;
49+
if (DragCursors.TryGetValue(operation, out cursor))
50+
{
51+
return cursor;
52+
}
53+
return Cursors.Arrow;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)