|
30 | 30 |
|
31 | 31 | #include "display_server_windows.h" |
32 | 32 |
|
| 33 | +#include "drop_target_windows.h" |
33 | 34 | #include "os_windows.h" |
34 | 35 | #include "wgl_detect_version.h" |
35 | 36 |
|
@@ -1617,11 +1618,17 @@ void DisplayServerWindows::delete_sub_window(WindowID p_window) { |
1617 | 1618 | } |
1618 | 1619 | #endif |
1619 | 1620 |
|
1620 | | - if ((tablet_get_current_driver() == "wintab") && wintab_available && windows[p_window].wtctx) { |
1621 | | - wintab_WTClose(windows[p_window].wtctx); |
1622 | | - windows[p_window].wtctx = nullptr; |
| 1621 | + if ((tablet_get_current_driver() == "wintab") && wintab_available && wd.wtctx) { |
| 1622 | + wintab_WTClose(wd.wtctx); |
| 1623 | + wd.wtctx = nullptr; |
| 1624 | + } |
| 1625 | + |
| 1626 | + if (wd.drop_target != nullptr) { |
| 1627 | + RevokeDragDrop(wd.hWnd); |
| 1628 | + wd.drop_target->Release(); |
1623 | 1629 | } |
1624 | | - DestroyWindow(windows[p_window].hWnd); |
| 1630 | + |
| 1631 | + DestroyWindow(wd.hWnd); |
1625 | 1632 | windows.erase(p_window); |
1626 | 1633 |
|
1627 | 1634 | if (last_focused_window == p_window) { |
@@ -1731,7 +1738,14 @@ void DisplayServerWindows::window_set_drop_files_callback(const Callable &p_call |
1731 | 1738 | _THREAD_SAFE_METHOD_ |
1732 | 1739 |
|
1733 | 1740 | ERR_FAIL_COND(!windows.has(p_window)); |
1734 | | - windows[p_window].drop_files_callback = p_callable; |
| 1741 | + WindowData &window_data = windows[p_window]; |
| 1742 | + |
| 1743 | + window_data.drop_files_callback = p_callable; |
| 1744 | + |
| 1745 | + if (window_data.drop_target == nullptr) { |
| 1746 | + window_data.drop_target = memnew(DropTargetWindows(&window_data)); |
| 1747 | + ERR_FAIL_COND(RegisterDragDrop(window_data.hWnd, window_data.drop_target) != S_OK); |
| 1748 | + } |
1735 | 1749 | } |
1736 | 1750 |
|
1737 | 1751 | void DisplayServerWindows::window_set_title(const String &p_title, WindowID p_window) { |
@@ -5320,32 +5334,6 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA |
5320 | 5334 | } |
5321 | 5335 | } |
5322 | 5336 | } break; |
5323 | | - case WM_DROPFILES: { |
5324 | | - HDROP hDropInfo = (HDROP)wParam; |
5325 | | - const int buffsize = 4096; |
5326 | | - WCHAR buf[buffsize]; |
5327 | | - |
5328 | | - int fcount = DragQueryFileW(hDropInfo, 0xFFFFFFFF, nullptr, 0); |
5329 | | - |
5330 | | - Vector<String> files; |
5331 | | - |
5332 | | - for (int i = 0; i < fcount; i++) { |
5333 | | - DragQueryFileW(hDropInfo, i, buf, buffsize); |
5334 | | - String file = String::utf16((const char16_t *)buf); |
5335 | | - files.push_back(file); |
5336 | | - } |
5337 | | - |
5338 | | - if (files.size() && windows[window_id].drop_files_callback.is_valid()) { |
5339 | | - Variant v_files = files; |
5340 | | - const Variant *v_args[1] = { &v_files }; |
5341 | | - Variant ret; |
5342 | | - Callable::CallError ce; |
5343 | | - windows[window_id].drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce); |
5344 | | - if (ce.error != Callable::CallError::CALL_OK) { |
5345 | | - ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(windows[window_id].drop_files_callback, v_args, 1, ce))); |
5346 | | - } |
5347 | | - } |
5348 | | - } break; |
5349 | 5337 | default: { |
5350 | 5338 | if (user_proc) { |
5351 | 5339 | return CallWindowProcW(user_proc, hWnd, uMsg, wParam, lParam); |
@@ -6174,6 +6162,8 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win |
6174 | 6162 | FreeLibrary(comctl32); |
6175 | 6163 | } |
6176 | 6164 |
|
| 6165 | + OleInitialize(nullptr); |
| 6166 | + |
6177 | 6167 | memset(&wc, 0, sizeof(WNDCLASSEXW)); |
6178 | 6168 | wc.cbSize = sizeof(WNDCLASSEXW); |
6179 | 6169 | wc.style = CS_OWNDC | CS_DBLCLKS; |
@@ -6606,6 +6596,12 @@ DisplayServerWindows::~DisplayServerWindows() { |
6606 | 6596 | wintab_WTClose(windows[MAIN_WINDOW_ID].wtctx); |
6607 | 6597 | windows[MAIN_WINDOW_ID].wtctx = nullptr; |
6608 | 6598 | } |
| 6599 | + |
| 6600 | + if (windows[MAIN_WINDOW_ID].drop_target != nullptr) { |
| 6601 | + RevokeDragDrop(windows[MAIN_WINDOW_ID].hWnd); |
| 6602 | + windows[MAIN_WINDOW_ID].drop_target->Release(); |
| 6603 | + } |
| 6604 | + |
6609 | 6605 | DestroyWindow(windows[MAIN_WINDOW_ID].hWnd); |
6610 | 6606 | } |
6611 | 6607 |
|
@@ -6637,4 +6633,6 @@ DisplayServerWindows::~DisplayServerWindows() { |
6637 | 6633 | if (tts) { |
6638 | 6634 | memdelete(tts); |
6639 | 6635 | } |
| 6636 | + |
| 6637 | + OleUninitialize(); |
6640 | 6638 | } |
0 commit comments