1 | /** @file
|
---|
2 | * Shared Clipboard - Common Guest and Host Code, for Windows OSes.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef VBOX_INCLUDED_GuestHost_SharedClipboard_win_h
|
---|
37 | #define VBOX_INCLUDED_GuestHost_SharedClipboard_win_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/critsect.h>
|
---|
43 | #include <iprt/types.h>
|
---|
44 | #include <iprt/req.h>
|
---|
45 | #include <iprt/win/windows.h>
|
---|
46 |
|
---|
47 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
48 |
|
---|
49 | # ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
50 | # include <vector>
|
---|
51 |
|
---|
52 | # include <iprt/cpp/ministring.h> /* For RTCString. */
|
---|
53 | # include <iprt/win/shlobj.h> /* For DROPFILES and friends. */
|
---|
54 | # include <VBox/com/string.h> /* For Utf8Str. */
|
---|
55 | # include <oleidl.h>
|
---|
56 |
|
---|
57 | # include <VBox/GuestHost/SharedClipboard-transfers.h>
|
---|
58 |
|
---|
59 | using namespace com;
|
---|
60 | # endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
|
---|
61 |
|
---|
62 | #ifndef WM_CLIPBOARDUPDATE
|
---|
63 | # define WM_CLIPBOARDUPDATE 0x031D
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | #define SHCL_WIN_WNDCLASS_NAME "VBoxSharedClipboardClass"
|
---|
67 |
|
---|
68 | /** See: https://docs.microsoft.com/en-us/windows/desktop/dataxchg/html-clipboard-format
|
---|
69 | * Do *not* change the name, as this will break compatbility with other (legacy) applications! */
|
---|
70 | #define SHCL_WIN_REGFMT_HTML "HTML Format"
|
---|
71 |
|
---|
72 | /** Default timeout (in ms) for passing down messages down the clipboard chain. */
|
---|
73 | #define SHCL_WIN_CBCHAIN_TIMEOUT_MS 5000
|
---|
74 |
|
---|
75 | /** Reports clipboard formats. */
|
---|
76 | #define SHCL_WIN_WM_REPORT_FORMATS WM_USER
|
---|
77 | /** Reads data from the clipboard and sends it to the destination. */
|
---|
78 | #define SHCL_WIN_WM_READ_DATA WM_USER + 1
|
---|
79 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
80 | /** Starts a transfer on the guest.
|
---|
81 | * This creates the necessary IDataObject in the matching window thread. */
|
---|
82 | # define SHCL_WIN_WM_TRANSFER_START WM_USER + 2
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | /* Dynamically load clipboard functions from User32.dll. */
|
---|
86 | typedef BOOL WINAPI FNADDCLIPBOARDFORMATLISTENER(HWND);
|
---|
87 | typedef FNADDCLIPBOARDFORMATLISTENER *PFNADDCLIPBOARDFORMATLISTENER;
|
---|
88 |
|
---|
89 | typedef BOOL WINAPI FNREMOVECLIPBOARDFORMATLISTENER(HWND);
|
---|
90 | typedef FNREMOVECLIPBOARDFORMATLISTENER *PFNREMOVECLIPBOARDFORMATLISTENER;
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Structure for keeping function pointers for the new clipboard API.
|
---|
94 | * If the new API is not available, those function pointer are NULL.
|
---|
95 | */
|
---|
96 | typedef struct _SHCLWINAPINEW
|
---|
97 | {
|
---|
98 | PFNADDCLIPBOARDFORMATLISTENER pfnAddClipboardFormatListener;
|
---|
99 | PFNREMOVECLIPBOARDFORMATLISTENER pfnRemoveClipboardFormatListener;
|
---|
100 | } SHCLWINAPINEW, *PSHCLWINAPINEW;
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Structure for keeping variables which are needed to drive the old clipboard API.
|
---|
104 | */
|
---|
105 | typedef struct _SHCLWINAPIOLD
|
---|
106 | {
|
---|
107 | /** Timer ID for the refresh timer. */
|
---|
108 | UINT timerRefresh;
|
---|
109 | /** Whether "pinging" the clipboard chain currently is in progress or not. */
|
---|
110 | bool fCBChainPingInProcess;
|
---|
111 | } SHCLWINAPIOLD, *PSHCLWINAPIOLD;
|
---|
112 |
|
---|
113 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
114 | /** Forward declaration for the Windows data object. */
|
---|
115 | class SharedClipboardWinDataObject;
|
---|
116 | #endif
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Structure for maintaining a Shared Clipboard context on Windows platforms.
|
---|
120 | */
|
---|
121 | typedef struct _SHCLWINCTX
|
---|
122 | {
|
---|
123 | /** Critical section to serialize access. */
|
---|
124 | RTCRITSECT CritSect;
|
---|
125 | /** Window handle of our (invisible) clipbaord window. */
|
---|
126 | HWND hWnd;
|
---|
127 | /** Window handle which is next to us in the clipboard chain. */
|
---|
128 | HWND hWndNextInChain;
|
---|
129 | /** Window handle of the clipboard owner *if* we are the owner.
|
---|
130 | * @todo r=bird: Ignore the misleading statement above. This is only set to
|
---|
131 | * NULL by the initialization code and then it's set to the clipboard owner
|
---|
132 | * after we announce data to the clipboard. So, essentially this will be our
|
---|
133 | * windows handle or NULL. End of story. */
|
---|
134 | HWND hWndClipboardOwnerUs;
|
---|
135 | /** Structure for maintaining the new clipboard API. */
|
---|
136 | SHCLWINAPINEW newAPI;
|
---|
137 | /** Structure for maintaining the old clipboard API. */
|
---|
138 | SHCLWINAPIOLD oldAPI;
|
---|
139 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
140 | /** The "in-flight" data object for file transfers.
|
---|
141 | * This is the current data object which has been created and sent to the Windows clipboard.
|
---|
142 | * That way Windows knows that a potential file transfer is available, but the actual transfer
|
---|
143 | * hasn't been started yet.
|
---|
144 | * Can be NULL if currently not being used / no current "in-flight" transfer present. */
|
---|
145 | SharedClipboardWinDataObject
|
---|
146 | *pDataObjInFlight;
|
---|
147 | #endif
|
---|
148 | /** Request queue.
|
---|
149 | * Needed for processing HGCM requests within the HGCM (main) thread from the Windows event thread. */
|
---|
150 | RTREQQUEUE hReqQ;
|
---|
151 | } SHCLWINCTX, *PSHCLWINCTX;
|
---|
152 |
|
---|
153 | int SharedClipboardWinOpen(HWND hWnd);
|
---|
154 | int SharedClipboardWinClose(void);
|
---|
155 | int SharedClipboardWinClear(void);
|
---|
156 |
|
---|
157 | int SharedClipboardWinCtxInit(PSHCLWINCTX pWinCtx);
|
---|
158 | void SharedClipboardWinCtxDestroy(PSHCLWINCTX pWinCtx);
|
---|
159 |
|
---|
160 | int SharedClipboardWinCheckAndInitNewAPI(PSHCLWINAPINEW pAPI);
|
---|
161 | bool SharedClipboardWinIsNewAPI(PSHCLWINAPINEW pAPI);
|
---|
162 |
|
---|
163 | int SharedClipboardWinDataWrite(UINT cfFormat, void *pvData, uint32_t cbData);
|
---|
164 |
|
---|
165 | int SharedClipboardWinChainAdd(PSHCLWINCTX pCtx);
|
---|
166 | int SharedClipboardWinChainRemove(PSHCLWINCTX pCtx);
|
---|
167 | VOID CALLBACK SharedClipboardWinChainPingProc(HWND hWnd, UINT uMsg, ULONG_PTR dwData, LRESULT lResult) RT_NOTHROW_DEF;
|
---|
168 | LRESULT SharedClipboardWinChainPassToNext(PSHCLWINCTX pWinCtx, UINT msg, WPARAM wParam, LPARAM lParam);
|
---|
169 |
|
---|
170 | SHCLFORMAT SharedClipboardWinClipboardFormatToVBox(UINT uFormat);
|
---|
171 | int SharedClipboardWinGetFormats(PSHCLWINCTX pCtx, PSHCLFORMATS pfFormats);
|
---|
172 |
|
---|
173 | int SharedClipboardWinGetCFHTMLHeaderValue(const char *pszSrc, const char *pszOption, uint32_t *puValue);
|
---|
174 | bool SharedClipboardWinIsCFHTML(const char *pszSource);
|
---|
175 | int SharedClipboardWinConvertCFHTMLToMIME(const char *pszSource, const uint32_t cch, char **ppszOutput, uint32_t *pcbOutput);
|
---|
176 | int SharedClipboardWinConvertMIMEToCFHTML(const char *pszSource, size_t cb, char **ppszOutput, uint32_t *pcbOutput);
|
---|
177 |
|
---|
178 | LRESULT SharedClipboardWinHandleWMChangeCBChain(PSHCLWINCTX pWinCtx, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
---|
179 | int SharedClipboardWinHandleWMDestroy(PSHCLWINCTX pWinCtx);
|
---|
180 | int SharedClipboardWinHandleWMRenderAllFormats(PSHCLWINCTX pWinCtx, HWND hWnd);
|
---|
181 | int SharedClipboardWinHandleWMTimer(PSHCLWINCTX pWinCtx);
|
---|
182 |
|
---|
183 | int SharedClipboardWinClearAndAnnounceFormats(PSHCLWINCTX pWinCtx, SHCLFORMATS fFormats, HWND hWnd);
|
---|
184 |
|
---|
185 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
186 | class SharedClipboardTransferList;
|
---|
187 | # ifndef FILEGROUPDESCRIPTOR
|
---|
188 | class FILEGROUPDESCRIPTOR;
|
---|
189 | # endif
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Generic Windows class implementing IDataObject for Shared Clipboard data transfers.
|
---|
193 | */
|
---|
194 | class SharedClipboardWinDataObject : public IDataObject //, public IDataObjectAsyncCapability
|
---|
195 | {
|
---|
196 | public:
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Structure for keeping a data object callback context.
|
---|
200 | */
|
---|
201 | struct CALLBACKCTX
|
---|
202 | {
|
---|
203 | /** Pointer to the data object of this callback. */
|
---|
204 | SharedClipboardWinDataObject *pThis;
|
---|
205 | /** User-supplied pointer to more context data. */
|
---|
206 | void *pvUser;
|
---|
207 | };
|
---|
208 | /** Pointer to a Shared Clipboard Windows data object callback table. */
|
---|
209 | typedef CALLBACKCTX *PCALLBACKCTX;
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * @name Shared Clipboard Windows data object callback table.
|
---|
213 | */
|
---|
214 | struct CALLBACKS
|
---|
215 | {
|
---|
216 | /**
|
---|
217 | * Called by the data object if a transfer needs to be started.
|
---|
218 | *
|
---|
219 | * @returns VBox status code.
|
---|
220 | * @param pCbCtx Pointer to callback context.
|
---|
221 | */
|
---|
222 | DECLCALLBACKMEMBER(int, pfnTransferBegin, (PCALLBACKCTX pCbCtx));
|
---|
223 | /**
|
---|
224 | * Called by the data object if a transfer has been ended (succeeded or failed).
|
---|
225 | *
|
---|
226 | * @returns VBox status code.
|
---|
227 | * @param pCbCtx Pointer to callback context.
|
---|
228 | * @param pTransfer Pointer to transfer being completed.
|
---|
229 | * @param rcTransfer Result (IPRT-style) code.
|
---|
230 | */
|
---|
231 | DECLCALLBACKMEMBER(int, pfnTransferEnd, (PCALLBACKCTX pCbCtx, PSHCLTRANSFER pTransfer, int rcTransfer));
|
---|
232 | };
|
---|
233 | /** Pointer to a Shared Clipboard Windows data object callback table. */
|
---|
234 | typedef CALLBACKS *PCALLBACKS;
|
---|
235 |
|
---|
236 | enum Status
|
---|
237 | {
|
---|
238 | /** The object is uninitialized (not ready). */
|
---|
239 | Uninitialized = 0,
|
---|
240 | /** The object is initialized and ready to use.
|
---|
241 | * A transfer is *not* running yet! */
|
---|
242 | Initialized,
|
---|
243 | /** Transfer is running. */
|
---|
244 | Running,
|
---|
245 | /** The operation has been successfully completed. */
|
---|
246 | Completed,
|
---|
247 | /** The operation has been canceled. */
|
---|
248 | Canceled,
|
---|
249 | /** An (unrecoverable) error occurred. */
|
---|
250 | Error
|
---|
251 | };
|
---|
252 |
|
---|
253 | public:
|
---|
254 |
|
---|
255 | SharedClipboardWinDataObject(void);
|
---|
256 | virtual ~SharedClipboardWinDataObject(void);
|
---|
257 |
|
---|
258 | public:
|
---|
259 |
|
---|
260 | int Init(PSHCLCONTEXT pCtx, SharedClipboardWinDataObject::PCALLBACKS pCallbacks, LPFORMATETC pFormatEtc = NULL, LPSTGMEDIUM pStgMed = NULL, ULONG cFormats = 0);
|
---|
261 | void Uninit(void);
|
---|
262 | void Destroy(void);
|
---|
263 |
|
---|
264 | public: /* IUnknown methods. */
|
---|
265 |
|
---|
266 | STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
|
---|
267 | STDMETHOD_(ULONG, AddRef)(void);
|
---|
268 | STDMETHOD_(ULONG, Release)(void);
|
---|
269 |
|
---|
270 | public: /* IDataObject methods. */
|
---|
271 |
|
---|
272 | STDMETHOD(GetData)(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium);
|
---|
273 | STDMETHOD(GetDataHere)(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium);
|
---|
274 | STDMETHOD(QueryGetData)(LPFORMATETC pFormatEtc);
|
---|
275 | STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC pFormatEct, LPFORMATETC pFormatEtcOut);
|
---|
276 | STDMETHOD(SetData)(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium, BOOL fRelease);
|
---|
277 | STDMETHOD(EnumFormatEtc)(DWORD dwDirection, IEnumFORMATETC **ppEnumFormatEtc);
|
---|
278 | STDMETHOD(DAdvise)(LPFORMATETC pFormatEtc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection);
|
---|
279 | STDMETHOD(DUnadvise)(DWORD dwConnection);
|
---|
280 | STDMETHOD(EnumDAdvise)(IEnumSTATDATA **ppEnumAdvise);
|
---|
281 |
|
---|
282 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_WIN_ASYNC
|
---|
283 | public: /* IDataObjectAsyncCapability methods. */
|
---|
284 |
|
---|
285 | STDMETHOD(EndOperation)(HRESULT hResult, IBindCtx* pbcReserved, DWORD dwEffects);
|
---|
286 | STDMETHOD(GetAsyncMode)(BOOL* pfIsOpAsync);
|
---|
287 | STDMETHOD(InOperation)(BOOL* pfInAsyncOp);
|
---|
288 | STDMETHOD(SetAsyncMode)(BOOL fDoOpAsync);
|
---|
289 | STDMETHOD(StartOperation)(IBindCtx* pbcReserved);
|
---|
290 | #endif /* VBOX_WITH_SHARED_CLIPBOARD_WIN_ASYNC */
|
---|
291 |
|
---|
292 | public:
|
---|
293 |
|
---|
294 | int SetTransfer(PSHCLTRANSFER pTransfer);
|
---|
295 | int SetStatus(Status enmStatus, int rcSts = VINF_SUCCESS);
|
---|
296 |
|
---|
297 | public:
|
---|
298 |
|
---|
299 | static DECLCALLBACK(int) readThread(PSHCLTRANSFER pTransfer, void *pvUser);
|
---|
300 |
|
---|
301 | static void logFormat(CLIPFORMAT fmt);
|
---|
302 |
|
---|
303 | protected:
|
---|
304 |
|
---|
305 | void uninitInternal(void);
|
---|
306 |
|
---|
307 | static int Thread(RTTHREAD hThread, void *pvUser);
|
---|
308 |
|
---|
309 | inline int lock(void);
|
---|
310 | inline int unlock(void);
|
---|
311 |
|
---|
312 | int readDir(PSHCLTRANSFER pTransfer, const Utf8Str &strPath);
|
---|
313 |
|
---|
314 | int copyToHGlobal(const void *pvData, size_t cbData, UINT fFlags, HGLOBAL *phGlobal);
|
---|
315 | int createFileGroupDescriptorFromTransfer(PSHCLTRANSFER pTransfer,
|
---|
316 | bool fUnicode, HGLOBAL *phGlobal);
|
---|
317 |
|
---|
318 | bool lookupFormatEtc(LPFORMATETC pFormatEtc, ULONG *puIndex);
|
---|
319 | void registerFormat(LPFORMATETC pFormatEtc, CLIPFORMAT clipFormat, TYMED tyMed = TYMED_HGLOBAL,
|
---|
320 | LONG lindex = -1, DWORD dwAspect = DVASPECT_CONTENT, DVTARGETDEVICE *pTargetDevice = NULL);
|
---|
321 | int setTransferLocked(PSHCLTRANSFER pTransfer);
|
---|
322 | int setStatusLocked(Status enmStatus, int rc = VINF_SUCCESS);
|
---|
323 |
|
---|
324 | protected:
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * Structure for keeping a single file system object entry.
|
---|
328 | */
|
---|
329 | struct FSOBJENTRY
|
---|
330 | {
|
---|
331 | /** Relative path of the object. */
|
---|
332 | char *pszPath;
|
---|
333 | /** Related (cached) object information. */
|
---|
334 | SHCLFSOBJINFO objInfo;
|
---|
335 | };
|
---|
336 |
|
---|
337 | /** Vector containing file system objects with its (cached) objection information. */
|
---|
338 | typedef std::vector<FSOBJENTRY> FsObjEntryList;
|
---|
339 |
|
---|
340 | /** Shared Clipboard context to use. */
|
---|
341 | PSHCLCONTEXT m_pCtx;
|
---|
342 | /** The object's current status. */
|
---|
343 | Status m_enmStatus;
|
---|
344 | /** Last (IPRT-style) error set in conjunction with the status. */
|
---|
345 | int m_rcStatus;
|
---|
346 | /** Data object callback table to use. */
|
---|
347 | CALLBACKS m_Callbacks;
|
---|
348 | /** Data object callback table context to use. */
|
---|
349 | CALLBACKCTX m_CallbackCtx;
|
---|
350 | /** The object's current reference count. */
|
---|
351 | ULONG m_lRefCount;
|
---|
352 | /** How many formats have been registered. */
|
---|
353 | ULONG m_cFormats;
|
---|
354 | LPFORMATETC m_pFormatEtc;
|
---|
355 | LPSTGMEDIUM m_pStgMedium;
|
---|
356 | /** Pointer to the associated transfer object being handled. */
|
---|
357 | PSHCLTRANSFER m_pTransfer;
|
---|
358 | /** Current stream object being used. */
|
---|
359 | IStream *m_pStream;
|
---|
360 | /** Current object index being handled by the data object.
|
---|
361 | * This is needed to create the next IStream object for e.g. the next upcoming file/dir/++ in the transfer. */
|
---|
362 | ULONG m_uObjIdx;
|
---|
363 | /** List of (cached) file system objects. */
|
---|
364 | FsObjEntryList m_lstEntries;
|
---|
365 | /** Critical section to serialize access. */
|
---|
366 | RTCRITSECT m_CritSect;
|
---|
367 | /** Event being triggered when reading the transfer list been completed. */
|
---|
368 | RTSEMEVENT m_EventListComplete;
|
---|
369 | /** Event being triggered when the object status has been changed. */
|
---|
370 | RTSEMEVENT m_EventStatusChanged;
|
---|
371 | /** Registered format for CFSTR_FILEDESCRIPTORA. */
|
---|
372 | UINT m_cfFileDescriptorA;
|
---|
373 | /** Registered format for CFSTR_FILEDESCRIPTORW. */
|
---|
374 | UINT m_cfFileDescriptorW;
|
---|
375 | /** Registered format for CFSTR_FILECONTENTS. */
|
---|
376 | UINT m_cfFileContents;
|
---|
377 | /** Registered format for CFSTR_PERFORMEDDROPEFFECT. */
|
---|
378 | UINT m_cfPerformedDropEffect;
|
---|
379 | };
|
---|
380 |
|
---|
381 | /**
|
---|
382 | * Generic Windows class implementing IEnumFORMATETC for Shared Clipboard data transfers.
|
---|
383 | */
|
---|
384 | class SharedClipboardWinEnumFormatEtc : public IEnumFORMATETC
|
---|
385 | {
|
---|
386 | public:
|
---|
387 |
|
---|
388 | SharedClipboardWinEnumFormatEtc(void);
|
---|
389 | virtual ~SharedClipboardWinEnumFormatEtc(void);
|
---|
390 |
|
---|
391 | public:
|
---|
392 |
|
---|
393 | int Init(LPFORMATETC pFormatEtc, ULONG cFormats);
|
---|
394 | void Destroy(void);
|
---|
395 |
|
---|
396 | public: /* IUnknown methods. */
|
---|
397 |
|
---|
398 | STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
|
---|
399 | STDMETHOD_(ULONG, AddRef)(void);
|
---|
400 | STDMETHOD_(ULONG, Release)(void);
|
---|
401 |
|
---|
402 | public: /* IEnumFORMATETC methods. */
|
---|
403 |
|
---|
404 | STDMETHOD(Next)(ULONG cFormats, LPFORMATETC pFormatEtc, ULONG *pcFetched);
|
---|
405 | STDMETHOD(Skip)(ULONG cFormats);
|
---|
406 | STDMETHOD(Reset)(void);
|
---|
407 | STDMETHOD(Clone)(IEnumFORMATETC **ppEnumFormatEtc);
|
---|
408 |
|
---|
409 | public:
|
---|
410 |
|
---|
411 | static void CopyFormat(LPFORMATETC pFormatDest, LPFORMATETC pFormatSource);
|
---|
412 | static HRESULT CreateEnumFormatEtc(UINT cFormats, LPFORMATETC pFormatEtc, IEnumFORMATETC **ppEnumFormatEtc);
|
---|
413 |
|
---|
414 | private:
|
---|
415 |
|
---|
416 | LONG m_lRefCount;
|
---|
417 | ULONG m_nIndex;
|
---|
418 | ULONG m_nNumFormats;
|
---|
419 | LPFORMATETC m_pFormatEtc;
|
---|
420 | };
|
---|
421 |
|
---|
422 | /**
|
---|
423 | * Generic Windows class implementing IStream for Shared Clipboard data transfers.
|
---|
424 | */
|
---|
425 | class SharedClipboardWinStreamImpl : public IStream
|
---|
426 | {
|
---|
427 | public:
|
---|
428 |
|
---|
429 | SharedClipboardWinStreamImpl(SharedClipboardWinDataObject *pParent, PSHCLTRANSFER pTransfer,
|
---|
430 | const Utf8Str &strPath, PSHCLFSOBJINFO pObjInfo);
|
---|
431 | virtual ~SharedClipboardWinStreamImpl(void);
|
---|
432 |
|
---|
433 | public: /* IUnknown methods. */
|
---|
434 |
|
---|
435 | STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject);
|
---|
436 | STDMETHOD_(ULONG, AddRef)(void);
|
---|
437 | STDMETHOD_(ULONG, Release)(void);
|
---|
438 |
|
---|
439 | public: /* IStream methods. */
|
---|
440 |
|
---|
441 | STDMETHOD(Clone)(IStream** ppStream);
|
---|
442 | STDMETHOD(Commit)(DWORD dwFrags);
|
---|
443 | STDMETHOD(CopyTo)(IStream* pDestStream, ULARGE_INTEGER nBytesToCopy, ULARGE_INTEGER* nBytesRead, ULARGE_INTEGER* nBytesWritten);
|
---|
444 | STDMETHOD(LockRegion)(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes,DWORD dwFlags);
|
---|
445 | STDMETHOD(Read)(void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead);
|
---|
446 | STDMETHOD(Revert)(void);
|
---|
447 | STDMETHOD(Seek)(LARGE_INTEGER nMove, DWORD dwOrigin, ULARGE_INTEGER* nNewPos);
|
---|
448 | STDMETHOD(SetSize)(ULARGE_INTEGER nNewSize);
|
---|
449 | STDMETHOD(Stat)(STATSTG* statstg, DWORD dwFlags);
|
---|
450 | STDMETHOD(UnlockRegion)(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags);
|
---|
451 | STDMETHOD(Write)(const void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead);
|
---|
452 |
|
---|
453 | public: /* Own methods. */
|
---|
454 |
|
---|
455 | static HRESULT Create(SharedClipboardWinDataObject *pParent, PSHCLTRANSFER pTransfer, const Utf8Str &strPath,
|
---|
456 | PSHCLFSOBJINFO pObjInfo, IStream **ppStream);
|
---|
457 | private:
|
---|
458 |
|
---|
459 | /** Pointer to the parent data object. */
|
---|
460 | SharedClipboardWinDataObject *m_pParent;
|
---|
461 | /** The stream object's current reference count. */
|
---|
462 | LONG m_lRefCount;
|
---|
463 | /** Pointer to the associated Shared Clipboard transfer. */
|
---|
464 | PSHCLTRANSFER m_pTransfer;
|
---|
465 | /** The object handle to use. */
|
---|
466 | SHCLOBJHANDLE m_hObj;
|
---|
467 | /** Object path. */
|
---|
468 | Utf8Str m_strPath;
|
---|
469 | /** (Cached) object information. */
|
---|
470 | SHCLFSOBJINFO m_objInfo;
|
---|
471 | /** Number of bytes already processed. */
|
---|
472 | uint64_t m_cbProcessed;
|
---|
473 | /** Whether this object already is in completed state or not. */
|
---|
474 | bool m_fIsComplete;
|
---|
475 | };
|
---|
476 |
|
---|
477 | /**
|
---|
478 | * Class for Windows-specifics for maintaining a single Shared Clipboard transfer.
|
---|
479 | * Set as pvUser / cbUser for SHCLTRANSFER on Windows hosts / guests.
|
---|
480 | */
|
---|
481 | class SharedClipboardWinTransferCtx
|
---|
482 | {
|
---|
483 | public:
|
---|
484 | SharedClipboardWinTransferCtx()
|
---|
485 | : pDataObj(NULL) { }
|
---|
486 |
|
---|
487 | virtual ~SharedClipboardWinTransferCtx() { }
|
---|
488 |
|
---|
489 | /** Pointer to data object to use for this transfer. Not owned.
|
---|
490 | * Can be NULL if not being used. */
|
---|
491 | SharedClipboardWinDataObject *pDataObj;
|
---|
492 | };
|
---|
493 |
|
---|
494 | int SharedClipboardWinTransferGetRoots(PSHCLWINCTX pWinCtx, PSHCLTRANSFER pTransfer);
|
---|
495 | int SharedClipboardWinTransferDropFilesToStringList(DROPFILES *pDropFiles, char **papszList, uint32_t *pcbList);
|
---|
496 | int SharedClipboardWinTransferGetRootsFromClipboard(PSHCLWINCTX pWinCtx, PSHCLTRANSFER pTransfer);
|
---|
497 |
|
---|
498 | int SharedClipboardWinTransferCreate(PSHCLWINCTX pWinCtx, PSHCLTRANSFER pTransfer);
|
---|
499 | void SharedClipboardWinTransferDestroy(PSHCLWINCTX pWinCtx, PSHCLTRANSFER pTransfer);
|
---|
500 |
|
---|
501 | int SharedClipboardWinTransferCreateAndSetDataObject(PSHCLWINCTX pWinCtx, PSHCLCONTEXT pCtx, SharedClipboardWinDataObject::PCALLBACKS pCallbacks);
|
---|
502 | # endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
|
---|
503 | #endif /* !VBOX_INCLUDED_GuestHost_SharedClipboard_win_h */
|
---|
504 |
|
---|