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>
This commit is contained in:
Friedemann Kleint 2012-02-17 16:08:17 +01:00 committed by Qt by Nokia
parent 3ca194eb12
commit 400c865f29
3 changed files with 40 additions and 12 deletions

View File

@ -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();
}
}

View File

@ -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.

View File

@ -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