diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-03-31 10:03:31 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-03-31 10:03:31 +0200 |
commit | ce9519593a0b3deb99d1dd2529770f7e9fffef92 (patch) | |
tree | c9bca05230dd68f49494240ae930bad1fe0c5956 /src/plugins/platforms/windows/qwindowsmousehandler.cpp | |
parent | 509f77cca28aa3edea5523c5869bae4412ed2ccc (diff) | |
parent | 7baaec17edb06634f1d6235a55c7adbd112cba3e (diff) |
Merge remote-tracking branch 'origin/5.4' into 5.5
Conflicts:
mkspecs/android-g++/qmake.conf
qmake/generators/unix/unixmake2.cpp
src/gui/image/qimage_conversions.cpp
Change-Id: Ib76264b8c2d29a0228438ec02bd97d4b97545be0
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsmousehandler.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsmousehandler.cpp | 73 |
1 files changed, 56 insertions, 17 deletions
diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index b1ced95a71..db635b602b 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -42,6 +42,7 @@ #include <QtGui/QGuiApplication> #include <QtGui/QScreen> #include <QtGui/QWindow> +#include <QtGui/QCursor> #include <QtCore/QDebug> #include <QtCore/QScopedArrayPointer> @@ -386,6 +387,31 @@ static bool isValidWheelReceiver(QWindow *candidate) return false; } +static void redirectWheelEvent(QWindow *window, const QPoint &globalPos, int delta, + Qt::Orientation orientation, Qt::KeyboardModifiers mods) +{ + // Redirect wheel event to one of the following, in order of preference: + // 1) The window under mouse + // 2) The window receiving the event + // If a window is blocked by modality, it can't get the event. + + QWindow *receiver = QWindowsScreen::windowAt(globalPos, CWP_SKIPINVISIBLE); + bool handleEvent = true; + if (!isValidWheelReceiver(receiver)) { + receiver = window; + if (!isValidWheelReceiver(receiver)) + handleEvent = false; + } + + if (handleEvent) { + const QPoint posDip = QWindowsGeometryHint::mapFromGlobal(receiver, globalPos) / QWindowsScaling::factor(); + QWindowSystemInterface::handleWheelEvent(receiver, + posDip, globalPos / QWindowsScaling::factor(), + delta / QWindowsScaling::factor(), + orientation, mods); + } +} + bool QWindowsMouseHandler::translateMouseWheelEvent(QWindow *window, HWND, MSG msg, LRESULT *) { @@ -408,27 +434,40 @@ bool QWindowsMouseHandler::translateMouseWheelEvent(QWindow *window, HWND, if (msg.message == WM_MOUSEHWHEEL) delta = -delta; - // Redirect wheel event to one of the following, in order of preference: - // 1) The window under mouse - // 2) The window receiving the event - // If a window is blocked by modality, it can't get the event. const QPoint globalPos(GET_X_LPARAM(msg.lParam), GET_Y_LPARAM(msg.lParam)); - QWindow *receiver = QWindowsScreen::windowAt(globalPos, CWP_SKIPINVISIBLE); - bool handleEvent = true; - if (!isValidWheelReceiver(receiver)) { - receiver = window; - if (!isValidWheelReceiver(receiver)) - handleEvent = false; - } + redirectWheelEvent(window, globalPos, delta, orientation, mods); - if (handleEvent) { - const QPoint posDip = QWindowsGeometryHint::mapFromGlobal(receiver, globalPos) / QWindowsScaling::factor(); - QWindowSystemInterface::handleWheelEvent(receiver, - posDip, globalPos / QWindowsScaling::factor(), - delta / QWindowsScaling::factor(), - orientation, mods); + return true; +} + +bool QWindowsMouseHandler::translateScrollEvent(QWindow *window, HWND, + MSG msg, LRESULT *) +{ + // This is a workaround against some touchpads that send WM_HSCROLL instead of WM_MOUSEHWHEEL. + // We could also handle vertical scroll here but there's no reason to, there's no bug for vertical + // (broken vertical scroll would have been noticed long time ago), so lets keep the change small + // and minimize the chance for regressions. + + int delta = 0; + switch (LOWORD(msg.wParam)) { + case SB_LINELEFT: + delta = 120; + break; + case SB_LINERIGHT: + delta = -120; + break; + case SB_PAGELEFT: + delta = 240; + break; + case SB_PAGERIGHT: + delta = -240; + break; + default: + return false; } + redirectWheelEvent(window, QCursor::pos(), delta, Qt::Horizontal, Qt::NoModifier); + return true; } |