diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2013-06-29 16:46:04 +0400 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2013-06-29 18:56:42 +0400 |
commit | 3cc2419939723cf1caa2e16c42ac4e5553bbb934 (patch) | |
tree | 393eebc28391763a9481cbf80225c1fc6ab73027 /plugins | |
parent | be75138d8bd294b297f1a1eab09fa77d6c91cec8 (diff) |
mumble, plugins: fix QWidget-for-HWND lookup for the 'manual' plugin.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/manual/manual.cpp | 43 | ||||
-rw-r--r-- | plugins/manual/manual.pro | 5 |
2 files changed, 34 insertions, 14 deletions
diff --git a/plugins/manual/manual.cpp b/plugins/manual/manual.cpp index 0d807fbd5..edab2c567 100644 --- a/plugins/manual/manual.cpp +++ b/plugins/manual/manual.cpp @@ -33,9 +33,12 @@ #include <QtCore/QtCore> #include <QtGui/QtGui> #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include <QtWidgets/QMessageBox> +# if defined(Q_OS_WIN) +# include <qpa/qplatformnativeinterface.h> +# endif +# include <QtWidgets/QMessageBox> #else -#include <QMessageBox> +# include <QMessageBox> #endif #include <QPointer> @@ -75,6 +78,26 @@ static struct { std::string(), std::wstring() }; +#ifdef Q_OS_WIN +static QWidget *QWidgetForHWND(HWND hwnd) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + QList<QWidget *> windows = qApp->topLevelWidgets(); + foreach (QWidget *w, windows) { + QWindow *window = w->windowHandle(); + if (window == NULL || window->handle() == 0) { + continue; + } + HWND whwnd = static_cast<HWND>(qApp->platformNativeInterface()->nativeResourceForWindow("handle", window)); + if (whwnd == hwnd) { + return w; + } + } + return NULL; +#else + return QWidget::find(hwnd); +#endif +} +#endif Manual::Manual(QWidget *p) : QDialog(p) { setupUi(this); @@ -247,19 +270,15 @@ static void unlock() { static void config(HWND h) { if (mDlg) { -#if defined(Q_OS_WIN) && QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - mDlg->setParent(QWidget::find(reinterpret_cast<WId>(h)), Qt::Dialog); -#elif defined(Q_OS_WIN) && QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - mDlg->setParent(QWidget::find(h), Qt::Dialog); +#if defined(Q_OS_WIN) + mDlg->setParent(QWidgetForHWND(h), Qt::Dialog); #else mDlg->setParent(reinterpret_cast<QWidget *>(h), Qt::Dialog); #endif mDlg->qpbUnhinge->setEnabled(true); } else { -#if defined(Q_OS_WIN) && QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - mDlg = new Manual(QWidget::find(reinterpret_cast<WId>(h))); -#elif defined(Q_OS_WIN) && QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - mDlg = new Manual(QWidget::find(h)); +#if defined(Q_OS_WIN) + mDlg = new Manual(QWidgetForHWND(h)); #else mDlg = new Manual(reinterpret_cast<QWidget *>(h)); #endif @@ -302,9 +321,7 @@ static std::wstring shortname(L"Manual placement"); static void about(HWND h) { QMessageBox::about( #if defined(Q_OS_WIN) && QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - QWidget::find(reinterpret_cast<WId>(h)), -#elif defined(Q_OS_WIN) && QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QWidget::find(h), + QWidgetForHWND(h), #else reinterpret_cast<QWidget *>(h), #endif diff --git a/plugins/manual/manual.pro b/plugins/manual/manual.pro index 38f4a916d..ae35671e0 100644 --- a/plugins/manual/manual.pro +++ b/plugins/manual/manual.pro @@ -3,7 +3,10 @@ include(../plugins.pri) TARGET = manual CONFIG += qt isEqual(QT_MAJOR_VERSION, 5) { - QT *= widgets + QT *= widgets + # On Windows, we use QPlatformNativeInterface + # to get access to HWNDs. + QT *= gui-private } HEADERS = manual.h SOURCES = manual.cpp |