Qt 4.8
Public Functions | Static Public Functions | Static Private Functions | Friends | List of all members
QWindowsMime Class Referenceabstract

The QWindowsMime class maps open-standard MIME to Window Clipboard formats. More...

#include <qmime.h>

Inheritance diagram for QWindowsMime:
QBuiltInMimes QLastResortMimes QWindowsMimeHtml QWindowsMimeImage QWindowsMimeText QWindowsMimeURI

Public Functions

virtual bool canConvertFromMime (const FORMATETC &formatetc, const QMimeData *mimeData) const =0
 Returns true if the converter can convert from the mimeData to the format specified in formatetc. More...
 
virtual bool canConvertToMime (const QString &mimeType, IDataObject *pDataObj) const =0
 Returns true if the converter can convert to the mimeType from the available formats in pDataObj. More...
 
virtual bool convertFromMime (const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM *pmedium) const =0
 Convert the mimeData to the format specified in formatetc. More...
 
virtual QVariant convertToMime (const QString &mimeType, IDataObject *pDataObj, QVariant::Type preferredType) const =0
 Returns a QVariant containing the converted data for mimeType from pDataObj. More...
 
virtual QVector< FORMATETCformatsForMime (const QString &mimeType, const QMimeData *mimeData) const =0
 Returns a QVector of FORMATETC structures representing the different windows clipboard formats that can be provided for the mimeType from the mimeData. More...
 
virtual QString mimeForFormat (const FORMATETC &formatetc) const =0
 Returns the mime type that will be created form the format specified in formatetc, or an empty string if this converter does not support formatetc. More...
 
 QWindowsMime ()
 Constructs a new conversion object, adding it to the globally accessed list of available converters. More...
 
virtual ~QWindowsMime ()
 Destroys a conversion object, removing it from the global list of available converters. More...
 

Static Public Functions

static int registerMimeType (const QString &mime)
 Registers the MIME type mime, and returns an ID number identifying the format on Windows. More...
 

Static Private Functions

static QVector< FORMATETCallFormatsForMime (const QMimeData *mimeData)
 
static QStringList allMimesForFormats (IDataObject *pDataObj)
 
static QWindowsMimeconverterFromMime (const FORMATETC &formatetc, const QMimeData *mimeData)
 
static QWindowsMimeconverterToMime (const QString &mimeType, IDataObject *pDataObj)
 

Friends

class QClipboardWatcher
 
class QDragManager
 
class QDropData
 
class QOleDataObject
 

Detailed Description

The QWindowsMime class maps open-standard MIME to Window Clipboard formats.

Qt's drag-and-drop and clipboard facilities use the MIME standard. On X11, this maps trivially to the Xdnd protocol, but on Windows although some applications use MIME types to describe clipboard formats, others use arbitrary non-standardized naming conventions, or unnamed built-in formats of Windows.

By instantiating subclasses of QWindowsMime that provide conversions between Windows Clipboard and MIME formats, you can convert proprietary clipboard formats to MIME formats.

Qt has predefined support for the following Windows Clipboard formats:

Windows Format Equivalent MIME type
CF_UNICODETEXT text/plain
CF_TEXT text/plain
CF_DIB image/xyz, where xyz is a Qt image format
CF_HDROP text/uri-list
CF_INETURL text/uri-list
CF_HTML text/html

An example use of this class would be to map the Windows Metafile clipboard format (CF_METAFILEPICT) to and from the MIME type image/x-wmf. This conversion might simply be adding or removing a header, or even just passing on the data. See Drag and Drop for more information on choosing and definition MIME types.

You can check if a MIME type is convertible using canConvertFromMime() and can perform conversions with convertToMime() and convertFromMime().

Definition at line 79 of file qmime.h.

Constructors and Destructors

◆ QWindowsMime()

QWindowsMime::QWindowsMime ( )

Constructs a new conversion object, adding it to the globally accessed list of available converters.

Definition at line 264 of file qmime_win.cpp.

265 {
266  theMimeList()->addWindowsMime(this);
267 }

◆ ~QWindowsMime()

QWindowsMime::~QWindowsMime ( )
virtual

Destroys a conversion object, removing it from the global list of available converters.

Definition at line 273 of file qmime_win.cpp.

274 {
275  theMimeList()->removeWindowsMime(this);
276 }

Functions

◆ allFormatsForMime()

QVector< FORMATETC > QWindowsMime::allFormatsForMime ( const QMimeData mimeData)
staticprivate

