// @pymethod <o PySTGMEDIUM>|PyIDataObject|GetData|Retrieves data from the object in specified format PyObject *PyIDataObject::GetData(PyObject *self, PyObject *args) { IDataObject *pIDO = GetI(self); if ( pIDO == NULL ) return NULL; FORMATETC formatetcIn; PyObject *obpformatetcIn; // @pyparm <o PyFORMATETC>|pformatetcIn||Tuple representing a FORMATETC struct describing how the data should be returned if ( !PyArg_ParseTuple(args, "O:GetData", &obpformatetcIn) ) return NULL; PySTGMEDIUM *pymedium = PyObject_FromSTGMEDIUM(); BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyObject_AsFORMATETC( obpformatetcIn, &formatetcIn )) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIDO->GetData( &formatetcIn, &pymedium->medium); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) { Py_DECREF(pymedium); return PyCom_BuildPyException(hr, pIDO, IID_IDataObject ); } return pymedium; }
void ShellDirectory::fill_w32fdata_shell(LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* pw32fdata, bool do_access) { CONTEXT("ShellDirectory::fill_w32fdata_shell()"); if (do_access && !( (attribs&SFGAO_FILESYSTEM) && SUCCEEDED( SHGetDataFromIDList(_folder, pidl, SHGDFIL_FINDDATA, pw32fdata, sizeof(WIN32_FIND_DATA))) )) { WIN32_FILE_ATTRIBUTE_DATA fad; IDataObject* pDataObj; STGMEDIUM medium = {0, {0}, 0}; FORMATETC fmt = {g_Globals._cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; HRESULT hr = _folder->GetUIObjectOf(0, 1, &pidl, IID_IDataObject, 0, (LPVOID*)&pDataObj); if (SUCCEEDED(hr)) { hr = pDataObj->GetData(&fmt, &medium); pDataObj->Release(); if (SUCCEEDED(hr)) { LPCTSTR path = (LPCTSTR)GlobalLock(medium.hGlobal); // fill with drive names "C:", ... assert(_tcslen(path) < GlobalSize(medium.hGlobal)); _tcscpy(pw32fdata->cFileName, path); UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS); if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) { pw32fdata->dwFileAttributes = fad.dwFileAttributes; pw32fdata->ftCreationTime = fad.ftCreationTime; pw32fdata->ftLastAccessTime = fad.ftLastAccessTime; pw32fdata->ftLastWriteTime = fad.ftLastWriteTime; if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { pw32fdata->nFileSizeLow = fad.nFileSizeLow; pw32fdata->nFileSizeHigh = fad.nFileSizeHigh; } } SetErrorMode(sem_org); GlobalUnlock(medium.hGlobal); GlobalFree(medium.hGlobal); } } } if (!do_access || !(attribs&SFGAO_FILESYSTEM)) // Archiv files should not be displayed as folders in explorer view. if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER)) pw32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY; if (attribs & SFGAO_READONLY) pw32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY; if (attribs & SFGAO_COMPRESSED) pw32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED; }
bool ng_playlist_view_t::do_drag_drop(WPARAM wp) { metadb_handle_list_t<pfc::alloc_fast_aggressive> data; m_playlist_api->activeplaylist_get_selected_items(data); if (data.get_count() > 0) { static_api_ptr_t<playlist_incoming_item_filter> incoming_api; IDataObject * pDataObject = incoming_api->create_dataobject(data); if (pDataObject) { //IDataObject * pDataObjectFixed = new CDataObject; #if 0 mmh::comptr_t<IEnumFORMATETC> pEnumFORMATETC; pDataObject->EnumFormatEtc(DATADIR_GET, pEnumFORMATETC.get_pp()); FORMATETC fe; memset(&fe,0,sizeof(fe)); while (S_OK == pEnumFORMATETC->Next(1, &fe, NULL)) { STGMEDIUM stgm; memset(&stgm, 0, sizeof(0)); if (SUCCEEDED(pDataObject->GetData(&fe, &stgm))) { //if (stgm.tymed != TYMED_ISTREAM) // pDataObjectFixed->SetData(&fe, &stgm, FALSE); ReleaseStgMedium(&stgm); } memset(&fe,0,sizeof(fe)); } pEnumFORMATETC.release(); #endif //pfc::com_ptr_t<IAsyncOperation> pAsyncOperation; //HRESULT hr = pDataObject->QueryInterface(IID_IAsyncOperation, (void**)pAsyncOperation.receive_ptr()); DWORD blah = DROPEFFECT_NONE; { m_dragging = true; m_DataObject = pDataObject; m_dragging_initial_playlist = m_playlist_api->get_active_playlist(); pfc::com_ptr_t<mmh::ole::IDropSource_Generic> p_IDropSource_playlist = new mmh::ole::IDropSource_Generic(get_wnd(), pDataObject, wp); HRESULT hr = DoDragDrop(pDataObject,p_IDropSource_playlist.get_ptr(),DROPEFFECT_COPY|DROPEFFECT_MOVE,&blah); //SHDoDragDrop(get_wnd(), pDataObject,NULL,DROPEFFECT_COPY|DROPEFFECT_MOVE,&blah); m_dragging=false; m_DataObject.release(); m_dragging_initial_playlist = pfc_infinite; /*if (DRAGDROP_S_DROP == hr && blah == DROPEFFECT_MOVE) m_playlist_api->playlist_remove_selection(playlist);*/ } //pDataObjectFixed->Release(); pDataObject->Release(); } } return true; }
// IShellFolder + PIDL -> full qualified PIDL LPITEMIDLIST Pidl::getFullPidl(LPSHELLFOLDER aShellFolder, LPCITEMIDLIST aSimplePidl) { if (XPR_IS_NULL(aShellFolder) || XPR_IS_NULL(aSimplePidl)) { return XPR_NULL; } LPITEMIDLIST sFullPidl = XPR_NULL; IDataObject *sDataObject = XPR_NULL; HRESULT sComResult; sComResult = aShellFolder->GetUIObjectOf(0, 1, &aSimplePidl, IID_IDataObject, 0, (LPVOID *)&sDataObject); if (SUCCEEDED(sComResult)) { FORMATETC sFormatEtc = {0}; sFormatEtc.cfFormat = RegisterClipboardFormat(CFSTR_SHELLIDLIST); sFormatEtc.ptd = XPR_NULL; sFormatEtc.dwAspect = DVASPECT_CONTENT; sFormatEtc.lindex = -1; sFormatEtc.tymed = TYMED_HGLOBAL; STGMEDIUM sStgMedium = {0,}; sComResult = sDataObject->GetData(&sFormatEtc, &sStgMedium); if (SUCCEEDED(sComResult)) { LPIDA sPida = (LPIDA)::GlobalLock(sStgMedium.hGlobal); LPCITEMIDLIST sFolderPidl = (LPCITEMIDLIST)((xpr_byte_t *)sPida + sPida->aoffset[0]); LPCITEMIDLIST sChildPidl = (LPCITEMIDLIST)((xpr_byte_t *)sPida + sPida->aoffset[1]); sFullPidl = concat(sFolderPidl, sChildPidl); ::GlobalUnlock(sStgMedium.hGlobal); if (XPR_IS_NOT_NULL(sStgMedium.pUnkForRelease)) { ::ReleaseStgMedium(&sStgMedium); } } COM_RELEASE(sDataObject); } return sFullPidl; }
STDMETHODIMP CGFXProperty::SetObjects (ULONG nObjects, IUnknown **ppUnk) { IDataObject *pDataObject; FORMATETC DataFormat; STGMEDIUM GFXObject; // Check paramters. We expect one IUnknown. if (ppUnk == NULL) { ATLTRACE(_T("[CGFXProperty::SetObjects] IUnknown is NULL\n")); return E_POINTER; } if (nObjects != 1) { ATLTRACE(_T("[CGFXProperty::SetObjects] Not one object passed but %d\n"), nObjects); return E_INVALIDARG; } // Query for IDataObject interface. if (ppUnk[0]->QueryInterface (IID_IDataObject, (PVOID *)&pDataObject) != S_OK) { ATLTRACE(_T("[CGFXProperty::SetObjects] QueryInterface failed!\n")); return E_FAIL; } // Get the handle memset ((PVOID)&DataFormat, 0, sizeof (DataFormat)); DataFormat.tymed = TYMED_HGLOBAL; if (pDataObject->GetData (&DataFormat, &GFXObject) != S_OK) { ATLTRACE(_T("[CGFXProperty::SetObjects] GetData failed!\n")); return E_FAIL; } // Store the handle of the GFX filter. m_hGFXFilter = GFXObject.hGlobal; return S_OK; }
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 }
LRESULT C_Edit::OnDrop(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { try { IDataObject* pdto = *reinterpret_cast<IDataObject**>(lParam); if (pdto) { HRESULT hres = E_FAIL; FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; STGMEDIUM medium; int files = 0; if (pdto && SUCCEEDED (pdto->GetData(&fmte, &medium))) { //char szFileDropped [MAX_PATH]; files = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 0); } OleSetClipboard(pdto); OleFlushClipboard(); C_ClipboardPtr clipboard; clipboard.Create(); if (clipboard) { if (0 == files) { clipboard->Load(CF_TEXT); short s = -1; clipboard->get_Type(&s); switch (s) { case CF_OEMTEXT: case CF_TEXT: BSTR bs = NULL; clipboard->get_Text(&bs); String s(bs); String::FreeBSTR(&bs); int len = s.GetLength(); SetFocus(); TCHAR t[1024]; SendMessage(WM_GETTEXT, 1023, reinterpret_cast<LPARAM>(t)); String old(t); POINT p = { reinterpret_cast<POINT*>(wParam)->x, reinterpret_cast<POINT*>(wParam)->y }; ScreenToClient(&p); int selpos = LOWORD(SendMessage(EM_CHARFROMPOS, 0, MAKELPARAM(p.x, p.y))); if (selpos >= 0 && selpos < old.GetLength()) { s = old.Left(selpos) + s + old.Right(old.GetLength() - selpos); } if (selpos < m_dwSelEnd) { m_dwSelStart += len; m_dwSelEnd += len; } SendMessage(WM_SETTEXT, 0, reinterpret_cast<LPARAM>(s.toLPCTSTR())); SendMessage(EM_SETSEL, selpos, selpos + len); } } } } OnDragLeave(uMsg, wParam, lParam, bHandled); } catch (C_STLNonStackException const &exception) { exception.Log(_T("Exception in C_Edit::OnCanDrop")); } return S_OK; }
/* TODO: Use CDropHandler. */ int PasteFilesFromClipboardSpecial(TCHAR *szDestination,UINT fPasteType) { IDataObject *ClipboardObject = NULL; DROPFILES *pdf = NULL; FORMATETC ftc; STGMEDIUM stg; HRESULT hr; TCHAR szFileName[MAX_PATH]; TCHAR szLinkFileName[MAX_PATH]; TCHAR szOldFileName[MAX_PATH]; int nFilesCopied = -1; int i = 0; hr = OleGetClipboard(&ClipboardObject); if(SUCCEEDED(hr)) { ftc.cfFormat = CF_HDROP; ftc.ptd = NULL; ftc.dwAspect = DVASPECT_CONTENT; ftc.lindex = -1; ftc.tymed = TYMED_HGLOBAL; hr = ClipboardObject->GetData(&ftc,&stg); if(SUCCEEDED(hr)) { pdf = (DROPFILES *)GlobalLock(stg.hGlobal); if(pdf != NULL) { nFilesCopied = DragQueryFile((HDROP)pdf, 0xFFFFFFFF,NULL,0); for(i = 0;i < nFilesCopied;i++) { DragQueryFile((HDROP)pdf,i,szOldFileName,SIZEOF_ARRAY(szOldFileName)); StringCchCopy(szLinkFileName,SIZEOF_ARRAY(szLinkFileName),szDestination); StringCchCopy(szFileName,SIZEOF_ARRAY(szFileName),szOldFileName); PathStripPath(szFileName); PathAppend(szLinkFileName,szFileName); switch(fPasteType) { case PASTE_CLIPBOARD_LINK: PathRenameExtension(szLinkFileName,_T(".lnk")); CreateLinkToFile(szOldFileName,szLinkFileName,EMPTY_STRING); break; case PASTE_CLIPBOARD_HARDLINK: CreateHardLink(szLinkFileName,szOldFileName,NULL); break; } } GlobalUnlock(stg.hGlobal); } ReleaseStgMedium(&stg); } ClipboardObject->Release(); } return nFilesCopied; }
bool ShellDirectory::fill_w32fdata_shell(LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATA* pw32fdata, BY_HANDLE_FILE_INFORMATION* pbhfi, bool do_access) { CONTEXT("ShellDirectory::fill_w32fdata_shell()"); bool bhfi_valid = false; if (do_access && !( (attribs&SFGAO_FILESYSTEM) && SUCCEEDED( SHGetDataFromIDList(_folder, pidl, SHGDFIL_FINDDATA, pw32fdata, sizeof(WIN32_FIND_DATA))) )) { WIN32_FILE_ATTRIBUTE_DATA fad; IDataObject* pDataObj; STGMEDIUM medium = {0, {0}, 0}; FORMATETC fmt = {g_Globals._cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; HRESULT hr = _folder->GetUIObjectOf(0, 1, &pidl, IID_IDataObject, 0, (LPVOID*)&pDataObj); if (SUCCEEDED(hr)) { hr = pDataObj->GetData(&fmt, &medium); pDataObj->Release(); if (SUCCEEDED(hr)) { LPCTSTR path = (LPCTSTR)GlobalLock(medium.UNION_MEMBER(hGlobal)); if (path) { // fill with drive names "C:", ... assert(_tcslen(path) < GlobalSize(medium.UNION_MEMBER(hGlobal))); _tcscpy(pw32fdata->cFileName, path); UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS); if (GetFileAttributesEx(path, GetFileExInfoStandard, &fad)) { pw32fdata->dwFileAttributes = fad.dwFileAttributes; pw32fdata->ftCreationTime = fad.ftCreationTime; pw32fdata->ftLastAccessTime = fad.ftLastAccessTime; pw32fdata->ftLastWriteTime = fad.ftLastWriteTime; if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { // copy file size pw32fdata->nFileSizeLow = fad.nFileSizeLow; pw32fdata->nFileSizeHigh = fad.nFileSizeHigh; } else { // ignore FILE_ATTRIBUTE_HIDDEN attribute of NTFS drives - this would hide those drives in ShellBrowser if (pw32fdata->dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { if (path[1]==':' && path[2]=='\\' && !path[3]) // Is it a drive path? pw32fdata->dwFileAttributes &= ~FILE_ATTRIBUTE_HIDDEN; } } } HANDLE hFile = CreateFile(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); if (hFile != INVALID_HANDLE_VALUE) { if (GetFileInformationByHandle(hFile, pbhfi)) bhfi_valid = true; CloseHandle(hFile); } SetErrorMode(sem_org); GlobalUnlock(medium.UNION_MEMBER(hGlobal)); GlobalFree(medium.UNION_MEMBER(hGlobal)); } } } } if (!do_access || !(attribs&SFGAO_FILESYSTEM)) // Archiv files should not be displayed as folders in explorer view. if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER)) pw32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY; if (attribs & SFGAO_READONLY) pw32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY; if (attribs & SFGAO_COMPRESSED) pw32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED; return bhfi_valid; }