From 964f5757ea00c5fd4a8c617e8df1bfa353c5b225 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 27 Jul 2020 15:47:59 +0200 Subject: [PATCH] Windows QPA: Move some internal functions to the new interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move createMessageWindow(), the GPU detection for qtdiag and the async expose setting (used by Active Qt) from QWindowsNativeInterface to QWindowsApplication. Remove unused registerWindowClass() and use logFontToQFont() directly from the font database. Task-number: QTBUG-83252 Change-Id: I9c72351970b47457d08125557c2580016c66e586 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qguiapplication_p.h | 10 ++++ .../platforms/windows/qwindowsapplication.cpp | 41 ++++++++++++++ .../platforms/windows/qwindowsapplication.h | 10 ++++ .../windows/qwindowsnativeinterface.cpp | 55 ------------------- .../windows/qwindowsnativeinterface.h | 16 ------ .../styles/windowsvista/qwindowsxpstyle.cpp | 22 +++----- src/widgets/dialogs/qwizard_win.cpp | 8 +-- 7 files changed, 72 insertions(+), 90 deletions(-) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 0eed5d4f43..1d68cc560b 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -420,6 +420,16 @@ struct Q_GUI_EXPORT QWindowsApplication virtual void unregisterMime(QWindowsMime *mime) = 0; virtual int registerMimeType(const QString &mime) = 0; + + virtual HWND createMessageWindow(const QString &classNameTemplate, + const QString &windowName, + QFunctionPointer eventProc = nullptr) const = 0; + + virtual bool asyncExpose() const = 0; // internal, used by Active Qt + virtual void setAsyncExpose(bool value) = 0; + + virtual QVariant gpu() const = 0; // internal, used by qtdiag + virtual QVariant gpuList() const = 0; }; #endif // Q_OS_WIN diff --git a/src/plugins/platforms/windows/qwindowsapplication.cpp b/src/plugins/platforms/windows/qwindowsapplication.cpp index 83f42a8c86..fc495d999f 100644 --- a/src/plugins/platforms/windows/qwindowsapplication.cpp +++ b/src/plugins/platforms/windows/qwindowsapplication.cpp @@ -42,7 +42,9 @@ #include "qwindowscontext.h" #include "qwindowsmime.h" #include "qwin10helpers.h" +#include "qwindowsopengltester.h" +#include QT_BEGIN_NAMESPACE @@ -127,4 +129,43 @@ int QWindowsApplication::registerMimeType(const QString &mime) return QWindowsMimeConverter::registerMimeType(mime); } +HWND QWindowsApplication::createMessageWindow(const QString &classNameTemplate, + const QString &windowName, + QFunctionPointer eventProc) const +{ + QWindowsContext *ctx = QWindowsContext::instance(); + if (!ctx) + return nullptr; + auto wndProc = eventProc ? reinterpret_cast(eventProc) : DefWindowProc; + return ctx->createDummyWindow(classNameTemplate, + reinterpret_cast(windowName.utf16()), + wndProc); +} + +bool QWindowsApplication::asyncExpose() const +{ + QWindowsContext *ctx = QWindowsContext::instance(); + return ctx && ctx->asyncExpose(); +} + +void QWindowsApplication::setAsyncExpose(bool value) +{ + if (QWindowsContext *ctx = QWindowsContext::instance()) + ctx->setAsyncExpose(value); +} + +QVariant QWindowsApplication::gpu() const +{ + return GpuDescription::detect().toVariant(); +} + +QVariant QWindowsApplication::gpuList() const +{ + QVariantList result; + const auto gpus = GpuDescription::detectAll(); + for (const auto &gpu : gpus) + result.append(gpu.toVariant()); + return result; +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsapplication.h b/src/plugins/platforms/windows/qwindowsapplication.h index 6e488e3ed0..25a0cc7437 100644 --- a/src/plugins/platforms/windows/qwindowsapplication.h +++ b/src/plugins/platforms/windows/qwindowsapplication.h @@ -67,6 +67,16 @@ public: int registerMimeType(const QString &mime) override; + HWND createMessageWindow(const QString &classNameTemplate, + const QString &windowName, + QFunctionPointer eventProc = nullptr) const override; + + bool asyncExpose() const override; + void setAsyncExpose(bool value) override; + + QVariant gpu() const override; + QVariant gpuList() const override; + private: WindowActivationBehavior m_windowActivationBehavior = DefaultActivateWindow; TouchWindowTouchTypes m_touchWindowTouchTypes = NormalTouch; diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp index fe0da98a47..a971cdae0b 100644 --- a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp +++ b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp @@ -43,7 +43,6 @@ #include "qwindowscontext.h" #include "qwindowscursor.h" #include "qwindowsopenglcontext.h" -#include "qwindowsopengltester.h" #include "qwindowsintegration.h" #include "qwindowstheme.h" #include "qwin10helpers.h" @@ -52,7 +51,6 @@ #include #include #include -#include QT_BEGIN_NAMESPACE @@ -170,57 +168,4 @@ void *QWindowsNativeInterface::nativeResourceForContext(const QByteArray &resour } #endif // !QT_NO_OPENGL -/*! - \brief Creates a non-visible window handle for filtering messages. -*/ - -void *QWindowsNativeInterface::createMessageWindow(const QString &classNameTemplate, - const QString &windowName, - void *eventProc) const -{ - QWindowsContext *ctx = QWindowsContext::instance(); - const HWND hwnd = ctx->createDummyWindow(classNameTemplate, - (wchar_t*)windowName.utf16(), - (WNDPROC)eventProc); - return hwnd; -} - -/*! - \brief Registers a unique window class with a callback function based on \a classNameIn. -*/ - -QString QWindowsNativeInterface::registerWindowClass(const QString &classNameIn, void *eventProc) const -{ - return QWindowsContext::instance()->registerWindowClass(classNameIn, (WNDPROC)eventProc); -} - -bool QWindowsNativeInterface::asyncExpose() const -{ - return QWindowsContext::instance()->asyncExpose(); -} - -void QWindowsNativeInterface::setAsyncExpose(bool value) -{ - QWindowsContext::instance()->setAsyncExpose(value); -} - -QFont QWindowsNativeInterface::logFontToQFont(const void *logFont, int verticalDpi) -{ - return QWindowsFontDatabase::LOGFONT_to_QFont(*reinterpret_cast(logFont), verticalDpi); -} - -QVariant QWindowsNativeInterface::gpu() const -{ - return GpuDescription::detect().toVariant(); -} - -QVariant QWindowsNativeInterface::gpuList() const -{ - QVariantList result; - const auto gpus = GpuDescription::detectAll(); - for (const auto &gpu : gpus) - result.append(gpu.toVariant()); - return result; -} - QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.h b/src/plugins/platforms/windows/qwindowsnativeinterface.h index 68a795f466..8ef14e8603 100644 --- a/src/plugins/platforms/windows/qwindowsnativeinterface.h +++ b/src/plugins/platforms/windows/qwindowsnativeinterface.h @@ -62,9 +62,6 @@ QT_BEGIN_NAMESPACE class QWindowsNativeInterface : public QPlatformNativeInterface { Q_OBJECT - Q_PROPERTY(bool asyncExpose READ asyncExpose WRITE setAsyncExpose) - Q_PROPERTY(QVariant gpu READ gpu STORED false) - Q_PROPERTY(QVariant gpuList READ gpuList STORED false) public: void *nativeResourceForIntegration(const QByteArray &resource) override; @@ -76,19 +73,6 @@ public: #ifndef QT_NO_CURSOR void *nativeResourceForCursor(const QByteArray &resource, const QCursor &cursor) override; #endif - Q_INVOKABLE void *createMessageWindow(const QString &classNameTemplate, - const QString &windowName, - void *eventProc) const; - - Q_INVOKABLE QString registerWindowClass(const QString &classNameIn, void *eventProc) const; - - Q_INVOKABLE QFont logFontToQFont(const void *logFont, int verticalDpi); - - bool asyncExpose() const; - void setAsyncExpose(bool value); - - QVariant gpu() const; - QVariant gpuList() const; }; QT_END_NAMESPACE diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index e57ebfeeff..601f715245 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -52,7 +51,7 @@ #include #include #include -#include +#include #if QT_CONFIG(toolbutton) #include @@ -279,18 +278,13 @@ void QWindowsXPStylePrivate::cleanup(bool force) static inline HWND createTreeViewHelperWindow() { - if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) { - void *hwnd = nullptr; - void *wndProc = reinterpret_cast(DefWindowProc); - if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection, - Q_RETURN_ARG(void*, hwnd), - Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindowClass")), - Q_ARG(QString, QStringLiteral("QTreeViewThemeHelperWindow")), - Q_ARG(void*, wndProc)) && hwnd) { - return reinterpret_cast(hwnd); - } - } - return nullptr; + using QWindowsApplication = QPlatformInterface::Private::QWindowsApplication; + + HWND result = nullptr; + if (auto nativeWindowsApp = dynamic_cast(QGuiApplicationPrivate::platformIntegration())) + result = nativeWindowsApp->createMessageWindow(QStringLiteral("QTreeViewThemeHelperWindowClass"), + QStringLiteral("QTreeViewThemeHelperWindow")); + return result; } bool QWindowsXPStylePrivate::initVistaTreeViewTheming() diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index 8edbe14150..c80db1fd94 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -43,6 +43,7 @@ #include "qwizard_win_p.h" #include +#include #include #include #include "qwizard.h" @@ -259,11 +260,8 @@ static bool getCaptionQFont(int dpi, QFont *result) return false; // Call into QWindowsNativeInterface to convert the LOGFONT into a QFont. const LOGFONT logFont = getCaptionLogFont(hTheme); - QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface(); - return ni && QMetaObject::invokeMethod(ni, "logFontToQFont", Qt::DirectConnection, - Q_RETURN_ARG(QFont, *result), - Q_ARG(const void*, &logFont), - Q_ARG(int, dpi)); + *result = QWindowsFontDatabaseBase::LOGFONT_to_QFont(logFont, dpi); + return true; } void QVistaHelper::drawTitleBar(QPainter *painter)