STDMETHODIMP QOleDataObject::QueryGetData( FORMATETC *pformatetc ) { #ifdef DEBUG_QDND_SRC qDebug( "QOleDataObject::QueryGetData( %p )", pformatetc ); #endif if ( !pformatetc ) { return E_INVALIDARG; } if ( pformatetc->lindex != -1 ) { return DV_E_LINDEX; } if ( pformatetc->dwAspect != DVASPECT_CONTENT ) { return DV_E_DVASPECT; } int tymed = pformatetc->tymed; /* Currently we only support HGLOBAL */ if ( !( tymed & TYMED_HGLOBAL ) ) { return DV_E_TYMED; } int cf = pformatetc->cfFormat; QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { const char * mime = c->mimeFor( cf ); if ( mime && m_dragObj->provides( mime ) ) { return S_OK; } } return DV_E_FORMATETC; }
STDMETHODIMP QOleDataObject::GetData( FORMATETC *pformatetcIn, STGMEDIUM *pmedium ) { // is data is in our format? HRESULT hr = QueryGetData( pformatetcIn ); if ( hr != S_OK ) return hr; int cf = pformatetcIn->cfFormat; pmedium->tymed = TYMED_HGLOBAL; QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { const char * mime = c->mimeFor( cf ); if ( mime && m_dragObj->provides( mime ) ) { QByteArray ba = m_dragObj->encodedData( mime ); ba = c->convertFromMime( ba, mime, cf ); HGLOBAL hGlobal = GlobalAlloc ( GMEM_MOVEABLE | GMEM_SHARE, ba.size() ); if ( !hGlobal ) return E_OUTOFMEMORY; memcpy ( GlobalLock ( hGlobal ), ba.data(), ba.size() ); GlobalUnlock ( hGlobal ); pmedium->hGlobal = hGlobal; pmedium->pUnkForRelease = NULL; return S_OK; } } return E_UNEXPECTED; }
STDMETHODIMP QOleDataObject::GetDataHere( FORMATETC *pformatetc, STGMEDIUM *pmedium ) { // is data is in our format? HRESULT hr = QueryGetData( pformatetc ); if ( hr != S_OK ) return hr; if ( pmedium->tymed != TYMED_HGLOBAL ) return DV_E_TYMED; if ( !pmedium->hGlobal ) return STG_E_MEDIUMFULL; HGLOBAL hGlobal = pmedium->hGlobal; uint size = GlobalSize( hGlobal ); int cf = pformatetc->cfFormat; QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { const char * mime = c->mimeFor( cf ); if ( mime && m_dragObj->provides( mime ) ) { QByteArray ba = m_dragObj->encodedData( mime ); if ( ba.size() > size ) return STG_E_MEDIUMFULL; memcpy ( GlobalLock ( hGlobal ), ba.data(), ba.size() ); GlobalUnlock ( hGlobal ); return S_OK; } } return E_UNEXPECTED; }
const char* QDropEvent::format( int n ) const { #ifdef DEBUG_QDND_WIN qDebug( "QDropEvent::format ( %d )", n ); #endif if ( !pIDataObject ) return NULL; FORMATETC fmtMemory = { 0, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; if ( n >= 0 ) { QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { for ( int i = 0; i < c->countCf(); i++ ) { int cf = c->cf( i ); fmtMemory.cfFormat = cf; if ( pIDataObject->QueryGetData( &fmtMemory ) == S_OK ) { if ( n == 0 ) { #ifdef DEBUG_QDND_WIN qDebug( "format: %s", c->mimeFor( cf ) ); #endif return c->mimeFor( cf ); } n--; } } } } return NULL; }