summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp45
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.h3
-rw-r--r--src/plugins/platforms/windows/qwindowsintegration.cpp12
-rw-r--r--src/plugins/platforms/windows/qwindowsmousehandler.cpp17
-rw-r--r--src/plugins/platforms/windows/qwindowsmousehandler.h1
5 files changed, 57 insertions, 21 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index 3f355db607..00049bd0d6 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -33,6 +33,7 @@
****************************************************************************/
#include "qwindowscontext.h"
+#include "qwindowsintegration.h"
#include "qwindowswindow.h"
#include "qwindowskeymapper.h"
#include "qwindowsguieventdispatcher.h"
@@ -201,12 +202,14 @@ void QWindowsUser32DLL::init()
bool QWindowsUser32DLL::initTouch()
{
- QSystemLibrary library(QStringLiteral("user32"));
- isTouchWindow = (IsTouchWindow)(library.resolve("IsTouchWindow"));
- registerTouchWindow = (RegisterTouchWindow)(library.resolve("RegisterTouchWindow"));
- unregisterTouchWindow = (UnregisterTouchWindow)(library.resolve("UnregisterTouchWindow"));
- getTouchInputInfo = (GetTouchInputInfo)(library.resolve("GetTouchInputInfo"));
- closeTouchInputHandle = (CloseTouchInputHandle)(library.resolve("CloseTouchInputHandle"));
+ if (!isTouchWindow && QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) {
+ QSystemLibrary library(QStringLiteral("user32"));
+ isTouchWindow = (IsTouchWindow)(library.resolve("IsTouchWindow"));
+ registerTouchWindow = (RegisterTouchWindow)(library.resolve("RegisterTouchWindow"));
+ unregisterTouchWindow = (UnregisterTouchWindow)(library.resolve("UnregisterTouchWindow"));
+ getTouchInputInfo = (GetTouchInputInfo)(library.resolve("GetTouchInputInfo"));
+ closeTouchInputHandle = (CloseTouchInputHandle)(library.resolve("CloseTouchInputHandle"));
+ }
return isTouchWindow && registerTouchWindow && unregisterTouchWindow && getTouchInputInfo && closeTouchInputHandle;
}
@@ -359,6 +362,36 @@ QWindowsContext::~QWindowsContext()
m_instance = 0;
}
+bool QWindowsContext::initTouch()
+{
+ return initTouch(QWindowsIntegration::instance()->options());
+}
+
+bool QWindowsContext::initTouch(unsigned integrationOptions)
+{
+ if (d->m_systemInfo & QWindowsContext::SI_SupportsTouch)
+ return true;
+
+ QTouchDevice *touchDevice = d->m_mouseHandler.ensureTouchDevice();
+ if (!touchDevice)
+ return false;
+
+#ifndef Q_OS_WINCE
+ if (!QWindowsContext::user32dll.initTouch()) {
+ delete touchDevice;
+ return false;
+ }
+#endif // !Q_OS_WINCE
+
+ if (!(integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch))
+ touchDevice->setCapabilities(touchDevice->capabilities() | QTouchDevice::MouseEmulation);
+
+ QWindowSystemInterface::registerTouchDevice(touchDevice);
+
+ d->m_systemInfo |= QWindowsContext::SI_SupportsTouch;
+ return true;
+}
+
void QWindowsContext::setTabletAbsoluteRange(int a)
{
#if !defined(QT_NO_TABLETEVENT) && !defined(Q_OS_WINCE)
diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h
index d2a3481b28..641e3ed41f 100644
--- a/src/plugins/platforms/windows/qwindowscontext.h
+++ b/src/plugins/platforms/windows/qwindowscontext.h
@@ -170,6 +170,9 @@ public:
explicit QWindowsContext();
~QWindowsContext();
+ bool initTouch();
+ bool initTouch(unsigned integrationOptions); // For calls from QWindowsIntegration::QWindowsIntegration() only.
+
int defaultDPI() const;
QString registerWindowClass(const QWindow *w);
diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp
index 79df6ce720..089c3cd0fe 100644
--- a/src/plugins/platforms/windows/qwindowsintegration.cpp
+++ b/src/plugins/platforms/windows/qwindowsintegration.cpp
@@ -230,17 +230,7 @@ QWindowsIntegrationPrivate::QWindowsIntegrationPrivate(const QStringList &paramL
<< __FUNCTION__ << "DpiAwareness=" << dpiAwareness <<",Scaling="
<< QWindowsScaling::factor();
- QTouchDevice *touchDevice = m_context.touchDevice();
- if (touchDevice) {
-#ifdef Q_OS_WINCE
- touchDevice->setCapabilities(touchDevice->capabilities() | QTouchDevice::MouseEmulation);
-#else
- if (!(m_options & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch)) {
- touchDevice->setCapabilities(touchDevice->capabilities() | QTouchDevice::MouseEmulation);
- }
-#endif
- QWindowSystemInterface::registerTouchDevice(touchDevice);
- }
+ m_context.initTouch(m_options);
}
QWindowsIntegrationPrivate::~QWindowsIntegrationPrivate()
diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp
index e6b80f2b93..e83354157b 100644
--- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp
+++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp
@@ -150,12 +150,19 @@ static inline QTouchDevice *createTouchDevice()
QWindowsMouseHandler::QWindowsMouseHandler() :
m_windowUnderMouse(0),
m_trackedWindow(0),
- m_touchDevice(createTouchDevice()),
+ m_touchDevice(Q_NULLPTR),
m_leftButtonDown(false),
m_previousCaptureWindow(0)
{
}
+QTouchDevice *QWindowsMouseHandler::ensureTouchDevice()
+{
+ if (!m_touchDevice)
+ m_touchDevice = createTouchDevice();
+ return m_touchDevice;
+}
+
Qt::MouseButtons QWindowsMouseHandler::queryMouseButtons()
{
Qt::MouseButtons result = 0;
@@ -480,7 +487,11 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND,
typedef QWindowSystemInterface::TouchPoint QTouchPoint;
typedef QList<QWindowSystemInterface::TouchPoint> QTouchPointList;
- Q_ASSERT(m_touchDevice);
+ if (!QWindowsContext::instance()->initTouch()) {
+ qWarning("Unable to initialize touch handling.");
+ return true;
+ }
+
const QRect screenGeometry = window->screen()->geometry();
const int winTouchPointCount = msg.wParam;
@@ -491,8 +502,6 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND,
touchPoints.reserve(winTouchPointCount);
Qt::TouchPointStates allStates = 0;
- Q_ASSERT(QWindowsContext::user32dll.getTouchInputInfo);
-
QWindowsContext::user32dll.getTouchInputInfo((HANDLE) msg.lParam, msg.wParam, winTouchInputs.data(), sizeof(TOUCHINPUT));
const qreal screenPosFactor = 0.01 / qreal(QWindowsScaling::factor());
for (int i = 0; i < winTouchPointCount; ++i) {
diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.h b/src/plugins/platforms/windows/qwindowsmousehandler.h
index 61aa8d6084..4b5078567d 100644
--- a/src/plugins/platforms/windows/qwindowsmousehandler.h
+++ b/src/plugins/platforms/windows/qwindowsmousehandler.h
@@ -52,6 +52,7 @@ public:
QWindowsMouseHandler();
QTouchDevice *touchDevice() const { return m_touchDevice; }
+ QTouchDevice *ensureTouchDevice();
bool translateMouseEvent(QWindow *widget, HWND hwnd,
QtWindows::WindowsEventType t, MSG msg,