From e84b8a34758a1f23a7f2b61820b72b3edb6c4472 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 3 Nov 2011 13:08:51 +0100 Subject: Fixed returned geometry of toplevel child widgets If a widget has got a parent widget but also is a toplevel widget it should not return its geometry relative to its parent. In addition to that, child widgets which are not toplevel should not change their left and top values according to their parent but also keep their width and height intact. Change-Id: I5e641abf5ddc0b8d056ba023f8de52af1d2ccc9f Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowswindow.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 21d02ab664..f61e15dded 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -158,16 +158,20 @@ QDebug operator<<(QDebug d, const NCCALCSIZE_PARAMS &p) // Return the frame geometry relative to the parent // if there is one. -// Note: This has been observed to return invalid sizes for child windows. -static inline QRect frameGeometry(HWND hwnd) +static inline QRect frameGeometry(HWND hwnd, bool topLevel) { RECT rect = { 0, 0, 0, 0 }; GetWindowRect(hwnd, &rect); // Screen coordinates. - if (const HWND parent = GetParent(hwnd)) { + const HWND parent = GetParent(hwnd); + if (parent && !topLevel) { + const int width = rect.right - rect.left; + const int height = rect.bottom - rect.top; POINT leftTop = { rect.left, rect.top }; ScreenToClient(parent, &leftTop); rect.left = leftTop.x; rect.top = leftTop.y; + rect.right = leftTop.x + width; + rect.bottom = leftTop.y + height; } return qrectFromRECT(rect); } @@ -363,7 +367,7 @@ QWindowsWindow::WindowData if (desktop) { // desktop widget. No frame, hopefully? result.hwnd = GetDesktopWindow(); - result.geometry = frameGeometry(result.hwnd); + result.geometry = frameGeometry(result.hwnd, true); if (QWindowsContext::verboseWindows) qDebug().nospace() << "Created desktop window " << w << result.hwnd; return result; @@ -903,13 +907,7 @@ void QWindowsWindow::setGeometry_sys(const QRect &rect) const QRect QWindowsWindow::geometry_sys() const { // Warning: Returns bogus values when minimized. - // Note: Using frameGeometry (based on GetWindowRect) - // has been observed to return a size based on a standard top level - // frame for WS_CHILD windows (whose frame is zero), thus, use the real - // client size instead. - QRect result = frameGeometry(m_data.hwnd) - frameMargins(); - if (result.isValid() && !window()->isTopLevel()) - result.setSize(clientSize(m_data.hwnd)); + QRect result = frameGeometry(m_data.hwnd, window()->isTopLevel()) - frameMargins(); return result; } -- cgit v1.2.3