From e1402c0d278b4570444e3e20b93fd5ab5619c8fc Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Thu, 3 May 2012 22:15:38 +0200 Subject: [PATCH] Add a method for querying window activation status from QPA. Add QPlatformWindow::isActive(), where the platform can do further isActive tests, and Windows implementation for it. Change-Id: I1acfc44d3a4ab36a3aaee52fb7b5f5b40661095e Reviewed-by: Miikka Heikkinen Reviewed-by: Friedemann Kleint Reviewed-by: Girish Ramakrishnan --- src/gui/kernel/qplatformwindow.h | 1 + src/gui/kernel/qplatformwindow_qpa.cpp | 11 +++++++++++ src/plugins/platforms/windows/qwindowswindow.cpp | 9 +++++++++ src/plugins/platforms/windows/qwindowswindow.h | 1 + 4 files changed, 22 insertions(+) diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index d9f79f25eb..cded1fe316 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -102,6 +102,7 @@ public: virtual void lower(); virtual bool isExposed() const; + virtual bool isActive() const; virtual void propagateSizeHints(); diff --git a/src/gui/kernel/qplatformwindow_qpa.cpp b/src/gui/kernel/qplatformwindow_qpa.cpp index 88f2a6481e..d2ec6833b0 100644 --- a/src/gui/kernel/qplatformwindow_qpa.cpp +++ b/src/gui/kernel/qplatformwindow_qpa.cpp @@ -168,6 +168,17 @@ bool QPlatformWindow::isExposed() const return window()->isVisible(); } +/*! + Returns true if the window should appear active from a style perspective. + + This function can make platform-specific isActive checks, such as checking + if the QWindow is embedded in an active native window. +*/ +bool QPlatformWindow::isActive() const +{ + return false; +} + /*! Requests setting the window state of this surface to \a type. Returns the actual state set. diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index aabea04c20..a7140a3d6d 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -807,6 +807,15 @@ bool QWindowsWindow::isVisible() const return m_data.hwnd && IsWindowVisible(m_data.hwnd); } +bool QWindowsWindow::isActive() const +{ + // Check for native windows or children of the active native window. + if (const HWND activeHwnd = GetActiveWindow()) + if (m_data.hwnd == activeHwnd || IsChild(activeHwnd, m_data.hwnd)) + return true; + return false; +} + // partially from QWidgetPrivate::show_sys() void QWindowsWindow::show_sys() const { diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 743e10dff9..182bef78e4 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -150,6 +150,7 @@ public: virtual void setVisible(bool visible); bool isVisible() const; + virtual bool isActive() const; virtual Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags); virtual Qt::WindowState setWindowState(Qt::WindowState state);