bool QDropEvent::provides( const char * mimeType ) const { #ifdef DEBUG_QDND_WIN qDebug( "QDropEvent::provides ( %s )", mimeType ); #endif if ( !pIDataObject ) return false; FORMATETC fmtMemory = { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; /* Search all available mimes for mimeType and look if pIDataObject can give us data in this clipboard format */ QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { int cf = c->cfFor( mimeType ); if ( c->canConvert( mimeType, cf ) ) { fmtMemory.cfFormat = cf; if ( pIDataObject->QueryGetData( &fmtMemory ) == S_OK ) { return true; } } } return false; }
STDMETHODIMP QOleDataObject::EnumFormatEtc( DWORD dwDir, IEnumFORMATETC **ppenumFormatEtc ) { if ( dwDir == DATADIR_SET ) return E_NOTIMPL; int count = 0; while ( m_dragObj->format( count ) ) count++; int *formats = new int[ count ]; for ( int i = 0; i < count; i++ ) { const char *mime = m_dragObj->format( i ); QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { int cf = c->cfFor( mime ); if ( cf ) { formats[ i ] = cf; break; } } } qIEnumFORMATETC *pEnum = new qIEnumFORMATETC( formats, count ); pEnum->AddRef(); *ppenumFormatEtc = pEnum; delete[] formats; return ResultFromScode( S_OK ); }
/*********************************************** QDropEvent ************************************************/ QByteArray QDropEvent::encodedData( const char * format ) const { #ifdef DEBUG_QDND_WIN qDebug( "QDropEvent::encodedData ( %s )", format ); #endif QByteArray ba; /* Currently we only support TYMED_HGLOBAL ... */ FORMATETC fmtMemory = { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stm; if ( !pIDataObject ) { return ba; } QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { int cf = c->cfFor( format ); if ( c->canConvert( format, cf ) ) { fmtMemory.cfFormat = cf; if ( pIDataObject->QueryGetData( &fmtMemory ) == S_OK ) { HRESULT hr = pIDataObject->GetData( &fmtMemory, &stm ); if ( ( hr != S_OK ) || ( !stm.hGlobal ) ) continue; QByteArray data; QBuffer buf ( data ); buf.open( IO_WriteOnly ); buf.writeBlock ( ( char* ) GlobalLock( stm.hGlobal ), GlobalSize ( stm.hGlobal ) ); buf.close(); GlobalUnlock ( stm.hGlobal ); ReleaseStgMedium( &stm ); ba = c->convertToMime( data, format, cf ); ReleaseStgMedium( &stm ); return ba; } } } return ba; }