VBoxDnDDataObject.cpp revision b8e7a8042499abf6f2551c545f6141b36868ab4d
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * VBoxDnDDataObject.cpp - IDataObject implementation.
b8e7a8042499abf6f2551c545f6141b36868ab4dvboxsync * Copyright (C) 2013-2014 Oracle Corporation
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * available from http://www.virtualbox.org. This file is free software;
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * you can redistribute it and/or modify it under the terms of the GNU
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * General Public License (GPL) as published by the Free Software
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync/** @todo Implement IDataObjectAsyncCapability interface? */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncVBoxDnDDataObject::VBoxDnDDataObject(FORMATETC *pFormatEtc,
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /* Make sure that there's enough room for our fixed formats. */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync RT_BZERO(mpFormatEtc, sizeof(FORMATETC) * cAllFormats);
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync RT_BZERO(mpStgMedium, sizeof(STGMEDIUM) * cAllFormats);
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("Format %RU32: cfFormat=%RI16, tyMed=%RU32, dwAspect=%RU32\n",
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync i, pFormatEtc[i].cfFormat, pFormatEtc[i].tymed, pFormatEtc[i].dwAspect));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /* Most commonly used format. */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /* IStream. */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /* Required for e.g. Windows Media Player. */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("cFormats=%RU32, hr=%Rhrc\n", cFormats, hr));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync/* static */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncint VBoxDnDDataObject::CreateDataObject(FORMATETC *pFormatEtc, STGMEDIUM *pStgMeds,
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync AssertPtrReturn(ppDataObject, VERR_INVALID_POINTER);
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync *ppDataObject = new VBoxDnDDataObject(pFormatEtc, pStgMeds, cFormats);
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * IUnknown methods.
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP_(ULONG) VBoxDnDDataObject::AddRef(void)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP_(ULONG) VBoxDnDDataObject::Release(void)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync delete this;
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::QueryInterface(REFIID iid, void **ppvObject)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * Retrieves the data stored in this object and store the result in
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @return IPRT status code.
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @return HRESULT
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @param pFormatEtc
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @param pMedium
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::GetData(FORMATETC *pFormatEtc, STGMEDIUM *pMedium)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("pFormatEtc=%p, pMedium=%p\n", pFormatEtc, pMedium));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync if (!LookupFormatEtc(pFormatEtc, &lIndex)) /* Format supported? */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync int rc2 = RTSemEventWait(mSemEvent, RT_INDEFINITE_WAIT);
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("rc=%Rrc, mStatus=%ld\n", rc2, mStatus));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("cfFormat=%RI16, sFormat=%s, tyMed=%RU32, dwAspect=%RU32\n",
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync pThisFormat->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(pFormatEtc->cfFormat),
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("Got strFormat=%s, pvData=%p, cbData=%RU32\n",
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync RTCList<RTCString> lstFilesURI = RTCString((char*)mpvData, mcbData).split("\r\n");
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /* Extract path from URI. */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync char *pszPath = RTUriPath(lstFilesURI.at(i).c_str());
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync pszPath++; /** @todo Skip first '/' (part of URI). Correct? */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync pszPath = RTPathChangeToDosSlashes(pszPath, false /* fForce */);
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("\tFile: %s\n", lstFiles.at(i).c_str()));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync && (pFormatEtc->cfFormat == CF_PREFERREDDROPEFFECT))
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE | GMEM_ZEROINIT, sizeof(DWORD));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /** @todo Not working yet -- needs URI to plain ASCII conversion. */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync char *pcDst = (char *)GlobalLock(pMedium->hGlobal);
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync size_t cchFiles = 0; /* Number of ASCII characters. */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync size_t cbBuf = sizeof(DROPFILES) + ((cchFiles + 1) * sizeof(RTUTF16));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync uint8_t *pCurFile = (uint8_t *)pBuf + pBuf->pFiles;
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync for (size_t i = 0; i < lstFiles.size() && RT_SUCCESS(rc); i++)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync rc = RTStrToUtf16(lstFiles.at(i).c_str(), &pwszFile);
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync memcpy(pCurFile, pwszFile, cchCurFile * sizeof(RTUTF16));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /* Terminate current file name. */
b8e7a8042499abf6f2551c545f6141b36868ab4dvboxsync pMedium->hGlobal = (HGLOBAL)OleDuplicateData(pThisMedium->hGlobal,
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * Only required for IStream / IStorage interfaces.
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @return IPRT status code.
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @return HRESULT
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @param pFormatEtc
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @param pMedium
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::GetDataHere(FORMATETC *pFormatEtc, STGMEDIUM *pMedium)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * Query if this objects supports a specific format.
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @return IPRT status code.
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @return HRESULT
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * @param pFormatEtc
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::QueryGetData(FORMATETC *pFormatEtc)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return (LookupFormatEtc(pFormatEtc, NULL /* puIndex */)) ? S_OK : DV_E_FORMATETC;
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::GetCanonicalFormatEtc(FORMATETC *pFormatEct, FORMATETC *pFormatEtcOut)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /* Set this to NULL in any case. */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::SetData(FORMATETC *pFormatEtc, STGMEDIUM *pMedium, BOOL fRelease)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppEnumFormatEtc)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("dwDirection=%RI32, mcFormats=%RI32, mpFormatEtc=%p\n",
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync hr = VBoxDnDEnumFormatEtc::CreateEnumFormatEtc(mcFormats, mpFormatEtc, ppEnumFormatEtc);
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::DAdvise(FORMATETC *pFormatEtc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::DUnadvise(DWORD dwConnection)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncSTDMETHODIMP VBoxDnDDataObject::EnumDAdvise(IEnumSTATDATA **ppEnumAdvise)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync * Own stuff.
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync/* static */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncconst char* VBoxDnDDataObject::ClipboardFormatToString(CLIPFORMAT fmt)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync if (GetClipboardFormatName(fmt, szFormat, sizeof(szFormat)))
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("wFormat=%RI16, szName=%s\n", fmt, szFormat));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_TEXT";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_BITMAP";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_METAFILEPICT";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_SYLK";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_DIF";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_TIFF";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_OEMTEXT";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_DIB";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_PALETTE";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_PENDATA";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_RIFF";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_WAVE";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_UNICODETEXT";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_ENHMETAFILE";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_HDROP";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_LOCALE";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_DIBV5";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "CF_MAX";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49158:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "FileName";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49159:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "FileNameW";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49161:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "DATAOBJECT";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49171:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "Ole Private Data";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49314:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "Shell Object Offsets";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49316:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "File Contents";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49317:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "File Group Descriptor";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49323:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "Preferred Drop Effect";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49380:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "Shell Object Offsets";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49382:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "FileContents";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49383:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "FileGroupDescriptor";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49389:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "Preferred DropEffect";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49268:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "Shell IDList Array";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync case 49619:
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "RenPrivateFileAttachments";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return "unknown";
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncbool VBoxDnDDataObject::LookupFormatEtc(FORMATETC *pFormatEtc, ULONG *puIndex)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /* puIndex is optional. */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync && pFormatEtc->dwAspect == mpFormatEtc[i].dwAspect)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("Format found: tyMed=%RI32, cfFormat=%RI16, sFormats=%s, dwAspect=%RI32, ulIndex=%RU32\n",
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync pFormatEtc->tymed, pFormatEtc->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(mpFormatEtc[i].cfFormat),
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync return true;
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("Format NOT found: tyMed=%RI32, cfFormat=%RI16, sFormats=%s, dwAspect=%RI32\n",
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync pFormatEtc->tymed, pFormatEtc->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(pFormatEtc->cfFormat),
b8e7a8042499abf6f2551c545f6141b36868ab4dvboxsync return false;
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync/* static */
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncHGLOBAL VBoxDnDDataObject::MemDup(HGLOBAL hMemSource)
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncvoid VBoxDnDDataObject::RegisterFormat(FORMATETC *pFormatEtc, CLIPFORMAT clipFormat,
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync LogFlowFunc(("Registered format=%ld, sFormat=%s\n",
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync pFormatEtc->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(pFormatEtc->cfFormat)));
81f46059436c6145937a4cc2c7424023a289fcd8vboxsyncint VBoxDnDDataObject::Signal(const RTCString &strFormat,
81f46059436c6145937a4cc2c7424023a289fcd8vboxsync /* Signal in any case. */