1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-02 22:36:00 +02:00

Add support for file drag drop

This commit is contained in:
disarray2077 2022-01-07 12:51:57 -03:00
parent 73376d2f75
commit 6d2803dbb1
7 changed files with 94 additions and 18 deletions

View file

@ -48,6 +48,7 @@ namespace Beefy
ShowMinimized = 0x0200'0000,
ShowMaximized = 0x0400'0000,
AllowFullscreen = 0x0800'0000,
AcceptFiles = 0x1000'0000
};
[AllowDuplicates]
@ -127,7 +128,8 @@ namespace Beefy
delegate void NativeMouseUpDelegate(void* window, int32 x, int32 y, int32 btn);
delegate void NativeMouseWheelDelegate(void* window, int32 x, int32 y, float deltaX, float deltaY);
delegate void NativeMouseLeaveDelegate(void* window);
delegate void NativeMenuItemSelectedDelegate(void* window, void* menu);
delegate void NativeMenuItemSelectedDelegate(void* window, void* menu);
delegate void NativeDragDropFileDelegate(void* window, char8* filePath);
public void* mNativeWindow;
public bool mNativeWindowClosed;
@ -178,6 +180,7 @@ namespace Beefy
static NativeMouseWheelDelegate sNativeMouseWheelDelegate ~ delete _;
static NativeMouseLeaveDelegate sNativeMouseLeaveDelegate ~ delete _;
static NativeMenuItemSelectedDelegate sNativeMenuItemSelectedDelegate ~ delete _;
static NativeDragDropFileDelegate sNativeDragDropFileDelegate ~ delete _;
[CallingConvention(.Stdcall), CLink]
static extern void* BFApp_CreateWindow(void* parent, char8* title, int32 x, int32 y, int32 width, int32 height, int32 windowFlags);
@ -190,7 +193,7 @@ namespace Beefy
void* gotFocusDelegate, void* lostFocusDelegate,
void* keyCharDelegate, void* keyDownDelegate, void* keyUpDelegate, void* hitTestDelegate,
void* mouseMoveDelegate, void* mouseProxyMoveDelegate, void* mouseDownDelegate, void* mouseUpDelegate, void* mouseWheelDelegate, void* mouseLeaveDelegate,
void* menuItemSelectedDelegate);
void* menuItemSelectedDelegate, void* dragDropFileDelegate);
[CallingConvention(.Stdcall), CLink]
static extern void BFWindow_SetTitle(void* window, char8* title);
@ -299,6 +302,7 @@ namespace Beefy
static void Static_NativeMouseWheelDelegate(void* window, int32 mouseX, int32 mouseY, float deltaX, float deltaY) { GetBFWindow(window).MouseWheel(mouseX, mouseY, deltaX, deltaY); }
static void Static_NativeMouseLeaveDelegate(void* window) { GetBFWindow(window).MouseLeave(); }
static void Static_NativeMenuItemSelectedDelegate(void* window, void* item) { GetBFWindow(window).NativeMenuItemSelected(item); }
static void Static_NativeDragDropFileDelegate(void* window, char8* filePath) { GetBFWindow(window).DragDropFile(StringView(filePath)); }
#endif
public this()
@ -351,12 +355,13 @@ namespace Beefy
sNativeMouseWheelDelegate = new => Static_NativeMouseWheelDelegate;
sNativeMouseLeaveDelegate = new => Static_NativeMouseLeaveDelegate;
sNativeMenuItemSelectedDelegate = new => Static_NativeMenuItemSelectedDelegate;
sNativeDragDropFileDelegate = new => Static_NativeDragDropFileDelegate;
}
BFWindow_SetCallbacks(mNativeWindow, sNativeMovedDelegate.GetFuncPtr(), sNativeCloseQueryDelegate.GetFuncPtr(), sNativeClosedDelegate.GetFuncPtr(), sNativeGotFocusDelegate.GetFuncPtr(), sNativeLostFocusDelegate.GetFuncPtr(),
sNativeKeyCharDelegate.GetFuncPtr(), sNativeKeyDownDelegate.GetFuncPtr(), sNativeKeyUpDelegate.GetFuncPtr(), sNativeHitTestDelegate.GetFuncPtr(),
sNativeMouseMoveDelegate.GetFuncPtr(), sNativeMouseProxyMoveDelegate.GetFuncPtr(), sNativeMouseDownDelegate.GetFuncPtr(), sNativeMouseUpDelegate.GetFuncPtr(), sNativeMouseWheelDelegate.GetFuncPtr(), sNativeMouseLeaveDelegate.GetFuncPtr(),
sNativeMenuItemSelectedDelegate.GetFuncPtr());
sNativeMenuItemSelectedDelegate.GetFuncPtr(), sNativeDragDropFileDelegate.GetFuncPtr());
BFApp.sApp.mWindows.Add(this);
mDefaultDrawLayer = new DrawLayer(this);
@ -575,6 +580,10 @@ namespace Beefy
MenuItemSelected(aSysMenu);
}
public virtual void DragDropFile(StringView filePath)
{
}
public virtual SysBitmap LoadSysBitmap(String path)
{
return null;

View file

@ -17,6 +17,7 @@ namespace Beefy.widgets
public delegate void MouseWheelHandler(MouseEvent mouseEvent);
public delegate void KeyDownHandler(KeyDownEvent keyboardEvent);
//public delegate void CloseTemporaryHandler(WidgetWindow window);
public delegate void DragDropFileHandler(StringView filePath);
public class WidgetWindow : BFWindow
{
@ -31,6 +32,7 @@ namespace Beefy.widgets
public Event<MenuItemSelectedHandler> mOnMenuItemSelected ~ _.Dispose();
public Event<KeyDownHandler> mOnWindowKeyDown ~ _.Dispose();
public Event<delegate HitTestResult(int32, int32)> mOnHitTest ~ _.Dispose();
public Event<DragDropFileHandler> mOnDragDropFile ~ _.Dispose();
public static Event<MouseLeftWindowHandler> sOnMouseLeftWindow ~ _.Dispose();
public static Event<WindowLostFocusHandler> sOnWindowLostFocus ~ _.Dispose();
@ -811,6 +813,12 @@ namespace Beefy.widgets
sOnMenuItemSelected(sysMenu);
base.MenuItemSelected(sysMenu);
}
public override void DragDropFile(StringView filePath)
{
mOnDragDropFile(filePath);
base.DragDropFile(filePath);
}
public void TransferMouse(WidgetWindow newMouseWindow)
{