From 14efcaa3921687129d4dca9b7d5794668a329cd6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 8 Jan 2016 14:59:22 +0100 Subject: Windows QPA: Improve handling of windows of type Qt::ForeignWindow. Extract a base class QWindowsBaseWindow from QWindowsWindow that provides _sys() getters for geometry and margin calculation and implements QPlatformWindow::geometry()/ frameMargins() to be calculated from the HWND. Implement a QWindowsDesktopWindow class directly inheriting QWindowsBaseWindow which does not allow any manipulation. Add a thin QWindowsForeignWindow class that wraps a foreign window id and always returns correct geometry/margin information when queried. Simple reparenting and manipulation of geometry for child windows is also implemented, allowing for embedding foreign windows into Qt. When calling other setters on it, the unimplemented warnings of QPlatformWindow will trigger. Remove the special casing for foreign/desktop window from QWindowsWindow. The existing mechanism to cache the geometry/margin values in QWindowsWindow remains as is. Rename the existing QWindowsWindow::baseWindowOf() and add checks there. Task-number: QTBUG-50206 Task-number: QTBUG-41186 Change-Id: Ib57cb87e3981312d32920fe3e49f0b1c4ad516a3 Reviewed-by: Joerg Bornemann --- .../platforms/windows/qwindowsintegration.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/plugins/platforms/windows/qwindowsintegration.cpp') diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index d975460ec7..2904999d96 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -302,6 +302,26 @@ bool QWindowsIntegration::hasCapability(QPlatformIntegration::Capability cap) co QPlatformWindow *QWindowsIntegration::createPlatformWindow(QWindow *window) const { + if (window->type() == Qt::Desktop) { + QWindowsDesktopWindow *result = new QWindowsDesktopWindow(window); + qCDebug(lcQpaWindows) << "Desktop window:" << window + << showbase << hex << result->winId() << noshowbase << dec << result->geometry(); + return result; + } + + if (window->type() == Qt::ForeignWindow) { + QWindowsForeignWindow *result = new QWindowsForeignWindow(window, reinterpret_cast(window->winId())); + const QRect obtainedGeometry = result->geometry(); + QScreen *screen = Q_NULLPTR; + if (const QPlatformScreen *pScreen = result->screenForGeometry(obtainedGeometry)) + screen = pScreen->screen(); + if (screen && screen != window->screen()) + window->setScreen(screen); + qCDebug(lcQpaWindows) << "Foreign window:" << window << showbase << hex + << result->winId() << noshowbase << dec << obtainedGeometry << screen; + return result; + } + QWindowsWindowData requested; requested.flags = window->flags(); requested.geometry = QHighDpi::toNativePixels(window->geometry(), window); -- cgit v1.2.3