diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-11-08 10:48:43 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-11-08 11:34:11 +0100 |
commit | 1dd83dd202eccf0d68b6dd0b2c2155a7cc3018d2 (patch) | |
tree | 4fe460da27f7dc5f809abd86ffab9182d95d1242 /tests/manual/diaglib | |
parent | a866055d18b2c2efc0f3cf5307d8eac78cce26eb (diff) |
Diaglib/Windows: Output more information on geometry for native handles
Obtain the client area and output frame and position relative to the
parent window.
Task-number: QTBUG-79861
Change-Id: I193dfbcdec7e27d32a70ada08ba271260eedc969
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'tests/manual/diaglib')
-rw-r--r-- | tests/manual/diaglib/nativewindowdump_win.cpp | 71 |
1 files changed, 67 insertions, 4 deletions
diff --git a/tests/manual/diaglib/nativewindowdump_win.cpp b/tests/manual/diaglib/nativewindowdump_win.cpp index aae8746413..d91e673d1c 100644 --- a/tests/manual/diaglib/nativewindowdump_win.cpp +++ b/tests/manual/diaglib/nativewindowdump_win.cpp @@ -32,6 +32,7 @@ #include <QtCore/QTextStream> #include <QtCore/QSharedPointer> #include <QtCore/QDebug> +#include <QtCore/QRect> #include <QtCore/QVector> #include <QtCore/qt_windows.h> @@ -54,14 +55,76 @@ struct DumpContext { if (style & styleConstant) \ str << ' ' << #styleConstant; +static QTextStream &operator<<(QTextStream &str, const QPoint &p) +{ + str << p.x() << ", " << p.y(); + return str; +} + +static QTextStream &operator<<(QTextStream &str, const QSize &s) +{ + str << s.width() << 'x' << s.height(); + return str; +} + +static QTextStream &operator<<(QTextStream &str, const QRect &rect) +{ + str << rect.size() << forcesign << rect.x() << rect.y() << noforcesign; + return str; +} + +static inline QSize qsizeFromRECT(const RECT &rect) +{ + return QSize(rect.right -rect.left, rect.bottom - rect.top); +} + +static inline QRect qrectFromRECT(const RECT &rect) +{ + return QRect(QPoint(rect.left, rect.top), qsizeFromRECT(rect)); +} + +static QRect getFrameGeometry(HWND hwnd) +{ + RECT rect; + return GetWindowRect(hwnd, &rect) ? qrectFromRECT(rect) : QRect(); +} + +static QPoint getClientAreaScreenPos(HWND hwnd) +{ + POINT clientPos{0, 0}; + return ClientToScreen(hwnd, &clientPos) ? QPoint(clientPos.x, clientPos.y) : QPoint(); +} + +static QRect getClientAreaGeometry(HWND hwnd) +{ + RECT clientRect; + return GetClientRect(hwnd, &clientRect) + ? QRect(getClientAreaScreenPos(hwnd), qsizeFromRECT(clientRect)) : QRect(); +} + +static bool isTopLevel(HWND hwnd) +{ + auto parent = GetParent(hwnd); + return !parent || parent == GetDesktopWindow(); +} + static void formatNativeWindow(HWND hwnd, QTextStream &str) { str << hex << showbase << quintptr(hwnd) << noshowbase << dec; - RECT rect; - if (GetWindowRect(hwnd, &rect)) { - str << ' ' << (rect.right - rect.left) << 'x' << (rect.bottom - rect.top) - << forcesign << rect.left << rect.top << noforcesign; + + const bool topLevel = isTopLevel(hwnd); + if (topLevel) + str << " [top]"; + const auto frameGeometry = getFrameGeometry(hwnd); + const auto clientGeometry = getClientAreaGeometry(hwnd); + str << ' ' << frameGeometry; + if (!topLevel) + str << " local: " << (clientGeometry.topLeft() - getClientAreaScreenPos(GetParent(hwnd))); + if (clientGeometry != frameGeometry) { + str << " client: " << clientGeometry << " frame: " + << (clientGeometry.topLeft() - frameGeometry.topLeft()); } + if (IsWindowVisible(hwnd)) str << " [visible]"; |