Skip to content

Commit d4858fd

Browse files
authored
Merge b1d222c into 8ffd29f
2 parents 8ffd29f + b1d222c commit d4858fd

File tree

3 files changed

+63
-1
lines changed

3 files changed

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

0 commit comments

Comments
 (0)