- FORMATETC formatetc;
- formatetc.cfFormat = cf;
- formatetc.ptd = NULL;
- formatetc.dwAspect = DVASPECT_CONTENT;
- formatetc.lindex = -1;
- if (cf == CF_ENHMETAFILE)
- formatetc.tymed = TYMED_ENHMF;
- if (cf == CF_METAFILEPICT)
- formatetc.tymed = TYMED_MFPICT;
- return formatetc;
-}
-
-
-static bool canGetData(int cf, IDataObject * pDataObj)
-{
- FORMATETC formatetc = setCf(cf);
- return pDataObj->QueryGetData(&formatetc) == S_OK;
-}
-
-
-class QWindowsMimeMetafile : public QWindowsMime {
-public:
- bool canConvertFromMime(FORMATETC const & formatetc, QMimeData const * mimeData) const;
- bool canConvertToMime(QString const & mimeType, IDataObject * pDataObj) const;
- bool convertFromMime(FORMATETC const & formatetc, const QMimeData * mimeData, STGMEDIUM * pmedium) const;
- QVariant convertToMime(QString const & mimeType, IDataObject * pDataObj, QVariant::Type preferredType) const;
- QVector<FORMATETC> formatsForMime(QString const & mimeType, QMimeData const * mimeData) const;
- QString mimeForFormat(FORMATETC const &) const;
-};
-
-
-QString QWindowsMimeMetafile::mimeForFormat(const FORMATETC & formatetc) const
-{
- QString f;
- if (formatetc.cfFormat == CF_ENHMETAFILE)
- f = emf_mime_type;
- else if (formatetc.cfFormat == CF_METAFILEPICT)
- f = wmf_mime_type;
- return f;
-}
-
-
-bool QWindowsMimeMetafile::canConvertFromMime(
- const FORMATETC & formatetc, const QMimeData * mimeData) const
-{
- return false;
-}
-
-
-bool QWindowsMimeMetafile::canConvertToMime(
- const QString & mimeType, IDataObject * pDataObj) const
-{
- return (mimeType == "image/x-emf" && canGetData(CF_ENHMETAFILE, pDataObj))
- || (mimeType == "image/x-wmf" && canGetData(CF_METAFILEPICT, pDataObj));
-}
-
-
-bool QWindowsMimeMetafile::convertFromMime(
- const FORMATETC & formatetc, const QMimeData * mimeData,
- STGMEDIUM * pmedium) const
-{
- return false;
-}
-
-
-QVariant QWindowsMimeMetafile::convertToMime(
- const QString & mimeType, IDataObject * pDataObj,
- QVariant::Type preferredType) const
-{
- QVariant ret;
-
- if (canConvertToMime(mimeType, pDataObj)) {
- FORMATETC formatetc;
- if (mimeType == "image/x-emf")
- formatetc = setCf(CF_ENHMETAFILE);
- if (mimeType == "image/x-wmf")
- formatetc = setCf(CF_METAFILEPICT);
- STGMEDIUM s;
- QByteArray data;
- int dataSize;
-
- if (pDataObj->GetData(&formatetc, &s) == S_OK) {
- if (s.tymed == TYMED_ENHMF) {
- dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, 0, NULL);
- data.resize(dataSize);
- dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, dataSize, (LPBYTE)data.data());
- } else if (s.tymed == TYMED_MFPICT) {
- dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, 0, NULL);
- data.resize(dataSize);
- dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, dataSize, (LPBYTE)data.data());
- }
- data.detach();
- ReleaseStgMedium(&s);
- }
- ret = data;