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 <Friedemann.Kleint@nokia.com>
This commit is contained in:
parent
faa6113c41
commit
e84b8a3475
@ -158,16 +158,20 @@ QDebug operator<<(QDebug d, const NCCALCSIZE_PARAMS &p)
|
|||||||
|
|
||||||
// Return the frame geometry relative to the parent
|
// Return the frame geometry relative to the parent
|
||||||
// if there is one.
|
// if there is one.
|
||||||
// Note: This has been observed to return invalid sizes for child windows.
|
static inline QRect frameGeometry(HWND hwnd, bool topLevel)
|
||||||
static inline QRect frameGeometry(HWND hwnd)
|
|
||||||
{
|
{
|
||||||
RECT rect = { 0, 0, 0, 0 };
|
RECT rect = { 0, 0, 0, 0 };
|
||||||
GetWindowRect(hwnd, &rect); // Screen coordinates.
|
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 };
|
POINT leftTop = { rect.left, rect.top };
|
||||||
ScreenToClient(parent, &leftTop);
|
ScreenToClient(parent, &leftTop);
|
||||||
rect.left = leftTop.x;
|
rect.left = leftTop.x;
|
||||||
rect.top = leftTop.y;
|
rect.top = leftTop.y;
|
||||||
|
rect.right = leftTop.x + width;
|
||||||
|
rect.bottom = leftTop.y + height;
|
||||||
}
|
}
|
||||||
return qrectFromRECT(rect);
|
return qrectFromRECT(rect);
|
||||||
}
|
}
|
||||||
@ -363,7 +367,7 @@ QWindowsWindow::WindowData
|
|||||||
|
|
||||||
if (desktop) { // desktop widget. No frame, hopefully?
|
if (desktop) { // desktop widget. No frame, hopefully?
|
||||||
result.hwnd = GetDesktopWindow();
|
result.hwnd = GetDesktopWindow();
|
||||||
result.geometry = frameGeometry(result.hwnd);
|
result.geometry = frameGeometry(result.hwnd, true);
|
||||||
if (QWindowsContext::verboseWindows)
|
if (QWindowsContext::verboseWindows)
|
||||||
qDebug().nospace() << "Created desktop window " << w << result.hwnd;
|
qDebug().nospace() << "Created desktop window " << w << result.hwnd;
|
||||||
return result;
|
return result;
|
||||||
@ -903,13 +907,7 @@ void QWindowsWindow::setGeometry_sys(const QRect &rect) const
|
|||||||
QRect QWindowsWindow::geometry_sys() const
|
QRect QWindowsWindow::geometry_sys() const
|
||||||
{
|
{
|
||||||
// Warning: Returns bogus values when minimized.
|
// Warning: Returns bogus values when minimized.
|
||||||
// Note: Using frameGeometry (based on GetWindowRect)
|
QRect result = frameGeometry(m_data.hwnd, window()->isTopLevel()) - frameMargins();
|
||||||
// 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));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user