diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index 0003ffb9..bbfe62a6 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -263,6 +263,20 @@ class Window { return false; } + /// called when user dragged file(s) to application window + void handleDroppedFiles(string[] filenames) { + //Log.d("handleDroppedFiles(", filenames, ")"); + if (_onFilesDropped) + _onFilesDropped(filenames); + } + + protected void delegate(string[]) _onFilesDropped; + /// get handler for files dropped to app window + @property void delegate(string[]) onFilesDropped() { return _onFilesDropped; } + /// set handler for files dropped to app window + @property Window onFilesDropped(void delegate(string[]) handler) { _onFilesDropped = handler; return this; } + + /// hide tooltip if shown and cancel tooltip timer if set void hideTooltip() { if (_tooltip.popup) { diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d index ba7b46b9..72b6c061 100644 --- a/src/dlangui/platforms/windows/winapp.d +++ b/src/dlangui/platforms/windows/winapp.d @@ -200,7 +200,6 @@ class Win32Window : Window { null, // window menu handle _hInstance, // program instance handle cast(void*)this); // creation parameters - version (USE_OPENGL) { import derelict.opengl3.wgl; @@ -324,6 +323,13 @@ class Win32Window : Window { PostMessageW(_hwnd, CUSTOM_MESSAGE_ID, 0, event.uniqueId); } + /// set handler for files dropped to app window + override @property Window onFilesDropped(void delegate(string[]) handler) { + super.onFilesDropped(handler); + DragAcceptFiles(_hwnd, handler ? TRUE : FALSE); + return this; + } + private long _nextExpectedTimerTs; private UINT_PTR _timerId = 1; @@ -1141,6 +1147,23 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) return 0; } break; + case WM_DROPFILES: + if (window !is null) { + HDROP hdrop = cast(HDROP)wParam; + string[] files; + wchar[] buf; + auto count = DragQueryFileW(hdrop, 0xFFFFFFFF, cast(wchar*)NULL, 0); + for (int i = 0; i < count; i++) { + auto sz = DragQueryFileW(hdrop, i, cast(wchar*)NULL, 0); + buf.length = sz + 2; + sz = DragQueryFileW(hdrop, i, buf.ptr, sz + 1); + files ~= toUTF8(buf[0..sz]); + } + if (files.length) + window.handleDroppedFiles(files); + DragFinish(hdrop); + } + return 0; case WM_GETMINMAXINFO: case WM_NCCREATE: case WM_NCCALCSIZE: