Windows QPA: Move mime-type related classes to the new interface
Move QWindowsMime (which was a public class in Qt 4 and moved to the QPA plugin in Qt 5) to the platform namespace and add register functions to the native application. Move in test code from QtWinExtras. Task-number: QTBUG-83252 Change-Id: Iaac440e2d5cb370110919921b1eeb779600b5b65 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>bb10
parent
904eaec9de
commit
2405aa9d67
|
|
@ -310,6 +310,7 @@ qt_extend_target(Gui CONDITION WIN32
|
|||
image/qpixmap_win.cpp
|
||||
kernel/qwindowdefs_win.h
|
||||
platform/windows/qwindowsguieventdispatcher.cpp platform/windows/qwindowsguieventdispatcher_p.h
|
||||
platform/windows/qwindowsmime_p.h
|
||||
platform/windows/qwindowsplatforminterface.cpp
|
||||
rhi/qrhid3d11.cpp rhi/qrhid3d11_p.h
|
||||
rhi/qrhid3d11_p_p.h
|
||||
|
|
|
|||
|
|
@ -390,6 +390,7 @@ qt_extend_target(Gui CONDITION WIN32
|
|||
image/qpixmap_win.cpp
|
||||
kernel/qwindowdefs_win.h
|
||||
platform/windows/qwindowsguieventdispatcher.cpp platform/windows/qwindowsguieventdispatcher_p.h
|
||||
platform/windows/qwindowsmime_p.h
|
||||
platform/windows/qwindowsplatforminterface.cpp
|
||||
rhi/qrhid3d11.cpp rhi/qrhid3d11_p.h
|
||||
rhi/qrhid3d11_p_p.h
|
||||
|
|
|
|||
|
|
@ -373,6 +373,9 @@ Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey
|
|||
namespace QPlatformInterface::Private {
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
|
||||
class QWindowsMime;
|
||||
|
||||
struct Q_GUI_EXPORT QWindowsApplication
|
||||
{
|
||||
QT_DECLARE_PLATFORM_INTERFACE(QWindowsApplication)
|
||||
|
|
@ -412,6 +415,11 @@ struct Q_GUI_EXPORT QWindowsApplication
|
|||
|
||||
virtual DarkModeHandling darkModeHandling() const = 0;
|
||||
virtual void setDarkModeHandling(DarkModeHandling handling) = 0;
|
||||
|
||||
virtual void registerMime(QWindowsMime *mime) = 0;
|
||||
virtual void unregisterMime(QWindowsMime *mime) = 0;
|
||||
|
||||
virtual int registerMimeType(const QString &mime) = 0;
|
||||
};
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSMIME_P_H
|
||||
#define QWINDOWSMIME_P_H
|
||||
|
||||
#include <QtCore/qt_windows.h>
|
||||
#include <QtCore/qvariant.h>
|
||||
|
||||
#include <QtGui/qtguiglobal.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QMimeData;
|
||||
|
||||
namespace QPlatformInterface::Private {
|
||||
|
||||
class Q_GUI_EXPORT QWindowsMime
|
||||
{
|
||||
public:
|
||||
virtual ~QWindowsMime() = default;
|
||||
|
||||
// for converting from Qt
|
||||
virtual bool canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const = 0;
|
||||
virtual bool convertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM * pmedium) const = 0;
|
||||
virtual QList<FORMATETC> formatsForMime(const QString &mimeType, const QMimeData *mimeData) const = 0;
|
||||
|
||||
// for converting to Qt
|
||||
virtual bool canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const = 0;
|
||||
virtual QVariant convertToMime(const QString &mimeType, IDataObject *pDataObj, QVariant::Type preferredType) const = 0;
|
||||
virtual QString mimeForFormat(const FORMATETC &formatetc) const = 0;
|
||||
};
|
||||
|
||||
} // QPlatformInterface::Private
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSMIME_P_H
|
||||
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include <QtGui/qopenglcontext.h>
|
||||
#include <QtGui/private/qguiapplication_p.h>
|
||||
#include <QtGui/private/qwindowsmime_p.h>
|
||||
#include <qpa/qplatformopenglcontext.h>
|
||||
#include <qpa/qplatformintegration.h>
|
||||
#include <qpa/qplatformwindow.h>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
HEADERS += platform/windows/qwindowsguieventdispatcher_p.h
|
||||
HEADERS += \
|
||||
platform/windows/qwindowsguieventdispatcher_p.h \
|
||||
platform/windows/qwindowsmime_p.h
|
||||
|
||||
SOURCES += \
|
||||
platform/windows/qwindowsguieventdispatcher.cpp \
|
||||
platform/windows/qwindowsplatforminterface.cpp
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#include "qwindowsapplication.h"
|
||||
#include "qwindowsclipboard.h"
|
||||
#include "qwindowscontext.h"
|
||||
#include "qwindowsmime.h"
|
||||
#include "qwin10helpers.h"
|
||||
|
||||
|
||||
|
|
@ -109,4 +110,21 @@ void QWindowsApplication::setDarkModeHandling(QWindowsApplication::DarkModeHandl
|
|||
m_darkModeHandling = handling;
|
||||
}
|
||||
|
||||
void QWindowsApplication::registerMime(QPlatformInterface::Private::QWindowsMime *mime)
|
||||
{
|
||||
if (auto ctx = QWindowsContext::instance())
|
||||
ctx->mimeConverter().registerMime(mime);
|
||||
}
|
||||
|
||||
void QWindowsApplication::unregisterMime(QPlatformInterface::Private::QWindowsMime *mime)
|
||||
{
|
||||
if (auto ctx = QWindowsContext::instance())
|
||||
ctx->mimeConverter().unregisterMime(mime);
|
||||
}
|
||||
|
||||
int QWindowsApplication::registerMimeType(const QString &mime)
|
||||
{
|
||||
return QWindowsMimeConverter::registerMimeType(mime);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -62,6 +62,11 @@ public:
|
|||
DarkModeHandling darkModeHandling() const override;
|
||||
void setDarkModeHandling(DarkModeHandling handling) override;
|
||||
|
||||
void registerMime(QPlatformInterface::Private::QWindowsMime *mime) override;
|
||||
void unregisterMime(QPlatformInterface::Private::QWindowsMime *mime) override;
|
||||
|
||||
int registerMimeType(const QString &mime) override;
|
||||
|
||||
private:
|
||||
WindowActivationBehavior m_windowActivationBehavior = DefaultActivateWindow;
|
||||
TouchWindowTouchTypes m_touchWindowTouchTypes = NormalTouch;
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@
|
|||
#include "qwindowscontext.h"
|
||||
#include "qwindowsmime.h"
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qvariant.h>
|
||||
|
||||
/*!
|
||||
\class QWindowsInternalMimeDataBase
|
||||
\brief Base for implementations of QInternalMimeData using a IDataObject COM object.
|
||||
|
|
@ -97,7 +99,7 @@ QVariant QWindowsInternalMimeData::retrieveData_sys(const QString &mimeType,
|
|||
|
||||
QVariant result;
|
||||
const QWindowsMimeConverter &mc = QWindowsContext::instance()->mimeConverter();
|
||||
if (const QWindowsMime *converter = mc.converterToMime(mimeType, pDataObj))
|
||||
if (auto converter = mc.converterToMime(mimeType, pDataObj))
|
||||
result = converter->convertToMime(mimeType, pDataObj, type);
|
||||
releaseDataObject(pDataObj);
|
||||
if (QWindowsContext::verbose) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
|
|
@ -485,30 +485,6 @@ QDebug operator<<(QDebug d, IDataObject *dataObj)
|
|||
\sa QWindowsMimeConverter
|
||||
*/
|
||||
|
||||
/*!
|
||||
Constructs a new conversion object, adding it to the globally accessed
|
||||
list of available converters.
|
||||
*/
|
||||
QWindowsMime::QWindowsMime() = default;
|
||||
|
||||
/*!
|
||||
Destroys a conversion object, removing it from the global
|
||||
list of available converters.
|
||||
*/
|
||||
QWindowsMime::~QWindowsMime() = default;
|
||||
|
||||
/*!
|
||||
Registers the MIME type \a mime, and returns an ID number
|
||||
identifying the format on Windows.
|
||||
*/
|
||||
int QWindowsMime::registerMimeType(const QString &mime)
|
||||
{
|
||||
const UINT f = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (mime.utf16()));
|
||||
if (!f)
|
||||
qErrnoWarning("QWindowsMime::registerMimeType: Failed to register clipboard format");
|
||||
|
||||
return int(f);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool QWindowsMime::canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
|
||||
|
|
@ -568,7 +544,7 @@ int QWindowsMime::registerMimeType(const QString &mime)
|
|||
All subclasses must reimplement this pure virtual function.
|
||||
*/
|
||||
|
||||
class QWindowsMimeText : public QWindowsMime
|
||||
class QWindowsMimeText : public QPlatformInterface::Private::QWindowsMime
|
||||
{
|
||||
public:
|
||||
bool canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const override;
|
||||
|
|
@ -724,7 +700,7 @@ QVariant QWindowsMimeText::convertToMime(const QString &mime, LPDATAOBJECT pData
|
|||
return ret;
|
||||
}
|
||||
|
||||
class QWindowsMimeURI : public QWindowsMime
|
||||
class QWindowsMimeURI : public QPlatformInterface::Private::QWindowsMime
|
||||
{
|
||||
public:
|
||||
QWindowsMimeURI();
|
||||
|
|
@ -741,8 +717,8 @@ private:
|
|||
|
||||
QWindowsMimeURI::QWindowsMimeURI()
|
||||
{
|
||||
CF_INETURL_W = QWindowsMime::registerMimeType(QStringLiteral("UniformResourceLocatorW"));
|
||||
CF_INETURL = QWindowsMime::registerMimeType(QStringLiteral("UniformResourceLocator"));
|
||||
CF_INETURL_W = QWindowsMimeConverter::registerMimeType(QStringLiteral("UniformResourceLocatorW"));
|
||||
CF_INETURL = QWindowsMimeConverter::registerMimeType(QStringLiteral("UniformResourceLocator"));
|
||||
}
|
||||
|
||||
bool QWindowsMimeURI::canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
|
||||
|
|
@ -890,7 +866,7 @@ QVariant QWindowsMimeURI::convertToMime(const QString &mimeType, LPDATAOBJECT pD
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
class QWindowsMimeHtml : public QWindowsMime
|
||||
class QWindowsMimeHtml : public QPlatformInterface::Private::QWindowsMime
|
||||
{
|
||||
public:
|
||||
QWindowsMimeHtml();
|
||||
|
|
@ -911,7 +887,7 @@ private:
|
|||
|
||||
QWindowsMimeHtml::QWindowsMimeHtml()
|
||||
{
|
||||
CF_HTML = QWindowsMime::registerMimeType(QStringLiteral("HTML Format"));
|
||||
CF_HTML = QWindowsMimeConverter::registerMimeType(QStringLiteral("HTML Format"));
|
||||
}
|
||||
|
||||
QList<FORMATETC> QWindowsMimeHtml::formatsForMime(const QString &mimeType, const QMimeData *mimeData) const
|
||||
|
|
@ -1028,7 +1004,7 @@ bool QWindowsMimeHtml::convertFromMime(const FORMATETC &formatetc, const QMimeDa
|
|||
|
||||
|
||||
#ifndef QT_NO_IMAGEFORMAT_BMP
|
||||
class QWindowsMimeImage : public QWindowsMime
|
||||
class QWindowsMimeImage : public QPlatformInterface::Private::QWindowsMime
|
||||
{
|
||||
public:
|
||||
QWindowsMimeImage();
|
||||
|
|
@ -1182,7 +1158,7 @@ QVariant QWindowsMimeImage::convertToMime(const QString &mimeType, IDataObject *
|
|||
}
|
||||
#endif
|
||||
|
||||
class QBuiltInMimes : public QWindowsMime
|
||||
class QBuiltInMimes : public QPlatformInterface::Private::QWindowsMime
|
||||
{
|
||||
public:
|
||||
QBuiltInMimes();
|
||||
|
|
@ -1205,8 +1181,8 @@ private:
|
|||
QBuiltInMimes::QBuiltInMimes()
|
||||
: QWindowsMime()
|
||||
{
|
||||
outFormats.insert(QWindowsMime::registerMimeType(QStringLiteral("application/x-color")), QStringLiteral("application/x-color"));
|
||||
inFormats.insert(QWindowsMime::registerMimeType(QStringLiteral("application/x-color")), QStringLiteral("application/x-color"));
|
||||
outFormats.insert(QWindowsMimeConverter::registerMimeType(QStringLiteral("application/x-color")), QStringLiteral("application/x-color"));
|
||||
inFormats.insert(QWindowsMimeConverter::registerMimeType(QStringLiteral("application/x-color")), QStringLiteral("application/x-color"));
|
||||
}
|
||||
|
||||
bool QBuiltInMimes::canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
|
||||
|
|
@ -1303,7 +1279,7 @@ QString QBuiltInMimes::mimeForFormat(const FORMATETC &formatetc) const
|
|||
}
|
||||
|
||||
|
||||
class QLastResortMimes : public QWindowsMime
|
||||
class QLastResortMimes : public QPlatformInterface::Private::QWindowsMime
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
@ -1387,7 +1363,7 @@ QList<FORMATETC> QLastResortMimes::formatsForMime(const QString &mimeType, const
|
|||
auto mit = std::find(formats.begin(), formats.end(), mimeType);
|
||||
// register any other available formats
|
||||
if (mit == formats.end() && !excludeList.contains(mimeType, Qt::CaseInsensitive))
|
||||
mit = formats.insert(QWindowsMime::registerMimeType(mimeType), mimeType);
|
||||
mit = formats.insert(QWindowsMimeConverter::registerMimeType(mimeType), mimeType);
|
||||
if (mit != formats.end())
|
||||
formatetcs += setCf(mit.key());
|
||||
|
||||
|
|
@ -1431,7 +1407,7 @@ bool QLastResortMimes::canConvertToMime(const QString &mimeType, IDataObject *pD
|
|||
}
|
||||
// if it is not in there then register it and see if we can get it
|
||||
const auto mit = std::find(formats.cbegin(), formats.cend(), mimeType);
|
||||
const int cf = mit != formats.cend() ? mit.key() : QWindowsMime::registerMimeType(mimeType);
|
||||
const int cf = mit != formats.cend() ? mit.key() : QWindowsMimeConverter::registerMimeType(mimeType);
|
||||
return canGetData(cf, pDataObj);
|
||||
}
|
||||
|
||||
|
|
@ -1448,7 +1424,7 @@ QVariant QLastResortMimes::convertToMime(const QString &mimeType, IDataObject *p
|
|||
data = getData(int(cf), pDataObj, lindex);
|
||||
} else {
|
||||
const auto mit = std::find(formats.cbegin(), formats.cend(), mimeType);
|
||||
const int cf = mit != formats.cend() ? mit.key() : QWindowsMime::registerMimeType(mimeType);
|
||||
const int cf = mit != formats.cend() ? mit.key() : QWindowsMimeConverter::registerMimeType(mimeType);
|
||||
data = getData(cf, pDataObj);
|
||||
}
|
||||
if (!data.isEmpty())
|
||||
|
|
@ -1506,7 +1482,7 @@ QWindowsMimeConverter::~QWindowsMimeConverter()
|
|||
qDeleteAll(m_mimes.begin(), m_mimes.begin() + m_internalMimeCount);
|
||||
}
|
||||
|
||||
QWindowsMime * QWindowsMimeConverter::converterToMime(const QString &mimeType, IDataObject *pDataObj) const
|
||||
QWindowsMimeConverter::QWindowsMime *QWindowsMimeConverter::converterToMime(const QString &mimeType, IDataObject *pDataObj) const
|
||||
{
|
||||
ensureInitialized();
|
||||
for (int i = m_mimes.size()-1; i >= 0; --i) {
|
||||
|
|
@ -1545,7 +1521,7 @@ QStringList QWindowsMimeConverter::allMimesForFormats(IDataObject *pDataObj) con
|
|||
return formats;
|
||||
}
|
||||
|
||||
QWindowsMime * QWindowsMimeConverter::converterFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
|
||||
QWindowsMimeConverter::QWindowsMime *QWindowsMimeConverter::converterFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
|
||||
{
|
||||
ensureInitialized();
|
||||
qCDebug(lcQpaMime) << __FUNCTION__ << formatetc;
|
||||
|
|
@ -1623,4 +1599,17 @@ void QWindowsMimeConverter::registerMime(QWindowsMime *mime)
|
|||
m_mimes.append(mime);
|
||||
}
|
||||
|
||||
/*!
|
||||
Registers the MIME type \a mime, and returns an ID number
|
||||
identifying the format on Windows.
|
||||
*/
|
||||
int QWindowsMimeConverter::registerMimeType(const QString &mime)
|
||||
{
|
||||
const UINT f = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (mime.utf16()));
|
||||
if (!f)
|
||||
qErrnoWarning("QWindowsApplication::registerMimeType: Failed to register clipboard format");
|
||||
|
||||
return int(f);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@
|
|||
#ifndef QWINDOWSMIME_H
|
||||
#define QWINDOWSMIME_H
|
||||
|
||||
#include <QtGui/private/qwindowsmime_p.h>
|
||||
|
||||
#include <QtCore/qt_windows.h>
|
||||
|
||||
#include <QtCore/qlist.h>
|
||||
|
|
@ -50,30 +52,12 @@ QT_BEGIN_NAMESPACE
|
|||
class QDebug;
|
||||
class QMimeData;
|
||||
|
||||
class QWindowsMime
|
||||
{
|
||||
Q_DISABLE_COPY_MOVE(QWindowsMime)
|
||||
public:
|
||||
QWindowsMime();
|
||||
virtual ~QWindowsMime();
|
||||
|
||||
// for converting from Qt
|
||||
virtual bool canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const = 0;
|
||||
virtual bool convertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM * pmedium) const = 0;
|
||||
virtual QList<FORMATETC> formatsForMime(const QString &mimeType, const QMimeData *mimeData) const = 0;
|
||||
|
||||
// for converting to Qt
|
||||
virtual bool canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const = 0;
|
||||
virtual QVariant convertToMime(const QString &mimeType, IDataObject *pDataObj, QVariant::Type preferredType) const = 0;
|
||||
virtual QString mimeForFormat(const FORMATETC &formatetc) const = 0;
|
||||
|
||||
static int registerMimeType(const QString &mime);
|
||||
};
|
||||
|
||||
class QWindowsMimeConverter
|
||||
{
|
||||
Q_DISABLE_COPY_MOVE(QWindowsMimeConverter)
|
||||
public:
|
||||
using QWindowsMime = QPlatformInterface::Private::QWindowsMime;
|
||||
|
||||
QWindowsMimeConverter();
|
||||
~QWindowsMimeConverter();
|
||||
|
||||
|
|
@ -89,6 +73,8 @@ public:
|
|||
void registerMime(QWindowsMime *mime);
|
||||
void unregisterMime(QWindowsMime *mime) { m_mimes.removeOne(mime); }
|
||||
|
||||
static int registerMimeType(const QString &mime);
|
||||
|
||||
static QString clipboardFormatName(int cf);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@
|
|||
#include "qwindowsopenglcontext.h"
|
||||
#include "qwindowsopengltester.h"
|
||||
#include "qwindowsintegration.h"
|
||||
#include "qwindowsmime.h"
|
||||
#include "qwindowstheme.h"
|
||||
#include "qwin10helpers.h"
|
||||
|
||||
|
|
@ -205,21 +204,6 @@ void QWindowsNativeInterface::setAsyncExpose(bool value)
|
|||
QWindowsContext::instance()->setAsyncExpose(value);
|
||||
}
|
||||
|
||||
void QWindowsNativeInterface::registerWindowsMime(void *mimeIn)
|
||||
{
|
||||
QWindowsContext::instance()->mimeConverter().registerMime(reinterpret_cast<QWindowsMime *>(mimeIn));
|
||||
}
|
||||
|
||||
void QWindowsNativeInterface::unregisterWindowsMime(void *mimeIn)
|
||||
{
|
||||
QWindowsContext::instance()->mimeConverter().unregisterMime(reinterpret_cast<QWindowsMime *>(mimeIn));
|
||||
}
|
||||
|
||||
int QWindowsNativeInterface::registerMimeType(const QString &mimeType)
|
||||
{
|
||||
return QWindowsMime::registerMimeType(mimeType);
|
||||
}
|
||||
|
||||
QFont QWindowsNativeInterface::logFontToQFont(const void *logFont, int verticalDpi)
|
||||
{
|
||||
return QWindowsFontDatabase::LOGFONT_to_QFont(*reinterpret_cast<const LOGFONT *>(logFont), verticalDpi);
|
||||
|
|
|
|||
|
|
@ -82,9 +82,6 @@ public:
|
|||
|
||||
Q_INVOKABLE QString registerWindowClass(const QString &classNameIn, void *eventProc) const;
|
||||
|
||||
Q_INVOKABLE void registerWindowsMime(void *mimeIn);
|
||||
Q_INVOKABLE void unregisterWindowsMime(void *mime);
|
||||
Q_INVOKABLE int registerMimeType(const QString &mimeType);
|
||||
Q_INVOKABLE QFont logFontToQFont(const void *logFont, int verticalDpi);
|
||||
|
||||
bool asyncExpose() const;
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ QWindowsOleDataObject::GetData(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium)
|
|||
|
||||
if (data) {
|
||||
const QWindowsMimeConverter &mc = QWindowsContext::instance()->mimeConverter();
|
||||
if (QWindowsMime *converter = mc.converterFromMime(*pformatetc, data))
|
||||
if (auto converter = mc.converterFromMime(*pformatetc, data))
|
||||
if (converter->convertFromMime(*pformatetc, data, pmedium))
|
||||
hr = ResultFromScode(S_OK);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ qt_add_test(tst_qclipboard
|
|||
../tst_qclipboard.cpp
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
)
|
||||
|
||||
## Scopes:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
CONFIG += testcase
|
||||
SOURCES += ../tst_qclipboard.cpp
|
||||
TARGET = ../tst_qclipboard
|
||||
QT += testlib
|
||||
QT += testlib gui-private
|
||||
|
||||
osx: LIBS += -framework AppKit
|
||||
|
||||
|
|
|
|||
|
|
@ -31,12 +31,20 @@
|
|||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QClipboard>
|
||||
#include <QtGui/QImage>
|
||||
#include <QtGui/QPixmap>
|
||||
#include <QtGui/QColor>
|
||||
#include "../../../shared/platformclipboard.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
# include <QtGui/private/qguiapplication_p.h>
|
||||
# include <QtGui/private/qwindowsmime_p.h>
|
||||
# include <QtGui/qpa/qplatformintegration.h>
|
||||
#endif
|
||||
|
||||
class tst_QClipboard : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -53,7 +61,12 @@ private slots:
|
|||
void testSignals();
|
||||
void setMimeData();
|
||||
void clearBeforeSetText();
|
||||
#endif
|
||||
# ifdef Q_OS_WIN
|
||||
void testWindowsMimeRegisterType();
|
||||
void testWindowsMime_data();
|
||||
void testWindowsMime();
|
||||
# endif // Q_OS_WIN
|
||||
#endif // clipboard
|
||||
};
|
||||
|
||||
void tst_QClipboard::initTestCase()
|
||||
|
|
@ -431,6 +444,93 @@ void tst_QClipboard::clearBeforeSetText()
|
|||
QCOMPARE(QGuiApplication::clipboard()->text(), text);
|
||||
}
|
||||
|
||||
# ifdef Q_OS_WIN
|
||||
|
||||
using QWindowsMime = QPlatformInterface::Private::QWindowsMime;
|
||||
using QWindowsApplication = QPlatformInterface::Private::QWindowsApplication;
|
||||
|
||||
class TestMime : public QWindowsMime
|
||||
{
|
||||
public:
|
||||
bool canConvertFromMime(const FORMATETC &, const QMimeData *) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool convertFromMime(const FORMATETC &, const QMimeData *, STGMEDIUM *) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<FORMATETC> formatsForMime(const QString &, const QMimeData *) const override
|
||||
{
|
||||
formatsForMimeCalled = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
bool canConvertToMime(const QString &, IDataObject *) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant convertToMime(const QString &, IDataObject *, QVariant::Type) const override
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QString mimeForFormat(const FORMATETC &) const override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
mutable bool formatsForMimeCalled = false;
|
||||
};
|
||||
|
||||
void tst_QClipboard::testWindowsMimeRegisterType()
|
||||
{
|
||||
auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration());
|
||||
QVERIFY(nativeWindowsApp);
|
||||
const int type = nativeWindowsApp->registerMimeType("foo/bar");
|
||||
QVERIFY2(type >= 0, QByteArray::number(type));
|
||||
}
|
||||
|
||||
void tst_QClipboard::testWindowsMime_data()
|
||||
{
|
||||
QTest::addColumn<QVariant>("data");
|
||||
QTest::newRow("string") << QVariant(QStringLiteral("bla"));
|
||||
QPixmap pm(10, 10);
|
||||
pm.fill(Qt::black);
|
||||
QTest::newRow("pixmap") << QVariant(pm);
|
||||
}
|
||||
|
||||
void tst_QClipboard::testWindowsMime()
|
||||
{
|
||||
QFETCH(QVariant, data);
|
||||
// Basic smoke test for crashes, copy some text into clipboard and check whether
|
||||
// the test implementation is called.
|
||||
TestMime testMime;
|
||||
auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration());
|
||||
QVERIFY(nativeWindowsApp);
|
||||
nativeWindowsApp->registerMime(&testMime);
|
||||
|
||||
auto clipboard = QGuiApplication::clipboard();
|
||||
switch (data.type()) {
|
||||
case QVariant::String:
|
||||
clipboard->setText(data.toString());
|
||||
break;
|
||||
case QVariant::Pixmap:
|
||||
clipboard->setPixmap(data.value<QPixmap>());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
QTRY_VERIFY(testMime.formatsForMimeCalled);
|
||||
|
||||
nativeWindowsApp->unregisterMime(&testMime);
|
||||
}
|
||||
|
||||
# endif // Q_OS_WIN
|
||||
|
||||
#endif // QT_CONFIG(clipboard)
|
||||
|
||||
QTEST_MAIN(tst_QClipboard)
|
||||
|
|
|
|||
Loading…
Reference in New Issue