VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnD.h@ 78425

Last change on this file since 78425 was 76563, checked in by vboxsync, 6 years ago

Additions: Use GA_INCLUDED_ and variations_ as header guard prefixes with scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: VBoxDnD.h 76563 2019-01-01 03:53:56Z vboxsync $ */
2/** @file
3 * VBoxDnD.h - Windows-specific bits of the drag'n drop service.
4 */
5
6/*
7 * Copyright (C) 2013-2019 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#ifndef GA_INCLUDED_SRC_WINNT_VBoxTray_VBoxDnD_h
19#define GA_INCLUDED_SRC_WINNT_VBoxTray_VBoxDnD_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <iprt/critsect.h>
25
26#include <iprt/cpp/mtlist.h>
27#include <iprt/cpp/ministring.h>
28
29class VBoxDnDWnd;
30
31class VBoxDnDDataObject : public IDataObject
32{
33public:
34
35 enum Status
36 {
37 Uninitialized = 0,
38 Initialized,
39 Dropping,
40 Dropped,
41 Aborted
42 };
43
44public:
45
46 VBoxDnDDataObject(LPFORMATETC pFormatEtc = NULL, LPSTGMEDIUM pStgMed = NULL, ULONG cFormats = 0);
47 virtual ~VBoxDnDDataObject(void);
48
49public: /* IUnknown methods. */
50
51 STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
52 STDMETHOD_(ULONG, AddRef)(void);
53 STDMETHOD_(ULONG, Release)(void);
54
55public: /* IDataObject methods. */
56
57 STDMETHOD(GetData)(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium);
58 STDMETHOD(GetDataHere)(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium);
59 STDMETHOD(QueryGetData)(LPFORMATETC pFormatEtc);
60 STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC pFormatEct, LPFORMATETC pFormatEtcOut);
61 STDMETHOD(SetData)(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium, BOOL fRelease);
62 STDMETHOD(EnumFormatEtc)(DWORD dwDirection, IEnumFORMATETC **ppEnumFormatEtc);
63 STDMETHOD(DAdvise)(LPFORMATETC pFormatEtc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection);
64 STDMETHOD(DUnadvise)(DWORD dwConnection);
65 STDMETHOD(EnumDAdvise)(IEnumSTATDATA **ppEnumAdvise);
66
67public:
68
69 static const char* ClipboardFormatToString(CLIPFORMAT fmt);
70
71 int Abort(void);
72 void SetStatus(Status status);
73 int Signal(const RTCString &strFormat, const void *pvData, uint32_t cbData);
74
75protected:
76
77 bool LookupFormatEtc(LPFORMATETC pFormatEtc, ULONG *puIndex);
78 static HGLOBAL MemDup(HGLOBAL hMemSource);
79 void RegisterFormat(LPFORMATETC pFormatEtc, CLIPFORMAT clipFormat, TYMED tyMed = TYMED_HGLOBAL,
80 LONG lindex = -1, DWORD dwAspect = DVASPECT_CONTENT, DVTARGETDEVICE *pTargetDevice = NULL);
81
82 Status mStatus;
83 LONG mRefCount;
84 ULONG mcFormats;
85 LPFORMATETC mpFormatEtc;
86 LPSTGMEDIUM mpStgMedium;
87 RTSEMEVENT mEventDropped;
88 RTCString mstrFormat;
89 void *mpvData;
90 uint32_t mcbData;
91};
92
93class VBoxDnDDropSource : public IDropSource
94{
95public:
96
97 VBoxDnDDropSource(VBoxDnDWnd *pThis);
98 virtual ~VBoxDnDDropSource(void);
99
100public:
101
102 VBOXDNDACTION GetCurrentAction(void) { return mDnDActionCurrent; }
103
104public: /* IUnknown methods. */
105
106 STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
107 STDMETHOD_(ULONG, AddRef)(void);
108 STDMETHOD_(ULONG, Release)(void);
109
110public: /* IDropSource methods. */
111
112 STDMETHOD(QueryContinueDrag)(BOOL fEscapePressed, DWORD dwKeyState);
113 STDMETHOD(GiveFeedback)(DWORD dwEffect);
114
115protected:
116
117 /** Reference count of this object. */
118 LONG mRefCount;
119 /** Pointer to parent proxy window. */
120 VBoxDnDWnd *mpWndParent;
121 /** Current drag effect. */
122 DWORD mdwCurEffect;
123 /** Current action to perform on the host. */
124 VBOXDNDACTION mDnDActionCurrent;
125};
126
127class VBoxDnDDropTarget : public IDropTarget
128{
129public:
130
131 VBoxDnDDropTarget(VBoxDnDWnd *pThis);
132 virtual ~VBoxDnDDropTarget(void);
133
134public: /* IUnknown methods. */
135
136 STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
137 STDMETHOD_(ULONG, AddRef)(void);
138 STDMETHOD_(ULONG, Release)(void);
139
140public: /* IDropTarget methods. */
141
142 STDMETHOD(DragEnter)(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
143 STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
144 STDMETHOD(DragLeave)(void);
145 STDMETHOD(Drop)(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
146
147protected:
148
149 static void DumpFormats(IDataObject *pDataObject);
150 static DWORD GetDropEffect(DWORD grfKeyState, DWORD dwAllowedEffects);
151 void reset(void);
152
153public:
154
155 void *DataMutableRaw(void) const { return mpvData; }
156 size_t DataSize(void) const { return mcbData; }
157 RTCString Formats(void) const;
158 int WaitForDrop(RTMSINTERVAL msTimeout);
159
160protected:
161
162 /** Reference count of this object. */
163 LONG mRefCount;
164 /** Pointer to parent proxy window. */
165 VBoxDnDWnd *mpWndParent;
166 /** Current drop effect. */
167 DWORD mdwCurEffect;
168 /** Copy of the data object's current FORMATETC struct.
169 * Note: We don't keep the pointer of the DVTARGETDEVICE here! */
170 FORMATETC mFormatEtc;
171 /** Stringified data object's formats string. */
172 RTCString mstrFormats;
173 /** Pointer to actual format data. */
174 void *mpvData;
175 /** Size (in bytes) of format data. */
176 size_t mcbData;
177 /** Event for waiting on the "drop" event. */
178 RTSEMEVENT hEventDrop;
179 /** Result of the drop event. */
180 int mDroppedRc;
181};
182
183class VBoxDnDEnumFormatEtc : public IEnumFORMATETC
184{
185public:
186
187 VBoxDnDEnumFormatEtc(LPFORMATETC pFormatEtc, ULONG cFormats);
188 virtual ~VBoxDnDEnumFormatEtc(void);
189
190public:
191
192 STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
193 STDMETHOD_(ULONG, AddRef)(void);
194 STDMETHOD_(ULONG, Release)(void);
195
196 STDMETHOD(Next)(ULONG cFormats, LPFORMATETC pFormatEtc, ULONG *pcFetched);
197 STDMETHOD(Skip)(ULONG cFormats);
198 STDMETHOD(Reset)(void);
199 STDMETHOD(Clone)(IEnumFORMATETC **ppEnumFormatEtc);
200
201public:
202
203 static void CopyFormat(LPFORMATETC pFormatDest, LPFORMATETC pFormatSource);
204 static HRESULT CreateEnumFormatEtc(UINT cFormats, LPFORMATETC pFormatEtc, IEnumFORMATETC **ppEnumFormatEtc);
205
206private:
207
208 LONG m_lRefCount;
209 ULONG m_nIndex;
210 ULONG m_nNumFormats;
211 LPFORMATETC m_pFormatEtc;
212};
213
214struct VBOXDNDCONTEXT;
215class VBoxDnDWnd;
216
217/*
218 * A drag'n drop event from the host.
219 */
220typedef struct VBOXDNDEVENT
221{
222 /** The actual DnD HGCM event data. */
223 PVBGLR3DNDEVENT pVbglR3Event;
224
225} VBOXDNDEVENT, *PVBOXDNDEVENT;
226
227/**
228 * DnD context data.
229 */
230typedef struct VBOXDNDCONTEXT
231{
232 /** Pointer to the service environment. */
233 const VBOXSERVICEENV *pEnv;
234 /** Started indicator. */
235 bool fStarted;
236 /** Shutdown indicator. */
237 bool fShutdown;
238 /** The registered window class. */
239 ATOM wndClass;
240 /** The DnD main event queue. */
241 RTCMTList<VBOXDNDEVENT> lstEvtQueue;
242 /** Semaphore for waiting on main event queue
243 * events. */
244 RTSEMEVENT hEvtQueueSem;
245 /** List of drag'n drop proxy windows.
246 * Note: At the moment only one window is supported. */
247 RTCMTList<VBoxDnDWnd*> lstWnd;
248 /** The DnD command context. */
249 VBGLR3GUESTDNDCMDCTX cmdCtx;
250
251} VBOXDNDCONTEXT, *PVBOXDNDCONTEXT;
252
253/**
254 * Everything which is required to successfully start
255 * a drag'n drop operation via DoDragDrop().
256 */
257typedef struct VBOXDNDSTARTUPINFO
258{
259 /** Our DnD data object, holding
260 * the raw DnD data. */
261 VBoxDnDDataObject *pDataObject;
262 /** The drop source for sending the
263 * DnD request to a IDropTarget. */
264 VBoxDnDDropSource *pDropSource;
265 /** The DnD effects which are wanted / allowed. */
266 DWORD dwOKEffects;
267
268} VBOXDNDSTARTUPINFO, *PVBOXDNDSTARTUPINFO;
269
270/**
271 * Class for handling a DnD proxy window.
272 ** @todo Unify this and VBoxClient's DragInstance!
273 */
274class VBoxDnDWnd
275{
276 /**
277 * Current state of a DnD proxy
278 * window.
279 */
280 enum State
281 {
282 Uninitialized = 0,
283 Initialized,
284 Dragging,
285 Dropped,
286 Canceled
287 };
288
289 /**
290 * Current operation mode of
291 * a DnD proxy window.
292 */
293 enum Mode
294 {
295 /** Unknown mode. */
296 Unknown = 0,
297 /** Host to guest. */
298 HG,
299 /** Guest to host. */
300 GH
301 };
302
303public:
304
305 VBoxDnDWnd(void);
306 virtual ~VBoxDnDWnd(void);
307
308public:
309
310 int Initialize(PVBOXDNDCONTEXT pContext);
311 void Destroy(void);
312
313public:
314
315 /** The window's thread for the native message pump and
316 * OLE context. */
317 static int Thread(RTTHREAD hThread, void *pvUser);
318
319public:
320
321 static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM lParam);
322 /** The per-instance wndproc routine. */
323 LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
324
325public:
326
327#ifdef VBOX_WITH_DRAG_AND_DROP_GH
328 int RegisterAsDropTarget(void);
329 int UnregisterAsDropTarget(void);
330#endif
331
332public:
333
334 int OnCreate(void);
335 void OnDestroy(void);
336
337 int Abort(void);
338
339 /* Host -> Guest */
340 int OnHgEnter(const RTCList<RTCString> &formats, VBOXDNDACTIONLIST dndLstActionsAllowed);
341 int OnHgMove(uint32_t u32xPos, uint32_t u32yPos, VBOXDNDACTION dndAction);
342 int OnHgDrop(void);
343 int OnHgLeave(void);
344 int OnHgDataReceive(PVBGLR3GUESTDNDMETADATA pMeta);
345 int OnHgCancel(void);
346
347#ifdef VBOX_WITH_DRAG_AND_DROP_GH
348 /* Guest -> Host */
349 int OnGhIsDnDPending(void);
350 int OnGhDrop(const RTCString &strFormat, VBOXDNDACTION dndActionDefault);
351#endif
352
353 void PostMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
354 int ProcessEvent(PVBOXDNDEVENT pEvent);
355
356 int Hide(void);
357 void Reset(void);
358
359protected:
360
361 int checkForSessionChange(void);
362 int makeFullscreen(void);
363 int mouseMove(int x, int y, DWORD dwMouseInputFlags);
364 int mouseRelease(void);
365 int setMode(Mode enmMode);
366
367public: /** @todo Make protected! */
368
369 /** Pointer to DnD context. */
370 PVBOXDNDCONTEXT pCtx;
371 /** The proxy window's main thread for processing
372 * window messages. */
373 RTTHREAD hThread;
374 RTCRITSECT mCritSect;
375 RTSEMEVENT mEventSem;
376#ifdef RT_OS_WINDOWS
377 /** The window's handle. */
378 HWND hWnd;
379 /** List of allowed MIME types this
380 * client can handle. Make this a per-instance
381 * property so that we can selectively allow/forbid
382 * certain types later on runtime. */
383 RTCList<RTCString> lstFmtSup;
384 /** List of formats for the current
385 * drag'n drop operation. */
386 RTCList<RTCString> lstFmtActive;
387 /** List of all current drag'n drop actions allowed. */
388 VBOXDNDACTIONLIST dndLstActionsAllowed;
389 /** The startup information required
390 * for the actual DoDragDrop() call. */
391 VBOXDNDSTARTUPINFO startupInfo;
392 /** Is the left mouse button being pressed
393 * currently while being in this window? */
394 bool mfMouseButtonDown;
395# ifdef VBOX_WITH_DRAG_AND_DROP_GH
396 /** IDropTarget implementation for guest -> host
397 * support. */
398 VBoxDnDDropTarget *pDropTarget;
399# endif /* VBOX_WITH_DRAG_AND_DROP_GH */
400#else /* !RT_OS_WINDOWS */
401 /** @todo Implement me. */
402#endif /* !RT_OS_WINDOWS */
403
404 /** The window's own DnD context. */
405 VBGLR3GUESTDNDCMDCTX mDnDCtx;
406 /** The current operation mode. */
407 Mode mMode;
408 /** The current state. */
409 State mState;
410 /** Format being requested. */
411 RTCString mFormatRequested;
412};
413
414#endif /* !GA_INCLUDED_SRC_WINNT_VBoxTray_VBoxDnD_h */
415
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette