From 5f04a127a7b25f4e393e1c33639c7a83ec2f375a Mon Sep 17 00:00:00 2001 From: Bjoern Breitmeyer Date: Wed, 4 Jul 2012 16:14:29 +0200 Subject: fixed cursor handling on wince Change-Id: Iea91dde458b0e41a55ba6cb3e157756a1473f653 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qtwindowsglobal.h | 3 ++ src/plugins/platforms/windows/qwindowscontext.cpp | 11 +++++ src/plugins/platforms/windows/qwindowscursor.cpp | 52 ++++++++++++++++++++++ .../platforms/windows/qwindowsmousehandler.cpp | 3 +- 4 files changed, 68 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qtwindowsglobal.h b/src/plugins/platforms/windows/qtwindowsglobal.h index ab23b06302..59e6422962 100644 --- a/src/plugins/platforms/windows/qtwindowsglobal.h +++ b/src/plugins/platforms/windows/qtwindowsglobal.h @@ -85,6 +85,7 @@ enum WindowsEventType // Simplify event types FocusOutEvent = WindowEventFlag + 18, MouseEvent = MouseEventFlag + 1, MouseWheelEvent = MouseEventFlag + 2, + CursorEvent = MouseEventFlag + 3, TouchEvent = TouchEventFlag + 1, NonClientMouseEvent = NonClientEventFlag + MouseEventFlag + 1, KeyEvent = KeyEventFlag + 1, @@ -124,6 +125,8 @@ inline QtWindows::WindowsEventType windowsEventType(UINT message, WPARAM wParamI case WM_ACTIVATE: return LOWORD(wParamIn) == WA_INACTIVE ? QtWindows::DeactivateWindowEvent : QtWindows::ActivateWindowEvent; + case WM_SETCURSOR: + return QtWindows::CursorEvent; case WM_MOUSELEAVE: return QtWindows::MouseEvent; case WM_MOUSEWHEEL: diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 2c9750a327..a988aef589 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -837,6 +837,17 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, if (platformWindow->frameStrutEventsEnabled()) return d->m_mouseHandler.translateMouseEvent(platformWindow->window(), hwnd, et, msg, result); break; +/* the mouse tracking on windows already handles the reset of the cursor + * and does not like somebody else handling it. + * on WINCE its necessary to handle this event to get the correct cursor + */ +#ifdef Q_OS_WINCE + case QtWindows::CursorEvent: + { + QWindowsWindow::baseWindowOf(platformWindow->window())->applyCursor(); + return true; + } +#endif case QtWindows::MouseWheelEvent: case QtWindows::MouseEvent: case QtWindows::LeaveEvent: diff --git a/src/plugins/platforms/windows/qwindowscursor.cpp b/src/plugins/platforms/windows/qwindowscursor.cpp index 370234e8aa..48ef52ca56 100644 --- a/src/plugins/platforms/windows/qwindowscursor.cpp +++ b/src/plugins/platforms/windows/qwindowscursor.cpp @@ -295,6 +295,7 @@ HCURSOR QWindowsCursor::createSystemCursor(const QCursor &c) } const int n = qMax(1, bbits.width() / 8); const int h = bbits.height(); +#if !defined(Q_OS_WINCE) QScopedArrayPointer xBits(new uchar[h * n]); QScopedArrayPointer xMask(new uchar[h * n]); int x = 0; @@ -315,6 +316,53 @@ HCURSOR QWindowsCursor::createSystemCursor(const QCursor &c) } return CreateCursor(GetModuleHandle(0), hx, hy, bbits.width(), bbits.height(), xBits.data(), xMask.data()); +#elif defined(GWES_ICONCURS) // Q_WS_WINCE + // Windows CE only supports fixed cursor size. + int sysW = GetSystemMetrics(SM_CXCURSOR); + int sysH = GetSystemMetrics(SM_CYCURSOR); + int sysN = qMax(1, sysW / 8); + uchar* xBits = new uchar[sysH * sysN]; + uchar* xMask = new uchar[sysH * sysN]; + int x = 0; + for (int i = 0; i < sysH; ++i) { + if (i >= h) { + memset(&xBits[x] , 255, sysN); + memset(&xMask[x] , 0, sysN); + x += sysN; + } else { + int fillWidth = n > sysN ? sysN : n; + uchar *bits = bbits.scanLine(i); + uchar *mask = mbits.scanLine(i); + for (int j = 0; j < fillWidth; ++j) { + uchar b = bits[j]; + uchar m = mask[j]; + if (invb) + b ^= 0xFF; + if (invm) + m ^= 0xFF; + xBits[x] = ~m; + xMask[x] = b ^ m; + ++x; + } + for (int j = fillWidth; j < sysN; ++j ) { + xBits[x] = 255; + xMask[x] = 0; + ++x; + } + } + } + + HCURSOR hcurs = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH, + xBits, xMask); + delete [] xBits; + delete [] xMask; + return hcurs; +#else + Q_UNUSED(n); + Q_UNUSED(h); + return 0; +#endif + } case Qt::DragCopyCursor: case Qt::DragMoveCursor: @@ -326,7 +374,11 @@ HCURSOR QWindowsCursor::createSystemCursor(const QCursor &c) qWarning("%s: Invalid cursor shape %d", __FUNCTION__, cshape); return 0; } +#ifdef Q_OS_WINCE + return LoadCursor(0, sh); +#else return (HCURSOR)LoadImage(0, sh, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED); +#endif } /*! diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index a0b27c1f4a..f1e3d70d96 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -198,8 +198,9 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd, if (QWindowsContext::verboseEvents) qDebug() << "Entering " << window; QWindowsWindow::baseWindowOf(window)->applyCursor(); -#ifndef Q_OS_WINCE +//#ifndef Q_OS_WINCE QWindowSystemInterface::handleEnterEvent(window); +#ifndef Q_OS_WINCE TRACKMOUSEEVENT tme; tme.cbSize = sizeof(TRACKMOUSEEVENT); tme.dwFlags = TME_LEAVE; -- cgit v1.2.3