diff --git a/GlitchyEditor/src/Platform/Windows/DataObject.bf b/GlitchyEditor/src/Platform/Windows/DataObject.bf new file mode 100644 index 0000000..4505e55 --- /dev/null +++ b/GlitchyEditor/src/Platform/Windows/DataObject.bf @@ -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 +{ + 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); + 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); + return instance.GetDataHere(ref pformatetc, out pmedium); + } + + [CallingConvention(.Stdcall)] + private static HResult QueryGetDataImpl(IDataObject* self, ref FORMATETC pformatetc) + { + Self instance = GetInstance(self); + return instance.QueryGetData(ref pformatetc); + } + + [CallingConvention(.Stdcall)] + private static HResult GetCanonicalFormatEtcImpl(IDataObject* self, ref FORMATETC pformatectIn, out FORMATETC pformatetcOut) + { + Self instance = GetInstance(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); + 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); + 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); + return instance.DAdvise(ref pformatetc, advf, ref pAdvSink, out pdwConnection); + } + + [CallingConvention(.Stdcall)] + private static HResult DUnadviseImpl(IDataObject* self, uint32 dwConnection) + { + Self instance = GetInstance(self); + return instance.DUnadvise(dwConnection); + } + + [CallingConvention(.Stdcall)] + private static HResult EnumDAdviseImpl(IDataObject* self, out IUnknown* ppenumAdvise) + { + Self instance = GetInstance(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); +} diff --git a/GlitchyEditor/src/Platform/Windows/DropSource.bf b/GlitchyEditor/src/Platform/Windows/DropSource.bf index 3659c24..885a9e4 100644 --- a/GlitchyEditor/src/Platform/Windows/DropSource.bf +++ b/GlitchyEditor/src/Platform/Windows/DropSource.bf @@ -31,6 +31,9 @@ abstract class IDropSourceImplBase : IUnknownImplBase QueryContinueDragImpl; vTable.GiveFeedback = => GiveFeedbackImpl; } + + private const int32 DRAGDROP_S_DROP = 262400; + private const int32 DRAGDROP_S_CANCEL = 262401; [CallingConvention(.Stdcall)] private static HResult QueryContinueDragImpl(IDropSource* self, BigBool fEscapePressed, uint32 grfKeyState) @@ -39,12 +42,15 @@ abstract class IDropSourceImplBase : IUnknownImplBase QueryContinueDrag(bool escapePressed, uint32 grfKeyState); + + public enum ContinueDrag + { + Continue, + Drop, + Cancel + } + + public abstract ContinueDrag QueryContinueDrag(bool escapePressed, uint32 grfKeyState); public abstract Result GiveFeedback(DropEffect effect); } -class MyDropSource : IDropSourceImplBase -{ - public override Result QueryContinueDrag(bool escapePressed, uint32 grfKeyState) - { - Runtime.NotImplemented(); - } - - public override Result GiveFeedback(DropEffect effect) - { - Runtime.NotImplemented(); - } -} - #endif diff --git a/GlitchyEditor/src/Platform/Windows/DropTarget.bf b/GlitchyEditor/src/Platform/Windows/DropTarget.bf index f17c586..b24b9dc 100644 --- a/GlitchyEditor/src/Platform/Windows/DropTarget.bf +++ b/GlitchyEditor/src/Platform/Windows/DropTarget.bf @@ -101,43 +101,12 @@ public struct STGMEDIUM public HBITMAP hBitmap; public void* hMetaFilePict; public HENHMETAFILE hEnhMetaFile; - public int hGlobal; + public Handle hGlobal; public PWSTR lpszFileName; public /*IStream*/IUnknown* pstm; 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] enum DropEffect diff --git a/GlitchyEditor/src/Platform/Windows/WindowsDragDropManager.bf b/GlitchyEditor/src/Platform/Windows/WindowsDragDropManager.bf index 0df0134..6ee0a9e 100644 --- a/GlitchyEditor/src/Platform/Windows/WindowsDragDropManager.bf +++ b/GlitchyEditor/src/Platform/Windows/WindowsDragDropManager.bf @@ -27,20 +27,6 @@ extension DragDropManager _dragDropTarget.Unregister(); 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. diff --git a/GlitchyEngine/src/Platform/Windows/Com/IUnknownImpBase.bf b/GlitchyEngine/src/Platform/Windows/Com/IUnknownImpBase.bf index 3c8561a..3fd8ce5 100644 --- a/GlitchyEngine/src/Platform/Windows/Com/IUnknownImpBase.bf +++ b/GlitchyEngine/src/Platform/Windows/Com/IUnknownImpBase.bf @@ -19,7 +19,7 @@ abstract class IUnknownImplBase : RefCounter where TInterfa private static TVTable vTable; - protected TInterface* InterfacePtr => (TInterface*)&impl; + public TInterface* InterfacePtr => (TInterface*)&impl; public this() {