diff options
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]"; |