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
qwindowsmimeconverter.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 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
"qwindowsmimeconverter.h"
6
7
#
include
<
QtCore
/
qt_windows
.
h
>
8
9
#
include
<
QtGui
/
private
/
qguiapplication_p
.
h
>
10
#
include
<
QtGui
/
qpa
/
qplatformintegration
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
/*!
15
\class QWindowsMimeConverter
16
\brief The QWindowsMimeConverter class maps open-standard MIME to Window Clipboard formats.
17
\inmodule QtGui
18
19
Qt's drag-and-drop and clipboard facilities use the MIME standard.
20
On X11, this maps trivially to the Xdnd protocol, but on Windows
21
although some applications use MIME types to describe clipboard
22
formats, others use arbitrary non-standardized naming conventions,
23
or unnamed built-in formats of Windows.
24
25
By instantiating subclasses of QWindowsMimeConverter that provide
26
conversions between Windows Clipboard and MIME formats, you can convert
27
proprietary clipboard formats to MIME formats.
28
29
Construct an instance of your converter implementation after instantiating
30
QGuiApplication:
31
32
\code
33
int main(int argc, char **argv)
34
{
35
QGuiApplication app(argc, argv);
36
JsonMimeConverter jsonConverter;
37
}
38
\endcode
39
40
Destroying the instance will unregister the converter and remove support
41
for the conversion. It is also valid to heap-allocate the converter
42
instance; Qt takes ownership and will delete the converter object during
43
QGuiApplication shut-down.
44
45
Qt has predefined support for the following Windows Clipboard formats:
46
47
\table
48
\header \li Windows Format \li Equivalent MIME type
49
\row \li \c CF_UNICODETEXT \li \c text/plain
50
\row \li \c CF_TEXT \li \c text/plain
51
\row \li \c CF_DIB \li \c{image/xyz}, where \c xyz is
52
a \l{QImageWriter::supportedImageFormats()}{Qt image format}
53
\row \li \c CF_HDROP \li \c text/uri-list
54
\row \li \c CF_INETURL \li \c text/uri-list
55
\row \li \c CF_HTML \li \c text/html
56
\endtable
57
58
An example use of this class would be to map the Windows Metafile
59
clipboard format (\c CF_METAFILEPICT) to and from the MIME type
60
\c{image/x-wmf}. This conversion might simply be adding or removing
61
a header, or even just passing on the data. See \l{Drag and Drop}
62
for more information on choosing and definition MIME types.
63
64
You can check if a MIME type is convertible using canConvertFromMime() and
65
can perform conversions with convertToMime() and convertFromMime().
66
*/
67
68
69
/*!
70
\fn bool QWindowsMimeConverter::canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
71
72
Returns \c true if the converter can convert from the \a mimeData to
73
the format specified in \a formatetc.
74
75
All subclasses must reimplement this pure virtual function.
76
*/
77
78
/*!
79
\fn bool QWindowsMimeConverter::canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const
80
81
Returns \c true if the converter can convert to the \a mimeType from
82
the available formats in \a pDataObj.
83
84
All subclasses must reimplement this pure virtual function.
85
*/
86
87
/*!
88
\fn QString QWindowsMimeConverter::mimeForFormat(const FORMATETC &formatetc) const
89
90
Returns the mime type that will be created form the format specified
91
in \a formatetc, or an empty string if this converter does not support
92
\a formatetc.
93
94
All subclasses must reimplement this pure virtual function.
95
*/
96
97
/*!
98
\fn QList<FORMATETC> QWindowsMimeConverter::formatsForMime(const QString &mimeType, const QMimeData *mimeData) const
99
100
Returns a QList of FORMATETC structures representing the different windows clipboard
101
formats that can be provided for the \a mimeType from the \a mimeData.
102
103
All subclasses must reimplement this pure virtual function.
104
*/
105
106
/*!
107
\fn QVariant QWindowsMimeConverter::convertToMime(const QString &mimeType, IDataObject *pDataObj,
108
QMetaType preferredType) const
109
110
Returns a QVariant containing the converted data for \a mimeType from \a pDataObj.
111
If possible the QVariant should be of the \a preferredType to avoid needless conversions.
112
113
All subclasses must reimplement this pure virtual function.
114
*/
115
116
/*!
117
\fn bool QWindowsMimeConverter::convertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM * pmedium) const
118
119
Convert the \a mimeData to the format specified in \a formatetc.
120
The converted data should then be placed in \a pmedium structure.
121
122
Return true if the conversion was successful.
123
124
All subclasses must reimplement this pure virtual function.
125
*/
126
127
/*!
128
Constructs a QWindowsMimeConverter instance.
129
130
The instance is automatically registered, and will be called to convert data during
131
clipboard or drag'n'drop operations.
132
133
Call this constructor after QGuiApplication has been created.
134
*/
135
QWindowsMimeConverter::QWindowsMimeConverter()
136
{
137
using
QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
138
auto
nativeWindowsApp =
dynamic_cast
<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration());
139
Q_ASSERT(nativeWindowsApp);
140
nativeWindowsApp->registerMime(
this
);
141
}
142
143
/*!
144
Constructs a QWindowsMimeConverter instance.
145
146
The instance is automatically unregistered.
147
*/
148
QWindowsMimeConverter::~QWindowsMimeConverter()
149
{
150
using
QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
151
auto
nativeWindowsApp =
dynamic_cast
<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration());
152
Q_ASSERT(nativeWindowsApp);
153
nativeWindowsApp->unregisterMime(
this
);
154
}
155
156
/*!
157
Registers the MIME type \a mimeType, and returns an ID number
158
identifying the format on Windows.
159
160
A mime type \c {application/x-qt-windows-mime;value="WindowsType"} will be
161
registered as the clipboard format for \c WindowsType.
162
*/
163
int
QWindowsMimeConverter::registerMimeType(
const
QString &mimeType)
164
{
165
using
QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
166
auto
nativeWindowsApp =
dynamic_cast
<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration());
167
Q_ASSERT(nativeWindowsApp);
168
return
nativeWindowsApp->registerMimeType(mimeType);
169
}
170
171
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
gui
platform
windows
qwindowsmimeconverter.cpp
Generated on
for Qt by
1.18.0