Definition at line 375 of file qmime_win.cpp.

Referenced by QOleDataObject::EnumFormatEtc().

376 {
377  QList<QWindowsMime*> mimes = theMimeList()->windowsMimes();
378  QVector<FORMATETC> formatics;
379  formatics.reserve(20);
380 #ifndef QT_NO_DRAGANDDROP
381  QStringList formats = QInternalMimeData::formatsHelper(mimeData);
382  for (int f=0; f<formats.size(); ++f) {
383  for (int i=mimes.size()-1; i>=0; --i)
384  formatics += mimes.at(i)->formatsForMime(formats.at(f), mimeData);
385  }
386 #else
387  Q_UNUSED(mimeData);
388 #endif //QT_NO_DRAGANDDROP
389  return formatics;
390 }
static QStringList formatsHelper(const QMimeData *data)
Definition: qdnd.cpp:414
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
virtual QVector< FORMATETC > formatsForMime(const QString &mimeType, const QMimeData *mimeData) const =0
Returns a QVector of FORMATETC structures representing the different windows clipboard formats that c...
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ allMimesForFormats()

QStringList QWindowsMime::allMimesForFormats ( IDataObject *  pDataObj)
staticprivate

Definition at line 392 of file qmime_win.cpp.

Referenced by QOleDropTarget::Drop(), and QClipboardWatcher::formats_sys().

