Windows QPA: Move some internal functions to the new interface

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ø <tor.arne.vestbo@qt.io>
This commit is contained in:
Friedemann Kleint 2020-07-27 15:47:59 +02:00
parent 2405aa9d67
commit 964f5757ea
7 changed files with 72 additions and 90 deletions

View File

@ -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

View File

@ -42,7 +42,9 @@
#include "qwindowscontext.h"
#include "qwindowsmime.h"
#include "qwin10helpers.h"
#include "qwindowsopengltester.h"
#include <QtCore/QVariant>
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<WNDPROC>(eventProc) : DefWindowProc;
return ctx->createDummyWindow(classNameTemplate,
reinterpret_cast<const wchar_t*>(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

View File

@ -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;

View File

@ -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 <QtGui/qopenglcontext.h>
#include <QtGui/qscreen.h>
#include <qpa/qplatformscreen.h>
#include <QtGui/private/qwindowsfontdatabase_p.h>
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<const LOGFONT *>(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

View File

@ -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

View File

@ -42,7 +42,6 @@
#include <private/qobject_p.h>
#include <private/qpaintengine_raster_p.h>
#include <private/qapplication_p.h>
#include <qpa/qplatformnativeinterface.h>
#include <private/qstylehelper_p.h>
#include <private/qwidget_p.h>
#include <qpainter.h>
@ -52,7 +51,7 @@
#include <qapplication.h>
#include <qpixmapcache.h>
#include <private/qapplication_p.h>
#include <qpa/qplatformnativeinterface.h>
#include <qpa/qplatformintegration.h>
#if QT_CONFIG(toolbutton)
#include <qtoolbutton.h>
@ -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<void *>(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>(hwnd);
}
}
return nullptr;
using QWindowsApplication = QPlatformInterface::Private::QWindowsApplication;
HWND result = nullptr;
if (auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration()))
result = nativeWindowsApp->createMessageWindow(QStringLiteral("QTreeViewThemeHelperWindowClass"),
QStringLiteral("QTreeViewThemeHelperWindow"));
return result;
}
bool QWindowsXPStylePrivate::initVistaTreeViewTheming()

View File

@ -43,6 +43,7 @@
#include "qwizard_win_p.h"
#include <private/qapplication_p.h>
#include <private/qwindowsfontdatabasebase_p.h>
#include <qpa/qplatformwindow.h>
#include <qpa/qplatformwindow_p.h>
#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)