Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
6
7#include <QtCore/qurl.h>
8#include <QtCore/qmimedata.h>
10
12
13using namespace Qt::StringLiterals;
14
15/*!
16 \class QWindowsDropDataObject
17 \brief QWindowsOleDataObject subclass specialized for handling Drag&Drop.
18
19 Prevents "text/uri-list" data for local files from being exported as text
20 or URLs, to allow dropped files to be attached to Office applications
21 (instead of creating local hyperlinks).
22
23 \internal
24*/
25
30
32
34QWindowsDropDataObject::GetData(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium) noexcept
35{
36 if (shouldIgnore(pformatetc))
37 return ResultFromScode(DATA_E_FORMATETC);
38
39 return QWindowsOleDataObject::GetData(pformatetc, pmedium);
40}
41
43QWindowsDropDataObject::QueryGetData(LPFORMATETC pformatetc) noexcept
44{
45 if (shouldIgnore(pformatetc))
46 return ResultFromScode(DATA_E_FORMATETC);
47
48 return QWindowsOleDataObject::QueryGetData(pformatetc);
49}
50
51// If the data is "text/uri-list" only, and all URIs are for local files,
52// we prevent it from being exported as text or URLs, to make target applications
53// like MS Office attach or open the files instead of creating local hyperlinks.
54bool QWindowsDropDataObject::shouldIgnore(LPFORMATETC pformatetc) const
55{
56 QMimeData *dropData = mimeData();
57
58 if (dropData && dropData->formats().size() == 1 && dropData->hasUrls()) {
59 QString formatName = QWindowsMimeRegistry::clipboardFormatName(pformatetc->cfFormat);
60 if (pformatetc->cfFormat == CF_UNICODETEXT
61 || pformatetc->cfFormat == CF_TEXT
62 || formatName == "UniformResourceLocator"_L1
63 || formatName == "UniformResourceLocatorW"_L1) {
64 const auto urls = dropData->urls();
65 return std::all_of(urls.cbegin(), urls.cend(), [] (const QUrl &u) { return u.isLocalFile(); });
66 }
67 }
68
69 return false;
70}
71
72QT_END_NAMESPACE
QWindowsOleDataObject subclass specialized for handling Drag&Drop.
STDMETHOD GetData(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium) noexcept override
STDMETHOD QueryGetData(LPFORMATETC pformatetc) noexcept override
QWindowsDropDataObject(QMimeData *mimeData)
~QWindowsDropDataObject() override
OLE data container.
Definition qwindowsole.h:23
QWindowsOleDataObject(QMimeData *mimeData)
QMimeData * mimeData() const
Combined button and popup list for selecting options.