bool QWindowsMouseHandler::translateMouseWheelEvent(QWindow *window, HWND, MSG msg, LRESULT *) { const Qt::MouseButtons buttons = keyStateToMouseButtons((int)msg.wParam); const Qt::KeyboardModifiers mods = keyStateToModifiers((int)msg.wParam); int delta; if (msg.message == WM_MOUSEWHEEL || msg.message == WM_MOUSEHWHEEL) delta = (short) HIWORD (msg.wParam); else delta = (int) msg.wParam; Qt::Orientation orientation = (msg.message == WM_MOUSEHWHEEL || (buttons & Qt::AltModifier)) ? Qt::Horizontal : Qt::Vertical; // according to the MSDN documentation on WM_MOUSEHWHEEL: // a positive value indicates that the wheel was rotated to the right; // a negative value indicates that the wheel was rotated to the left. // Qt defines this value as the exact opposite, so we have to flip the value! 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); bool handleEvent = true; if (!isValidWheelReceiver(receiver)) { receiver = window; if (!isValidWheelReceiver(receiver)) handleEvent = false; } if (handleEvent) { QWindowSystemInterface::handleWheelEvent(receiver, QWindowsGeometryHint::mapFromGlobal(receiver, globalPos), globalPos, delta, orientation, mods); } return true; }
static void redirectWheelEvent(QWindow *window, const QPoint &globalPos, int delta, Qt::Orientation orientation, Qt::KeyboardModifiers mods) { // If a window is blocked by modality, it can't get the event. if (isValidWheelReceiver(window)) { QWindowSystemInterface::handleWheelEvent(window, QWindowsGeometryHint::mapFromGlobal(window, globalPos), globalPos, delta, orientation, mods); } }