Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
5
#
include
"qwindowsdropdataobject.h"
6
7
#
include
<
QtCore
/
qurl
.
h
>
8
#
include
<
QtCore
/
qmimedata
.
h
>
9
#
include
"qwindowsmimeregistry.h"
10
11
QT_BEGIN_NAMESPACE
12
13
using
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
26
QWindowsDropDataObject
::
QWindowsDropDataObject
(QMimeData *mimeData) :
27
QWindowsOleDataObject
(
mimeData
)
28
{
29
}
30
31
QWindowsDropDataObject
::~
QWindowsDropDataObject
() =
default
;
32
33
STDMETHODIMP
34
QWindowsDropDataObject
::
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
42
STDMETHODIMP
43
QWindowsDropDataObject
::
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.
54
bool
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
72
QT_END_NAMESPACE
QWindowsDropDataObject
QWindowsOleDataObject subclass specialized for handling Drag&Drop.
Definition
qwindowsdropdataobject.h:13
QWindowsDropDataObject::GetData
STDMETHOD GetData(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium) noexcept override
Definition
qwindowsdropdataobject.cpp:34
QWindowsDropDataObject::QueryGetData
STDMETHOD QueryGetData(LPFORMATETC pformatetc) noexcept override
Definition
qwindowsdropdataobject.cpp:43
QWindowsDropDataObject::QWindowsDropDataObject
QWindowsDropDataObject(QMimeData *mimeData)
Definition
qwindowsdropdataobject.cpp:26
QWindowsDropDataObject::~QWindowsDropDataObject
~QWindowsDropDataObject() override
QWindowsOleDataObject
OLE data container.
Definition
qwindowsole.h:23
QWindowsOleDataObject::QWindowsOleDataObject
QWindowsOleDataObject(QMimeData *mimeData)
Definition
qwindowsole.cpp:40
QWindowsOleDataObject::mimeData
QMimeData * mimeData() const
Definition
qwindowsole.cpp:54
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
plugins
platforms
windows
qwindowsdropdataobject.cpp
Generated on
for Qt by
1.18.0