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>
This commit is contained in:
Friedemann Kleint 2019-11-08 10:48:43 +01:00
parent a866055d18
commit 1dd83dd202

View File

@ -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]";