|
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 |
|
@@ -1600,11 +1601,17 @@ void DisplayServerWindows::delete_sub_window(WindowID p_window) { |
1600 | 1601 | } |
1601 | 1602 | #endif |
1602 | 1603 |
|
1603 | | - if ((tablet_get_current_driver() == "wintab") && wintab_available && windows[p_window].wtctx) { |
1604 | | - wintab_WTClose(windows[p_window].wtctx); |
1605 | | - windows[p_window].wtctx = nullptr; |
| 1604 | + if ((tablet_get_current_driver() == "wintab") && wintab_available && wd.wtctx) { |
| 1605 | + wintab_WTClose(wd.wtctx); |
| 1606 | + wd.wtctx = nullptr; |
| 1607 | + } |
| 1608 | + |
| 1609 | + if (wd.drop_target != nullptr) { |
| 1610 | + RevokeDragDrop(wd.hWnd); |
| 1611 | + wd.drop_target->Release(); |
1606 | 1612 | } |
1607 | | - DestroyWindow(windows[p_window].hWnd); |
| 1613 | + |
| 1614 | + DestroyWindow(wd.hWnd); |
1608 | 1615 | windows.erase(p_window); |
1609 | 1616 |
|
1610 | 1617 | if (last_focused_window == p_window) { |
@@ -1702,7 +1709,14 @@ void DisplayServerWindows::window_set_drop_files_callback(const Callable &p_call |
1702 | 1709 | _THREAD_SAFE_METHOD_ |
1703 | 1710 |
|
1704 | 1711 | ERR_FAIL_COND(!windows.has(p_window)); |
1705 | | - windows[p_window].drop_files_callback = p_callable; |
| 1712 | + WindowData &window_data = windows[p_window]; |
| 1713 | + |
| 1714 | + window_data.drop_files_callback = p_callable; |
| 1715 | + |
| 1716 | + if (window_data.drop_target == nullptr) { |
| 1717 | + window_data.drop_target = memnew(DropTargetWindows(&window_data)); |
| 1718 | + ERR_FAIL_COND(RegisterDragDrop(window_data.hWnd, window_data.drop_target) != S_OK); |
| 1719 | + } |
1706 | 1720 | } |
1707 | 1721 |
|
1708 | 1722 | void DisplayServerWindows::window_set_title(const String &p_title, WindowID p_window) { |
@@ -5264,32 +5278,6 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA |
5264 | 5278 | } |
5265 | 5279 | } |
5266 | 5280 | } break; |
5267 | | - case WM_DROPFILES: { |
5268 | | - HDROP hDropInfo = (HDROP)wParam; |
5269 | | - const int buffsize = 4096; |
5270 | | - WCHAR buf[buffsize]; |
5271 | | - |
5272 | | - int fcount = DragQueryFileW(hDropInfo, 0xFFFFFFFF, nullptr, 0); |
5273 | | - |
5274 | | - Vector<String> files; |
5275 | | - |
5276 | | - for (int i = 0; i < fcount; i++) { |
5277 | | - DragQueryFileW(hDropInfo, i, buf, buffsize); |
5278 | | - String file = String::utf16((const char16_t *)buf); |
5279 | | - files.push_back(file); |
5280 | | - } |
5281 | | - |
5282 | | - if (files.size() && windows[window_id].drop_files_callback.is_valid()) { |
5283 | | - Variant v_files = files; |
5284 | | - const Variant *v_args[1] = { &v_files }; |
5285 | | - Variant ret; |
5286 | | - Callable::CallError ce; |
5287 | | - windows[window_id].drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce); |
5288 | | - if (ce.error != Callable::CallError::CALL_OK) { |
5289 | | - 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))); |
5290 | | - } |
5291 | | - } |
5292 | | - } break; |
5293 | 5281 | default: { |
5294 | 5282 | if (user_proc) { |
5295 | 5283 | return CallWindowProcW(user_proc, hWnd, uMsg, wParam, lParam); |
@@ -6112,6 +6100,8 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win |
6112 | 6100 | FreeLibrary(comctl32); |
6113 | 6101 | } |
6114 | 6102 |
|
| 6103 | + OleInitialize(nullptr); |
| 6104 | + |
6115 | 6105 | memset(&wc, 0, sizeof(WNDCLASSEXW)); |
6116 | 6106 | wc.cbSize = sizeof(WNDCLASSEXW); |
6117 | 6107 | wc.style = CS_OWNDC | CS_DBLCLKS; |
@@ -6538,6 +6528,12 @@ DisplayServerWindows::~DisplayServerWindows() { |
6538 | 6528 | wintab_WTClose(windows[MAIN_WINDOW_ID].wtctx); |
6539 | 6529 | windows[MAIN_WINDOW_ID].wtctx = nullptr; |
6540 | 6530 | } |
| 6531 | + |
| 6532 | + if (windows[MAIN_WINDOW_ID].drop_target != nullptr) { |
| 6533 | + RevokeDragDrop(windows[MAIN_WINDOW_ID].hWnd); |
| 6534 | + windows[MAIN_WINDOW_ID].drop_target->Release(); |
| 6535 | + } |
| 6536 | + |
6541 | 6537 | DestroyWindow(windows[MAIN_WINDOW_ID].hWnd); |
6542 | 6538 | } |
6543 | 6539 |
|
@@ -6569,4 +6565,6 @@ DisplayServerWindows::~DisplayServerWindows() { |
6569 | 6565 | if (tts) { |
6570 | 6566 | memdelete(tts); |
6571 | 6567 | } |
| 6568 | + |
| 6569 | + OleUninitialize(); |
6572 | 6570 | } |
0 commit comments