Skip to content

Commit 6d7872c

Browse files
committed
Implemented UpdateDragCursor
1 parent fff4f6d commit 6d7872c

File tree

3 files changed

+57
-1
lines changed

3 files changed

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

0 commit comments

Comments
 (0)