393 {
394  QList<QWindowsMime*> mimes = theMimeList()->windowsMimes();
395  QStringList formats;
396  LPENUMFORMATETC FAR fmtenum;
397  HRESULT hr = pDataObj->EnumFormatEtc(DATADIR_GET, &fmtenum);
398 
399  if (hr == NOERROR) {
400  FORMATETC fmtetc;
401  while (S_OK == fmtenum->Next(1, &fmtetc, 0)) {
402 #if defined(QMIME_DEBUG) && !defined(Q_OS_WINCE)
403  qDebug("QWindowsMime::allMimesForFormats()");
404  wchar_t buf[256] = {0};
405  GetClipboardFormatName(fmtetc.cfFormat, buf, 255);
406  qDebug("CF = %d : %s", fmtetc.cfFormat, QString::fromWCharArray(buf));
407 #endif
408  for (int i=mimes.size()-1; i>=0; --i) {
409  QString format = mimes.at(i)->mimeForFormat(fmtetc);
410  if (!format.isEmpty() && !formats.contains(format)) {
411  formats += format;
412  }
413  }
414  // as documented in MSDN to avoid possible memleak
415  if (fmtetc.ptd)
416  CoTaskMemFree(fmtetc.ptd);
417  }
418  fmtenum->Release();
419  }
420 
421  return formats;
422 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
struct tagFORMATETC FORMATETC
Definition: qmime.h:66
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
virtual QString mimeForFormat(const FORMATETC &formatetc) const =0
Returns the mime type that will be created form the format specified in formatetc, or an empty string if this converter does not support formatetc.
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
long HRESULT
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ canConvertFromMime()

bool QWindowsMime::canConvertFromMime ( const FORMATETC formatetc,
const QMimeData mimeData 
) const
pure virtual

Returns true if the converter can convert from the mimeData to the format specified in formatetc.

All subclasses must reimplement this pure virtual function.

Implemented in QLastResortMimes, QBuiltInMimes, QWindowsMimeImage, QWindowsMimeHtml, QWindowsMimeURI, and QWindowsMimeText.

Referenced by converterFromMime().

◆ canConvertToMime()

bool QWindowsMime::canConvertToMime ( const QString mimeType,
IDataObject *  pDataObj 
) const
pure virtual

Returns true if the converter can convert to the mimeType from the available formats in pDataObj.

All subclasses must reimplement this pure virtual function.

Implemented in QLastResortMimes, QBuiltInMimes, QWindowsMimeImage, QWindowsMimeHtml, QWindowsMimeURI, and QWindowsMimeText.

Referenced by converterToMime().

◆ converterFromMime()

QWindowsMime * QWindowsMime::converterFromMime ( const FORMATETC formatetc,
const QMimeData mimeData 
)
staticprivate

Definition at line 355 of file qmime_win.cpp.

Referenced by QOleDataObject::GetData(), and QOleDataObject::QueryGetData().

356 {
357  QList<QWindowsMime*> mimes = theMimeList()->windowsMimes();
358  for (int i=mimes.size()-1; i>=0; --i) {
359  if (mimes.at(i)->canConvertFromMime(formatetc, mimeData))
360  return mimes.at(i);
361  }
362  return 0;
363 }
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual bool canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const =0
Returns true if the converter can convert from the mimeData to the format specified in formatetc...
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ converterToMime()

QWindowsMime * QWindowsMime::converterToMime ( const QString mimeType,
IDataObject *  pDataObj 
)
staticprivate

Definition at line 365 of file qmime_win.cpp.

Referenced by QOleDropTarget::Drop(), QClipboardWatcher::hasFormat_sys(), and QClipboardWatcher::retrieveData_sys().

366 {
367  QList<QWindowsMime*> mimes = theMimeList()->windowsMimes();
368  for (int i=mimes.size()-1; i>=0; --i) {
369  if (mimes.at(i)->canConvertToMime(mimeType, pDataObj))
370  return mimes.at(i);
371  }
372  return 0;
373 }
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual bool canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const =0
Returns true if the converter can convert to the mimeType from the available formats in pDataObj...
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ convertFromMime()

bool QWindowsMime::convertFromMime ( const FORMATETC formatetc,
const QMimeData mimeData,
STGMEDIUM pmedium 
) const
pure virtual

Convert the mimeData to the format specified in formatetc.

The converted data should then be placed in pmedium structure.

Return true if the conversion was successful.

All subclasses must reimplement this pure virtual function.

Implemented in QLastResortMimes, QBuiltInMimes, QWindowsMimeImage, QWindowsMimeHtml, QWindowsMimeURI, and QWindowsMimeText.

Referenced by QOleDataObject::GetData().

◆ convertToMime()

QVariant QWindowsMime::convertToMime ( const QString mimeType,
IDataObject *  pDataObj,
QVariant::Type  preferredType 
) const
pure virtual

Returns a QVariant containing the converted data for mimeType from pDataObj.

If possible the QVariant should be of the preferredType to avoid needless conversions.

All subclasses must reimplement this pure virtual function.

Implemented in QLastResortMimes, QBuiltInMimes, QWindowsMimeImage, and QWindowsMimeHtml.

Referenced by QOleDropTarget::Drop(), and QClipboardWatcher::retrieveData_sys().

◆ formatsForMime()

QVector< FORMATETC > QWindowsMime::formatsForMime ( const QString mimeType,
const QMimeData mimeData 
) const
pure virtual

Returns a QVector of FORMATETC structures representing the different windows clipboard formats that can be provided for the mimeType from the mimeData.

All subclasses must reimplement this pure virtual function.

Implemented in QLastResortMimes, QBuiltInMimes, QWindowsMimeImage, QWindowsMimeHtml, QWindowsMimeURI, and QWindowsMimeText.

Referenced by allFormatsForMime().

◆ mimeForFormat()

QString QWindowsMime::mimeForFormat ( const FORMATETC formatetc) const
pure virtual

Returns the mime type that will be created form the format specified in formatetc, or an empty string if this converter does not support formatetc.

All subclasses must reimplement this pure virtual function.

Implemented in QLastResortMimes, QBuiltInMimes, QWindowsMimeImage, QWindowsMimeHtml, QWindowsMimeURI, and QWindowsMimeText.

Referenced by allMimesForFormats().

◆ registerMimeType()

int QWindowsMime::registerMimeType ( const QString mime)
static

Registers the MIME type mime, and returns an ID number identifying the format on Windows.

Definition at line 283 of file qmime_win.cpp.

Referenced by QLastResortMimes::canConvertToMime(), QLastResortMimes::convertToMime(), QLastResortMimes::formatsForMime(), QBuiltInMimes::QBuiltInMimes(), QWindowsMimeHtml::QWindowsMimeHtml(), and QWindowsMimeURI::QWindowsMimeURI().

284 {
285  int f = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (mime.utf16()));
286  if (!f)
287  qErrnoWarning("QWindowsMime::registerMimeType: Failed to register clipboard format");
288 
289  return f;
290 }
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

Friends and Related Functions

◆ QClipboardWatcher

friend class QClipboardWatcher
friend

Definition at line 98 of file qmime.h.

◆ QDragManager

friend class QDragManager
friend

Definition at line 99 of file qmime.h.

◆ QDropData

friend class QDropData
friend

Definition at line 100 of file qmime.h.

◆ QOleDataObject

friend class QOleDataObject
friend

Definition at line 101 of file qmime.h.


The documentation for this class was generated from the following files: