Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsdropdataobject.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtCore/qurl.h>
7#include <QtCore/qmimedata.h>
9
11
12using namespace Qt::Literals::StringLiterals;
13
29
31
32STDMETHODIMP
33QWindowsDropDataObject::GetData(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium)
34{
35 if (shouldIgnore(pformatetc))
36 return ResultFromScode(DATA_E_FORMATETC);
37
38 return QWindowsOleDataObject::GetData(pformatetc, pmedium);
39}
40
41STDMETHODIMP
43{
44 if (shouldIgnore(pformatetc))
45 return ResultFromScode(DATA_E_FORMATETC);
46
47 return QWindowsOleDataObject::QueryGetData(pformatetc);
48}
49
50// If the data is "text/uri-list" only, and all URIs are for local files,
51// we prevent it from being exported as text or URLs, to make target applications
52// like MS Office attach or open the files instead of creating local hyperlinks.
53bool QWindowsDropDataObject::shouldIgnore(LPFORMATETC pformatetc) const
54{
55 QMimeData *dropData = mimeData();
56
57 if (dropData && dropData->formats().size() == 1 && dropData->hasUrls()) {
59 if (pformatetc->cfFormat == CF_UNICODETEXT
60 || pformatetc->cfFormat == CF_TEXT
61 || formatName == "UniformResourceLocator"_L1
62 || formatName == "UniformResourceLocatorW"_L1) {
63 const auto urls = dropData->urls();
64 return std::all_of(urls.cbegin(), urls.cend(), [] (const QUrl &u) { return u.isLocalFile(); });
65 }
66 }
67
68 return false;
69}
70
\inmodule QtCore
Definition qmimedata.h:16
bool hasUrls() const
Returns true if the object can return a list of urls; otherwise returns false.
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
virtual QStringList formats() const
Returns a list of formats supported by the object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
STDMETHOD QueryGetData(LPFORMATETC pformatetc) override
STDMETHOD GetData(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium) override
QWindowsDropDataObject(QMimeData *mimeData)
~QWindowsDropDataObject() override
static QString clipboardFormatName(int cf)
OLE data container.
Definition qwindowsole.h:22
QMimeData * mimeData() const
STDMETHOD QueryGetData(LPFORMATETC pformatetc) override
STDMETHOD GetData(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium) override
Combined button and popup list for selecting options.
static QByteArray formatName(int format)
QMimeData * mimeData