From a57f2128b15d363b88c063325eac1d36c2ff1578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 31 Jan 2017 13:29:14 +0100 Subject: Add QPlatformWindow::isForeignWindow() Simplifies code at call sites and allows for refactoring how to decide if a window is foreign or not at a later point. Change-Id: Icc51a83bac187f4975535366b53b4990832b6c82 Reviewed-by: Lars Knoll --- src/plugins/platforms/android/qandroidplatformwindow.h | 2 +- src/plugins/platforms/cocoa/qcocoahelpers.mm | 3 ++- src/plugins/platforms/cocoa/qcocoawindow.mm | 12 ++++++------ src/plugins/platforms/cocoa/qnswindowdelegate.mm | 2 +- src/plugins/platforms/windows/qwindowsmousehandler.cpp | 2 +- src/plugins/platforms/windows/qwindowswindow.cpp | 2 +- src/plugins/platforms/windows/qwindowswindow.h | 17 ++++++++--------- src/plugins/platforms/xcb/qxcbwindow.cpp | 4 ++-- 8 files changed, 22 insertions(+), 22 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidplatformwindow.h b/src/plugins/platforms/android/qandroidplatformwindow.h index 87e5cbaa4f..91cb1e76e6 100644 --- a/src/plugins/platforms/android/qandroidplatformwindow.h +++ b/src/plugins/platforms/android/qandroidplatformwindow.h @@ -71,7 +71,7 @@ public: void requestActivateWindow() override; void updateStatusBarVisibility(); inline bool isRaster() const { - if ((window()->flags() & Qt::ForeignWindow) == Qt::ForeignWindow) + if (isForeignWindow()) return false; return window()->surfaceType() == QSurface::RasterSurface diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 3e637b5db3..232e40769b 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -151,7 +151,8 @@ Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions) a no-op. For extra verbosity and clearer code, please consider checking - that window()->type() != Qt::ForeignWindow before using this cast. + that the platform window is not a foreign window before using + this cast, via QPlatformWindow::isForeignWindow(). Do not use this method soley to check for foreign windows, as that will make the code harder to read for people not working diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index fe24f95db4..114efc3e92 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -485,7 +485,7 @@ QCocoaWindow::~QCocoaWindow() // Make sure to disconnect observer in all case if view is valid // to avoid notifications received when deleting when using Qt::AA_NativeWindows attribute - if (window()->type() != Qt::ForeignWindow) + if (!isForeignWindow()) [[NSNotificationCenter defaultCenter] removeObserver:m_view]; // While it is unlikely that this window will be in the popup stack @@ -557,7 +557,7 @@ void QCocoaWindow::setCocoaGeometry(const QRect &rect) QMacAutoReleasePool pool; if (m_viewIsEmbedded) { - if (window()->type() != Qt::ForeignWindow) { + if (!isForeignWindow()) { [m_view setFrame:NSMakeRect(0, 0, rect.width(), rect.height())]; } else { QPlatformWindow::setGeometry(rect); @@ -581,7 +581,7 @@ void QCocoaWindow::setCocoaGeometry(const QRect &rect) [m_view setFrame:NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height())]; } - if (window()->type() == Qt::ForeignWindow) + if (isForeignWindow()) QPlatformWindow::setGeometry(rect); // will call QPlatformWindow::setGeometry(rect) during resize confirmation (see qnsview.mm) @@ -1288,7 +1288,7 @@ void QCocoaWindow::windowDidEndLiveResize() void QCocoaWindow::windowDidBecomeKey() { - if (window()->type() == Qt::ForeignWindow) + if (isForeignWindow()) return; if (m_windowUnderMouse) { @@ -1304,7 +1304,7 @@ void QCocoaWindow::windowDidBecomeKey() void QCocoaWindow::windowDidResignKey() { - if (window()->type() == Qt::ForeignWindow) + if (isForeignWindow()) return; // Key window will be non-nil if another window became key, so do not @@ -1885,7 +1885,7 @@ void QCocoaWindow::setWindowCursor(NSCursor *cursor) return; // Setting a cursor in a foregin view is not supported. - if (window()->type() == Qt::ForeignWindow) + if (isForeignWindow()) return; [m_windowCursor release]; diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm index 3781a4cc65..2d5afa9375 100644 --- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm +++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm @@ -66,7 +66,7 @@ - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame { Q_UNUSED(newFrame); - if (m_cocoaWindow && m_cocoaWindow->window()->type() != Qt::ForeignWindow) + if (m_cocoaWindow && !m_cocoaWindow->isForeignWindow()) [qnsview_cast(m_cocoaWindow->view()) notifyWindowWillZoom:![window isZoomed]]; return YES; } diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index 81abf24131..34c34fd28e 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -414,7 +414,7 @@ static bool isValidWheelReceiver(QWindow *candidate) { if (candidate) { const QWindow *toplevel = QWindowsWindow::topLevelOf(candidate); - if (toplevel->type() == Qt::ForeignWindow) + if (toplevel->handle() && toplevel->handle()->isForeignWindow()) return true; if (const QWindowsWindow *ww = QWindowsWindow::windowsWindowOf(toplevel)) return !ww->testFlag(QWindowsWindow::BlockedByModal); diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 04db975360..68d69f3765 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1122,7 +1122,7 @@ void QWindowsWindow::updateDropSite(bool topLevel) // if the parent window is a foreign window wrapped via QWindow::fromWinId, we need to enable the drop site // on the first child window const QWindow *parent = window()->parent(); - if (parent && (parent->type() == Qt::ForeignWindow)) + if (parent && parent->handle() && parent->handle()->isForeignWindow()) parentIsEmbedded = true; } diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 22ba49b0a5..8179280bb3 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -385,15 +385,14 @@ QPoint QWindowsGeometryHint::mapFromGlobal(const QWindow *w, const QPoint &p) inline QWindowsWindow *QWindowsWindow::windowsWindowOf(const QWindow *w) { - QWindowsWindow *result = Q_NULLPTR; - if (w) { - const Qt::WindowType type = w->type(); - if (type != Qt::Desktop && type != Qt::ForeignWindow) { - if (QPlatformWindow *pw = w->handle()) - result = static_cast(pw); - } - } - return result; + if (!w || !w->handle()) + return nullptr; + + const Qt::WindowType type = w->type(); + if (type == Qt::Desktop || w->handle()->isForeignWindow()) + return nullptr; + + return static_cast(w->handle()); } void *QWindowsWindow::userDataOf(HWND hwnd) diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 756806108e..fd23179075 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -397,7 +397,7 @@ void QXcbWindow::create() xcb_window_t xcb_parent_id = platformScreen->root(); if (parent()) { xcb_parent_id = static_cast(parent())->xcb_window(); - m_embedded = parent()->window()->type() == Qt::ForeignWindow; + m_embedded = parent()->isForeignWindow(); QSurfaceFormat parentFormat = parent()->window()->requestedFormat(); if (window()->surfaceType() != QSurface::OpenGLSurface && parentFormat.hasAlpha()) { @@ -1508,7 +1508,7 @@ void QXcbWindow::setParent(const QPlatformWindow *parent) if (parent) { const QXcbWindow *qXcbParent = static_cast(parent); xcb_parent_id = qXcbParent->xcb_window(); - m_embedded = qXcbParent->window()->type() == Qt::ForeignWindow; + m_embedded = qXcbParent->isForeignWindow(); } else { xcb_parent_id = xcbScreen()->root(); m_embedded = false; -- cgit v1.2.3