summaryrefslogtreecommitdiffstats
path: root/qtwinmigrate
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2013-01-02 15:58:08 +0100
committerAndy Shaw <andy.shaw@digia.com>2013-01-08 07:01:34 +0100
commit1b2773642cc630d4772c2c1213e767e243d53517 (patch)
tree85e01d2dede3364134b97ac353f9c1ae19c2b580 /qtwinmigrate
parent49d3fe90aea461d4cbb1ef1ff755642fdce9f18a (diff)
Make the QtWinMigrate solution work with Qt 5.0
Change-Id: Ia4957fc75e89665c8b187a7932bd6b41e9230ee7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'qtwinmigrate')
-rw-r--r--qtwinmigrate/examples/winhost/main.cpp13
-rw-r--r--qtwinmigrate/examples/winwidget/main.cpp12
-rw-r--r--qtwinmigrate/src/qmfcapp.cpp32
-rw-r--r--qtwinmigrate/src/qmfcapp.h12
-rw-r--r--qtwinmigrate/src/qtwinmigrate.pri1
-rw-r--r--qtwinmigrate/src/qwinhost.cpp32
-rw-r--r--qtwinmigrate/src/qwinhost.h6
-rw-r--r--qtwinmigrate/src/qwinwidget.cpp31
-rw-r--r--qtwinmigrate/src/qwinwidget.h9
9 files changed, 116 insertions, 32 deletions
diff --git a/qtwinmigrate/examples/winhost/main.cpp b/qtwinmigrate/examples/winhost/main.cpp
index f73ebfb..76321f1 100644
--- a/qtwinmigrate/examples/winhost/main.cpp
+++ b/qtwinmigrate/examples/winhost/main.cpp
@@ -38,8 +38,13 @@
**
****************************************************************************/
-#include <QtGui>
-
+#include <QApplication>
+#include <QLineEdit>
+#include <QMainWindow>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStatusBar>
+#include <QVBoxLayout>
#include <qwinhost.h>
#include <windows.h>
@@ -48,7 +53,7 @@ class HostWindow : public QWinHost
{
Q_OBJECT
public:
- HostWindow(QWidget *parent = 0, Qt::WFlags f = 0)
+ HostWindow(QWidget *parent = 0, Qt::WindowFlags f = 0)
: QWinHost(parent, f)
{
setFocusPolicy(Qt::StrongFocus);
@@ -93,7 +98,7 @@ public slots:
protected:
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- QWidget *widget = QWidget::find(GetParent(hWnd));
+ QWidget *widget = QWidget::find((WId)GetParent(hWnd));
HostWindow *window = qobject_cast<HostWindow*>(widget);
if (window) switch (message) {
diff --git a/qtwinmigrate/examples/winwidget/main.cpp b/qtwinmigrate/examples/winwidget/main.cpp
index f04f4a1..502c17d 100644
--- a/qtwinmigrate/examples/winwidget/main.cpp
+++ b/qtwinmigrate/examples/winwidget/main.cpp
@@ -38,7 +38,11 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QPushButton>
#include <qwinwidget.h>
#include <windows.h>
@@ -91,7 +95,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_SETFOCUS:
{
QString str("Got focus");
- QWidget *widget = QWidget::find(HWND(wParam));
+ QWidget *widget = QWidget::find((WId)HWND(wParam));
if (widget)
str += QString(" from %1 (%2)").arg(widget->objectName()).arg(widget->metaObject()->className());
str += "\n";
@@ -102,7 +106,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_KILLFOCUS:
{
QString str("Lost focus");
- QWidget *widget = QWidget::find(HWND(wParam));
+ QWidget *widget = QWidget::find((WId)HWND(wParam));
if (widget)
str += QString(" to %1 (%2)").arg(widget->objectName()).arg(widget->metaObject()->className());
str += "\n";
@@ -153,7 +157,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
QApplication a(argc, 0);
QWinWidget win(hWnd);
- winId = win.winId();
+ winId = (HWND)win.winId();
QHBoxLayout hbox(&win);
hbox.setSpacing(5);
hbox.setMargin(0);
diff --git a/qtwinmigrate/src/qmfcapp.cpp b/qtwinmigrate/src/qmfcapp.cpp
index 5ec52bd..ac6b816 100644
--- a/qtwinmigrate/src/qmfcapp.cpp
+++ b/qtwinmigrate/src/qmfcapp.cpp
@@ -68,6 +68,15 @@ int QMfcApp::mfc_argc = 0;
#if QT_VERSION >= 0x050000
#define QT_WA(unicode, ansi) unicode
+
+QMfcAppEventFilter::QMfcAppEventFilter() : QAbstractNativeEventFilter()
+{
+}
+
+bool QMfcAppEventFilter::nativeEventFilter(const QByteArray &, void *message, long *result)
+{
+ return static_cast<QMfcApp*>(qApp)->winEventFilter((MSG*)message, result);
+}
#endif
/*! \class QMfcApp qmfcapp.h
@@ -200,6 +209,10 @@ bool QMfcApp::pluginInstance(Qt::HANDLE plugin)
return TRUE;
}
+#if QT_VERSION >= 0x050000
+Q_GLOBAL_STATIC(QMfcAppEventFilter, qmfcEventFilter);
+#endif
+
#ifdef QTWINMIGRATE_WITHMFC
/*!
Runs the event loop for both Qt and the MFC application object \a
@@ -349,11 +362,21 @@ QMfcApp::QMfcApp(CWinApp *mfcApp, int &argc, char **argv)
: QApplication(argc, argv), idleCount(0), doIdle(FALSE)
{
mfc_app = mfcApp;
+#if QT_VERSION >= 0x050000
+ QAbstractEventDispatcher::instance()->installNativeEventFilter(qmfcEventFilter());
+#else
QAbstractEventDispatcher::instance()->setEventFilter(qmfc_eventFilter);
+#endif
setQuitOnLastWindowClosed(false);
}
#endif
+QMfcApp::QMfcApp(int &argc, char **argv) : QApplication(argc, argv)
+{
+#if QT_VERSION >= 0x050000
+ QAbstractEventDispatcher::instance()->installNativeEventFilter(qmfcEventFilter());
+#endif
+}
/*!
Destroys the QMfcApp object, freeing all allocated resources.
*/
@@ -388,10 +411,10 @@ bool QMfcApp::winEventFilter(MSG *msg, long *result)
recursion = true;
- QWidget *widget = QWidget::find(msg->hwnd);
+ QWidget *widget = QWidget::find((WId)msg->hwnd);
HWND toplevel = 0;
if (widget) {
- HWND parent = widget->winId();
+ HWND parent = (HWND)widget->winId();
while(parent) {
toplevel = parent;
parent = GetParent(parent);
@@ -432,5 +455,10 @@ bool QMfcApp::winEventFilter(MSG *msg, long *result)
#endif
recursion = false;
+#if QT_VERSION < 0x050000
return QApplication::winEventFilter(msg, result);
+#else
+ Q_UNUSED(result);
+ return false;
+#endif
}
diff --git a/qtwinmigrate/src/qmfcapp.h b/qtwinmigrate/src/qmfcapp.h
index dc002e2..ac232e4 100644
--- a/qtwinmigrate/src/qmfcapp.h
+++ b/qtwinmigrate/src/qmfcapp.h
@@ -67,6 +67,17 @@ class CWinApp;
# define QT_QTWINMIGRATE_EXPORT
#endif
+#if QT_VERSION >= 0x050000
+#include <QAbstractNativeEventFilter>
+
+class QT_QTWINMIGRATE_EXPORT QMfcAppEventFilter : public QAbstractNativeEventFilter
+{
+public:
+ QMfcAppEventFilter();
+ bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
+};
+#endif
+
class QT_QTWINMIGRATE_EXPORT QMfcApp : public QApplication
{
public:
@@ -77,6 +88,7 @@ public:
static QApplication *instance(CWinApp *mfcApp);
QMfcApp(CWinApp *mfcApp, int &argc, char **argv);
#endif
+ QMfcApp(int &argc, char **argv);
~QMfcApp();
bool winEventFilter(MSG *msg, long *result);
diff --git a/qtwinmigrate/src/qtwinmigrate.pri b/qtwinmigrate/src/qtwinmigrate.pri
index d5a8d1e..facdc8f 100644
--- a/qtwinmigrate/src/qtwinmigrate.pri
+++ b/qtwinmigrate/src/qtwinmigrate.pri
@@ -20,3 +20,4 @@ win32 {
qtwinmigrate-buildlib:DEFINES += QT_QTWINMIGRATE_EXPORT
else:qtwinmigrate-uselib:DEFINES += QT_QTWINMIGRATE_IMPORT
}
+contains(QT_MAJOR_VERSION, 5): QT += widgets gui-private \ No newline at end of file
diff --git a/qtwinmigrate/src/qwinhost.cpp b/qtwinmigrate/src/qwinhost.cpp
index fc2082d..d3ae886 100644
--- a/qtwinmigrate/src/qwinhost.cpp
+++ b/qtwinmigrate/src/qwinhost.cpp
@@ -84,7 +84,7 @@
after the native window has been created, i.e. do not call
QWidget::setParent or move the QWinHost into a different layout.
*/
-QWinHost::QWinHost(QWidget *parent, Qt::WFlags f)
+QWinHost::QWinHost(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f), wndproc(0),own_hwnd(false), hwnd(0)
{
setAttribute(Qt::WA_NoBackground);
@@ -153,12 +153,12 @@ void QWinHost::fixParent()
hwnd = 0;
return;
}
- if (::GetParent(hwnd) == winId())
+ if (::GetParent(hwnd) == (HWND)winId())
return;
long style = GetWindowLong(hwnd, GWL_STYLE);
if (style & WS_OVERLAPPED)
return;
- ::SetParent(hwnd, winId());
+ ::SetParent(hwnd, (HWND)winId());
}
/*!
@@ -201,7 +201,7 @@ void *getWindowProc(QWinHost *host)
LRESULT CALLBACK WinHostProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- QWinHost *widget = qobject_cast<QWinHost*>(QWidget::find(::GetParent(hwnd)));
+ QWinHost *widget = qobject_cast<QWinHost*>(QWidget::find((WId)::GetParent(hwnd)));
WNDPROC oldproc = (WNDPROC)getWindowProc(widget);
if (widget) {
switch(msg) {
@@ -214,18 +214,18 @@ LRESULT CALLBACK WinHostProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
QT_WA({
- SendMessage(widget->winId(), msg, wParam, lParam);
+ SendMessage((HWND)widget->winId(), msg, wParam, lParam);
}, {
- SendMessageA(widget->winId(), msg, wParam, lParam);
+ SendMessageA((HWND)widget->winId(), msg, wParam, lParam);
})
break;
case WM_KEYDOWN:
if (wParam == VK_TAB) {
QT_WA({
- SendMessage(widget->winId(), msg, wParam, lParam);
+ SendMessage((HWND)widget->winId(), msg, wParam, lParam);
}, {
- SendMessageA(widget->winId(), msg, wParam, lParam);
+ SendMessageA((HWND)widget->winId(), msg, wParam, lParam);
})
}
break;
@@ -254,11 +254,11 @@ bool QWinHost::event(QEvent *e)
switch(e->type()) {
case QEvent::Polish:
if (!hwnd) {
- hwnd = createWindow(winId(), qWinAppInst());
+ hwnd = createWindow((HWND)winId(), qWinAppInst());
fixParent();
own_hwnd = hwnd != 0;
}
- if (hwnd && !wndproc && GetParent(hwnd) == winId()) {
+ if (hwnd && !wndproc && GetParent(hwnd) == (HWND)winId()) {
#if defined(GWLP_WNDPROC)
QT_WA({
wndproc = (void*)GetWindowLongPtr(hwnd, GWLP_WNDPROC);
@@ -335,8 +335,15 @@ void QWinHost::resizeEvent(QResizeEvent *e)
/*!
\reimp
*/
+#if QT_VERSION >= 0x050000
+bool QWinHost::nativeEvent(const QByteArray &eventType, void *message, long *result)
+#else
bool QWinHost::winEvent(MSG *msg, long *result)
+#endif
{
+#if QT_VERSION >= 0x050000
+ MSG *msg = (MSG *)message;
+#endif
switch (msg->message)
{
case WM_SETFOCUS:
@@ -347,6 +354,9 @@ bool QWinHost::winEvent(MSG *msg, long *result)
default:
break;
}
-
+#if QT_VERSION >= 0x050000
+ return QWidget::nativeEvent(eventType, message, result);
+#else
return QWidget::winEvent(msg, result);
+#endif
}
diff --git a/qtwinmigrate/src/qwinhost.h b/qtwinmigrate/src/qwinhost.h
index 0d5e8a6..328065a 100644
--- a/qtwinmigrate/src/qwinhost.h
+++ b/qtwinmigrate/src/qwinhost.h
@@ -66,7 +66,7 @@ class QT_QTWINMIGRATE_EXPORT QWinHost : public QWidget
{
Q_OBJECT
public:
- QWinHost(QWidget *parent = 0, Qt::WFlags f = 0);
+ QWinHost(QWidget *parent = 0, Qt::WindowFlags f = 0);
~QWinHost();
void setWindow(HWND);
@@ -80,7 +80,11 @@ protected:
void focusInEvent(QFocusEvent*);
void resizeEvent(QResizeEvent*);
+#if QT_VERSION >= 0x050000
+ bool nativeEvent(const QByteArray &eventType, void *message, long *result);
+#else
bool winEvent(MSG *msg, long *result);
+#endif
private:
void fixParent();
diff --git a/qtwinmigrate/src/qwinwidget.cpp b/qtwinmigrate/src/qwinwidget.cpp
index a3786b4..6396544 100644
--- a/qtwinmigrate/src/qwinwidget.cpp
+++ b/qtwinmigrate/src/qwinwidget.cpp
@@ -61,6 +61,8 @@
#include <qt_windows.h>
#if QT_VERSION >= 0x050000
+#include <QWindow>
+#include <qpa/qplatformnativeinterface.h>
#define QT_WA(unicode, ansi) unicode
#endif
@@ -88,7 +90,7 @@
the native Win32 parent. If a \a parent is provided the object is
owned by that QObject. \a f is passed on to the QWidget constructor.
*/
-QWinWidget::QWinWidget(HWND hParentWnd, QObject *parent, Qt::WFlags f)
+QWinWidget::QWinWidget(HWND hParentWnd, QObject *parent, Qt::WindowFlags f)
: QWidget(0, f), hParent(hParentWnd), prevFocus(0), reenable_parent(false)
{
if (parent)
@@ -105,7 +107,7 @@ QWinWidget::QWinWidget(HWND hParentWnd, QObject *parent, Qt::WFlags f)
MFC window object. If a \a parent is provided the object is owned
by that QObject. \a f is passed on to the QWidget constructor.
*/
-QWinWidget::QWinWidget(CWnd *parentWnd, QObject *parent, Qt::WFlags f)
+QWinWidget::QWinWidget(CWnd *parentWnd, QObject *parent, Qt::WindowFlags f)
: QWidget(0, f), hParent(parentWnd ? parentWnd->m_hWnd : 0), prevFocus(0), reenable_parent(false)
{
if (parent)
@@ -123,12 +125,20 @@ void QWinWidget::init()
if (hParent) {
// make the widget window style be WS_CHILD so SetParent will work
QT_WA({
- SetWindowLong(winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
+ SetWindowLong((HWND)winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
}, {
- SetWindowLongA(winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
+ SetWindowLongA((HWND)winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
})
- SetParent(winId(), hParent);
-
+#if QT_VERSION >= 0x050000
+ QWindow *window = windowHandle();
+ window->setProperty("_q_embedded_native_parent_handle", (WId)hParent);
+ HWND h = static_cast<HWND>(QGuiApplication::platformNativeInterface()->
+ nativeResourceForWindow("handle", window));
+ SetParent(h, hParent);
+ window->setFlags(Qt::FramelessWindowHint);
+#else
+ SetParent(winId(), hParent);
+#endif
QEvent e(QEvent::EmbeddingControl);
QApplication::sendEvent(this, &e);
}
@@ -205,7 +215,7 @@ void QWinWidget::show()
*/
void QWinWidget::center()
{
- const QWidget *child = qFindChild<QWidget*>(this);
+ const QWidget *child = findChild<QWidget*>();
if (child && !child->isWindow()) {
qWarning("QWinWidget::center: Call this function only for QWinWidgets with toplevel children");
}
@@ -240,8 +250,15 @@ void QWinWidget::resetFocus()
/*! \reimp
*/
+#if QT_VERSION >= 0x050000
+bool QWinWidget::nativeEvent(const QByteArray &, void *message, long *)
+#else
bool QWinWidget::winEvent(MSG *msg, long *)
+#endif
{
+#if QT_VERSION >= 0x050000
+ MSG *msg = (MSG *)message;
+#endif
if (msg->message == WM_SETFOCUS) {
Qt::FocusReason reason;
if (::GetKeyState(VK_SHIFT) < 0)
diff --git a/qtwinmigrate/src/qwinwidget.h b/qtwinmigrate/src/qwinwidget.h
index b7db2c9..a6ca3cf 100644
--- a/qtwinmigrate/src/qwinwidget.h
+++ b/qtwinmigrate/src/qwinwidget.h
@@ -69,9 +69,9 @@ class QT_QTWINMIGRATE_EXPORT QWinWidget : public QWidget
{
Q_OBJECT
public:
- QWinWidget( HWND hParentWnd, QObject *parent = 0, Qt::WFlags f = 0 );
+ QWinWidget( HWND hParentWnd, QObject *parent = 0, Qt::WindowFlags f = 0 );
#ifdef QTWINMIGRATE_WITHMFC
- QWinWidget( CWnd *parnetWnd, QObject *parent = 0, Qt::WFlags f = 0 );
+ QWinWidget( CWnd *parnetWnd, QObject *parent = 0, Qt::WindowFlags f = 0 );
#endif
~QWinWidget();
@@ -87,8 +87,11 @@ protected:
bool focusNextPrevChild(bool next);
void focusInEvent(QFocusEvent *e);
-
+#if QT_VERSION >= 0x050000
+ bool nativeEvent(const QByteArray &eventType, void *message, long *result);
+#else
bool winEvent(MSG *msg, long *result);
+#endif
private:
void init();