The functional remains of drop source

This commit is contained in:
Simon Lübeß
2025-06-29 21:40:55 +02:00
parent 39c9109919
commit 173942114f
5 changed files with 147 additions and 65 deletions
@@ -0,0 +1,127 @@
using System;
using DirectX.Common;
using GlitchyEngine.Platform.Windows.Com;
namespace GlitchyEditor.Platform.Windows;
[CRepr]
public struct IDataObject : IUnknown
{
public const new Guid IID = .(0x0000010e, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
public new VTable* VT { get => (.)mVT; }
public HResult GetData(ref FORMATETC pformatetcIn, out STGMEDIUM pmedium) mut => VT.GetData(&this, ref pformatetcIn, out pmedium);
public HResult GetDataHere(ref FORMATETC pformatetc, out STGMEDIUM pmedium) mut => VT.GetDataHere(&this, ref pformatetc, out pmedium);
public HResult QueryGetData(ref FORMATETC pformatetc) mut => VT.QueryGetData(&this, ref pformatetc);
public HResult GetCanonicalFormatEtc(ref FORMATETC pformatectIn, out FORMATETC pformatetcOut) mut => VT.GetCanonicalFormatEtc(&this, ref pformatectIn, out pformatetcOut);
public HResult SetData(ref FORMATETC pformatetc, ref STGMEDIUM pmedium, BigBool fRelease) mut => VT.SetData(&this, ref pformatetc, ref pmedium, fRelease);
public HResult EnumFormatEtc(uint32 dwDirection, out /*IEnumFORMATETC*/ IUnknown* ppenumFormatEtc) mut => VT.EnumFormatEtc(&this, dwDirection, out ppenumFormatEtc);
public HResult DAdvise(ref FORMATETC pformatetc, uint32 advf, ref /*IAdviseSink*/ IUnknown* pAdvSink, out uint32 pdwConnection) mut => VT.DAdvise(&this, ref pformatetc, advf, ref pAdvSink, out pdwConnection);
public HResult DUnadvise(uint32 dwConnection) mut => VT.DUnadvise(&this, dwConnection);
public HResult EnumDAdvise(out /*IEnumSTATDATA*/ IUnknown* ppenumAdvise) mut => VT.EnumDAdvise(&this, out ppenumAdvise);
[CRepr]
public struct VTable : IUnknown.VTable
{
public new function [CallingConvention(.Stdcall)] HResult(IDataObject* self, ref FORMATETC pformatetcIn, out STGMEDIUM pmedium) GetData;
public new function [CallingConvention(.Stdcall)] HResult(IDataObject* self, ref FORMATETC pformatetc, out STGMEDIUM pmedium) GetDataHere;
public new function [CallingConvention(.Stdcall)] HResult(IDataObject* self, ref FORMATETC pformatetc) QueryGetData;
public new function [CallingConvention(.Stdcall)] HResult(IDataObject* self, ref FORMATETC pformatectIn, out FORMATETC pformatetcOut) GetCanonicalFormatEtc;
public new function [CallingConvention(.Stdcall)] HResult(IDataObject* self, ref FORMATETC pformatetc, ref STGMEDIUM pmedium, BigBool fRelease) SetData;
public new function [CallingConvention(.Stdcall)] HResult(IDataObject* self, uint32 dwDirection, out /*IEnumFORMATETC*/ IUnknown* ppenumFormatEtc) EnumFormatEtc;
public new function [CallingConvention(.Stdcall)] HResult(IDataObject* self, ref FORMATETC pformatetc, uint32 advf, ref /*IAdviseSink*/ IUnknown* pAdvSink, out uint32 pdwConnection) DAdvise;
public new function [CallingConvention(.Stdcall)] HResult(IDataObject* self, uint32 dwConnection) DUnadvise;
public new function [CallingConvention(.Stdcall)] HResult(IDataObject* self, out /*IEnumSTATDATA*/ IUnknown* ppenumAdvise) EnumDAdvise;
}
}
abstract class IDataObjectImplBase : IUnknownImplBase<IDataObject, IDataObject.VTable>
{
protected override void InitVTable(ref IDataObject.VTable vTable)
{
vTable.GetData = => GetDataImpl;
vTable.GetDataHere = => GetDataHereImpl;
vTable.QueryGetData = => QueryGetDataImpl;
vTable.GetCanonicalFormatEtc = => GetCanonicalFormatEtcImpl;
vTable.SetData = => SetDataImpl;
vTable.EnumFormatEtc = => EnumFormatEtcImpl;
vTable.DAdvise = => DAdviseImpl;
vTable.DUnadvise = => DUnadviseImpl;
vTable.EnumDAdvise = => EnumDAdviseImpl;
}
[CallingConvention(.Stdcall)]
private static HResult GetDataImpl(IDataObject* self, ref FORMATETC pformatetcIn, out STGMEDIUM pmedium)
{
Self instance = GetInstance<Self>(self);
return instance.GetData(ref pformatetcIn, out pmedium);
}
[CallingConvention(.Stdcall)]
private static HResult GetDataHereImpl(IDataObject* self, ref FORMATETC pformatetc, out STGMEDIUM pmedium)
{
Self instance = GetInstance<Self>(self);
return instance.GetDataHere(ref pformatetc, out pmedium);
}
[CallingConvention(.Stdcall)]
private static HResult QueryGetDataImpl(IDataObject* self, ref FORMATETC pformatetc)
{
Self instance = GetInstance<Self>(self);
return instance.QueryGetData(ref pformatetc);
}
[CallingConvention(.Stdcall)]
private static HResult GetCanonicalFormatEtcImpl(IDataObject* self, ref FORMATETC pformatectIn, out FORMATETC pformatetcOut)
{
Self instance = GetInstance<Self>(self);
return instance.GetCanonicalFormatEtc(ref pformatectIn, out pformatetcOut);
}
[CallingConvention(.Stdcall)]
private static HResult SetDataImpl(IDataObject* self, ref FORMATETC pformatetc, ref STGMEDIUM pmedium, BigBool fRelease)
{
Self instance = GetInstance<Self>(self);
return instance.SetData(ref pformatetc, ref pmedium, fRelease);
}
[CallingConvention(.Stdcall)]
private static HResult EnumFormatEtcImpl(IDataObject* self, uint32 dwDirection, out IUnknown* ppenumFormatEtc)
{
Self instance = GetInstance<Self>(self);
return instance.EnumFormatEtc(dwDirection, out ppenumFormatEtc);
}
[CallingConvention(.Stdcall)]
private static HResult DAdviseImpl(IDataObject* self, ref FORMATETC pformatetc, uint32 advf, ref IUnknown* pAdvSink, out uint32 pdwConnection)
{
Self instance = GetInstance<Self>(self);
return instance.DAdvise(ref pformatetc, advf, ref pAdvSink, out pdwConnection);
}
[CallingConvention(.Stdcall)]
private static HResult DUnadviseImpl(IDataObject* self, uint32 dwConnection)
{
Self instance = GetInstance<Self>(self);
return instance.DUnadvise(dwConnection);
}
[CallingConvention(.Stdcall)]
private static HResult EnumDAdviseImpl(IDataObject* self, out IUnknown* ppenumAdvise)
{
Self instance = GetInstance<Self>(self);
return instance.EnumDAdvise(out ppenumAdvise);
}
// Abstract methods to be implemented by derived classes
public abstract HResult GetData(ref FORMATETC pformatetcIn, out STGMEDIUM pmedium);
public abstract HResult GetDataHere(ref FORMATETC pformatetc, out STGMEDIUM pmedium);
public abstract HResult QueryGetData(ref FORMATETC pformatetc);
public abstract HResult GetCanonicalFormatEtc(ref FORMATETC pformatectIn, out FORMATETC pformatetcOut);
public abstract HResult SetData(ref FORMATETC pformatetc, ref STGMEDIUM pmedium, BigBool fRelease);
public abstract HResult EnumFormatEtc(uint32 dwDirection, out IUnknown* ppenumFormatEtc);
public abstract HResult DAdvise(ref FORMATETC pformatetc, uint32 advf, ref IUnknown* pAdvSink, out uint32 pdwConnection);
public abstract HResult DUnadvise(uint32 dwConnection);
public abstract HResult EnumDAdvise(out IUnknown* ppenumAdvise);
}
@@ -31,6 +31,9 @@ abstract class IDropSourceImplBase : IUnknownImplBase<IDropSource, IDropSource.V
vTable.QueryContinueDrag = => QueryContinueDragImpl; vTable.QueryContinueDrag = => QueryContinueDragImpl;
vTable.GiveFeedback = => GiveFeedbackImpl; vTable.GiveFeedback = => GiveFeedbackImpl;
} }
private const int32 DRAGDROP_S_DROP = 262400;
private const int32 DRAGDROP_S_CANCEL = 262401;
[CallingConvention(.Stdcall)] [CallingConvention(.Stdcall)]
private static HResult QueryContinueDragImpl(IDropSource* self, BigBool fEscapePressed, uint32 grfKeyState) private static HResult QueryContinueDragImpl(IDropSource* self, BigBool fEscapePressed, uint32 grfKeyState)
@@ -39,12 +42,15 @@ abstract class IDropSourceImplBase : IUnknownImplBase<IDropSource, IDropSource.V
// TODO: Translate keyStates (MK_CONTROL, etc...) // TODO: Translate keyStates (MK_CONTROL, etc...)
if (instance.QueryContinueDrag(fEscapePressed, grfKeyState) case .Ok) switch (instance.QueryContinueDrag(fEscapePressed, grfKeyState))
{ {
case .Continue:
return .S_OK; return .S_OK;
case .Drop:
return (.)DRAGDROP_S_DROP;
case .Cancel:
return (.)DRAGDROP_S_CANCEL;
} }
return .E_FAIL;
} }
[CallingConvention(.Stdcall)] [CallingConvention(.Stdcall)]
@@ -59,22 +65,16 @@ abstract class IDropSourceImplBase : IUnknownImplBase<IDropSource, IDropSource.V
return .E_FAIL; return .E_FAIL;
} }
public abstract Result<void> QueryContinueDrag(bool escapePressed, uint32 grfKeyState); public enum ContinueDrag
{
Continue,
Drop,
Cancel
}
public abstract ContinueDrag QueryContinueDrag(bool escapePressed, uint32 grfKeyState);
public abstract Result<void> GiveFeedback(DropEffect effect); public abstract Result<void> GiveFeedback(DropEffect effect);
} }
class MyDropSource : IDropSourceImplBase
{
public override Result<void> QueryContinueDrag(bool escapePressed, uint32 grfKeyState)
{
Runtime.NotImplemented();
}
public override Result<void> GiveFeedback(DropEffect effect)
{
Runtime.NotImplemented();
}
}
#endif #endif
@@ -101,43 +101,12 @@ public struct STGMEDIUM
public HBITMAP hBitmap; public HBITMAP hBitmap;
public void* hMetaFilePict; public void* hMetaFilePict;
public HENHMETAFILE hEnhMetaFile; public HENHMETAFILE hEnhMetaFile;
public int hGlobal; public Handle hGlobal;
public PWSTR lpszFileName; public PWSTR lpszFileName;
public /*IStream*/IUnknown* pstm; public /*IStream*/IUnknown* pstm;
public /*IStorage*/IUnknown* pstg; public /*IStorage*/IUnknown* pstg;
} }
} }
[CRepr]
public struct IDataObject : IUnknown
{
public const new Guid IID = .(0x0000010e, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
public new VTable* VT { get => (.)mVT; }
public HResult GetData(ref FORMATETC pformatetcIn, out STGMEDIUM pmedium) mut => VT.GetData(ref this, ref pformatetcIn, out pmedium);
public HResult GetDataHere(ref FORMATETC pformatetc, out STGMEDIUM pmedium) mut => VT.GetDataHere(ref this, ref pformatetc, out pmedium);
public HResult QueryGetData(ref FORMATETC pformatetc) mut => VT.QueryGetData(ref this, ref pformatetc);
public HResult GetCanonicalFormatEtc(ref FORMATETC pformatectIn, out FORMATETC pformatetcOut) mut => VT.GetCanonicalFormatEtc(ref this, ref pformatectIn, out pformatetcOut);
public HResult SetData(ref FORMATETC pformatetc, ref STGMEDIUM pmedium, BigBool fRelease) mut => VT.SetData(ref this, ref pformatetc, ref pmedium, fRelease);
public HResult EnumFormatEtc(uint32 dwDirection, out /*IEnumFORMATETC*/ IUnknown* ppenumFormatEtc) mut => VT.EnumFormatEtc(ref this, dwDirection, out ppenumFormatEtc);
public HResult DAdvise(ref FORMATETC pformatetc, uint32 advf, ref /*IAdviseSink*/ IUnknown* pAdvSink, out uint32 pdwConnection) mut => VT.DAdvise(ref this, ref pformatetc, advf, ref pAdvSink, out pdwConnection);
public HResult DUnadvise(uint32 dwConnection) mut => VT.DUnadvise(ref this, dwConnection);
public HResult EnumDAdvise(out /*IEnumSTATDATA*/ IUnknown* ppenumAdvise) mut => VT.EnumDAdvise(ref this, out ppenumAdvise);
[CRepr]
public struct VTable : IUnknown.VTable
{
public new function [CallingConvention(.Stdcall)] HResult(ref IDataObject self, ref FORMATETC pformatetcIn, out STGMEDIUM pmedium) GetData;
public new function [CallingConvention(.Stdcall)] HResult(ref IDataObject self, ref FORMATETC pformatetc, out STGMEDIUM pmedium) GetDataHere;
public new function [CallingConvention(.Stdcall)] HResult(ref IDataObject self, ref FORMATETC pformatetc) QueryGetData;
public new function [CallingConvention(.Stdcall)] HResult(ref IDataObject self, ref FORMATETC pformatectIn, out FORMATETC pformatetcOut) GetCanonicalFormatEtc;
public new function [CallingConvention(.Stdcall)] HResult(ref IDataObject self, ref FORMATETC pformatetc, ref STGMEDIUM pmedium, BigBool fRelease) SetData;
public new function [CallingConvention(.Stdcall)] HResult(ref IDataObject self, uint32 dwDirection, out /*IEnumFORMATETC*/ IUnknown* ppenumFormatEtc) EnumFormatEtc;
public new function [CallingConvention(.Stdcall)] HResult(ref IDataObject self, ref FORMATETC pformatetc, uint32 advf, ref /*IAdviseSink*/ IUnknown* pAdvSink, out uint32 pdwConnection) DAdvise;
public new function [CallingConvention(.Stdcall)] HResult(ref IDataObject self, uint32 dwConnection) DUnadvise;
public new function [CallingConvention(.Stdcall)] HResult(ref IDataObject self, out /*IEnumSTATDATA*/ IUnknown* ppenumAdvise) EnumDAdvise;
}
}
[CRepr] [CRepr]
enum DropEffect enum DropEffect
@@ -27,20 +27,6 @@ extension DragDropManager
_dragDropTarget.Unregister(); _dragDropTarget.Unregister();
ReleaseRefAndNullify!(_dragDropTarget); ReleaseRefAndNullify!(_dragDropTarget);
} }
private static bool _isDragging;
public static void StartDragDrop()
{
if (_isDragging)
return;
_isDragging = true;
IDataObject* dataObject = null;
//HResult result = DoDragDrop(ref dataObject);
}
} }
/// Registers a Windows drag'n'drop target that will fire Windows drop related events using the engine's event system. /// Registers a Windows drag'n'drop target that will fire Windows drop related events using the engine's event system.
@@ -19,7 +19,7 @@ abstract class IUnknownImplBase<TInterface, TVTable> : RefCounter where TInterfa
private static TVTable vTable; private static TVTable vTable;
protected TInterface* InterfacePtr => (TInterface*)&impl; public TInterface* InterfacePtr => (TInterface*)&impl;
public this() public this()
{ {