Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsmousehandler.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWINDOWSMOUSEHANDLER_H
5#define QWINDOWSMOUSEHANDLER_H
6
7#include "qtwindowsglobal.h"
8#include <QtCore/qt_windows.h>
9
10#include <QtCore/qpointer.h>
11#include <QtCore/qhash.h>
12#include <QtCore/qsharedpointer.h>
13#include <QtGui/qevent.h>
14
16
17class QWindow;
18class QPointingDevice;
19
21{
22 Q_DISABLE_COPY_MOVE(QWindowsMouseHandler)
23public:
24 using QPointingDevicePtr = QSharedPointer<QPointingDevice>;
25
27
28 const QPointingDevicePtr &touchDevice() const { return m_touchDevice; }
29 void setTouchDevice(const QPointingDevicePtr &d) { m_touchDevice = d; }
30
31 bool translateMouseEvent(QWindow *widget, HWND hwnd,
33 LRESULT *result);
34 bool translateTouchEvent(QWindow *widget, HWND hwnd,
36 LRESULT *result);
37 bool translateGestureEvent(QWindow *window, HWND hwnd,
39 MSG msg, LRESULT *);
40 bool translateScrollEvent(QWindow *window, HWND hwnd,
41 MSG msg, LRESULT *result);
42
43 static inline Qt::MouseButtons keyStateToMouseButtons(WPARAM);
44 static inline Qt::KeyboardModifiers keyStateToModifiers(int);
45 static inline int mouseButtonsToKeyState(Qt::MouseButtons);
46
47 static Qt::MouseButtons queryMouseButtons();
48 QWindow *windowUnderMouse() const { return m_windowUnderMouse.data(); }
49 void clearWindowUnderMouse() { m_windowUnderMouse = nullptr; }
50 void clearEvents();
51
52 static const QPointingDevice *primaryMouse();
53
54private:
55 inline bool translateMouseWheelEvent(QWindow *window, HWND hwnd,
56 MSG msg, LRESULT *result);
57
58 QPointer<QWindow> m_windowUnderMouse;
59 QPointer<QWindow> m_trackedWindow;
60 QHash<DWORD, int> m_touchInputIDToTouchPointID;
61 QHash<int, QPointF> m_lastTouchPositions;
62 QPointingDevicePtr m_touchDevice;
63 bool m_leftButtonDown = false;
64 QWindow *m_previousCaptureWindow = nullptr;
65 QEvent::Type m_lastEventType = QEvent::None;
66 Qt::MouseButton m_lastEventButton = Qt::NoButton;
67};
68
69Qt::MouseButtons QWindowsMouseHandler::keyStateToMouseButtons(WPARAM wParam)
70{
71 Qt::MouseButtons mb(Qt::NoButton);
72 if (wParam & MK_LBUTTON)
73 mb |= Qt::LeftButton;
74 if (wParam & MK_MBUTTON)
75 mb |= Qt::MiddleButton;
76 if (wParam & MK_RBUTTON)
77 mb |= Qt::RightButton;
78 if (wParam & MK_XBUTTON1)
79 mb |= Qt::XButton1;
80 if (wParam & MK_XBUTTON2)
81 mb |= Qt::XButton2;
82 return mb;
83}
84
85Qt::KeyboardModifiers QWindowsMouseHandler::keyStateToModifiers(int wParam)
86{
87 Qt::KeyboardModifiers mods(Qt::NoModifier);
88 if (wParam & MK_CONTROL)
89 mods |= Qt::ControlModifier;
90 if (wParam & MK_SHIFT)
91 mods |= Qt::ShiftModifier;
92 if (GetKeyState(VK_MENU) < 0)
93 mods |= Qt::AltModifier;
94 return mods;
95}
96
98{
99 int result = 0;
100 if (mb & Qt::LeftButton)
101 result |= MK_LBUTTON;
102 if (mb & Qt::MiddleButton)
103 result |= MK_MBUTTON;
104 if (mb & Qt::RightButton)
105 result |= MK_RBUTTON;
106 if (mb & Qt::XButton1)
107 result |= MK_XBUTTON1;
108 if (mb & Qt::XButton2)
109 result |= MK_XBUTTON2;
110 return result;
111}
112
114
115#endif // QWINDOWSMOUSEHANDLER_H
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
T * data() const noexcept
Definition qpointer.h:73
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
\inmodule QtGui
Definition qwindow.h:63
Windows mouse handler.
static Qt::MouseButtons queryMouseButtons()
bool translateScrollEvent(QWindow *window, HWND hwnd, MSG msg, LRESULT *result)
bool translateTouchEvent(QWindow *widget, HWND hwnd, QtWindows::WindowsEventType t, MSG msg, LRESULT *result)
void setTouchDevice(const QPointingDevicePtr &d)
static Qt::KeyboardModifiers keyStateToModifiers(int)
static Qt::MouseButtons keyStateToMouseButtons(WPARAM)
static int mouseButtonsToKeyState(Qt::MouseButtons)
QWindow * windowUnderMouse() const
bool translateGestureEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType, MSG msg, LRESULT *)
static const QPointingDevice * primaryMouse()
QSharedPointer< QPointingDevice > QPointingDevicePtr
const QPointingDevicePtr & touchDevice() const
bool translateMouseEvent(QWindow *widget, HWND hwnd, QtWindows::WindowsEventType t, MSG msg, LRESULT *result)
QOpenGLWidget * widget
[1]
Combined button and popup list for selecting options.
WindowsEventType
Enumerations for WM_XX events.
MouseButton
Definition qnamespace.h:56
@ LeftButton
Definition qnamespace.h:58
@ RightButton
Definition qnamespace.h:59
@ MiddleButton
Definition qnamespace.h:60
@ XButton2
Definition qnamespace.h:65
@ NoButton
Definition qnamespace.h:57
@ XButton1
Definition qnamespace.h:62
@ ShiftModifier
@ ControlModifier
@ NoModifier
@ AltModifier
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint64EXT * result
[6]
struct tagMSG MSG
aWidget window() -> setWindowTitle("New Window Title")
[2]