Windows: Take custom margins into account for size constraints.

Fix a warning unearthed by the task's code example. The minimum
size of the window would be too big since it did not take the
negative custom top margin into account.

Task-number: QTBUG-29904

Change-Id: I8b71a39f0724bdd1b9359676ce1d86ef5384d685
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
This commit is contained in:
Friedemann Kleint 2013-03-04 09:52:37 +01:00 committed by The Qt Project
parent f2dc9f1dc2
commit f4933eba54
2 changed files with 10 additions and 8 deletions

View File

@ -575,9 +575,10 @@ void WindowCreationData::initialize(HWND hwnd, bool frameChange, qreal opacityLe
#define QWINDOWSIZE_MAX ((1<<24)-1)
QWindowsGeometryHint::QWindowsGeometryHint(const QWindow *w) :
QWindowsGeometryHint::QWindowsGeometryHint(const QWindow *w, const QMargins &cm) :
minimumSize(w->minimumSize()),
maximumSize(w->maximumSize())
maximumSize(w->maximumSize()),
customMargins(cm)
{
}
@ -650,8 +651,8 @@ void QWindowsGeometryHint::applyToMinMaxInfo(DWORD style, DWORD exStyle, MINMAXI
<< " in " << *mmi;
const QMargins margins = QWindowsGeometryHint::frame(style, exStyle);
const int frameWidth = margins.left() + margins.right();
const int frameHeight = margins.top() + margins.bottom();
const int frameWidth = margins.left() + margins.right() + customMargins.left() + customMargins.right();
const int frameHeight = margins.top() + margins.bottom() + customMargins.top() + customMargins.bottom();
if (minimumSize.width() > 0)
mmi->ptMinTrackSize.x = minimumSize.width() + frameWidth;
if (minimumSize.height() > 0)
@ -702,7 +703,7 @@ QWindowCreationContext::QWindowCreationContext(const QWindow *w,
const QRect &geometry,
const QMargins &cm,
DWORD style_, DWORD exStyle_) :
geometryHint(w), style(style_), exStyle(exStyle_),
geometryHint(w, cm), style(style_), exStyle(exStyle_),
requestedGeometry(geometry), obtainedGeometry(geometry),
margins(QWindowsGeometryHint::frame(style, exStyle)), customMargins(cm),
frameX(CW_USEDEFAULT), frameY(CW_USEDEFAULT),
@ -1095,7 +1096,7 @@ void QWindowsWindow::setGeometry(const QRect &rectIn)
const QSize newSize = rect.size();
// Check on hint.
if (newSize != oldSize) {
const QWindowsGeometryHint hint(window());
const QWindowsGeometryHint hint(window(), m_data.customMargins);
if (!hint.validSize(newSize)) {
qWarning("%s: Attempt to set a size (%dx%d) violating the constraints"
"(%dx%d - %dx%d) on window '%s'.", __FUNCTION__,
@ -1683,7 +1684,7 @@ void QWindowsWindow::setFrameStrutEventsEnabled(bool enabled)
#ifndef Q_OS_WINCE // maybe available on some SDKs revisit WM_GETMINMAXINFO
void QWindowsWindow::getSizeHints(MINMAXINFO *mmi) const
{
const QWindowsGeometryHint hint(window());
const QWindowsGeometryHint hint(window(), m_data.customMargins);
hint.applyToMinMaxInfo(m_data.hwnd, mmi);
if (QWindowsContext::verboseWindows)
qDebug() << __FUNCTION__ << window() << *mmi;

View File

@ -67,7 +67,7 @@ class QWindowsEGLStaticContext;
struct QWindowsGeometryHint
{
QWindowsGeometryHint() {}
explicit QWindowsGeometryHint(const QWindow *w);
explicit QWindowsGeometryHint(const QWindow *w, const QMargins &customMargins);
static QMargins frame(DWORD style, DWORD exStyle);
static bool handleCalculateSize(const QMargins &customMargins, const MSG &msg, LRESULT *result);
#ifndef Q_OS_WINCE //MinMax maybe define struct if not available
@ -85,6 +85,7 @@ struct QWindowsGeometryHint
QSize minimumSize;
QSize maximumSize;
QMargins customMargins;
};
struct QWindowCreationContext