1 | /* $Id: VBoxDnD.cpp 93299 2022-01-18 11:23:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxDnD.cpp - Windows-specific bits of the drag and drop service.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_GUEST_DND
|
---|
23 | #include <iprt/win/windows.h>
|
---|
24 | #include "VBoxTray.h"
|
---|
25 | #include "VBoxHelpers.h"
|
---|
26 | #include "VBoxDnD.h"
|
---|
27 |
|
---|
28 | #include <VBox/VBoxGuestLib.h>
|
---|
29 | #include "VBox/HostServices/DragAndDropSvc.h"
|
---|
30 |
|
---|
31 | using namespace DragAndDropSvc;
|
---|
32 |
|
---|
33 | #include <iprt/asm.h>
|
---|
34 | #include <iprt/assert.h>
|
---|
35 | #include <iprt/ldr.h>
|
---|
36 | #include <iprt/list.h>
|
---|
37 | #include <iprt/mem.h>
|
---|
38 |
|
---|
39 | #include <iprt/cpp/mtlist.h>
|
---|
40 | #include <iprt/cpp/ministring.h>
|
---|
41 |
|
---|
42 | #include <iprt/cpp/mtlist.h>
|
---|
43 |
|
---|
44 | #include <VBox/err.h>
|
---|
45 | #include <VBox/log.h>
|
---|
46 |
|
---|
47 |
|
---|
48 | /*********************************************************************************************************************************
|
---|
49 | * Defined Constants And Macros *
|
---|
50 | *********************************************************************************************************************************/
|
---|
51 | /* Enable this define to see the proxy window(s) when debugging
|
---|
52 | * their behavior. Don't have this enabled in release builds! */
|
---|
53 | #ifdef DEBUG
|
---|
54 | //# define VBOX_DND_DEBUG_WND
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | /** The drag and drop window's window class. */
|
---|
58 | #define VBOX_DND_WND_CLASS "VBoxTrayDnDWnd"
|
---|
59 |
|
---|
60 | /** @todo Merge this with messages from VBoxTray.h. */
|
---|
61 | #define WM_VBOXTRAY_DND_MESSAGE WM_APP + 401
|
---|
62 |
|
---|
63 |
|
---|
64 | /*********************************************************************************************************************************
|
---|
65 | * Structures and Typedefs *
|
---|
66 | *********************************************************************************************************************************/
|
---|
67 | /** Function pointer for SendInput(). This only is available starting
|
---|
68 | * at NT4 SP3+. */
|
---|
69 | typedef BOOL (WINAPI *PFNSENDINPUT)(UINT, LPINPUT, int);
|
---|
70 | typedef BOOL (WINAPI* PFNENUMDISPLAYMONITORS)(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
|
---|
71 |
|
---|
72 |
|
---|
73 | /*********************************************************************************************************************************
|
---|
74 | * Global Variables *
|
---|
75 | *********************************************************************************************************************************/
|
---|
76 | /** Static pointer to SendInput() function. */
|
---|
77 | static PFNSENDINPUT g_pfnSendInput = NULL;
|
---|
78 | static PFNENUMDISPLAYMONITORS g_pfnEnumDisplayMonitors = NULL;
|
---|
79 |
|
---|
80 | static VBOXDNDCONTEXT g_Ctx = { 0 };
|
---|
81 |
|
---|
82 |
|
---|
83 | /*********************************************************************************************************************************
|
---|
84 | * Internal Functions *
|
---|
85 | *********************************************************************************************************************************/
|
---|
86 | static LRESULT CALLBACK vboxDnDWndProcInstance(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) RT_NOTHROW_PROTO;
|
---|
87 | static LRESULT CALLBACK vboxDnDWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) RT_NOTHROW_PROTO;
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 | VBoxDnDWnd::VBoxDnDWnd(void)
|
---|
93 | : m_hThread(NIL_RTTHREAD),
|
---|
94 | m_EvtSem(NIL_RTSEMEVENT),
|
---|
95 | m_hWnd(NULL),
|
---|
96 | m_lstActionsAllowed(VBOX_DND_ACTION_IGNORE),
|
---|
97 | m_fMouseButtonDown(false),
|
---|
98 | #ifdef VBOX_WITH_DRAG_AND_DROP_GH
|
---|
99 | m_pDropTarget(NULL),
|
---|
100 | #endif
|
---|
101 | m_enmMode(Unknown),
|
---|
102 | m_enmState(Uninitialized)
|
---|
103 | {
|
---|
104 | RT_ZERO(m_startupInfo);
|
---|
105 |
|
---|
106 | LogFlowFunc(("Supported formats:\n"));
|
---|
107 | const RTCString arrEntries[] = { VBOX_DND_FORMATS_DEFAULT };
|
---|
108 | for (size_t i = 0; i < RT_ELEMENTS(arrEntries); i++)
|
---|
109 | {
|
---|
110 | LogFlowFunc(("\t%s\n", arrEntries[i].c_str()));
|
---|
111 | this->m_lstFmtSup.append(arrEntries[i]);
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | VBoxDnDWnd::~VBoxDnDWnd(void)
|
---|
116 | {
|
---|
117 | Destroy();
|
---|
118 | }
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Initializes the proxy window with a given DnD context.
|
---|
122 | *
|
---|
123 | * @return IPRT status code.
|
---|
124 | * @param a_pCtx Pointer to context to use.
|
---|
125 | */
|
---|
126 | int VBoxDnDWnd::Initialize(PVBOXDNDCONTEXT a_pCtx)
|
---|
127 | {
|
---|
128 | AssertPtrReturn(a_pCtx, VERR_INVALID_POINTER);
|
---|
129 |
|
---|
130 | /* Save the context. */
|
---|
131 | this->m_pCtx = a_pCtx;
|
---|
132 |
|
---|
133 | int rc = RTSemEventCreate(&m_EvtSem);
|
---|
134 | if (RT_SUCCESS(rc))
|
---|
135 | rc = RTCritSectInit(&m_CritSect);
|
---|
136 |
|
---|
137 | if (RT_SUCCESS(rc))
|
---|
138 | {
|
---|
139 | /* Message pump thread for our proxy window. */
|
---|
140 | rc = RTThreadCreate(&m_hThread, VBoxDnDWnd::Thread, this,
|
---|
141 | 0, RTTHREADTYPE_MSG_PUMP, RTTHREADFLAGS_WAITABLE,
|
---|
142 | "dndwnd"); /** @todo Include ID if there's more than one proxy window. */
|
---|
143 | if (RT_SUCCESS(rc))
|
---|
144 | {
|
---|
145 | int rc2 = RTThreadUserWait(m_hThread, 30 * 1000 /* Timeout in ms */);
|
---|
146 | AssertRC(rc2);
|
---|
147 |
|
---|
148 | if (!a_pCtx->fStarted) /* Did the thread fail to start? */
|
---|
149 | rc = VERR_NOT_SUPPORTED; /* Report back DnD as not being supported. */
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | if (RT_FAILURE(rc))
|
---|
154 | LogRel(("DnD: Failed to initialize proxy window, rc=%Rrc\n", rc));
|
---|
155 |
|
---|
156 | LogFlowThisFunc(("Returning rc=%Rrc\n", rc));
|
---|
157 | return rc;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Destroys the proxy window and releases all remaining
|
---|
162 | * resources again.
|
---|
163 | */
|
---|
164 | void VBoxDnDWnd::Destroy(void)
|
---|
165 | {
|
---|
166 | if (m_hThread != NIL_RTTHREAD)
|
---|
167 | {
|
---|
168 | int rcThread = VERR_WRONG_ORDER;
|
---|
169 | int rc = RTThreadWait(m_hThread, 60 * 1000 /* Timeout in ms */, &rcThread);
|
---|
170 | LogFlowFunc(("Waiting for thread resulted in %Rrc (thread exited with %Rrc)\n",
|
---|
171 | rc, rcThread));
|
---|
172 | NOREF(rc);
|
---|
173 | }
|
---|
174 |
|
---|
175 | Reset();
|
---|
176 |
|
---|
177 | RTCritSectDelete(&m_CritSect);
|
---|
178 | if (m_EvtSem != NIL_RTSEMEVENT)
|
---|
179 | {
|
---|
180 | RTSemEventDestroy(m_EvtSem);
|
---|
181 | m_EvtSem = NIL_RTSEMEVENT;
|
---|
182 | }
|
---|
183 |
|
---|
184 | if (m_pCtx->wndClass != 0)
|
---|
185 | {
|
---|
186 | UnregisterClass(VBOX_DND_WND_CLASS, m_pCtx->pEnv->hInstance);
|
---|
187 | m_pCtx->wndClass = 0;
|
---|
188 | }
|
---|
189 |
|
---|
190 | LogFlowFuncLeave();
|
---|
191 | }
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Thread for handling the window's message pump.
|
---|
195 | *
|
---|
196 | * @return IPRT status code.
|
---|
197 | * @param hThread Handle to this thread.
|
---|
198 | * @param pvUser Pointer to VBoxDnDWnd instance which
|
---|
199 | * is using the thread.
|
---|
200 | */
|
---|
201 | /*static*/ DECLCALLBACK(int) VBoxDnDWnd::Thread(RTTHREAD hThread, void *pvUser)
|
---|
202 | {
|
---|
203 | AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
|
---|
204 |
|
---|
205 | LogFlowFuncEnter();
|
---|
206 |
|
---|
207 | VBoxDnDWnd *pThis = (VBoxDnDWnd*)pvUser;
|
---|
208 | AssertPtr(pThis);
|
---|
209 |
|
---|
210 | PVBOXDNDCONTEXT m_pCtx = pThis->m_pCtx;
|
---|
211 | AssertPtr(m_pCtx);
|
---|
212 | AssertPtr(m_pCtx->pEnv);
|
---|
213 |
|
---|
214 | int rc = VINF_SUCCESS;
|
---|
215 |
|
---|
216 | AssertPtr(m_pCtx->pEnv);
|
---|
217 | HINSTANCE hInstance = m_pCtx->pEnv->hInstance;
|
---|
218 | Assert(hInstance != 0);
|
---|
219 |
|
---|
220 | /* Create our proxy window. */
|
---|
221 | WNDCLASSEX wc = { 0 };
|
---|
222 | wc.cbSize = sizeof(WNDCLASSEX);
|
---|
223 |
|
---|
224 | if (!GetClassInfoEx(hInstance, VBOX_DND_WND_CLASS, &wc))
|
---|
225 | {
|
---|
226 | wc.lpfnWndProc = vboxDnDWndProc;
|
---|
227 | wc.lpszClassName = VBOX_DND_WND_CLASS;
|
---|
228 | wc.hInstance = hInstance;
|
---|
229 | wc.style = CS_NOCLOSE;
|
---|
230 | #ifdef VBOX_DND_DEBUG_WND
|
---|
231 | wc.style |= CS_HREDRAW | CS_VREDRAW;
|
---|
232 | wc.hbrBackground = (HBRUSH)(CreateSolidBrush(RGB(255, 0, 0)));
|
---|
233 | #else
|
---|
234 | wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
|
---|
235 | #endif
|
---|
236 | if (!RegisterClassEx(&wc))
|
---|
237 | {
|
---|
238 | DWORD dwErr = GetLastError();
|
---|
239 | LogFlowFunc(("Unable to register proxy window class, error=%ld\n", dwErr));
|
---|
240 | rc = RTErrConvertFromWin32(dwErr);
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | if (RT_SUCCESS(rc))
|
---|
245 | {
|
---|
246 | DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE;
|
---|
247 | DWORD dwStyle = WS_POPUP;
|
---|
248 | #ifdef VBOX_DND_DEBUG_WND
|
---|
249 | dwExStyle &= ~WS_EX_TRANSPARENT; /* Remove transparency bit. */
|
---|
250 | dwStyle |= WS_VISIBLE; /* Make the window visible. */
|
---|
251 | #endif
|
---|
252 | pThis->m_hWnd = CreateWindowEx(dwExStyle,
|
---|
253 | VBOX_DND_WND_CLASS, VBOX_DND_WND_CLASS,
|
---|
254 | dwStyle,
|
---|
255 | #ifdef VBOX_DND_DEBUG_WND
|
---|
256 | CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, NULL, NULL,
|
---|
257 | #else
|
---|
258 | -200, -200, 100, 100, NULL, NULL,
|
---|
259 | #endif
|
---|
260 | hInstance, pThis /* lParm */);
|
---|
261 | if (!pThis->m_hWnd)
|
---|
262 | {
|
---|
263 | DWORD dwErr = GetLastError();
|
---|
264 | LogFlowFunc(("Unable to create proxy window, error=%ld\n", dwErr));
|
---|
265 | rc = RTErrConvertFromWin32(dwErr);
|
---|
266 | }
|
---|
267 | else
|
---|
268 | {
|
---|
269 | #ifndef VBOX_DND_DEBUG_WND
|
---|
270 | SetWindowPos(pThis->m_hWnd, HWND_TOPMOST, -200, -200, 0, 0,
|
---|
271 | SWP_NOACTIVATE | SWP_HIDEWINDOW
|
---|
272 | | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE);
|
---|
273 | LogFlowFunc(("Proxy window created, hWnd=0x%x\n", pThis->m_hWnd));
|
---|
274 | #else
|
---|
275 | LogFlowFunc(("Debug proxy window created, hWnd=0x%x\n", pThis->m_hWnd));
|
---|
276 |
|
---|
277 | /*
|
---|
278 | * Install some mouse tracking.
|
---|
279 | */
|
---|
280 | TRACKMOUSEEVENT me;
|
---|
281 | RT_ZERO(me);
|
---|
282 | me.cbSize = sizeof(TRACKMOUSEEVENT);
|
---|
283 | me.dwFlags = TME_HOVER | TME_LEAVE | TME_NONCLIENT;
|
---|
284 | me.hwndTrack = pThis->m_hWnd;
|
---|
285 | BOOL fRc = TrackMouseEvent(&me);
|
---|
286 | Assert(fRc);
|
---|
287 | #endif
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | HRESULT hr = OleInitialize(NULL);
|
---|
292 | if (SUCCEEDED(hr))
|
---|
293 | {
|
---|
294 | #ifdef VBOX_WITH_DRAG_AND_DROP_GH
|
---|
295 | rc = pThis->RegisterAsDropTarget();
|
---|
296 | #endif
|
---|
297 | }
|
---|
298 | else
|
---|
299 | {
|
---|
300 | LogRel(("DnD: Unable to initialize OLE, hr=%Rhrc\n", hr));
|
---|
301 | rc = VERR_COM_UNEXPECTED;
|
---|
302 | }
|
---|
303 |
|
---|
304 | if (RT_SUCCESS(rc))
|
---|
305 | m_pCtx->fStarted = true; /* Set started indicator on success. */
|
---|
306 |
|
---|
307 | int rc2 = RTThreadUserSignal(hThread);
|
---|
308 | bool fSignalled = RT_SUCCESS(rc2);
|
---|
309 |
|
---|
310 | if (RT_SUCCESS(rc))
|
---|
311 | {
|
---|
312 | bool fShutdown = false;
|
---|
313 | for (;;)
|
---|
314 | {
|
---|
315 | MSG uMsg;
|
---|
316 | BOOL fRet;
|
---|
317 | while ((fRet = GetMessage(&uMsg, 0, 0, 0)) > 0)
|
---|
318 | {
|
---|
319 | TranslateMessage(&uMsg);
|
---|
320 | DispatchMessage(&uMsg);
|
---|
321 | }
|
---|
322 | Assert(fRet >= 0);
|
---|
323 |
|
---|
324 | if (ASMAtomicReadBool(&m_pCtx->fShutdown))
|
---|
325 | fShutdown = true;
|
---|
326 |
|
---|
327 | if (fShutdown)
|
---|
328 | {
|
---|
329 | LogFlowFunc(("Closing proxy window ...\n"));
|
---|
330 | break;
|
---|
331 | }
|
---|
332 |
|
---|
333 | /** @todo Immediately drop on failure? */
|
---|
334 | }
|
---|
335 |
|
---|
336 | #ifdef VBOX_WITH_DRAG_AND_DROP_GH
|
---|
337 | rc2 = pThis->UnregisterAsDropTarget();
|
---|
338 | if (RT_SUCCESS(rc))
|
---|
339 | rc = rc2;
|
---|
340 | #endif
|
---|
341 | OleUninitialize();
|
---|
342 | }
|
---|
343 |
|
---|
344 | if (!fSignalled)
|
---|
345 | {
|
---|
346 | rc2 = RTThreadUserSignal(hThread);
|
---|
347 | AssertRC(rc2);
|
---|
348 | }
|
---|
349 |
|
---|
350 | LogFlowFuncLeaveRC(rc);
|
---|
351 | return rc;
|
---|
352 | }
|
---|
353 |
|
---|
354 | /**
|
---|
355 | * Monitor enumeration callback for building up a simple bounding
|
---|
356 | * box, capable of holding all enumerated monitors.
|
---|
357 | *
|
---|
358 | * @return BOOL TRUE if enumeration should continue,
|
---|
359 | * FALSE if not.
|
---|
360 | * @param hMonitor Handle to current monitor being enumerated.
|
---|
361 | * @param hdcMonitor The current monitor's DC (device context).
|
---|
362 | * @param lprcMonitor The current monitor's RECT.
|
---|
363 | * @param lParam Pointer to a RECT structure holding the
|
---|
364 | * bounding box to build.
|
---|
365 | */
|
---|
366 | /* static */
|
---|
367 | BOOL CALLBACK VBoxDnDWnd::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM lParam)
|
---|
368 | {
|
---|
369 | RT_NOREF(hMonitor, hdcMonitor);
|
---|
370 | LPRECT pRect = (LPRECT)lParam;
|
---|
371 | AssertPtrReturn(pRect, FALSE);
|
---|
372 |
|
---|
373 | AssertPtr(lprcMonitor);
|
---|
374 | LogFlowFunc(("Monitor is %ld,%ld,%ld,%ld\n",
|
---|
375 | lprcMonitor->left, lprcMonitor->top,
|
---|
376 | lprcMonitor->right, lprcMonitor->bottom));
|
---|
377 |
|
---|
378 | /* Build up a simple bounding box to hold the entire (virtual) screen. */
|
---|
379 | if (pRect->left > lprcMonitor->left)
|
---|
380 | pRect->left = lprcMonitor->left;
|
---|
381 | if (pRect->right < lprcMonitor->right)
|
---|
382 | pRect->right = lprcMonitor->right;
|
---|
383 | if (pRect->top > lprcMonitor->top)
|
---|
384 | pRect->top = lprcMonitor->top;
|
---|
385 | if (pRect->bottom < lprcMonitor->bottom)
|
---|
386 | pRect->bottom = lprcMonitor->bottom;
|
---|
387 |
|
---|
388 | return TRUE;
|
---|
389 | }
|
---|
390 |
|
---|
391 | /**
|
---|
392 | * The proxy window's WndProc.
|
---|
393 | */
|
---|
394 | LRESULT CALLBACK VBoxDnDWnd::WndProc(HWND a_hWnd, UINT a_uMsg, WPARAM a_wParam, LPARAM a_lParam)
|
---|
395 | {
|
---|
396 | switch (a_uMsg)
|
---|
397 | {
|
---|
398 | case WM_CREATE:
|
---|
399 | {
|
---|
400 | int rc = OnCreate();
|
---|
401 | if (RT_FAILURE(rc))
|
---|
402 | {
|
---|
403 | LogRel(("DnD: Failed to create proxy window, rc=%Rrc\n", rc));
|
---|
404 | return -1;
|
---|
405 | }
|
---|
406 | return 0;
|
---|
407 | }
|
---|
408 |
|
---|
409 | case WM_QUIT:
|
---|
410 | {
|
---|
411 | LogFlowThisFunc(("WM_QUIT\n"));
|
---|
412 | PostQuitMessage(0);
|
---|
413 | return 0;
|
---|
414 | }
|
---|
415 |
|
---|
416 | case WM_DESTROY:
|
---|
417 | {
|
---|
418 | LogFlowThisFunc(("WM_DESTROY\n"));
|
---|
419 |
|
---|
420 | OnDestroy();
|
---|
421 | return 0;
|
---|
422 | }
|
---|
423 |
|
---|
424 | case WM_LBUTTONDOWN:
|
---|
425 | {
|
---|
426 | LogFlowThisFunc(("WM_LBUTTONDOWN\n"));
|
---|
427 | m_fMouseButtonDown = true;
|
---|
428 | return 0;
|
---|
429 | }
|
---|
430 |
|
---|
431 | case WM_LBUTTONUP:
|
---|
432 | {
|
---|
433 | LogFlowThisFunc(("WM_LBUTTONUP\n"));
|
---|
434 | m_fMouseButtonDown = false;
|
---|
435 |
|
---|
436 | /* As the mouse button was released, Hide the proxy window again.
|
---|
437 | * This can happen if
|
---|
438 | * - the user bumped a guest window to the screen's edges
|
---|
439 | * - there was no drop data from the guest available and the user
|
---|
440 | * enters the guest screen again after this unsuccessful operation */
|
---|
441 | Reset();
|
---|
442 | return 0;
|
---|
443 | }
|
---|
444 |
|
---|
445 | case WM_MOUSELEAVE:
|
---|
446 | {
|
---|
447 | LogFlowThisFunc(("WM_MOUSELEAVE\n"));
|
---|
448 | return 0;
|
---|
449 | }
|
---|
450 |
|
---|
451 | /* Will only be called once; after the first mouse move, this
|
---|
452 | * window will be hidden! */
|
---|
453 | case WM_MOUSEMOVE:
|
---|
454 | {
|
---|
455 | LogFlowThisFunc(("WM_MOUSEMOVE: mfMouseButtonDown=%RTbool, mMode=%ld, mState=%ld\n",
|
---|
456 | m_fMouseButtonDown, m_enmMode, m_enmState));
|
---|
457 | #ifdef DEBUG_andy
|
---|
458 | POINT p;
|
---|
459 | GetCursorPos(&p);
|
---|
460 | LogFlowThisFunc(("WM_MOUSEMOVE: curX=%ld, curY=%ld\n", p.x, p.y));
|
---|
461 | #endif
|
---|
462 | int rc = VINF_SUCCESS;
|
---|
463 | if (m_enmMode == HG) /* Host to guest. */
|
---|
464 | {
|
---|
465 | /* Dragging not started yet? Kick it off ... */
|
---|
466 | if ( m_fMouseButtonDown
|
---|
467 | && (m_enmState != Dragging))
|
---|
468 | {
|
---|
469 | m_enmState = Dragging;
|
---|
470 | #if 0
|
---|
471 | /* Delay hiding the proxy window a bit when debugging, to see
|
---|
472 | * whether the desired range is covered correctly. */
|
---|
473 | RTThreadSleep(5000);
|
---|
474 | #endif
|
---|
475 | Hide();
|
---|
476 |
|
---|
477 | LogFlowThisFunc(("Starting drag and drop: dndLstActionsAllowed=0x%x, dwOKEffects=0x%x ...\n",
|
---|
478 | m_lstActionsAllowed, m_startupInfo.dwOKEffects));
|
---|
479 |
|
---|
480 | AssertPtr(m_startupInfo.pDataObject);
|
---|
481 | AssertPtr(m_startupInfo.pDropSource);
|
---|
482 | DWORD dwEffect;
|
---|
483 | HRESULT hr = DoDragDrop(m_startupInfo.pDataObject, m_startupInfo.pDropSource,
|
---|
484 | m_startupInfo.dwOKEffects, &dwEffect);
|
---|
485 | LogFlowThisFunc(("hr=%Rhrc, dwEffect=%RI32\n", hr, dwEffect));
|
---|
486 | switch (hr)
|
---|
487 | {
|
---|
488 | case DRAGDROP_S_DROP:
|
---|
489 | m_enmState = Dropped;
|
---|
490 | break;
|
---|
491 |
|
---|
492 | case DRAGDROP_S_CANCEL:
|
---|
493 | m_enmState = Canceled;
|
---|
494 | break;
|
---|
495 |
|
---|
496 | default:
|
---|
497 | LogFlowThisFunc(("Drag and drop failed with %Rhrc\n", hr));
|
---|
498 | m_enmState = Canceled;
|
---|
499 | rc = VERR_GENERAL_FAILURE; /** @todo Find a better status code. */
|
---|
500 | break;
|
---|
501 | }
|
---|
502 |
|
---|
503 | int rc2 = RTCritSectEnter(&m_CritSect);
|
---|
504 | if (RT_SUCCESS(rc2))
|
---|
505 | {
|
---|
506 | m_startupInfo.pDropSource->Release();
|
---|
507 | m_startupInfo.pDataObject->Release();
|
---|
508 |
|
---|
509 | RT_ZERO(m_startupInfo);
|
---|
510 |
|
---|
511 | rc2 = RTCritSectLeave(&m_CritSect);
|
---|
512 | if (RT_SUCCESS(rc))
|
---|
513 | rc = rc2;
|
---|
514 | }
|
---|
515 |
|
---|
516 | m_enmMode = Unknown;
|
---|
517 | }
|
---|
518 | }
|
---|
519 | else if (m_enmMode == GH) /* Guest to host. */
|
---|
520 | {
|
---|
521 | /* Starting here VBoxDnDDropTarget should
|
---|
522 | * take over; was instantiated when registering
|
---|
523 | * this proxy window as a (valid) drop target. */
|
---|
524 | }
|
---|
525 | else
|
---|
526 | rc = VERR_NOT_SUPPORTED;
|
---|
527 |
|
---|
528 | LogFlowThisFunc(("WM_MOUSEMOVE: mMode=%ld, mState=%ld, rc=%Rrc\n",
|
---|
529 | m_enmMode, m_enmState, rc));
|
---|
530 | return 0;
|
---|
531 | }
|
---|
532 |
|
---|
533 | case WM_NCMOUSEHOVER:
|
---|
534 | LogFlowThisFunc(("WM_NCMOUSEHOVER\n"));
|
---|
535 | return 0;
|
---|
536 |
|
---|
537 | case WM_NCMOUSELEAVE:
|
---|
538 | LogFlowThisFunc(("WM_NCMOUSELEAVE\n"));
|
---|
539 | return 0;
|
---|
540 |
|
---|
541 | case WM_VBOXTRAY_DND_MESSAGE:
|
---|
542 | {
|
---|
543 | PVBOXDNDEVENT pEvent = (PVBOXDNDEVENT)a_lParam;
|
---|
544 | if (!pEvent)
|
---|
545 | break; /* No event received, bail out. */
|
---|
546 |
|
---|
547 | PVBGLR3DNDEVENT pVbglR3Event = pEvent->pVbglR3Event;
|
---|
548 | AssertPtrBreak(pVbglR3Event);
|
---|
549 |
|
---|
550 | LogFlowThisFunc(("Received enmType=%RU32\n", pVbglR3Event->enmType));
|
---|
551 |
|
---|
552 | int rc;
|
---|
553 | switch (pVbglR3Event->enmType)
|
---|
554 | {
|
---|
555 | case VBGLR3DNDEVENTTYPE_HG_ENTER:
|
---|
556 | {
|
---|
557 | if (pVbglR3Event->u.HG_Enter.cbFormats)
|
---|
558 | {
|
---|
559 | RTCList<RTCString> lstFormats =
|
---|
560 | RTCString(pVbglR3Event->u.HG_Enter.pszFormats, pVbglR3Event->u.HG_Enter.cbFormats - 1).split(DND_FORMATS_SEPARATOR_STR);
|
---|
561 | rc = OnHgEnter(lstFormats, pVbglR3Event->u.HG_Enter.dndLstActionsAllowed);
|
---|
562 | if (RT_FAILURE(rc))
|
---|
563 | break;
|
---|
564 | }
|
---|
565 | else
|
---|
566 | {
|
---|
567 | AssertMsgFailed(("cbFormats is 0\n"));
|
---|
568 | rc = VERR_INVALID_PARAMETER;
|
---|
569 | break;
|
---|
570 | }
|
---|
571 |
|
---|
572 | /* Note: After HOST_DND_FN_HG_EVT_ENTER there immediately is a move
|
---|
573 | * event, so fall through is intentional here. */
|
---|
574 | RT_FALL_THROUGH();
|
---|
575 | }
|
---|
576 |
|
---|
577 | case VBGLR3DNDEVENTTYPE_HG_MOVE:
|
---|
578 | {
|
---|
579 | rc = OnHgMove(pVbglR3Event->u.HG_Move.uXpos, pVbglR3Event->u.HG_Move.uYpos,
|
---|
580 | pVbglR3Event->u.HG_Move.dndActionDefault);
|
---|
581 | break;
|
---|
582 | }
|
---|
583 |
|
---|
584 | case VBGLR3DNDEVENTTYPE_HG_LEAVE:
|
---|
585 | {
|
---|
586 | rc = OnHgLeave();
|
---|
587 | break;
|
---|
588 | }
|
---|
589 |
|
---|
590 | case VBGLR3DNDEVENTTYPE_HG_DROP:
|
---|
591 | {
|
---|
592 | rc = OnHgDrop();
|
---|
593 | break;
|
---|
594 | }
|
---|
595 |
|
---|
596 | /**
|
---|
597 | * The data header now will contain all the (meta) data the guest needs in
|
---|
598 | * order to complete the DnD operation.
|
---|
599 | */
|
---|
600 | case VBGLR3DNDEVENTTYPE_HG_RECEIVE:
|
---|
601 | {
|
---|
602 | rc = OnHgDataReceive(&pVbglR3Event->u.HG_Received.Meta);
|
---|
603 | break;
|
---|
604 | }
|
---|
605 |
|
---|
606 | case VBGLR3DNDEVENTTYPE_HG_CANCEL:
|
---|
607 | {
|
---|
608 | rc = OnHgCancel();
|
---|
609 | break;
|
---|
610 | }
|
---|
611 |
|
---|
612 | case VBGLR3DNDEVENTTYPE_QUIT:
|
---|
613 | {
|
---|
614 | LogRel(("DnD: Received quit message, shutting down ...\n"));
|
---|
615 | PostQuitMessage(0);
|
---|
616 | }
|
---|
617 |
|
---|
618 | #ifdef VBOX_WITH_DRAG_AND_DROP_GH
|
---|
619 | case VBGLR3DNDEVENTTYPE_GH_ERROR:
|
---|
620 | {
|
---|
621 | Reset();
|
---|
622 | rc = VINF_SUCCESS;
|
---|
623 | break;
|
---|
624 | }
|
---|
625 |
|
---|
626 | case VBGLR3DNDEVENTTYPE_GH_REQ_PENDING:
|
---|
627 | {
|
---|
628 | rc = OnGhIsDnDPending();
|
---|
629 | break;
|
---|
630 | }
|
---|
631 |
|
---|
632 | case VBGLR3DNDEVENTTYPE_GH_DROP:
|
---|
633 | {
|
---|
634 | rc = OnGhDrop(pVbglR3Event->u.GH_Drop.pszFormat, pVbglR3Event->u.GH_Drop.dndActionRequested);
|
---|
635 | break;
|
---|
636 | }
|
---|
637 | #endif
|
---|
638 | default:
|
---|
639 | {
|
---|
640 | LogRel(("DnD: Received unsupported message '%RU32'\n", pVbglR3Event->enmType));
|
---|
641 | rc = VERR_NOT_SUPPORTED;
|
---|
642 | break;
|
---|
643 | }
|
---|
644 | }
|
---|
645 |
|
---|
646 | LogFlowFunc(("Message %RU32 processed with %Rrc\n", pVbglR3Event->enmType, rc));
|
---|
647 | if (RT_FAILURE(rc))
|
---|
648 | {
|
---|
649 | /* Tell the user. */
|
---|
650 | LogRel(("DnD: Processing message %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc));
|
---|
651 |
|
---|
652 | /* If anything went wrong, do a reset and start over. */
|
---|
653 | Reset();
|
---|
654 | }
|
---|
655 |
|
---|
656 | if (pEvent)
|
---|
657 | {
|
---|
658 | VbglR3DnDEventFree(pEvent->pVbglR3Event);
|
---|
659 | pEvent->pVbglR3Event = NULL;
|
---|
660 |
|
---|
661 | RTMemFree(pEvent);
|
---|
662 | }
|
---|
663 |
|
---|
664 | return 0;
|
---|
665 | }
|
---|
666 |
|
---|
667 | default:
|
---|
668 | break;
|
---|
669 | }
|
---|
670 |
|
---|
671 | return DefWindowProc(a_hWnd, a_uMsg, a_wParam, a_lParam);
|
---|
672 | }
|
---|
673 |
|
---|
674 | #ifdef VBOX_WITH_DRAG_AND_DROP_GH
|
---|
675 | /**
|
---|
676 | * Registers this proxy window as a local drop target.
|
---|
677 | *
|
---|
678 | * @return IPRT status code.
|
---|
679 | */
|
---|
680 | int VBoxDnDWnd::RegisterAsDropTarget(void)
|
---|
681 | {
|
---|
682 | if (m_pDropTarget) /* Already registered as drop target? */
|
---|
683 | return VINF_SUCCESS;
|
---|
684 |
|
---|
685 | int rc;
|
---|
686 | try
|
---|
687 | {
|
---|
688 | m_pDropTarget = new VBoxDnDDropTarget(this /* pParent */);
|
---|
689 | HRESULT hr = CoLockObjectExternal(m_pDropTarget, TRUE /* fLock */,
|
---|
690 | FALSE /* fLastUnlockReleases */);
|
---|
691 | if (SUCCEEDED(hr))
|
---|
692 | hr = RegisterDragDrop(m_hWnd, m_pDropTarget);
|
---|
693 |
|
---|
694 | if (FAILED(hr))
|
---|
695 | {
|
---|
696 | if (hr != DRAGDROP_E_INVALIDHWND) /* Could be because the DnD host service is not available. */
|
---|
697 | LogRel(("DnD: Creating drop target failed with hr=%Rhrc\n", hr));
|
---|
698 | rc = VERR_NOT_SUPPORTED; /* Report back DnD as not being supported. */
|
---|
699 | }
|
---|
700 | else
|
---|
701 | {
|
---|
702 | rc = VINF_SUCCESS;
|
---|
703 | }
|
---|
704 | }
|
---|
705 | catch (std::bad_alloc)
|
---|
706 | {
|
---|
707 | rc = VERR_NO_MEMORY;
|
---|
708 | }
|
---|
709 |
|
---|
710 | LogFlowFuncLeaveRC(rc);
|
---|
711 | return rc;
|
---|
712 | }
|
---|
713 |
|
---|
714 | /**
|
---|
715 | * Unregisters this proxy as a drop target.
|
---|
716 | *
|
---|
717 | * @return IPRT status code.
|
---|
718 | */
|
---|
719 | int VBoxDnDWnd::UnregisterAsDropTarget(void)
|
---|
720 | {
|
---|
721 | LogFlowFuncEnter();
|
---|
722 |
|
---|
723 | if (!m_pDropTarget) /* No drop target? Bail out. */
|
---|
724 | return VINF_SUCCESS;
|
---|
725 |
|
---|
726 | HRESULT hr = RevokeDragDrop(m_hWnd);
|
---|
727 | if (SUCCEEDED(hr))
|
---|
728 | hr = CoLockObjectExternal(m_pDropTarget, FALSE /* fLock */,
|
---|
729 | TRUE /* fLastUnlockReleases */);
|
---|
730 | if (SUCCEEDED(hr))
|
---|
731 | {
|
---|
732 | ULONG cRefs = m_pDropTarget->Release();
|
---|
733 | Assert(cRefs == 0); NOREF(cRefs);
|
---|
734 | m_pDropTarget = NULL;
|
---|
735 | }
|
---|
736 |
|
---|
737 | int rc = SUCCEEDED(hr)
|
---|
738 | ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Fix this. */
|
---|
739 |
|
---|
740 | LogFlowFuncLeaveRC(rc);
|
---|
741 | return rc;
|
---|
742 | }
|
---|
743 | #endif /* VBOX_WITH_DRAG_AND_DROP_GH */
|
---|
744 |
|
---|
745 | /**
|
---|
746 | * Handles the creation of a proxy window.
|
---|
747 | *
|
---|
748 | * @return IPRT status code.
|
---|
749 | */
|
---|
750 | int VBoxDnDWnd::OnCreate(void)
|
---|
751 | {
|
---|
752 | LogFlowFuncEnter();
|
---|
753 | int rc = VbglR3DnDConnect(&m_cmdCtx);
|
---|
754 | if (RT_FAILURE(rc))
|
---|
755 | {
|
---|
756 | LogRel(("DnD: Connection to host service failed, rc=%Rrc\n", rc));
|
---|
757 | return rc;
|
---|
758 | }
|
---|
759 |
|
---|
760 | LogFlowThisFunc(("Client ID=%RU32, rc=%Rrc\n", m_cmdCtx.uClientID, rc));
|
---|
761 | return rc;
|
---|
762 | }
|
---|
763 |
|
---|
764 | /**
|
---|
765 | * Handles the destruction of a proxy window.
|
---|
766 | */
|
---|
767 | void VBoxDnDWnd::OnDestroy(void)
|
---|
768 | {
|
---|
769 | DestroyWindow(m_hWnd);
|
---|
770 |
|
---|
771 | VbglR3DnDDisconnect(&m_cmdCtx);
|
---|
772 | LogFlowThisFuncLeave();
|
---|
773 | }
|
---|
774 |
|
---|
775 | /**
|
---|
776 | * Aborts an in-flight DnD operation on the guest.
|
---|
777 | *
|
---|
778 | * @return VBox status code.
|
---|
779 | */
|
---|
780 | int VBoxDnDWnd::Abort(void)
|
---|
781 | {
|
---|
782 | LogFlowThisFunc(("mMode=%ld, mState=%RU32\n", m_enmMode, m_enmState));
|
---|
783 | LogRel(("DnD: Drag and drop operation aborted\n"));
|
---|
784 |
|
---|
785 | int rc = RTCritSectEnter(&m_CritSect);
|
---|
786 | if (RT_SUCCESS(rc))
|
---|
787 | {
|
---|
788 | if (m_startupInfo.pDataObject)
|
---|
789 | m_startupInfo.pDataObject->Abort();
|
---|
790 |
|
---|
791 | RTCritSectLeave(&m_CritSect);
|
---|
792 | }
|
---|
793 |
|
---|
794 | /* Post ESC to our window to officially abort the
|
---|
795 | * drag and drop operation. */
|
---|
796 | this->PostMessage(WM_KEYDOWN, VK_ESCAPE /* wParam */, 0 /* lParam */);
|
---|
797 |
|
---|
798 | Reset();
|
---|
799 |
|
---|
800 | return rc;
|
---|
801 | }
|
---|
802 |
|
---|
803 | /**
|
---|
804 | * Handles actions required when the host cursor enters
|
---|
805 | * the guest's screen to initiate a host -> guest DnD operation.
|
---|
806 | *
|
---|
807 | * @return IPRT status code.
|
---|
808 | * @param a_lstFormats Supported formats offered by the host.
|
---|
809 | * @param a_fDndLstActionsAllowed Supported actions offered by the host.
|
---|
810 | */
|
---|
811 | int VBoxDnDWnd::OnHgEnter(const RTCList<RTCString> &a_lstFormats, VBOXDNDACTIONLIST a_fDndLstActionsAllowed)
|
---|
812 | {
|
---|
813 | if (m_enmMode == GH) /* Wrong mode? Bail out. */
|
---|
814 | return VERR_WRONG_ORDER;
|
---|
815 |
|
---|
816 | #ifdef DEBUG
|
---|
817 | LogFlowThisFunc(("dndActionList=0x%x, a_lstFormats=%zu: ", a_fDndLstActionsAllowed, a_lstFormats.size()));
|
---|
818 | for (size_t i = 0; i < a_lstFormats.size(); i++)
|
---|
819 | LogFlow(("'%s' ", a_lstFormats.at(i).c_str()));
|
---|
820 | LogFlow(("\n"));
|
---|
821 | #endif
|
---|
822 |
|
---|
823 | Reset();
|
---|
824 | setMode(HG);
|
---|
825 |
|
---|
826 | /* Check if the VM session has changed and reconnect to the HGCM service if necessary. */
|
---|
827 | int rc = checkForSessionChange();
|
---|
828 | if (RT_FAILURE(rc))
|
---|
829 | return rc;
|
---|
830 |
|
---|
831 | try
|
---|
832 | {
|
---|
833 | /* Save all allowed actions. */
|
---|
834 | this->m_lstActionsAllowed = a_fDndLstActionsAllowed;
|
---|
835 |
|
---|
836 | /*
|
---|
837 | * Check if reported formats from host are compatible with this client.
|
---|
838 | */
|
---|
839 | size_t cFormatsSup = this->m_lstFmtSup.size();
|
---|
840 | ULONG cFormatsActive = 0;
|
---|
841 |
|
---|
842 | LPFORMATETC pFormatEtc = new FORMATETC[cFormatsSup];
|
---|
843 | RT_BZERO(pFormatEtc, sizeof(FORMATETC) * cFormatsSup);
|
---|
844 |
|
---|
845 | LPSTGMEDIUM pStgMeds = new STGMEDIUM[cFormatsSup];
|
---|
846 | RT_BZERO(pStgMeds, sizeof(STGMEDIUM) * cFormatsSup);
|
---|
847 |
|
---|
848 | LogRel2(("DnD: Reported formats:\n"));
|
---|
849 | for (size_t i = 0; i < a_lstFormats.size(); i++)
|
---|
850 | {
|
---|
851 | bool fSupported = false;
|
---|
852 | for (size_t a = 0; a < this->m_lstFmtSup.size(); a++)
|
---|
853 | {
|
---|
854 | const char *pszFormat = a_lstFormats.at(i).c_str();
|
---|
855 | LogFlowThisFunc(("\t\"%s\" <=> \"%s\"\n", this->m_lstFmtSup.at(a).c_str(), pszFormat));
|
---|
856 |
|
---|
857 | fSupported = RTStrICmp(this->m_lstFmtSup.at(a).c_str(), pszFormat) == 0;
|
---|
858 | if (fSupported)
|
---|
859 | {
|
---|
860 | this->m_lstFmtActive.append(a_lstFormats.at(i));
|
---|
861 |
|
---|
862 | /** @todo Put this into a \#define / struct. */
|
---|
863 | if (!RTStrICmp(pszFormat, "text/uri-list"))
|
---|
864 | {
|
---|
865 | pFormatEtc[cFormatsActive].cfFormat = CF_HDROP;
|
---|
866 | pFormatEtc[cFormatsActive].dwAspect = DVASPECT_CONTENT;
|
---|
867 | pFormatEtc[cFormatsActive].lindex = -1;
|
---|
868 | pFormatEtc[cFormatsActive].tymed = TYMED_HGLOBAL;
|
---|
869 |
|
---|
870 | pStgMeds [cFormatsActive].tymed = TYMED_HGLOBAL;
|
---|
871 | cFormatsActive++;
|
---|
872 | }
|
---|
873 | else if ( !RTStrICmp(pszFormat, "text/plain")
|
---|
874 | || !RTStrICmp(pszFormat, "text/html")
|
---|
875 | || !RTStrICmp(pszFormat, "text/plain;charset=utf-8")
|
---|
876 | || !RTStrICmp(pszFormat, "text/plain;charset=utf-16")
|
---|
877 | || !RTStrICmp(pszFormat, "text/plain")
|
---|
878 | || !RTStrICmp(pszFormat, "text/richtext")
|
---|
879 | || !RTStrICmp(pszFormat, "UTF8_STRING")
|
---|
880 | || !RTStrICmp(pszFormat, "TEXT")
|
---|
881 | || !RTStrICmp(pszFormat, "STRING"))
|
---|
882 | {
|
---|
883 | pFormatEtc[cFormatsActive].cfFormat = CF_TEXT;
|
---|
884 | pFormatEtc[cFormatsActive].dwAspect = DVASPECT_CONTENT;
|
---|
885 | pFormatEtc[cFormatsActive].lindex = -1;
|
---|
886 | pFormatEtc[cFormatsActive].tymed = TYMED_HGLOBAL;
|
---|
887 |
|
---|
888 | pStgMeds [cFormatsActive].tymed = TYMED_HGLOBAL;
|
---|
889 | cFormatsActive++;
|
---|
890 | }
|
---|
891 | else /* Should never happen. */
|
---|
892 | AssertReleaseMsgFailedBreak(("Format specification for '%s' not implemented\n", pszFormat));
|
---|
893 | break;
|
---|
894 | }
|
---|
895 | }
|
---|
896 |
|
---|
897 | LogRel2(("DnD: \t%s: %RTbool\n", a_lstFormats.at(i).c_str(), fSupported));
|
---|
898 | }
|
---|
899 |
|
---|
900 | /*
|
---|
901 | * Warn in the log if this guest does not accept anything.
|
---|
902 | */
|
---|
903 | Assert(cFormatsActive <= cFormatsSup);
|
---|
904 | if (cFormatsActive)
|
---|
905 | {
|
---|
906 | LogRel2(("DnD: %RU32 supported formats found:\n", cFormatsActive));
|
---|
907 | for (size_t i = 0; i < cFormatsActive; i++)
|
---|
908 | LogRel2(("DnD: \t%s\n", this->m_lstFmtActive.at(i).c_str()));
|
---|
909 | }
|
---|
910 | else
|
---|
911 | LogRel(("DnD: Warning: No supported drag and drop formats on the guest found!\n"));
|
---|
912 |
|
---|
913 | /*
|
---|
914 | * Prepare the startup info for DoDragDrop().
|
---|
915 | */
|
---|
916 |
|
---|
917 | /* Translate our drop actions into allowed Windows drop effects. */
|
---|
918 | m_startupInfo.dwOKEffects = DROPEFFECT_NONE;
|
---|
919 | if (a_fDndLstActionsAllowed)
|
---|
920 | {
|
---|
921 | if (a_fDndLstActionsAllowed & VBOX_DND_ACTION_COPY)
|
---|
922 | m_startupInfo.dwOKEffects |= DROPEFFECT_COPY;
|
---|
923 | if (a_fDndLstActionsAllowed & VBOX_DND_ACTION_MOVE)
|
---|
924 | m_startupInfo.dwOKEffects |= DROPEFFECT_MOVE;
|
---|
925 | if (a_fDndLstActionsAllowed & VBOX_DND_ACTION_LINK)
|
---|
926 | m_startupInfo.dwOKEffects |= DROPEFFECT_LINK;
|
---|
927 | }
|
---|
928 |
|
---|
929 | LogRel2(("DnD: Supported drop actions: 0x%x\n", m_startupInfo.dwOKEffects));
|
---|
930 |
|
---|
931 | m_startupInfo.pDropSource = new VBoxDnDDropSource(this);
|
---|
932 | m_startupInfo.pDataObject = new VBoxDnDDataObject(pFormatEtc, pStgMeds, cFormatsActive);
|
---|
933 |
|
---|
934 | if (pFormatEtc)
|
---|
935 | delete pFormatEtc;
|
---|
936 | if (pStgMeds)
|
---|
937 | delete pStgMeds;
|
---|
938 | }
|
---|
939 | catch (std::bad_alloc)
|
---|
940 | {
|
---|
941 | rc = VERR_NO_MEMORY;
|
---|
942 | }
|
---|
943 |
|
---|
944 | if (RT_SUCCESS(rc))
|
---|
945 | rc = makeFullscreen();
|
---|
946 |
|
---|
947 | LogFlowFuncLeaveRC(rc);
|
---|
948 | return rc;
|
---|
949 | }
|
---|
950 |
|
---|
951 | /**
|
---|
952 | * Handles actions required when the host cursor moves inside
|
---|
953 | * the guest's screen.
|
---|
954 | *
|
---|
955 | * @return IPRT status code.
|
---|
956 | * @param u32xPos Absolute X position (in pixels) of the host cursor
|
---|
957 | * inside the guest.
|
---|
958 | * @param u32yPos Absolute Y position (in pixels) of the host cursor
|
---|
959 | * inside the guest.
|
---|
960 | * @param dndAction Action the host wants to perform while moving.
|
---|
961 | * Currently ignored.
|
---|
962 | */
|
---|
963 | int VBoxDnDWnd::OnHgMove(uint32_t u32xPos, uint32_t u32yPos, VBOXDNDACTION dndAction)
|
---|
964 | {
|
---|
965 | RT_NOREF(dndAction);
|
---|
966 | int rc;
|
---|
967 |
|
---|
968 | uint32_t uActionNotify = VBOX_DND_ACTION_IGNORE;
|
---|
969 | if (m_enmMode == HG)
|
---|
970 | {
|
---|
971 | LogFlowThisFunc(("u32xPos=%RU32, u32yPos=%RU32, dndAction=0x%x\n",
|
---|
972 | u32xPos, u32yPos, dndAction));
|
---|
973 |
|
---|
974 | rc = mouseMove(u32xPos, u32yPos, MOUSEEVENTF_LEFTDOWN);
|
---|
975 |
|
---|
976 | if (RT_SUCCESS(rc))
|
---|
977 | rc = RTCritSectEnter(&m_CritSect);
|
---|
978 | if (RT_SUCCESS(rc))
|
---|
979 | {
|
---|
980 | if ( (Dragging == m_enmState)
|
---|
981 | && m_startupInfo.pDropSource)
|
---|
982 | uActionNotify = m_startupInfo.pDropSource->GetCurrentAction();
|
---|
983 |
|
---|
984 | RTCritSectLeave(&m_CritSect);
|
---|
985 | }
|
---|
986 | }
|
---|
987 | else /* Just acknowledge the operation with an ignore action. */
|
---|
988 | rc = VINF_SUCCESS;
|
---|
989 |
|
---|
990 | if (RT_SUCCESS(rc))
|
---|
991 | {
|
---|
992 | rc = VbglR3DnDHGSendAckOp(&m_cmdCtx, uActionNotify);
|
---|
993 | if (RT_FAILURE(rc))
|
---|
994 | LogFlowThisFunc(("Acknowledging operation failed with rc=%Rrc\n", rc));
|
---|
995 | }
|
---|
996 |
|
---|
997 | LogFlowThisFunc(("Returning uActionNotify=0x%x, rc=%Rrc\n", uActionNotify, rc));
|
---|
998 | return rc;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | /**
|
---|
1002 | * Handles actions required when the host cursor leaves
|
---|
1003 | * the guest's screen again.
|
---|
1004 | *
|
---|
1005 | * @return IPRT status code.
|
---|
1006 | */
|
---|
1007 | int VBoxDnDWnd::OnHgLeave(void)
|
---|
1008 | {
|
---|
1009 | if (m_enmMode == GH) /* Wrong mode? Bail out. */
|
---|
1010 | return VERR_WRONG_ORDER;
|
---|
1011 |
|
---|
1012 | int rc = Abort();
|
---|
1013 |
|
---|
1014 | LogFlowFuncLeaveRC(rc);
|
---|
1015 | return rc;
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | /**
|
---|
1019 | * Handles actions required when the host cursor wants to drop
|
---|
1020 | * and therefore start a "drop" action in the guest.
|
---|
1021 | *
|
---|
1022 | * @return IPRT status code.
|
---|
1023 | */
|
---|
1024 | int VBoxDnDWnd::OnHgDrop(void)
|
---|
1025 | {
|
---|
1026 | if (m_enmMode == GH)
|
---|
1027 | return VERR_WRONG_ORDER;
|
---|
1028 |
|
---|
1029 | LogFlowThisFunc(("mMode=%ld, mState=%RU32\n", m_enmMode, m_enmState));
|
---|
1030 |
|
---|
1031 | int rc = VINF_SUCCESS;
|
---|
1032 | if (m_enmState == Dragging)
|
---|
1033 | {
|
---|
1034 | if (m_lstFmtActive.size() >= 1)
|
---|
1035 | {
|
---|
1036 | /** @todo What to do when multiple formats are available? */
|
---|
1037 | m_strFmtReq = m_lstFmtActive.at(0);
|
---|
1038 |
|
---|
1039 | rc = RTCritSectEnter(&m_CritSect);
|
---|
1040 | if (RT_SUCCESS(rc))
|
---|
1041 | {
|
---|
1042 | if (m_startupInfo.pDataObject)
|
---|
1043 | m_startupInfo.pDataObject->SetStatus(VBoxDnDDataObject::Status_Dropping);
|
---|
1044 | else
|
---|
1045 | rc = VERR_NOT_FOUND;
|
---|
1046 |
|
---|
1047 | RTCritSectLeave(&m_CritSect);
|
---|
1048 | }
|
---|
1049 |
|
---|
1050 | if (RT_SUCCESS(rc))
|
---|
1051 | {
|
---|
1052 | LogRel(("DnD: Requesting data as '%s' ...\n", m_strFmtReq.c_str()));
|
---|
1053 | rc = VbglR3DnDHGSendReqData(&m_cmdCtx, m_strFmtReq.c_str());
|
---|
1054 | if (RT_FAILURE(rc))
|
---|
1055 | LogFlowThisFunc(("Requesting data failed with rc=%Rrc\n", rc));
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | }
|
---|
1059 | else /* Should never happen. */
|
---|
1060 | LogRel(("DnD: Error: Host did not specify a data format for drop data\n"));
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | LogFlowFuncLeaveRC(rc);
|
---|
1064 | return rc;
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | /**
|
---|
1068 | * Handles actions required when the host has sent over DnD data
|
---|
1069 | * to the guest after a "drop" event.
|
---|
1070 | *
|
---|
1071 | * @return IPRT status code.
|
---|
1072 | * @param pMeta Pointer to meta data received.
|
---|
1073 | */
|
---|
1074 | int VBoxDnDWnd::OnHgDataReceive(PVBGLR3GUESTDNDMETADATA pMeta)
|
---|
1075 | {
|
---|
1076 | LogFlowThisFunc(("mState=%ld, enmMetaType=%RU32\n", m_enmState, pMeta->enmType));
|
---|
1077 |
|
---|
1078 | int rc = RTCritSectEnter(&m_CritSect);
|
---|
1079 | if (RT_SUCCESS(rc))
|
---|
1080 | {
|
---|
1081 | m_enmState = Dropped;
|
---|
1082 |
|
---|
1083 | if (m_startupInfo.pDataObject)
|
---|
1084 | {
|
---|
1085 | switch (pMeta->enmType)
|
---|
1086 | {
|
---|
1087 | case VBGLR3GUESTDNDMETADATATYPE_RAW:
|
---|
1088 | {
|
---|
1089 | AssertBreakStmt(pMeta->u.Raw.pvMeta != NULL, rc = VERR_INVALID_POINTER);
|
---|
1090 | AssertBreakStmt(pMeta->u.Raw.cbMeta, rc = VERR_INVALID_PARAMETER);
|
---|
1091 |
|
---|
1092 | rc = m_startupInfo.pDataObject->Signal(m_strFmtReq, pMeta->u.Raw.pvMeta, pMeta->u.Raw.cbMeta);
|
---|
1093 | break;
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | case VBGLR3GUESTDNDMETADATATYPE_URI_LIST:
|
---|
1097 | {
|
---|
1098 | LogRel2(("DnD: URI transfer root directory is '%s'\n", DnDTransferListGetRootPathAbs(&pMeta->u.URI.Transfer)));
|
---|
1099 |
|
---|
1100 | char *pszBuf;
|
---|
1101 | size_t cbBuf;
|
---|
1102 | /* Note: The transfer list already has its root set to a temporary directory, so no need to set/add a new
|
---|
1103 | * path base here. */
|
---|
1104 | rc = DnDTransferListGetRootsEx(&pMeta->u.URI.Transfer, DNDTRANSFERLISTFMT_NATIVE, NULL /* pszPathBase */,
|
---|
1105 | DND_PATH_SEPARATOR_STR, &pszBuf, &cbBuf);
|
---|
1106 | if (RT_SUCCESS(rc))
|
---|
1107 | {
|
---|
1108 | rc = m_startupInfo.pDataObject->Signal(m_strFmtReq, pszBuf, cbBuf);
|
---|
1109 | RTStrFree(pszBuf);
|
---|
1110 | }
|
---|
1111 | break;
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | default:
|
---|
1115 | AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED);
|
---|
1116 | break;
|
---|
1117 | }
|
---|
1118 | }
|
---|
1119 | else
|
---|
1120 | rc = VERR_NOT_FOUND;
|
---|
1121 |
|
---|
1122 | int rc2 = mouseRelease();
|
---|
1123 | if (RT_SUCCESS(rc))
|
---|
1124 | rc = rc2;
|
---|
1125 |
|
---|
1126 | RTCritSectLeave(&m_CritSect);
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | LogFlowFuncLeaveRC(rc);
|
---|
1130 | return rc;
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | /**
|
---|
1134 | * Handles actions required when the host wants to cancel the current
|
---|
1135 | * host -> guest operation.
|
---|
1136 | *
|
---|
1137 | * @return IPRT status code.
|
---|
1138 | */
|
---|
1139 | int VBoxDnDWnd::OnHgCancel(void)
|
---|
1140 | {
|
---|
1141 | return Abort();
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | #ifdef VBOX_WITH_DRAG_AND_DROP_GH
|
---|
1145 | /**
|
---|
1146 | * Handles actions required to start a guest -> host DnD operation.
|
---|
1147 | * This works by letting the host ask whether a DnD operation is pending
|
---|
1148 | * on the guest. The guest must not know anything about the host's DnD state
|
---|
1149 | * and/or operations due to security reasons.
|
---|
1150 | *
|
---|
1151 | * To capture a pending DnD operation on the guest which then can be communicated
|
---|
1152 | * to the host the proxy window needs to be registered as a drop target. This drop
|
---|
1153 | * target then will act as a proxy target between the guest OS and the host. In other
|
---|
1154 | * words, the guest OS will use this proxy target as a regular (invisible) window
|
---|
1155 | * which can be used by the regular guest OS' DnD mechanisms, independently of the
|
---|
1156 | * host OS. To make sure this proxy target is able receive an in-progress DnD operation
|
---|
1157 | * on the guest, it will be shown invisibly across all active guest OS screens. Just
|
---|
1158 | * think of an opened umbrella across all screens here.
|
---|
1159 | *
|
---|
1160 | * As soon as the proxy target and its underlying data object receive appropriate
|
---|
1161 | * DnD messages they'll be hidden again, and the control will be transferred back
|
---|
1162 | * this class again.
|
---|
1163 | *
|
---|
1164 | * @return IPRT status code.
|
---|
1165 | */
|
---|
1166 | int VBoxDnDWnd::OnGhIsDnDPending(void)
|
---|
1167 | {
|
---|
1168 | LogFlowThisFunc(("mMode=%ld, mState=%ld\n", m_enmMode, m_enmState));
|
---|
1169 |
|
---|
1170 | if (m_enmMode == Unknown)
|
---|
1171 | setMode(GH);
|
---|
1172 |
|
---|
1173 | if (m_enmMode != GH)
|
---|
1174 | return VERR_WRONG_ORDER;
|
---|
1175 |
|
---|
1176 | if (m_enmState == Uninitialized)
|
---|
1177 | {
|
---|
1178 | /* Nothing to do here yet. */
|
---|
1179 | m_enmState = Initialized;
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | int rc;
|
---|
1183 | if (m_enmState == Initialized)
|
---|
1184 | {
|
---|
1185 | /* Check if the VM session has changed and reconnect to the HGCM service if necessary. */
|
---|
1186 | rc = checkForSessionChange();
|
---|
1187 | if (RT_SUCCESS(rc))
|
---|
1188 | {
|
---|
1189 | rc = makeFullscreen();
|
---|
1190 | if (RT_SUCCESS(rc))
|
---|
1191 | {
|
---|
1192 | /*
|
---|
1193 | * We have to release the left mouse button to
|
---|
1194 | * get into our (invisible) proxy window.
|
---|
1195 | */
|
---|
1196 | mouseRelease();
|
---|
1197 |
|
---|
1198 | /*
|
---|
1199 | * Even if we just released the left mouse button
|
---|
1200 | * we're still in the dragging state to handle our
|
---|
1201 | * own drop target (for the host).
|
---|
1202 | */
|
---|
1203 | m_enmState = Dragging;
|
---|
1204 | }
|
---|
1205 | }
|
---|
1206 | }
|
---|
1207 | else
|
---|
1208 | rc = VINF_SUCCESS;
|
---|
1209 |
|
---|
1210 | /**
|
---|
1211 | * Some notes regarding guest cursor movement:
|
---|
1212 | * - The host only sends an HOST_DND_FN_GH_REQ_PENDING message to the guest
|
---|
1213 | * if the mouse cursor is outside the VM's window.
|
---|
1214 | * - The guest does not know anything about the host's cursor
|
---|
1215 | * position / state due to security reasons.
|
---|
1216 | * - The guest *only* knows that the host currently is asking whether a
|
---|
1217 | * guest DnD operation is in progress.
|
---|
1218 | */
|
---|
1219 |
|
---|
1220 | if ( RT_SUCCESS(rc)
|
---|
1221 | && m_enmState == Dragging)
|
---|
1222 | {
|
---|
1223 | /** @todo Put this block into a function! */
|
---|
1224 | POINT p;
|
---|
1225 | GetCursorPos(&p);
|
---|
1226 | ClientToScreen(m_hWnd, &p);
|
---|
1227 | #ifdef DEBUG_andy
|
---|
1228 | LogFlowThisFunc(("Client to screen curX=%ld, curY=%ld\n", p.x, p.y));
|
---|
1229 | #endif
|
---|
1230 |
|
---|
1231 | /** @todo Multi-monitor setups? */
|
---|
1232 | #if 0 /* unused */
|
---|
1233 | int iScreenX = GetSystemMetrics(SM_CXSCREEN) - 1;
|
---|
1234 | int iScreenY = GetSystemMetrics(SM_CYSCREEN) - 1;
|
---|
1235 | #endif
|
---|
1236 |
|
---|
1237 | LONG px = p.x;
|
---|
1238 | if (px <= 0)
|
---|
1239 | px = 1;
|
---|
1240 | LONG py = p.y;
|
---|
1241 | if (py <= 0)
|
---|
1242 | py = 1;
|
---|
1243 |
|
---|
1244 | rc = mouseMove(px, py, 0 /* dwMouseInputFlags */);
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | if (RT_SUCCESS(rc))
|
---|
1248 | {
|
---|
1249 | VBOXDNDACTION dndActionDefault = VBOX_DND_ACTION_IGNORE;
|
---|
1250 |
|
---|
1251 | AssertPtr(m_pDropTarget);
|
---|
1252 | RTCString strFormats = m_pDropTarget->Formats();
|
---|
1253 | if (!strFormats.isEmpty())
|
---|
1254 | {
|
---|
1255 | dndActionDefault = VBOX_DND_ACTION_COPY;
|
---|
1256 |
|
---|
1257 | LogFlowFunc(("Acknowledging pDropTarget=0x%p, dndActionDefault=0x%x, dndLstActionsAllowed=0x%x, strFormats=%s\n",
|
---|
1258 | m_pDropTarget, dndActionDefault, m_lstActionsAllowed, strFormats.c_str()));
|
---|
1259 | }
|
---|
1260 | else
|
---|
1261 | {
|
---|
1262 | strFormats = "unknown"; /* Prevent VERR_IO_GEN_FAILURE for IOCTL. */
|
---|
1263 | LogFlowFunc(("No format data from proxy window available yet\n"));
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | /** @todo Support more than one action at a time. */
|
---|
1267 | m_lstActionsAllowed = dndActionDefault;
|
---|
1268 |
|
---|
1269 | int rc2 = VbglR3DnDGHSendAckPending(&m_cmdCtx,
|
---|
1270 | dndActionDefault, m_lstActionsAllowed,
|
---|
1271 | strFormats.c_str(), (uint32_t)strFormats.length() + 1 /* Include termination */);
|
---|
1272 | if (RT_FAILURE(rc2))
|
---|
1273 | {
|
---|
1274 | char szMsg[256]; /* Sizes according to MSDN. */
|
---|
1275 | char szTitle[64];
|
---|
1276 |
|
---|
1277 | /** @todo Add some i18l tr() macros here. */
|
---|
1278 | RTStrPrintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions Drag and Drop");
|
---|
1279 | RTStrPrintf(szMsg, sizeof(szMsg), "Drag and drop to the host either is not supported or disabled. "
|
---|
1280 | "Please enable Guest to Host or Bidirectional drag and drop mode "
|
---|
1281 | "or re-install the VirtualBox Guest Additions.");
|
---|
1282 | switch (rc2)
|
---|
1283 | {
|
---|
1284 | case VERR_ACCESS_DENIED:
|
---|
1285 | {
|
---|
1286 | rc = hlpShowBalloonTip(g_hInstance, g_hwndToolWindow, ID_TRAYICON,
|
---|
1287 | szMsg, szTitle,
|
---|
1288 | 15 * 1000 /* Time to display in msec */, NIIF_INFO);
|
---|
1289 | AssertRC(rc);
|
---|
1290 | break;
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | default:
|
---|
1294 | break;
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | LogRel2(("DnD: Host refuses drag and drop operation from guest: %Rrc\n", rc2));
|
---|
1298 | Reset();
|
---|
1299 | }
|
---|
1300 | }
|
---|
1301 |
|
---|
1302 | if (RT_FAILURE(rc))
|
---|
1303 | Reset(); /* Reset state on failure. */
|
---|
1304 |
|
---|
1305 | LogFlowFuncLeaveRC(rc);
|
---|
1306 | return rc;
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | /**
|
---|
1310 | * Handles actions required to let the guest know that the host
|
---|
1311 | * started a "drop" action on the host. This will tell the guest
|
---|
1312 | * to send data in a specific format the host requested.
|
---|
1313 | *
|
---|
1314 | * @return IPRT status code.
|
---|
1315 | * @param pszFormat Format the host requests the data in.
|
---|
1316 | * @param cbFormat Size (in bytes) of format string.
|
---|
1317 | * @param dndActionDefault Default action on the host.
|
---|
1318 | */
|
---|
1319 | int VBoxDnDWnd::OnGhDrop(const RTCString &strFormat, uint32_t dndActionDefault)
|
---|
1320 | {
|
---|
1321 | RT_NOREF(dndActionDefault);
|
---|
1322 |
|
---|
1323 | LogFlowThisFunc(("mMode=%ld, mState=%ld, pDropTarget=0x%p, strFormat=%s, dndActionDefault=0x%x\n",
|
---|
1324 | m_enmMode, m_enmState, m_pDropTarget, strFormat.c_str(), dndActionDefault));
|
---|
1325 | int rc;
|
---|
1326 | if (m_enmMode == GH)
|
---|
1327 | {
|
---|
1328 | if (m_enmState == Dragging)
|
---|
1329 | {
|
---|
1330 | AssertPtr(m_pDropTarget);
|
---|
1331 | rc = m_pDropTarget->WaitForDrop(5 * 1000 /* 5s timeout */);
|
---|
1332 |
|
---|
1333 | Reset();
|
---|
1334 | }
|
---|
1335 | else if (m_enmState == Dropped)
|
---|
1336 | {
|
---|
1337 | rc = VINF_SUCCESS;
|
---|
1338 | }
|
---|
1339 | else
|
---|
1340 | rc = VERR_WRONG_ORDER;
|
---|
1341 |
|
---|
1342 | if (RT_SUCCESS(rc))
|
---|
1343 | {
|
---|
1344 | /** @todo Respect uDefAction. */
|
---|
1345 | void *pvData = m_pDropTarget->DataMutableRaw();
|
---|
1346 | uint32_t cbData = (uint32_t)m_pDropTarget->DataSize();
|
---|
1347 | Assert(cbData == m_pDropTarget->DataSize());
|
---|
1348 |
|
---|
1349 | if ( pvData
|
---|
1350 | && cbData)
|
---|
1351 | {
|
---|
1352 | rc = VbglR3DnDGHSendData(&m_cmdCtx, strFormat.c_str(), pvData, cbData);
|
---|
1353 | LogFlowFunc(("Sent pvData=0x%p, cbData=%RU32, rc=%Rrc\n", pvData, cbData, rc));
|
---|
1354 | }
|
---|
1355 | else
|
---|
1356 | rc = VERR_NO_DATA;
|
---|
1357 | }
|
---|
1358 | }
|
---|
1359 | else
|
---|
1360 | rc = VERR_WRONG_ORDER;
|
---|
1361 |
|
---|
1362 | if (RT_FAILURE(rc))
|
---|
1363 | {
|
---|
1364 | /*
|
---|
1365 | * If an error occurred or the guest is in a wrong DnD mode,
|
---|
1366 | * send an error to the host in any case so that the host does
|
---|
1367 | * not wait for the data it expects from the guest.
|
---|
1368 | */
|
---|
1369 | int rc2 = VbglR3DnDGHSendError(&m_cmdCtx, rc);
|
---|
1370 | AssertRC(rc2);
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | LogFlowFuncLeaveRC(rc);
|
---|
1374 | return rc;
|
---|
1375 | }
|
---|
1376 | #endif /* VBOX_WITH_DRAG_AND_DROP_GH */
|
---|
1377 |
|
---|
1378 | void VBoxDnDWnd::PostMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
1379 | {
|
---|
1380 | LogFlowFunc(("Posting message %u\n"));
|
---|
1381 | BOOL fRc = ::PostMessage(m_hWnd, uMsg, wParam, lParam);
|
---|
1382 | Assert(fRc); NOREF(fRc);
|
---|
1383 | }
|
---|
1384 |
|
---|
1385 | /**
|
---|
1386 | * Injects a DnD event in this proxy window's Windows
|
---|
1387 | * event queue. The (allocated) event will be deleted by
|
---|
1388 | * this class after processing.
|
---|
1389 | *
|
---|
1390 | * @return IPRT status code.
|
---|
1391 | * @param pEvent Event to inject.
|
---|
1392 | */
|
---|
1393 | int VBoxDnDWnd::ProcessEvent(PVBOXDNDEVENT pEvent)
|
---|
1394 | {
|
---|
1395 | AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
|
---|
1396 |
|
---|
1397 | BOOL fRc = ::PostMessage(m_hWnd, WM_VBOXTRAY_DND_MESSAGE,
|
---|
1398 | 0 /* wParm */, (LPARAM)pEvent /* lParm */);
|
---|
1399 | if (!fRc)
|
---|
1400 | {
|
---|
1401 | DWORD dwErr = GetLastError();
|
---|
1402 |
|
---|
1403 | static int s_iBitchedAboutFailedDnDMessages = 0;
|
---|
1404 | if (s_iBitchedAboutFailedDnDMessages++ < 32)
|
---|
1405 | {
|
---|
1406 | LogRel(("DnD: Processing event %p failed with %ld (%Rrc), skipping\n",
|
---|
1407 | pEvent, dwErr, RTErrConvertFromWin32(dwErr)));
|
---|
1408 | }
|
---|
1409 |
|
---|
1410 | VbglR3DnDEventFree(pEvent->pVbglR3Event);
|
---|
1411 |
|
---|
1412 | RTMemFree(pEvent);
|
---|
1413 | pEvent = NULL;
|
---|
1414 |
|
---|
1415 | return RTErrConvertFromWin32(dwErr);
|
---|
1416 | }
|
---|
1417 |
|
---|
1418 | return VINF_SUCCESS;
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | /**
|
---|
1422 | * Checks if the VM session has changed (can happen when restoring the VM from a saved state)
|
---|
1423 | * and do a reconnect to the DnD HGCM service.
|
---|
1424 | *
|
---|
1425 | * @returns IPRT status code.
|
---|
1426 | */
|
---|
1427 | int VBoxDnDWnd::checkForSessionChange(void)
|
---|
1428 | {
|
---|
1429 | uint64_t uSessionID;
|
---|
1430 | int rc = VbglR3GetSessionId(&uSessionID);
|
---|
1431 | if ( RT_SUCCESS(rc)
|
---|
1432 | && uSessionID != m_cmdCtx.uSessionID)
|
---|
1433 | {
|
---|
1434 | LogFlowThisFunc(("VM session has changed to %RU64\n", uSessionID));
|
---|
1435 |
|
---|
1436 | rc = VbglR3DnDDisconnect(&m_cmdCtx);
|
---|
1437 | AssertRC(rc);
|
---|
1438 |
|
---|
1439 | rc = VbglR3DnDConnect(&m_cmdCtx);
|
---|
1440 | AssertRC(rc);
|
---|
1441 | }
|
---|
1442 |
|
---|
1443 | LogFlowFuncLeaveRC(rc);
|
---|
1444 | return rc;
|
---|
1445 | }
|
---|
1446 |
|
---|
1447 | /**
|
---|
1448 | * Hides the proxy window again.
|
---|
1449 | *
|
---|
1450 | * @return IPRT status code.
|
---|
1451 | */
|
---|
1452 | int VBoxDnDWnd::Hide(void)
|
---|
1453 | {
|
---|
1454 | #ifdef DEBUG_andy
|
---|
1455 | LogFlowFunc(("\n"));
|
---|
1456 | #endif
|
---|
1457 | ShowWindow(m_hWnd, SW_HIDE);
|
---|
1458 |
|
---|
1459 | return VINF_SUCCESS;
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | /**
|
---|
1463 | * Shows the (invisible) proxy window in fullscreen,
|
---|
1464 | * spawned across all active guest monitors.
|
---|
1465 | *
|
---|
1466 | * @return IPRT status code.
|
---|
1467 | */
|
---|
1468 | int VBoxDnDWnd::makeFullscreen(void)
|
---|
1469 | {
|
---|
1470 | int rc = VINF_SUCCESS;
|
---|
1471 |
|
---|
1472 | RECT r;
|
---|
1473 | RT_ZERO(r);
|
---|
1474 |
|
---|
1475 | BOOL fRc;
|
---|
1476 | HDC hDC = GetDC(NULL /* Entire screen */);
|
---|
1477 | if (hDC)
|
---|
1478 | {
|
---|
1479 | fRc = g_pfnEnumDisplayMonitors
|
---|
1480 | /* EnumDisplayMonitors is not available on NT4. */
|
---|
1481 | ? g_pfnEnumDisplayMonitors(hDC, NULL, VBoxDnDWnd::MonitorEnumProc, (LPARAM)&r):
|
---|
1482 | FALSE;
|
---|
1483 |
|
---|
1484 | if (!fRc)
|
---|
1485 | rc = VERR_NOT_FOUND;
|
---|
1486 | ReleaseDC(NULL, hDC);
|
---|
1487 | }
|
---|
1488 | else
|
---|
1489 | rc = VERR_ACCESS_DENIED;
|
---|
1490 |
|
---|
1491 | if (RT_FAILURE(rc))
|
---|
1492 | {
|
---|
1493 | /* If multi-monitor enumeration failed above, try getting at least the
|
---|
1494 | * primary monitor as a fallback. */
|
---|
1495 | r.left = 0;
|
---|
1496 | r.top = 0;
|
---|
1497 | r.right = GetSystemMetrics(SM_CXSCREEN);
|
---|
1498 | r.bottom = GetSystemMetrics(SM_CYSCREEN);
|
---|
1499 | rc = VINF_SUCCESS;
|
---|
1500 | }
|
---|
1501 |
|
---|
1502 | if (RT_SUCCESS(rc))
|
---|
1503 | {
|
---|
1504 | LONG lStyle = GetWindowLong(m_hWnd, GWL_STYLE);
|
---|
1505 | SetWindowLong(m_hWnd, GWL_STYLE,
|
---|
1506 | lStyle & ~(WS_CAPTION | WS_THICKFRAME));
|
---|
1507 | LONG lExStyle = GetWindowLong(m_hWnd, GWL_EXSTYLE);
|
---|
1508 | SetWindowLong(m_hWnd, GWL_EXSTYLE,
|
---|
1509 | lExStyle & ~( WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE
|
---|
1510 | | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
|
---|
1511 |
|
---|
1512 | fRc = SetWindowPos(m_hWnd, HWND_TOPMOST,
|
---|
1513 | r.left,
|
---|
1514 | r.top,
|
---|
1515 | r.right - r.left,
|
---|
1516 | r.bottom - r.top,
|
---|
1517 | #ifdef VBOX_DND_DEBUG_WND
|
---|
1518 | SWP_SHOWWINDOW | SWP_FRAMECHANGED);
|
---|
1519 | #else
|
---|
1520 | SWP_SHOWWINDOW | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOACTIVATE);
|
---|
1521 | #endif
|
---|
1522 | if (fRc)
|
---|
1523 | {
|
---|
1524 | LogFlowFunc(("Virtual screen is %ld,%ld,%ld,%ld (%ld x %ld)\n",
|
---|
1525 | r.left, r.top, r.right, r.bottom,
|
---|
1526 | r.right - r.left, r.bottom - r.top));
|
---|
1527 | }
|
---|
1528 | else
|
---|
1529 | {
|
---|
1530 | DWORD dwErr = GetLastError();
|
---|
1531 | LogRel(("DnD: Failed to set proxy window position, rc=%Rrc\n",
|
---|
1532 | RTErrConvertFromWin32(dwErr)));
|
---|
1533 | }
|
---|
1534 | }
|
---|
1535 | else
|
---|
1536 | LogRel(("DnD: Failed to determine virtual screen size, rc=%Rrc\n", rc));
|
---|
1537 |
|
---|
1538 | LogFlowFuncLeaveRC(rc);
|
---|
1539 | return rc;
|
---|
1540 | }
|
---|
1541 |
|
---|
1542 | /**
|
---|
1543 | * Moves the guest mouse cursor to a specific position.
|
---|
1544 | *
|
---|
1545 | * @return IPRT status code.
|
---|
1546 | * @param x X position (in pixels) to move cursor to.
|
---|
1547 | * @param y Y position (in pixels) to move cursor to.
|
---|
1548 | * @param dwMouseInputFlags Additional movement flags. @sa MOUSEEVENTF_ flags.
|
---|
1549 | */
|
---|
1550 | int VBoxDnDWnd::mouseMove(int x, int y, DWORD dwMouseInputFlags)
|
---|
1551 | {
|
---|
1552 | int iScreenX = GetSystemMetrics(SM_CXSCREEN) - 1;
|
---|
1553 | int iScreenY = GetSystemMetrics(SM_CYSCREEN) - 1;
|
---|
1554 |
|
---|
1555 | INPUT Input[1] = { {0} };
|
---|
1556 | Input[0].type = INPUT_MOUSE;
|
---|
1557 | Input[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE
|
---|
1558 | | dwMouseInputFlags;
|
---|
1559 | Input[0].mi.dx = x * (65535 / iScreenX);
|
---|
1560 | Input[0].mi.dy = y * (65535 / iScreenY);
|
---|
1561 |
|
---|
1562 | int rc;
|
---|
1563 | if (g_pfnSendInput(1 /* Number of inputs */,
|
---|
1564 | Input, sizeof(INPUT)))
|
---|
1565 | {
|
---|
1566 | #ifdef DEBUG_andy
|
---|
1567 | CURSORINFO ci;
|
---|
1568 | RT_ZERO(ci);
|
---|
1569 | ci.cbSize = sizeof(ci);
|
---|
1570 | BOOL fRc = GetCursorInfo(&ci);
|
---|
1571 | if (fRc)
|
---|
1572 | LogFlowThisFunc(("Cursor shown=%RTbool, cursor=0x%p, x=%d, y=%d\n",
|
---|
1573 | (ci.flags & CURSOR_SHOWING) ? true : false,
|
---|
1574 | ci.hCursor, ci.ptScreenPos.x, ci.ptScreenPos.y));
|
---|
1575 | #endif
|
---|
1576 | rc = VINF_SUCCESS;
|
---|
1577 | }
|
---|
1578 | else
|
---|
1579 | {
|
---|
1580 | DWORD dwErr = GetLastError();
|
---|
1581 | rc = RTErrConvertFromWin32(dwErr);
|
---|
1582 | LogFlowFunc(("SendInput failed with rc=%Rrc\n", rc));
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | return rc;
|
---|
1586 | }
|
---|
1587 |
|
---|
1588 | /**
|
---|
1589 | * Releases a previously pressed left guest mouse button.
|
---|
1590 | *
|
---|
1591 | * @return IPRT status code.
|
---|
1592 | */
|
---|
1593 | int VBoxDnDWnd::mouseRelease(void)
|
---|
1594 | {
|
---|
1595 | LogFlowFuncEnter();
|
---|
1596 |
|
---|
1597 | int rc;
|
---|
1598 |
|
---|
1599 | /* Release mouse button in the guest to start the "drop"
|
---|
1600 | * action at the current mouse cursor position. */
|
---|
1601 | INPUT Input[1] = { {0} };
|
---|
1602 | Input[0].type = INPUT_MOUSE;
|
---|
1603 | Input[0].mi.dwFlags = MOUSEEVENTF_LEFTUP;
|
---|
1604 | if (!g_pfnSendInput(1, Input, sizeof(INPUT)))
|
---|
1605 | {
|
---|
1606 | DWORD dwErr = GetLastError();
|
---|
1607 | rc = RTErrConvertFromWin32(dwErr);
|
---|
1608 | LogFlowFunc(("SendInput failed with rc=%Rrc\n", rc));
|
---|
1609 | }
|
---|
1610 | else
|
---|
1611 | rc = VINF_SUCCESS;
|
---|
1612 |
|
---|
1613 | return rc;
|
---|
1614 | }
|
---|
1615 |
|
---|
1616 | /**
|
---|
1617 | * Resets the proxy window.
|
---|
1618 | */
|
---|
1619 | void VBoxDnDWnd::Reset(void)
|
---|
1620 | {
|
---|
1621 | LogFlowThisFunc(("Resetting, old mMode=%ld, mState=%ld\n",
|
---|
1622 | m_enmMode, m_enmState));
|
---|
1623 |
|
---|
1624 | /*
|
---|
1625 | * Note: Don't clear this->lstAllowedFormats at the moment, as this value is initialized
|
---|
1626 | * on class creation. We might later want to modify the allowed formats at runtime,
|
---|
1627 | * so keep this in mind when implementing this.
|
---|
1628 | */
|
---|
1629 |
|
---|
1630 | this->m_lstFmtActive.clear();
|
---|
1631 | this->m_lstActionsAllowed = VBOX_DND_ACTION_IGNORE;
|
---|
1632 |
|
---|
1633 | int rc2 = setMode(Unknown);
|
---|
1634 | AssertRC(rc2);
|
---|
1635 |
|
---|
1636 | Hide();
|
---|
1637 | }
|
---|
1638 |
|
---|
1639 | /**
|
---|
1640 | * Sets the current operation mode of this proxy window.
|
---|
1641 | *
|
---|
1642 | * @return IPRT status code.
|
---|
1643 | * @param enmMode New mode to set.
|
---|
1644 | */
|
---|
1645 | int VBoxDnDWnd::setMode(Mode enmMode)
|
---|
1646 | {
|
---|
1647 | LogFlowThisFunc(("Old mode=%ld, new mode=%ld\n",
|
---|
1648 | m_enmMode, enmMode));
|
---|
1649 |
|
---|
1650 | m_enmMode = enmMode;
|
---|
1651 | m_enmState = Initialized;
|
---|
1652 |
|
---|
1653 | return VINF_SUCCESS;
|
---|
1654 | }
|
---|
1655 |
|
---|
1656 | /**
|
---|
1657 | * Static helper function for having an own WndProc for proxy
|
---|
1658 | * window instances.
|
---|
1659 | */
|
---|
1660 | static LRESULT CALLBACK vboxDnDWndProcInstance(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) RT_NOTHROW_DEF
|
---|
1661 | {
|
---|
1662 | LONG_PTR pUserData = GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
---|
1663 | AssertPtrReturn(pUserData, 0);
|
---|
1664 |
|
---|
1665 | VBoxDnDWnd *pWnd = reinterpret_cast<VBoxDnDWnd *>(pUserData);
|
---|
1666 | if (pWnd)
|
---|
1667 | return pWnd->WndProc(hWnd, uMsg, wParam, lParam);
|
---|
1668 |
|
---|
1669 | return 0;
|
---|
1670 | }
|
---|
1671 |
|
---|
1672 | /**
|
---|
1673 | * Static helper function for routing Windows messages to a specific
|
---|
1674 | * proxy window instance.
|
---|
1675 | */
|
---|
1676 | static LRESULT CALLBACK vboxDnDWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) RT_NOTHROW_DEF
|
---|
1677 | {
|
---|
1678 | /* Note: WM_NCCREATE is not the first ever message which arrives, but
|
---|
1679 | * early enough for us. */
|
---|
1680 | if (uMsg == WM_NCCREATE)
|
---|
1681 | {
|
---|
1682 | LPCREATESTRUCT pCS = (LPCREATESTRUCT)lParam;
|
---|
1683 | AssertPtr(pCS);
|
---|
1684 | SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)pCS->lpCreateParams);
|
---|
1685 | SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)vboxDnDWndProcInstance);
|
---|
1686 |
|
---|
1687 | return vboxDnDWndProcInstance(hWnd, uMsg, wParam, lParam);
|
---|
1688 | }
|
---|
1689 |
|
---|
1690 | /* No window associated yet. */
|
---|
1691 | return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
---|
1692 | }
|
---|
1693 |
|
---|
1694 | /**
|
---|
1695 | * Initializes drag and drop.
|
---|
1696 | *
|
---|
1697 | * @return IPRT status code.
|
---|
1698 | * @param pEnv The DnD service's environment.
|
---|
1699 | * @param ppInstance The instance pointer which refer to this object.
|
---|
1700 | */
|
---|
1701 | DECLCALLBACK(int) VBoxDnDInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
|
---|
1702 | {
|
---|
1703 | AssertPtrReturn(pEnv, VERR_INVALID_POINTER);
|
---|
1704 | AssertPtrReturn(ppInstance, VERR_INVALID_POINTER);
|
---|
1705 |
|
---|
1706 | LogFlowFuncEnter();
|
---|
1707 |
|
---|
1708 | PVBOXDNDCONTEXT pCtx = &g_Ctx; /* Only one instance at the moment. */
|
---|
1709 | AssertPtr(pCtx);
|
---|
1710 |
|
---|
1711 | int rc;
|
---|
1712 | bool fSupportedOS = true;
|
---|
1713 |
|
---|
1714 | if (VbglR3AutoLogonIsRemoteSession())
|
---|
1715 | {
|
---|
1716 | /* Do not do drag and drop for remote sessions. */
|
---|
1717 | LogRel(("DnD: Drag and drop has been disabled for a remote session\n"));
|
---|
1718 | rc = VERR_NOT_SUPPORTED;
|
---|
1719 | }
|
---|
1720 | else
|
---|
1721 | rc = VINF_SUCCESS;
|
---|
1722 |
|
---|
1723 | if (RT_SUCCESS(rc))
|
---|
1724 | {
|
---|
1725 | g_pfnSendInput = (PFNSENDINPUT)
|
---|
1726 | RTLdrGetSystemSymbol("User32.dll", "SendInput");
|
---|
1727 | fSupportedOS = !RT_BOOL(g_pfnSendInput == NULL);
|
---|
1728 | g_pfnEnumDisplayMonitors = (PFNENUMDISPLAYMONITORS)
|
---|
1729 | RTLdrGetSystemSymbol("User32.dll", "EnumDisplayMonitors");
|
---|
1730 | /* g_pfnEnumDisplayMonitors is optional. */
|
---|
1731 |
|
---|
1732 | if (!fSupportedOS)
|
---|
1733 | {
|
---|
1734 | LogRel(("DnD: Not supported Windows version, disabling drag and drop support\n"));
|
---|
1735 | rc = VERR_NOT_SUPPORTED;
|
---|
1736 | }
|
---|
1737 | }
|
---|
1738 |
|
---|
1739 | if (RT_SUCCESS(rc))
|
---|
1740 | {
|
---|
1741 | /* Assign service environment to our context. */
|
---|
1742 | pCtx->pEnv = pEnv;
|
---|
1743 |
|
---|
1744 | /* Create the proxy window. At the moment we
|
---|
1745 | * only support one window at a time. */
|
---|
1746 | VBoxDnDWnd *pWnd = NULL;
|
---|
1747 | try
|
---|
1748 | {
|
---|
1749 | pWnd = new VBoxDnDWnd();
|
---|
1750 | rc = pWnd->Initialize(pCtx);
|
---|
1751 |
|
---|
1752 | /* Add proxy window to our proxy windows list. */
|
---|
1753 | if (RT_SUCCESS(rc))
|
---|
1754 | pCtx->lstWnd.append(pWnd);
|
---|
1755 | }
|
---|
1756 | catch (std::bad_alloc)
|
---|
1757 | {
|
---|
1758 | rc = VERR_NO_MEMORY;
|
---|
1759 | }
|
---|
1760 | }
|
---|
1761 |
|
---|
1762 | if (RT_SUCCESS(rc))
|
---|
1763 | rc = RTSemEventCreate(&pCtx->hEvtQueueSem);
|
---|
1764 | if (RT_SUCCESS(rc))
|
---|
1765 | {
|
---|
1766 | *ppInstance = pCtx;
|
---|
1767 |
|
---|
1768 | LogRel(("DnD: Drag and drop service successfully started\n"));
|
---|
1769 | }
|
---|
1770 | else
|
---|
1771 | LogRel(("DnD: Initializing drag and drop service failed with rc=%Rrc\n", rc));
|
---|
1772 |
|
---|
1773 | LogFlowFuncLeaveRC(rc);
|
---|
1774 | return rc;
|
---|
1775 | }
|
---|
1776 |
|
---|
1777 | DECLCALLBACK(int) VBoxDnDStop(void *pInstance)
|
---|
1778 | {
|
---|
1779 | AssertPtrReturn(pInstance, VERR_INVALID_POINTER);
|
---|
1780 |
|
---|
1781 | LogFunc(("Stopping pInstance=%p\n", pInstance));
|
---|
1782 |
|
---|
1783 | PVBOXDNDCONTEXT pCtx = (PVBOXDNDCONTEXT)pInstance;
|
---|
1784 | AssertPtr(pCtx);
|
---|
1785 |
|
---|
1786 | /* Set shutdown indicator. */
|
---|
1787 | ASMAtomicWriteBool(&pCtx->fShutdown, true);
|
---|
1788 |
|
---|
1789 | /* Disconnect. */
|
---|
1790 | VbglR3DnDDisconnect(&pCtx->cmdCtx);
|
---|
1791 |
|
---|
1792 | LogFlowFuncLeaveRC(VINF_SUCCESS);
|
---|
1793 | return VINF_SUCCESS;
|
---|
1794 | }
|
---|
1795 |
|
---|
1796 | DECLCALLBACK(void) VBoxDnDDestroy(void *pInstance)
|
---|
1797 | {
|
---|
1798 | AssertPtrReturnVoid(pInstance);
|
---|
1799 |
|
---|
1800 | LogFunc(("Destroying pInstance=%p\n", pInstance));
|
---|
1801 |
|
---|
1802 | PVBOXDNDCONTEXT pCtx = (PVBOXDNDCONTEXT)pInstance;
|
---|
1803 | AssertPtr(pCtx);
|
---|
1804 |
|
---|
1805 | /** @todo At the moment we only have one DnD proxy window. */
|
---|
1806 | Assert(pCtx->lstWnd.size() == 1);
|
---|
1807 | VBoxDnDWnd *pWnd = pCtx->lstWnd.first();
|
---|
1808 | if (pWnd)
|
---|
1809 | {
|
---|
1810 | delete pWnd;
|
---|
1811 | pWnd = NULL;
|
---|
1812 | }
|
---|
1813 |
|
---|
1814 | if (pCtx->hEvtQueueSem != NIL_RTSEMEVENT)
|
---|
1815 | {
|
---|
1816 | RTSemEventDestroy(pCtx->hEvtQueueSem);
|
---|
1817 | pCtx->hEvtQueueSem = NIL_RTSEMEVENT;
|
---|
1818 | }
|
---|
1819 |
|
---|
1820 | LogFunc(("Destroyed pInstance=%p\n", pInstance));
|
---|
1821 | }
|
---|
1822 |
|
---|
1823 | DECLCALLBACK(int) VBoxDnDWorker(void *pInstance, bool volatile *pfShutdown)
|
---|
1824 | {
|
---|
1825 | AssertPtr(pInstance);
|
---|
1826 | AssertPtr(pfShutdown);
|
---|
1827 |
|
---|
1828 | LogFlowFunc(("pInstance=%p\n", pInstance));
|
---|
1829 |
|
---|
1830 | /*
|
---|
1831 | * Tell the control thread that it can continue
|
---|
1832 | * spawning services.
|
---|
1833 | */
|
---|
1834 | RTThreadUserSignal(RTThreadSelf());
|
---|
1835 |
|
---|
1836 | PVBOXDNDCONTEXT pCtx = (PVBOXDNDCONTEXT)pInstance;
|
---|
1837 | AssertPtr(pCtx);
|
---|
1838 |
|
---|
1839 | int rc = VbglR3DnDConnect(&pCtx->cmdCtx);
|
---|
1840 | if (RT_FAILURE(rc))
|
---|
1841 | return rc;
|
---|
1842 |
|
---|
1843 | /** @todo At the moment we only have one DnD proxy window. */
|
---|
1844 | Assert(pCtx->lstWnd.size() == 1);
|
---|
1845 | VBoxDnDWnd *pWnd = pCtx->lstWnd.first();
|
---|
1846 | AssertPtr(pWnd);
|
---|
1847 |
|
---|
1848 | /* Number of invalid messages skipped in a row. */
|
---|
1849 | int cMsgSkippedInvalid = 0;
|
---|
1850 | PVBOXDNDEVENT pEvent = NULL;
|
---|
1851 |
|
---|
1852 | for (;;)
|
---|
1853 | {
|
---|
1854 | pEvent = (PVBOXDNDEVENT)RTMemAllocZ(sizeof(VBOXDNDEVENT));
|
---|
1855 | if (!pEvent)
|
---|
1856 | {
|
---|
1857 | rc = VERR_NO_MEMORY;
|
---|
1858 | break;
|
---|
1859 | }
|
---|
1860 | /* Note: pEvent will be free'd by the consumer later. */
|
---|
1861 |
|
---|
1862 | PVBGLR3DNDEVENT pVbglR3Event = NULL;
|
---|
1863 | rc = VbglR3DnDEventGetNext(&pCtx->cmdCtx, &pVbglR3Event);
|
---|
1864 | if (RT_SUCCESS(rc))
|
---|
1865 | {
|
---|
1866 | LogFunc(("enmType=%RU32, rc=%Rrc\n", pVbglR3Event->enmType, rc));
|
---|
1867 |
|
---|
1868 | cMsgSkippedInvalid = 0; /* Reset skipped messages count. */
|
---|
1869 |
|
---|
1870 | LogRel2(("DnD: Received new event, type=%RU32, rc=%Rrc\n", pVbglR3Event->enmType, rc));
|
---|
1871 |
|
---|
1872 | /* pEvent now owns pVbglR3Event. */
|
---|
1873 | pEvent->pVbglR3Event = pVbglR3Event;
|
---|
1874 | pVbglR3Event = NULL;
|
---|
1875 |
|
---|
1876 | rc = pWnd->ProcessEvent(pEvent);
|
---|
1877 | if (RT_SUCCESS(rc))
|
---|
1878 | {
|
---|
1879 | /* Event was consumed and the proxy window till take care of the memory -- NULL it. */
|
---|
1880 | pEvent = NULL;
|
---|
1881 | }
|
---|
1882 | else
|
---|
1883 | LogRel(("DnD: Processing proxy window event %RU32 failed with %Rrc\n", pVbglR3Event->enmType, rc));
|
---|
1884 | }
|
---|
1885 |
|
---|
1886 | if (RT_FAILURE(rc))
|
---|
1887 | {
|
---|
1888 | if (pEvent)
|
---|
1889 | {
|
---|
1890 | RTMemFree(pEvent);
|
---|
1891 | pEvent = NULL;
|
---|
1892 | }
|
---|
1893 |
|
---|
1894 | LogFlowFunc(("Processing next message failed with rc=%Rrc\n", rc));
|
---|
1895 |
|
---|
1896 | /* Old(er) hosts either are broken regarding DnD support or otherwise
|
---|
1897 | * don't support the stuff we do on the guest side, so make sure we
|
---|
1898 | * don't process invalid messages forever. */
|
---|
1899 | if (cMsgSkippedInvalid++ > 32)
|
---|
1900 | {
|
---|
1901 | LogRel(("DnD: Too many invalid/skipped messages from host, exiting ...\n"));
|
---|
1902 | break;
|
---|
1903 | }
|
---|
1904 |
|
---|
1905 | /* Make sure our proxy window is hidden when an error occured to
|
---|
1906 | * not block the guest's UI. */
|
---|
1907 | int rc2 = pWnd->Abort();
|
---|
1908 | AssertRC(rc2);
|
---|
1909 | }
|
---|
1910 |
|
---|
1911 | if (*pfShutdown)
|
---|
1912 | break;
|
---|
1913 |
|
---|
1914 | if (ASMAtomicReadBool(&pCtx->fShutdown))
|
---|
1915 | break;
|
---|
1916 |
|
---|
1917 | if (RT_FAILURE(rc)) /* Don't hog the CPU on errors. */
|
---|
1918 | RTThreadSleep(1000 /* ms */);
|
---|
1919 | }
|
---|
1920 |
|
---|
1921 | if (pEvent)
|
---|
1922 | {
|
---|
1923 | VbglR3DnDEventFree(pEvent->pVbglR3Event);
|
---|
1924 |
|
---|
1925 | RTMemFree(pEvent);
|
---|
1926 | pEvent = NULL;
|
---|
1927 | }
|
---|
1928 |
|
---|
1929 | VbglR3DnDDisconnect(&pCtx->cmdCtx);
|
---|
1930 |
|
---|
1931 | LogRel(("DnD: Ended\n"));
|
---|
1932 |
|
---|
1933 | LogFlowFuncLeaveRC(rc);
|
---|
1934 | return rc;
|
---|
1935 | }
|
---|
1936 |
|
---|
1937 | /**
|
---|
1938 | * The service description.
|
---|
1939 | */
|
---|
1940 | VBOXSERVICEDESC g_SvcDescDnD =
|
---|
1941 | {
|
---|
1942 | /* pszName. */
|
---|
1943 | "draganddrop",
|
---|
1944 | /* pszDescription. */
|
---|
1945 | "Drag and Drop",
|
---|
1946 | /* methods */
|
---|
1947 | VBoxDnDInit,
|
---|
1948 | VBoxDnDWorker,
|
---|
1949 | VBoxDnDStop,
|
---|
1950 | VBoxDnDDestroy
|
---|
1951 | };
|
---|
1952 |
|
---|