IDataObject *QWindowsClipboardRetrievalMimeData::retrieveDataObject() const { IDataObject * pDataObj = 0; if (OleGetClipboard(&pDataObj) == S_OK) return pDataObj; return 0; }
/*********************************************************************** * OleUIPasteSpecialW (OLEDLG.22) */ UINT WINAPI OleUIPasteSpecialW(LPOLEUIPASTESPECIALW ps) { LPCDLGTEMPLATEW dlg_templ = (LPCDLGTEMPLATEW)ps->hResource; UINT ret; TRACE("(%p)\n", ps); if(TRACE_ON(ole)) dump_pastespecial(ps); if(!ps->lpSrcDataObj) OleGetClipboard(&ps->lpSrcDataObj); if(ps->hInstance || !ps->hResource) { HINSTANCE hInst = ps->hInstance ? ps->hInstance : OLEDLG_hInstance; const WCHAR *name = ps->hInstance ? ps->lpszTemplate : MAKEINTRESOURCEW(IDD_PASTESPECIAL4); HRSRC hrsrc; if(name == NULL) return OLEUI_ERR_LPSZTEMPLATEINVALID; hrsrc = FindResourceW(hInst, name, MAKEINTRESOURCEW(RT_DIALOG)); if(!hrsrc) return OLEUI_ERR_FINDTEMPLATEFAILURE; dlg_templ = LoadResource(hInst, hrsrc); if(!dlg_templ) return OLEUI_ERR_LOADTEMPLATEFAILURE; } ret = DialogBoxIndirectParamW(OLEDLG_hInstance, dlg_templ, ps->hWndOwner, ps_dlg_proc, (LPARAM)ps); return ret; }
PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy) { COMPtr<IDataObject> clipboardData; if (!SUCCEEDED(OleGetClipboard(&clipboardData))) clipboardData = 0; return ClipboardWin::create(false, clipboardData.get(), policy); }
void CClipSpyListCtrl::ReadClipboard() { CComPtr<IDataObject> pDO; if ( FAILED( OleGetClipboard ( &pDO ) )) return; ReadDataAndFillList ( pDO ); }
PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy, Frame* frame) { COMPtr<IDataObject> clipboardData; #if !OS(WINCE) if (!SUCCEEDED(OleGetClipboard(&clipboardData))) clipboardData = 0; #endif return ClipboardWin::create(Clipboard::CopyAndPaste, clipboardData.get(), policy, frame); }
HRESULT CTextObject::GetClipboard() { IDataObject* pDataObject; HRESULT hRes = OleGetClipboard(&pDataObject); if (SUCCEEDED(hRes)) { if (! SetObjectText(pDataObject)) hRes = E_FAIL; pDataObject->Release(); } return hRes; }
bool QClipboardWatcher::hasFormat_sys(const QString &mime) const { IDataObject * pDataObj = 0; if (OleGetClipboard(&pDataObj) != S_OK && !pDataObj) // Sanity return false; bool has = QWindowsMime::converterToMime(mime, pDataObj) != 0; pDataObj->Release(); return has; }
QStringList QClipboardWatcher::formats_sys() const { QStringList fmts; IDataObject * pDataObj = 0; if (OleGetClipboard(&pDataObj) != S_OK && !pDataObj) // Sanity return QStringList(); fmts = QWindowsMime::allMimesForFormats(pDataObj); pDataObj->Release(); return fmts; }
ClipboardReader::ClipboardReader(CLIPFORMAT format) { FORMATETC fmtetc; fmtetc.cfFormat = format; fmtetc.ptd = NULL; fmtetc.dwAspect = DVASPECT_CONTENT; fmtetc.lindex = -1; fmtetc.tymed = TYMED_HGLOBAL; if (OleGetClipboard(&pDataObj) != S_OK) pDataObj = NULL; if (pDataObj == NULL || pDataObj->GetData(&fmtetc, &stgmed) != S_OK) memset(&stgmed, 0, sizeof stgmed); }
QVariant QClipboardWatcher::retrieveData_sys(const QString &mimeType, QVariant::Type type) const { QVariant result; IDataObject * pDataObj = 0; if (OleGetClipboard(&pDataObj) != S_OK && !pDataObj) // Sanity return result; QWindowsMime *converter = QWindowsMime::converterToMime(mimeType, pDataObj); if (converter) result = converter->convertToMime(mimeType, pDataObj, type); pDataObj->Release(); return result; }
void Explorerplusplus::OnTreeViewPaste(void) { HTREEITEM hItem; LPITEMIDLIST pidl = NULL; TCHAR szFullFileName[MAX_PATH + 1]; hItem = TreeView_GetSelection(m_hTreeView); if(hItem != NULL) { IDataObject *pClipboardObject = NULL; HRESULT hr = OleGetClipboard(&pClipboardObject); if(hr == S_OK) { CDropHandler *pDropHandler = CDropHandler::CreateNew(); pidl = m_pMyTreeView->BuildPath(hItem); assert(pidl != NULL); GetDisplayName(pidl,szFullFileName,SIZEOF_ARRAY(szFullFileName),SHGDN_FORPARSING); /* Name must be double NULL terminated. */ szFullFileName[lstrlen(szFullFileName) + 1] = '\0'; pDropHandler->CopyClipboardData(pClipboardObject, m_hTreeView,szFullFileName,NULL, !m_bOverwriteExistingFilesConfirmation); CoTaskMemFree(pidl); pDropHandler->Release(); pClipboardObject->Release(); } } }
bool wxClipboard::GetData( wxDataObject& data ) { #if wxUSE_OLE_CLIPBOARD IDataObject *pDataObject = NULL; HRESULT hr = OleGetClipboard(&pDataObject); if ( FAILED(hr) || !pDataObject ) { wxLogSysError(hr, _("Failed to get data from the clipboard")); return false; } // build the list of supported formats size_t nFormats = data.GetFormatCount(wxDataObject::Set); wxDataFormat format; wxDataFormat *formats; if ( nFormats == 1 ) { // the most common case formats = &format; } else { // bad luck, need to alloc mem formats = new wxDataFormat[nFormats]; } data.GetAllFormats(formats, wxDataObject::Set); // get the data for the given formats FORMATETC formatEtc; CLIPFORMAT cf; bool result = false; // enumerate all explicit formats on the clipboard. // note that this does not include implicit / synthetic (automatically // converted) formats. #ifdef __WXDEBUG__ // get the format enumerator IEnumFORMATETC *pEnumFormatEtc = NULL; hr = pDataObject->EnumFormatEtc(DATADIR_GET, &pEnumFormatEtc); if ( FAILED(hr) || !pEnumFormatEtc ) { wxLogSysError(hr, _("Failed to retrieve the supported clipboard formats")); } else { // ask for the supported formats and see if there are any we support for ( ;; ) { ULONG nCount; hr = pEnumFormatEtc->Next(1, &formatEtc, &nCount); // don't use FAILED() because S_FALSE would pass it if ( hr != S_OK ) { // no more formats break; } cf = formatEtc.cfFormat; wxLogTrace(wxTRACE_OleCalls, wxT("Object on the clipboard supports format %s."), wxDataObject::GetFormatName(cf)); } pEnumFormatEtc->Release(); } #endif // Debug STGMEDIUM medium; // stop at the first valid format found on the clipboard for ( size_t n = 0; !result && (n < nFormats); n++ ) { // convert to NativeFormat Id cf = formats[n].GetFormatId(); // if the format is not available, try the next one // this test includes implicit / sythetic formats if ( !::IsClipboardFormatAvailable(cf) ) continue; formatEtc.cfFormat = cf; formatEtc.ptd = NULL; formatEtc.dwAspect = DVASPECT_CONTENT; formatEtc.lindex = -1; // use the appropriate tymed switch ( formatEtc.cfFormat ) { case CF_BITMAP: formatEtc.tymed = TYMED_GDI; break; #ifndef __WXWINCE__ case CF_METAFILEPICT: formatEtc.tymed = TYMED_MFPICT; break; case CF_ENHMETAFILE: formatEtc.tymed = TYMED_ENHMF; break; #endif default: formatEtc.tymed = TYMED_HGLOBAL; } // try to get data hr = pDataObject->GetData(&formatEtc, &medium); if ( FAILED(hr) ) { // try other tymed for GDI objects if ( formatEtc.cfFormat == CF_BITMAP ) { formatEtc.tymed = TYMED_HGLOBAL; hr = pDataObject->GetData(&formatEtc, &medium); } } if ( SUCCEEDED(hr) ) { // pass the data to the data object hr = data.GetInterface()->SetData(&formatEtc, &medium, true); if ( FAILED(hr) ) { wxLogDebug(wxT("Failed to set data in wxIDataObject")); // IDataObject only takes the ownership of data if it // successfully got it - which is not the case here ReleaseStgMedium(&medium); } else { result = true; } } //else: unsupported tymed? } if ( formats != &format ) { delete [] formats; } //else: we didn't allocate any memory // clean up and return pDataObject->Release(); return result; #elif wxUSE_DATAOBJ wxCHECK_MSG( wxIsClipboardOpened(), false, wxT("clipboard not open") ); wxDataFormat format = data.GetPreferredFormat(); switch ( format ) { case wxDF_TEXT: case wxDF_OEMTEXT: { wxTextDataObject& textDataObject = (wxTextDataObject &)data; char* s = (char*)wxGetClipboardData(format); if ( !s ) return false; textDataObject.SetText(wxString::FromAscii(s)); delete [] s; return true; } case wxDF_BITMAP: case wxDF_DIB: { wxBitmapDataObject& bitmapDataObject = (wxBitmapDataObject &)data; wxBitmap* bitmap = (wxBitmap *)wxGetClipboardData(data.GetPreferredFormat()); if ( !bitmap ) return false; bitmapDataObject.SetBitmap(*bitmap); delete bitmap; return true; } #if wxUSE_METAFILE case wxDF_METAFILE: { wxMetafileDataObject& metaFileDataObject = (wxMetafileDataObject &)data; wxMetafile* metaFile = (wxMetafile *)wxGetClipboardData(wxDF_METAFILE); if ( !metaFile ) return false; metaFileDataObject.SetMetafile(*metaFile); delete metaFile; return true; } #endif // wxUSE_METAFILE } return false; #else // !wxUSE_DATAOBJ wxFAIL_MSG( wxT("no clipboard implementation") ); return false; #endif // wxUSE_OLE_CLIPBOARD/wxUSE_DATAOBJ }
int wf_cliprdr_server_file_contents_request(CliprdrClientContext* context, CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest) { UINT32 uSize = 0; BYTE* pData = NULL; HRESULT hRet = S_OK; FORMATETC vFormatEtc; LPDATAOBJECT pDataObj = NULL; STGMEDIUM vStgMedium; LPSTREAM pStream = NULL; BOOL bIsStreamFile = TRUE; static LPSTREAM pStreamStc = NULL; static UINT32 uStreamIdStc = 0; wfClipboard* clipboard = (wfClipboard*) context->custom; if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE) fileContentsRequest->cbRequested = sizeof(UINT64); pData = (BYTE*) calloc(1, fileContentsRequest->cbRequested); if (!pData) goto error; hRet = OleGetClipboard(&pDataObj); if (FAILED(hRet)) { WLog_ERR(TAG, "filecontents: get ole clipboard failed."); goto error; } ZeroMemory(&vFormatEtc, sizeof(FORMATETC)); ZeroMemory(&vStgMedium, sizeof(STGMEDIUM)); vFormatEtc.cfFormat = clipboard->ID_FILECONTENTS; vFormatEtc.tymed = TYMED_ISTREAM; vFormatEtc.dwAspect = 1; vFormatEtc.lindex = fileContentsRequest->listIndex; vFormatEtc.ptd = NULL; if ((uStreamIdStc != fileContentsRequest->streamId) || !pStreamStc) { LPENUMFORMATETC pEnumFormatEtc; ULONG CeltFetched; FORMATETC vFormatEtc2; if (pStreamStc) { IStream_Release(pStreamStc); pStreamStc = NULL; } bIsStreamFile = FALSE; hRet = IDataObject_EnumFormatEtc(pDataObj, DATADIR_GET, &pEnumFormatEtc); if (hRet == S_OK) { do { hRet = IEnumFORMATETC_Next(pEnumFormatEtc, 1, &vFormatEtc2, &CeltFetched); if (hRet == S_OK) { if (vFormatEtc2.cfFormat == clipboard->ID_FILECONTENTS) { hRet = IDataObject_GetData(pDataObj, &vFormatEtc, &vStgMedium); if (hRet == S_OK) { pStreamStc = vStgMedium.pstm; uStreamIdStc = fileContentsRequest->streamId; bIsStreamFile = TRUE; } break; } } } while (hRet == S_OK); } } if (bIsStreamFile == TRUE) { if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE) { STATSTG vStatStg; ZeroMemory(&vStatStg, sizeof(STATSTG)); hRet = IStream_Stat(pStreamStc, &vStatStg, STATFLAG_NONAME); if (hRet == S_OK) { *((UINT32*) &pData[0]) = vStatStg.cbSize.LowPart; *((UINT32*) &pData[4]) = vStatStg.cbSize.HighPart; uSize = fileContentsRequest->cbRequested; } } else if (fileContentsRequest->dwFlags == FILECONTENTS_RANGE) { LARGE_INTEGER dlibMove; ULARGE_INTEGER dlibNewPosition; dlibMove.HighPart = fileContentsRequest->nPositionHigh; dlibMove.LowPart = fileContentsRequest->nPositionLow; hRet = IStream_Seek(pStreamStc, dlibMove, STREAM_SEEK_SET, &dlibNewPosition); if (SUCCEEDED(hRet)) { hRet = IStream_Read(pStreamStc, pData, fileContentsRequest->cbRequested, (PULONG) &uSize); } } } else { if (fileContentsRequest->dwFlags == FILECONTENTS_SIZE) { *((UINT32*) &pData[0]) = clipboard->fileDescriptor[fileContentsRequest->listIndex]->nFileSizeLow; *((UINT32*) &pData[4]) = clipboard->fileDescriptor[fileContentsRequest->listIndex]->nFileSizeHigh; uSize = fileContentsRequest->cbRequested; } else if (fileContentsRequest->dwFlags == FILECONTENTS_RANGE) { BOOL bRet; bRet = wf_cliprdr_get_file_contents(clipboard->file_names[fileContentsRequest->listIndex], pData, fileContentsRequest->nPositionLow, fileContentsRequest->nPositionHigh, fileContentsRequest->cbRequested, &uSize); if (bRet == FALSE) { WLog_ERR(TAG, "get file contents failed."); uSize = 0; goto error; } } } IDataObject_Release(pDataObj); if (uSize == 0) { free(pData); pData = NULL; } cliprdr_send_response_filecontents(clipboard, fileContentsRequest->streamId, uSize, pData); free(pData); return 1; error: if (pData) { free(pData); pData = NULL; } if (pDataObj) { IDataObject_Release(pDataObj); pDataObj = NULL; } WLog_ERR(TAG, "filecontents: send failed response."); cliprdr_send_response_filecontents(clipboard, fileContentsRequest->streamId, 0, NULL); return -1; }
static void wf_cliprdr_process_cb_data_request_event(wfContext* wfc, RDP_CB_DATA_REQUEST_EVENT* event) { HANDLE hClipdata; int size = 0; char* buff = NULL; char* globlemem = NULL; UINT32 local_format; cliprdrContext* cliprdr = (cliprdrContext*) wfc->cliprdr_context; RDP_CB_DATA_RESPONSE_EVENT* response_event; local_format = event->format; if (local_format == FORMAT_ID_PALETTE) { /* TODO: implement this */ DEBUG_CLIPRDR("FORMAT_ID_PALETTE is not supported yet."); } else if (local_format == FORMAT_ID_METAFILE) { /* TODO: implement this */ DEBUG_CLIPRDR("FORMAT_ID_MATEFILE is not supported yet."); } else if (local_format == RegisterClipboardFormatW(L"FileGroupDescriptorW")) { HRESULT result; LPDATAOBJECT dataObj; FORMATETC format_etc; STGMEDIUM stg_medium; DROPFILES *dropFiles; int len; int i; wchar_t *wFileName; unsigned int uSize; DEBUG_CLIPRDR("file descriptors request."); result = OleGetClipboard(&dataObj); if (!SUCCEEDED(result)) { DEBUG_CLIPRDR("OleGetClipboard failed."); } ZeroMemory(&format_etc, sizeof(FORMATETC)); ZeroMemory(&stg_medium, sizeof(STGMEDIUM)); /* try to get FileGroupDescriptorW struct from OLE */ format_etc.cfFormat = local_format; format_etc.tymed = TYMED_HGLOBAL; format_etc.dwAspect = 1; format_etc.lindex = -1; format_etc.ptd = 0; result = IDataObject_GetData(dataObj, &format_etc, &stg_medium); if (SUCCEEDED(result)) { DEBUG_CLIPRDR("Got FileGroupDescriptorW."); globlemem = (char *)GlobalLock(stg_medium.hGlobal); uSize = GlobalSize(stg_medium.hGlobal); size = uSize; buff = malloc(uSize); memcpy(buff, globlemem, uSize); GlobalUnlock(stg_medium.hGlobal); ReleaseStgMedium(&stg_medium); clear_file_array(cliprdr); } else { /* get DROPFILES struct from OLE */ format_etc.cfFormat = CF_HDROP; format_etc.tymed = TYMED_HGLOBAL; format_etc.dwAspect = 1; format_etc.lindex = -1; result = IDataObject_GetData(dataObj, &format_etc, &stg_medium); if (!SUCCEEDED(result)) { DEBUG_CLIPRDR("dataObj->GetData failed."); } globlemem = (char *)GlobalLock(stg_medium.hGlobal); if (globlemem == NULL) { GlobalUnlock(stg_medium.hGlobal); ReleaseStgMedium(&stg_medium); cliprdr->nFiles = 0; goto exit; } uSize = GlobalSize(stg_medium.hGlobal); dropFiles = (DROPFILES *)malloc(uSize); memcpy(dropFiles, globlemem, uSize); GlobalUnlock(stg_medium.hGlobal); ReleaseStgMedium(&stg_medium); clear_file_array(cliprdr); if (dropFiles->fWide) { wchar_t *p; int str_len; int offset; int pathLen; /* dropFiles contains file names */ for (wFileName = (wchar_t *)((char *)dropFiles + dropFiles->pFiles); (len = wcslen(wFileName)) > 0; wFileName += len + 1) { /* get path name */ str_len = wcslen(wFileName); offset = str_len; /* find the last '\' in full file name */ for (p = wFileName + offset; *p != L'\\'; p--) { ; } p += 1; pathLen = wcslen(wFileName) - wcslen(p); wf_cliprdr_add_to_file_arrays(cliprdr, wFileName, pathLen); if ((cliprdr->fileDescriptor[cliprdr->nFiles - 1]->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { /* this is a directory */ wf_cliprdr_traverse_directory(cliprdr, wFileName, pathLen); } } } else { char *p; for (p = (char *)((char *)dropFiles + dropFiles->pFiles); (len = strlen(p)) > 0; p += len + 1, cliprdr->nFiles++) { int cchWideChar; cchWideChar = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, NULL, 0); cliprdr->file_names[cliprdr->nFiles] = (LPWSTR)malloc(cchWideChar); MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, cliprdr->file_names[cliprdr->nFiles], cchWideChar); if (cliprdr->nFiles == cliprdr->file_array_size) { cliprdr->file_array_size *= 2; cliprdr->fileDescriptor = (FILEDESCRIPTORW **)realloc(cliprdr->fileDescriptor, cliprdr->file_array_size * sizeof(FILEDESCRIPTORW *)); cliprdr->file_names = (wchar_t **)realloc(cliprdr->file_names, cliprdr->file_array_size * sizeof(wchar_t *)); } } } exit: size = 4 + cliprdr->nFiles * sizeof(FILEDESCRIPTORW); buff = (char *)malloc(size); Write_UINT32(buff, cliprdr->nFiles); for (i = 0; i < cliprdr->nFiles; i++) { if (cliprdr->fileDescriptor[i]) { memcpy(buff + 4 + i * sizeof(FILEDESCRIPTORW), cliprdr->fileDescriptor[i], sizeof(FILEDESCRIPTORW)); } } } IDataObject_Release(dataObj); } else { if (!OpenClipboard(cliprdr->hwndClipboard)) { DEBUG_CLIPRDR("OpenClipboard failed with 0x%x", GetLastError()); return; } hClipdata = GetClipboardData(event->format); if (!hClipdata) { DEBUG_CLIPRDR("GetClipboardData failed."); CloseClipboard(); return; } globlemem = (char*) GlobalLock(hClipdata); size = (int) GlobalSize(hClipdata); buff = (char*) malloc(size); memcpy(buff, globlemem, size); GlobalUnlock(hClipdata); CloseClipboard(); } response_event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_DataResponse, NULL, NULL); response_event->data = (BYTE *)buff; response_event->size = size; freerdp_channels_send_event(cliprdr->channels, (wMessage*) response_event); /* Note: don't free buffer here. */ }
static void wf_cliprdr_process_cb_filecontents_request_event(wfContext *wfc, RDP_CB_FILECONTENTS_REQUEST_EVENT *event) { cliprdrContext *cliprdr = (cliprdrContext *)wfc->cliprdr_context; UINT32 uSize = 0; BYTE *pData = NULL; HRESULT hRet = S_OK; FORMATETC vFormatEtc; LPDATAOBJECT pDataObj = NULL; STGMEDIUM vStgMedium; LPSTREAM pStream = NULL; BOOL bIsStreamFile = TRUE; static LPSTREAM pStreamStc = NULL; static UINT32 uStreamIdStc = 0; pData = (BYTE *)calloc(1, event->cbRequested); if (!pData) goto error; hRet = OleGetClipboard(&pDataObj); if (!SUCCEEDED(hRet)) { fprintf(stderr, "filecontents: get ole clipboard failed.\n"); goto error; } ZeroMemory(&vFormatEtc, sizeof(FORMATETC)); ZeroMemory(&vStgMedium, sizeof(STGMEDIUM)); vFormatEtc.cfFormat = cliprdr->ID_FILECONTENTS; vFormatEtc.tymed = TYMED_ISTREAM; vFormatEtc.dwAspect = 1; vFormatEtc.lindex = event->lindex; vFormatEtc.ptd = NULL; if (uStreamIdStc != event->streamId || pStreamStc == NULL) { LPENUMFORMATETC pEnumFormatEtc; ULONG CeltFetched; FORMATETC vFormatEtc2; if (pStreamStc != NULL) { IStream_Release(pStreamStc); pStreamStc = NULL; } bIsStreamFile = FALSE; hRet = IDataObject_EnumFormatEtc(pDataObj, DATADIR_GET, &pEnumFormatEtc); if (hRet == S_OK) { do { hRet = IEnumFORMATETC_Next(pEnumFormatEtc, 1, &vFormatEtc2, &CeltFetched); if (hRet == S_OK) { if (vFormatEtc2.cfFormat == cliprdr->ID_FILECONTENTS) { hRet = IDataObject_GetData(pDataObj, &vFormatEtc, &vStgMedium); if (hRet == S_OK) { pStreamStc = vStgMedium.pstm; uStreamIdStc = event->streamId; bIsStreamFile = TRUE; } break; } } } while (hRet == S_OK); } } if (bIsStreamFile == TRUE) { if (event->dwFlags == 0x00000001) /* FILECONTENTS_SIZE */ { STATSTG vStatStg; ZeroMemory(&vStatStg, sizeof(STATSTG)); hRet = IStream_Stat(pStreamStc, &vStatStg, STATFLAG_NONAME); if (hRet == S_OK) { Write_UINT32(pData, vStatStg.cbSize.LowPart); Write_UINT32(pData + 4, vStatStg.cbSize.HighPart); uSize = event->cbRequested; } } else if (event->dwFlags == 0x00000002) /* FILECONTENTS_RANGE */ { LARGE_INTEGER dlibMove; ULARGE_INTEGER dlibNewPosition; dlibMove.HighPart = event->nPositionHigh; dlibMove.LowPart = event->nPositionLow; hRet = IStream_Seek(pStreamStc, dlibMove, STREAM_SEEK_SET, &dlibNewPosition); if (SUCCEEDED(hRet)) { hRet = IStream_Read(pStreamStc, pData, event->cbRequested, (PULONG)&uSize); } } } else // is local file { if (event->dwFlags == 0x00000001) /* FILECONTENTS_SIZE */ { Write_UINT32(pData, cliprdr->fileDescriptor[event->lindex]->nFileSizeLow); Write_UINT32(pData + 4, cliprdr->fileDescriptor[event->lindex]->nFileSizeHigh); uSize = event->cbRequested; } else if (event->dwFlags == 0x00000002) /* FILECONTENTS_RANGE */ { BOOL bRet; bRet = wf_cliprdr_get_file_contents(cliprdr->file_names[event->lindex], pData, event->nPositionLow, event->nPositionHigh, event->cbRequested, &uSize); if (bRet == FALSE) { fprintf(stderr, "get file contents failed.\n"); uSize = 0; goto error; } } } IDataObject_Release(pDataObj); if (uSize == 0) { free(pData); pData = NULL; } cliprdr_send_response_filecontents(cliprdr, event->streamId, uSize, pData); return; error: if (pData) { free(pData); pData = NULL; } if (pDataObj) { IDataObject_Release(pDataObj); pDataObj = NULL; } fprintf(stderr, "filecontents: send failed response.\n"); cliprdr_send_response_filecontents(cliprdr, event->streamId, 0, NULL); return; }
static int wf_cliprdr_server_format_data_request(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest) { int size = 0; char* buff = NULL; char* globlemem = NULL; HANDLE hClipdata = NULL; UINT32 requestedFormatId; CLIPRDR_FORMAT_DATA_RESPONSE response; wfClipboard* clipboard = (wfClipboard*) context->custom; requestedFormatId = formatDataRequest->requestedFormatId; if (requestedFormatId == RegisterClipboardFormatW(_T("FileGroupDescriptorW"))) { int len; int i; WCHAR* wFileName; unsigned int uSize; HRESULT result; LPDATAOBJECT dataObj; FORMATETC format_etc; STGMEDIUM stg_medium; DROPFILES* dropFiles; result = OleGetClipboard(&dataObj); if (FAILED(result)) return -1; ZeroMemory(&format_etc, sizeof(FORMATETC)); ZeroMemory(&stg_medium, sizeof(STGMEDIUM)); /* try to get FileGroupDescriptorW struct from OLE */ format_etc.cfFormat = requestedFormatId; format_etc.tymed = TYMED_HGLOBAL; format_etc.dwAspect = 1; format_etc.lindex = -1; format_etc.ptd = 0; result = IDataObject_GetData(dataObj, &format_etc, &stg_medium); if (SUCCEEDED(result)) { DEBUG_CLIPRDR("Got FileGroupDescriptorW."); globlemem = (char*) GlobalLock(stg_medium.hGlobal); uSize = GlobalSize(stg_medium.hGlobal); size = uSize; buff = (char*) malloc(uSize); CopyMemory(buff, globlemem, uSize); GlobalUnlock(stg_medium.hGlobal); ReleaseStgMedium(&stg_medium); clear_file_array(clipboard); } else { /* get DROPFILES struct from OLE */ format_etc.cfFormat = CF_HDROP; format_etc.tymed = TYMED_HGLOBAL; format_etc.dwAspect = 1; format_etc.lindex = -1; result = IDataObject_GetData(dataObj, &format_etc, &stg_medium); if (FAILED(result)) { DEBUG_CLIPRDR("dataObj->GetData failed."); } globlemem = (char*) GlobalLock(stg_medium.hGlobal); if (!globlemem) { GlobalUnlock(stg_medium.hGlobal); ReleaseStgMedium(&stg_medium); clipboard->nFiles = 0; goto exit; } uSize = GlobalSize(stg_medium.hGlobal); dropFiles = (DROPFILES*) malloc(uSize); memcpy(dropFiles, globlemem, uSize); GlobalUnlock(stg_medium.hGlobal); ReleaseStgMedium(&stg_medium); clear_file_array(clipboard); if (dropFiles->fWide) { WCHAR* p; int str_len; int offset; int pathLen; /* dropFiles contains file names */ for (wFileName = (WCHAR*)((char*)dropFiles + dropFiles->pFiles); (len = wcslen(wFileName)) > 0; wFileName += len + 1) { /* get path name */ str_len = wcslen(wFileName); offset = str_len; /* find the last '\' in full file name */ for (p = wFileName + offset; *p != L'\\'; p--) { ; } p += 1; pathLen = wcslen(wFileName) - wcslen(p); wf_cliprdr_add_to_file_arrays(clipboard, wFileName, pathLen); if ((clipboard->fileDescriptor[clipboard->nFiles - 1]->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { /* this is a directory */ wf_cliprdr_traverse_directory(clipboard, wFileName, pathLen); } } } else { char* p; for (p = (char*)((char*)dropFiles + dropFiles->pFiles); (len = strlen(p)) > 0; p += len + 1, clipboard->nFiles++) { int cchWideChar; cchWideChar = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, NULL, 0); clipboard->file_names[clipboard->nFiles] = (LPWSTR) malloc(cchWideChar * 2); MultiByteToWideChar(CP_ACP, MB_COMPOSITE, p, len, clipboard->file_names[clipboard->nFiles], cchWideChar); map_ensure_capacity(clipboard); } } exit: size = 4 + clipboard->nFiles * sizeof(FILEDESCRIPTORW); buff = (char*) malloc(size); *((UINT32*) buff) = clipboard->nFiles; for (i = 0; i < clipboard->nFiles; i++) { if (clipboard->fileDescriptor[i]) { memcpy(buff + 4 + i * sizeof(FILEDESCRIPTORW), clipboard->fileDescriptor[i], sizeof(FILEDESCRIPTORW)); } } } IDataObject_Release(dataObj); } else { if (!OpenClipboard(clipboard->hwnd)) return -1; hClipdata = GetClipboardData(requestedFormatId); if (!hClipdata) { CloseClipboard(); return -1; } globlemem = (char*) GlobalLock(hClipdata); size = (int) GlobalSize(hClipdata); buff = (char*) malloc(size); CopyMemory(buff, globlemem, size); GlobalUnlock(hClipdata); CloseClipboard(); } ZeroMemory(&response, sizeof(CLIPRDR_FORMAT_DATA_RESPONSE)); response.msgFlags = CB_RESPONSE_OK; response.dataLen = size; response.requestedFormatData = (BYTE*) buff; clipboard->context->ClientFormatDataResponse(clipboard->context, &response); free(buff); return 1; }
static BOOL DoPaste(ContextMenu *This) { BOOL bSuccess = FALSE; IDataObject * pda; TRACE("\n"); if(SUCCEEDED(OleGetClipboard(&pda))) { STGMEDIUM medium; FORMATETC formatetc; TRACE("pda=%p\n", pda); /* Set the FORMATETC structure*/ InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLISTW), TYMED_HGLOBAL); /* Get the pidls from IDataObject */ if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium))) { LPITEMIDLIST * apidl; LPITEMIDLIST pidl; IShellFolder *psfFrom = NULL, *psfDesktop; LPIDA lpcida = GlobalLock(medium.u.hGlobal); TRACE("cida=%p\n", lpcida); apidl = _ILCopyCidaToaPidl(&pidl, lpcida); /* bind to the source shellfolder */ SHGetDesktopFolder(&psfDesktop); if(psfDesktop) { IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom); IShellFolder_Release(psfDesktop); } if (psfFrom) { /* get source and destination shellfolder */ ISFHelper *psfhlpdst, *psfhlpsrc; IShellFolder_QueryInterface(This->parent, &IID_ISFHelper, (void**)&psfhlpdst); IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (void**)&psfhlpsrc); /* do the copy/move */ if (psfhlpdst && psfhlpsrc) { ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, (LPCITEMIDLIST*)apidl); /* FIXME handle move ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl); */ } if(psfhlpdst) ISFHelper_Release(psfhlpdst); if(psfhlpsrc) ISFHelper_Release(psfhlpsrc); IShellFolder_Release(psfFrom); } _ILFreeaPidl(apidl, lpcida->cidl); SHFree(pidl); /* release the medium*/ ReleaseStgMedium(&medium); } IDataObject_Release(pda); } #if 0 HGLOBAL hMem; OpenClipboard(NULL); hMem = GetClipboardData(CF_HDROP); if(hMem) { char * pDropFiles = GlobalLock(hMem); if(pDropFiles) { int len, offset = sizeof(DROPFILESTRUCT); while( pDropFiles[offset] != 0) { len = strlen(pDropFiles + offset); TRACE("%s\n", pDropFiles + offset); offset += len+1; } } GlobalUnlock(hMem); } CloseClipboard(); #endif return bSuccess; }