Browse Source
Merge pull request #3312 from MarchingCube/fix-oledroptarget-staticroot
Fix OleDropTarget not being unregistered
pull/3316/head
Jumar Macato
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
27 additions and
8 deletions
-
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
-
src/Windows/Avalonia.Win32/OleContext.cs
-
src/Windows/Avalonia.Win32/OleDropTarget.cs
-
src/Windows/Avalonia.Win32/WindowImpl.cs
|
|
|
@ -1098,7 +1098,10 @@ namespace Avalonia.Win32.Interop |
|
|
|
|
|
|
|
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] |
|
|
|
public static extern HRESULT RegisterDragDrop(IntPtr hwnd, IDropTarget target); |
|
|
|
|
|
|
|
|
|
|
|
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] |
|
|
|
public static extern HRESULT RevokeDragDrop(IntPtr hwnd); |
|
|
|
|
|
|
|
[DllImport("ole32.dll", EntryPoint = "OleInitialize")] |
|
|
|
public static extern HRESULT OleInitialize(IntPtr val); |
|
|
|
|
|
|
|
|
|
|
|
@ -7,9 +7,9 @@ using Avalonia.Win32.Interop; |
|
|
|
|
|
|
|
namespace Avalonia.Win32 |
|
|
|
{ |
|
|
|
class OleContext |
|
|
|
internal class OleContext |
|
|
|
{ |
|
|
|
private static OleContext fCurrent; |
|
|
|
private static OleContext s_current; |
|
|
|
|
|
|
|
internal static OleContext Current |
|
|
|
{ |
|
|
|
@ -18,13 +18,12 @@ namespace Avalonia.Win32 |
|
|
|
if (!IsValidOleThread()) |
|
|
|
return null; |
|
|
|
|
|
|
|
if (fCurrent == null) |
|
|
|
fCurrent = new OleContext(); |
|
|
|
return fCurrent; |
|
|
|
if (s_current == null) |
|
|
|
s_current = new OleContext(); |
|
|
|
return s_current; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private OleContext() |
|
|
|
{ |
|
|
|
UnmanagedMethods.HRESULT res = UnmanagedMethods.OleInitialize(IntPtr.Zero); |
|
|
|
@ -43,9 +42,21 @@ namespace Avalonia.Win32 |
|
|
|
internal bool RegisterDragDrop(IPlatformHandle hwnd, IDropTarget target) |
|
|
|
{ |
|
|
|
if (hwnd?.HandleDescriptor != "HWND" || target == null) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return UnmanagedMethods.RegisterDragDrop(hwnd.Handle, target) == UnmanagedMethods.HRESULT.S_OK; |
|
|
|
} |
|
|
|
|
|
|
|
internal bool UnregisterDragDrop(IPlatformHandle hwnd) |
|
|
|
{ |
|
|
|
if (hwnd?.HandleDescriptor != "HWND") |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return UnmanagedMethods.RevokeDragDrop(hwnd.Handle) == UnmanagedMethods.HRESULT.S_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -6,7 +6,7 @@ using IDataObject = Avalonia.Input.IDataObject; |
|
|
|
|
|
|
|
namespace Avalonia.Win32 |
|
|
|
{ |
|
|
|
class OleDropTarget : IDropTarget |
|
|
|
internal class OleDropTarget : IDropTarget |
|
|
|
{ |
|
|
|
private readonly IInputRoot _target; |
|
|
|
private readonly ITopLevelImpl _tl; |
|
|
|
|
|
|
|
@ -253,6 +253,11 @@ namespace Avalonia.Win32 |
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
{ |
|
|
|
if (_dropTarget != null) |
|
|
|
{ |
|
|
|
OleContext.Current?.UnregisterDragDrop(Handle); |
|
|
|
_dropTarget = null; |
|
|
|
} |
|
|
|
if (_hwnd != IntPtr.Zero) |
|
|
|
{ |
|
|
|
UnmanagedMethods.DestroyWindow(_hwnd); |
|
|
|
|