From 400c865f2994e67189108e36cfa206c365d57274 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 17 Feb 2012 16:08:17 +0100 Subject: Windows: Fix QWindow-test. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Save & Restore style and geometry when switching to full screen and back since it is not a real state on Windows. - Obey the positioning policy in setGeometry. Task-number: QTBUG-24185 Change-Id: I18dea4fd372e0b2e46273a7a27e0c6f4f4bde771 Reviewed-by: Samuel Rødal --- src/plugins/platforms/windows/qwindowswindow.cpp | 47 ++++++++++++++++++------ src/plugins/platforms/windows/qwindowswindow.h | 3 ++ tests/auto/gui/kernel/qwindow/qwindow.pro | 2 +- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 28ef2c3b6c..58db9b32c4 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -618,7 +619,8 @@ QWindowsWindow::QWindowsWindow(QWindow *aWindow, const WindowData &data) : m_opacity(1.0), m_mouseGrab(false), m_cursor(QWindowsScreen::screenOf(aWindow)->cursor().standardWindowCursor()), - m_dropTarget(0) + m_dropTarget(0), + m_savedStyle(0) { if (aWindow->surfaceType() == QWindow::OpenGLSurface) setFlag(OpenGLSurface); @@ -809,8 +811,15 @@ void QWindowsWindow::handleHidden() QWindowSystemInterface::handleUnmapEvent(window()); } -void QWindowsWindow::setGeometry(const QRect &rect) +void QWindowsWindow::setGeometry(const QRect &rectIn) { + QRect rect = rectIn; + // This means it is a call from QWindow::setFramePos() and + // the coordinates include the frame (size is still the contents rectangle). + if (qt_window_private(window())->positionPolicy == QWindowPrivate::WindowFrameInclusive) { + const QMargins margins = frameMargins(); + rect.moveTopLeft(rect.topLeft() + QPoint(margins.left(), margins.top())); + } const QSize oldSize = m_data.geometry.size(); m_data.geometry = rect; const QSize newSize = rect.size(); @@ -904,11 +913,15 @@ void QWindowsWindow::setGeometry_sys(const QRect &rect) const << " \n resulting " << rc << geometry_sys(); } -QRect QWindowsWindow::geometry_sys() const +QRect QWindowsWindow::frameGeometry_sys() const { // Warning: Returns bogus values when minimized. - QRect result = frameGeometry(m_data.hwnd, window()->isTopLevel()) - frameMargins(); - return result; + return frameGeometry(m_data.hwnd, window()->isTopLevel()); +} + +QRect QWindowsWindow::geometry_sys() const +{ + return frameGeometry_sys() - frameMargins(); } /*! @@ -1098,7 +1111,12 @@ void QWindowsWindow::setWindowState_sys(Qt::WindowState newState) #else UINT newStyle = WS_POPUP; #endif - if (style() & WS_SYSMENU) + // Save geometry and style to be restored when fullscreen + // is turned off again, since on Windows, it is not a real + // Window state but emulated by changing geometry and style. + m_savedStyle = style(); + m_savedFrameGeometry = frameGeometry_sys(); + if (m_savedStyle & WS_SYSMENU) newStyle |= WS_SYSMENU; if (visible) newStyle |= WS_VISIBLE; @@ -1108,19 +1126,26 @@ void QWindowsWindow::setWindowState_sys(Qt::WindowState newState) UINT swpf = SWP_FRAMECHANGED; if (newStates & Qt::WindowActive) swpf |= SWP_NOACTIVATE; - SetWindowPos(m_data.hwnd, HWND_TOP, r.left(), r.top(), r.width(), r.height(), swpf); } else { + // Restore saved state. + unsigned newStyle = m_savedStyle ? m_savedStyle : style(); if (visible) - setStyle(style() | WS_VISIBLE); - UINT swpf = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE; + newStyle |= WS_VISIBLE; + setStyle(newStyle); + + UINT swpf = SWP_FRAMECHANGED | SWP_NOZORDER; if (newStates & Qt::WindowActive) swpf |= SWP_NOACTIVATE; - SetWindowPos(m_data.hwnd, 0, 0, 0, 0, 0, swpf); - + if (!m_savedFrameGeometry.isValid()) + swpf |= SWP_NOSIZE | SWP_NOMOVE; + SetWindowPos(m_data.hwnd, 0, m_savedFrameGeometry.x(), m_savedFrameGeometry.y(), + m_savedFrameGeometry.width(), m_savedFrameGeometry.height(), swpf); // preserve maximized state if (visible) ShowWindow(m_data.hwnd, (newStates & Qt::WindowMaximized) ? max : normal); + m_savedStyle = 0; + m_savedFrameGeometry = QRect(); } } diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 1d5f3c29d6..e3336d1c3a 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -193,6 +193,7 @@ private: inline void show_sys() const; inline void hide_sys() const; inline void setGeometry_sys(const QRect &rect) const; + inline QRect frameGeometry_sys() const; inline QRect geometry_sys() const; inline WindowData setWindowFlags_sys(Qt::WindowFlags wt, unsigned flags = 0) const; inline void setWindowState_sys(Qt::WindowState newState); @@ -213,6 +214,8 @@ private: bool m_mouseGrab; QWindowsWindowCursor m_cursor; QWindowsOleDropTarget *m_dropTarget; + unsigned m_savedStyle; + QRect m_savedFrameGeometry; }; // Conveniences for window frames. diff --git a/tests/auto/gui/kernel/qwindow/qwindow.pro b/tests/auto/gui/kernel/qwindow/qwindow.pro index d191b9fb8e..363f7dd92e 100644 --- a/tests/auto/gui/kernel/qwindow/qwindow.pro +++ b/tests/auto/gui/kernel/qwindow/qwindow.pro @@ -6,4 +6,4 @@ QT += core-private gui-private testlib SOURCES += tst_qwindow.cpp mac: CONFIG += insignificant_test # QTBUG-23059 -win32:CONFIG += insignificant_test # QTBUG-24185 + -- cgit v1.2.3