summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-02-17 16:08:17 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-17 20:09:58 +0100
commit400c865f2994e67189108e36cfa206c365d57274 (patch)
tree569d3bcb82ba4b7378aedf3a19a276c916c497b2
parent3ca194eb129c227b81bf1f04bfb879c404dc9f89 (diff)
Windows: Fix QWindow-test.
- 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 <samuel.rodal@nokia.com>
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp47
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.h3
-rw-r--r--tests/auto/gui/kernel/qwindow/qwindow.pro2
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 <QtGui/QGuiApplication>
#include <QtGui/QScreen>
#include <QtGui/QWindow>
+#include <private/qwindow_p.h>
#include <QtGui/QWindowSystemInterface>
#include <QtCore/QDebug>
@@ -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
+