Windows QPA: Fix custom drop formats being ignored
Changes QWindowsDropDataObject to only ignore non-CF_HDROP formats when the drop contains only "text/uri-list" mime data, and the URIs are for local files, to avoid messing with custom formats set by the developer, while still fixing the case reported in QTBUG-62662. Fixes: QTBUG-74232 Change-Id: I946ced222377716876d0aea54b3eb05d40e7fa44 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
4298658bef
commit
c096d97097
@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
#include <QtCore/qurl.h>
|
#include <QtCore/qurl.h>
|
||||||
#include <QtCore/qmimedata.h>
|
#include <QtCore/qmimedata.h>
|
||||||
|
#include "qwindowsmime.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -48,8 +49,9 @@ QT_BEGIN_NAMESPACE
|
|||||||
\class QWindowsDropDataObject
|
\class QWindowsDropDataObject
|
||||||
\brief QWindowsOleDataObject subclass specialized for handling Drag&Drop.
|
\brief QWindowsOleDataObject subclass specialized for handling Drag&Drop.
|
||||||
|
|
||||||
Only allows "text/uri-list" data to be exported as CF_HDROP, to allow dropped
|
Prevents "text/uri-list" data for local files from being exported as text
|
||||||
files to be attached to Office applications (instead of adding an URL link).
|
or URLs, to allow dropped files to be attached to Office applications
|
||||||
|
(instead of creating local hyperlinks).
|
||||||
|
|
||||||
\internal
|
\internal
|
||||||
\ingroup qt-lighthouse-win
|
\ingroup qt-lighthouse-win
|
||||||
@ -80,14 +82,22 @@ QWindowsDropDataObject::QueryGetData(LPFORMATETC pformatetc)
|
|||||||
return QWindowsOleDataObject::QueryGetData(pformatetc);
|
return QWindowsOleDataObject::QueryGetData(pformatetc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the data is text/uri-list for local files, tell we can only export it as CF_HDROP.
|
// If the data is "text/uri-list" only, and all URIs are for local files,
|
||||||
|
// we prevent it from being exported as text or URLs, to make target applications
|
||||||
|
// like MS Office attach or open the files instead of creating local hyperlinks.
|
||||||
bool QWindowsDropDataObject::shouldIgnore(LPFORMATETC pformatetc) const
|
bool QWindowsDropDataObject::shouldIgnore(LPFORMATETC pformatetc) const
|
||||||
{
|
{
|
||||||
QMimeData *dropData = mimeData();
|
QMimeData *dropData = mimeData();
|
||||||
|
|
||||||
if (dropData && dropData->hasFormat(QStringLiteral("text/uri-list")) && (pformatetc->cfFormat != CF_HDROP)) {
|
if (dropData && dropData->formats().size() == 1 && dropData->hasUrls()) {
|
||||||
|
QString formatName = QWindowsMimeConverter::clipboardFormatName(pformatetc->cfFormat);
|
||||||
|
if (pformatetc->cfFormat == CF_UNICODETEXT
|
||||||
|
|| pformatetc->cfFormat == CF_TEXT
|
||||||
|
|| formatName == QStringLiteral("UniformResourceLocator")
|
||||||
|
|| formatName == QStringLiteral("UniformResourceLocatorW")) {
|
||||||
QList<QUrl> urls = dropData->urls();
|
QList<QUrl> urls = dropData->urls();
|
||||||
return std::any_of(urls.cbegin(), urls.cend(), [] (const QUrl &u) { return u.isLocalFile(); });
|
return std::all_of(urls.cbegin(), urls.cend(), [] (const QUrl &u) { return u.isLocalFile(); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user