1 | /* $Id: UIMouseHandler.h 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMouseHandler class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___UIMouseHandler_h___
|
---|
19 | #define ___UIMouseHandler_h___
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QMap>
|
---|
26 | #include <QObject>
|
---|
27 | #include <QPoint>
|
---|
28 | #include <QPointer>
|
---|
29 | #include <QRect>
|
---|
30 |
|
---|
31 | /* GUI includes: */
|
---|
32 | #include "UIExtraDataDefs.h"
|
---|
33 |
|
---|
34 | /* Forward declarations: */
|
---|
35 | class QTouchEvent;
|
---|
36 | class QWidget;
|
---|
37 | class UISession;
|
---|
38 | class UIMachineLogic;
|
---|
39 | class UIMachineWindow;
|
---|
40 | class UIMachineView;
|
---|
41 | class CDisplay;
|
---|
42 | class CMouse;
|
---|
43 |
|
---|
44 |
|
---|
45 | /* Delegate to control VM mouse functionality: */
|
---|
46 | class UIMouseHandler : public QObject
|
---|
47 | {
|
---|
48 | Q_OBJECT;
|
---|
49 |
|
---|
50 | signals:
|
---|
51 |
|
---|
52 | /** Notifies listeners about state-change. */
|
---|
53 | void sigStateChange(int iState);
|
---|
54 |
|
---|
55 | public:
|
---|
56 |
|
---|
57 | /* Factory functions to create/destroy mouse-handler: */
|
---|
58 | static UIMouseHandler* create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType);
|
---|
59 | static void destroy(UIMouseHandler *pMouseHandler);
|
---|
60 |
|
---|
61 | /* Prepare/cleanup listener for particular machine-window: */
|
---|
62 | void prepareListener(ulong uIndex, UIMachineWindow *pMachineWindow);
|
---|
63 | void cleanupListener(ulong uIndex);
|
---|
64 |
|
---|
65 | /* Commands to capture/release mouse: */
|
---|
66 | void captureMouse(ulong uScreenId);
|
---|
67 | void releaseMouse();
|
---|
68 |
|
---|
69 | /* Setter for mouse-integration feature: */
|
---|
70 | void setMouseIntegrationEnabled(bool fEnabled);
|
---|
71 |
|
---|
72 | /* Current mouse state: */
|
---|
73 | int state() const;
|
---|
74 |
|
---|
75 | /** Qt5: Performs pre-processing of all the native events. */
|
---|
76 | bool nativeEventFilter(void *pMessage, ulong uScreenId);
|
---|
77 |
|
---|
78 | protected slots:
|
---|
79 |
|
---|
80 | /* Machine state-change handler: */
|
---|
81 | virtual void sltMachineStateChanged();
|
---|
82 |
|
---|
83 | /* Mouse capability-change handler: */
|
---|
84 | virtual void sltMouseCapabilityChanged();
|
---|
85 |
|
---|
86 | /* Mouse pointer-shape-change handler: */
|
---|
87 | virtual void sltMousePointerShapeChanged();
|
---|
88 |
|
---|
89 | /** Activate hovered window if any. */
|
---|
90 | void sltMaybeActivateHoveredWindow();
|
---|
91 |
|
---|
92 | protected:
|
---|
93 |
|
---|
94 | /* Mouse-handler constructor/destructor: */
|
---|
95 | UIMouseHandler(UIMachineLogic *pMachineLogic);
|
---|
96 | virtual ~UIMouseHandler();
|
---|
97 |
|
---|
98 | /* Getters: */
|
---|
99 | UIMachineLogic* machineLogic() const;
|
---|
100 | UISession* uisession() const;
|
---|
101 |
|
---|
102 | /** Returns the console's display reference. */
|
---|
103 | CDisplay& display() const;
|
---|
104 | /** Returns the console's mouse reference. */
|
---|
105 | CMouse& mouse() const;
|
---|
106 |
|
---|
107 | /* Event handler for registered machine-view(s): */
|
---|
108 | bool eventFilter(QObject *pWatched, QEvent *pEvent);
|
---|
109 |
|
---|
110 | /* Separate function to handle most of existing mouse-events: */
|
---|
111 | bool mouseEvent(int iEventType, ulong uScreenId,
|
---|
112 | const QPoint &relativePos, const QPoint &globalPos,
|
---|
113 | Qt::MouseButtons mouseButtons,
|
---|
114 | int wheelDelta, Qt::Orientation wheelDirection);
|
---|
115 |
|
---|
116 | /* Separate function to handle incoming multi-touch events: */
|
---|
117 | bool multiTouchEvent(QTouchEvent *pTouchEvent, ulong uScreenId);
|
---|
118 |
|
---|
119 | #ifdef VBOX_WS_WIN
|
---|
120 | /* This method is actually required only because under win-host
|
---|
121 | * we do not really grab the mouse in case of capturing it: */
|
---|
122 | void updateMouseCursorClipping();
|
---|
123 | QRect m_mouseCursorClippingRect;
|
---|
124 | #endif /* VBOX_WS_WIN */
|
---|
125 |
|
---|
126 | /* Machine logic parent: */
|
---|
127 | UIMachineLogic *m_pMachineLogic;
|
---|
128 |
|
---|
129 | /* Registered machine-windows(s): */
|
---|
130 | QMap<ulong, QWidget*> m_windows;
|
---|
131 | /* Registered machine-view(s): */
|
---|
132 | QMap<ulong, UIMachineView*> m_views;
|
---|
133 | /* Registered machine-view-viewport(s): */
|
---|
134 | QMap<ulong, QWidget*> m_viewports;
|
---|
135 |
|
---|
136 | /** Hovered window to be activated. */
|
---|
137 | QPointer<QWidget> m_pHoveredWindow;
|
---|
138 |
|
---|
139 | /* Other mouse variables: */
|
---|
140 | QPoint m_lastMousePos;
|
---|
141 | QPoint m_capturedMousePos;
|
---|
142 | int m_iLastMouseWheelDelta;
|
---|
143 | int m_iMouseCaptureViewIndex;
|
---|
144 |
|
---|
145 | #ifdef VBOX_WS_WIN
|
---|
146 | /** Holds whether cursor position was just
|
---|
147 | * reseted to simulate infinite mouse moving. */
|
---|
148 | bool m_fCursorPositionReseted;
|
---|
149 | #endif
|
---|
150 | };
|
---|
151 |
|
---|
152 | #endif // !___UIMouseHandler_h___
|
---|
153 |
|
---|