VirtualBox

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

Last change on this file since 59010 was 58336, checked in by vboxsync, 9 years ago

DnD/VBoxTray: Not needed anymore.

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