1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxConsoleView class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License as published by the Free Software Foundation,
|
---|
14 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
15 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
16 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * If you received this file as part of a commercial VirtualBox
|
---|
19 | * distribution, then only the terms of your commercial VirtualBox
|
---|
20 | * license agreement apply instead of the previous paragraph.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef __VBoxConsoleView_h__
|
---|
24 | #define __VBoxConsoleView_h__
|
---|
25 |
|
---|
26 | #include "COMDefs.h"
|
---|
27 |
|
---|
28 | #include "VBoxDefs.h"
|
---|
29 | #include "VBoxGlobalSettings.h"
|
---|
30 |
|
---|
31 | #include <qdatetime.h>
|
---|
32 | #include <qscrollview.h>
|
---|
33 | #include <qpixmap.h>
|
---|
34 | #include <qimage.h>
|
---|
35 |
|
---|
36 | #include <qkeysequence.h>
|
---|
37 |
|
---|
38 | #if defined (Q_WS_MAC)
|
---|
39 | # include <Carbon/Carbon.h>
|
---|
40 | # include "DarwinCursor.h"
|
---|
41 | /** @todo remove this hack when somebody get around fixing the conflicting typedef/enum OSType. */
|
---|
42 | # define OSType VBoxOSType
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | class VBoxConsoleWnd;
|
---|
46 | class MousePointerChangeEvent;
|
---|
47 | class VBoxFrameBuffer;
|
---|
48 |
|
---|
49 | class QPainter;
|
---|
50 | class QLabel;
|
---|
51 | class QMenuData;
|
---|
52 |
|
---|
53 | class VBoxConsoleView : public QScrollView
|
---|
54 | {
|
---|
55 | Q_OBJECT
|
---|
56 |
|
---|
57 | public:
|
---|
58 |
|
---|
59 | enum {
|
---|
60 | MouseCaptured = 0x01,
|
---|
61 | MouseAbsolute = 0x02,
|
---|
62 | MouseAbsoluteDisabled = 0x04,
|
---|
63 | MouseNeedsHostCursor = 0x08,
|
---|
64 | KeyboardCaptured = 0x01,
|
---|
65 | HostKeyPressed = 0x02,
|
---|
66 | };
|
---|
67 |
|
---|
68 | VBoxConsoleView (VBoxConsoleWnd *mainWnd,
|
---|
69 | const CConsole &console,
|
---|
70 | VBoxDefs::RenderMode rm,
|
---|
71 | QWidget *parent = 0, const char *name = 0, WFlags f = 0);
|
---|
72 | ~VBoxConsoleView();
|
---|
73 |
|
---|
74 | QSize sizeHint() const;
|
---|
75 |
|
---|
76 | void attach();
|
---|
77 | void detach();
|
---|
78 | void refresh() { doRefresh(); }
|
---|
79 | void normalizeGeometry (bool adjustPosition = false);
|
---|
80 |
|
---|
81 | CConsole &console() { return cconsole; }
|
---|
82 |
|
---|
83 | bool pause (bool on);
|
---|
84 |
|
---|
85 | void setMouseIntegrationEnabled (bool enabled);
|
---|
86 |
|
---|
87 | bool isMouseAbsolute() const { return mouse_absolute; }
|
---|
88 |
|
---|
89 | void setAutoresizeGuest (bool on);
|
---|
90 |
|
---|
91 | void onFullscreenChange (bool on);
|
---|
92 |
|
---|
93 | void onViewOpened();
|
---|
94 |
|
---|
95 | void fixModifierState (LONG *codes, uint *count);
|
---|
96 |
|
---|
97 | bool isInSeamlessMode();
|
---|
98 |
|
---|
99 | signals:
|
---|
100 |
|
---|
101 | void keyboardStateChanged (int state);
|
---|
102 | void mouseStateChanged (int state);
|
---|
103 | void machineStateChanged (CEnums::MachineState state);
|
---|
104 | void additionsStateChanged (const QString &, bool, bool);
|
---|
105 |
|
---|
106 | protected:
|
---|
107 |
|
---|
108 | // events
|
---|
109 | bool event( QEvent *e );
|
---|
110 | bool eventFilter( QObject *watched, QEvent *e );
|
---|
111 |
|
---|
112 | #if defined(Q_WS_WIN32)
|
---|
113 | bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
|
---|
114 | bool winEvent (MSG *msg);
|
---|
115 | #elif defined(Q_WS_X11)
|
---|
116 | bool x11Event (XEvent *event );
|
---|
117 | #elif defined(Q_WS_MAC)
|
---|
118 | bool darwinKeyboardEvent (EventRef inEvent);
|
---|
119 | void darwinGrabKeyboardEvents (bool fGrab);
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | private:
|
---|
123 |
|
---|
124 | // flags for keyEvent()
|
---|
125 | enum {
|
---|
126 | KeyExtended = 0x01,
|
---|
127 | KeyPressed = 0x02,
|
---|
128 | KeyPause = 0x04,
|
---|
129 | KeyPrint = 0x08,
|
---|
130 | };
|
---|
131 |
|
---|
132 | void focusEvent (bool focus);
|
---|
133 | bool keyEvent (int key, uint8_t scan, int flags, wchar_t *aUniKey = NULL);
|
---|
134 | bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
|
---|
135 | ButtonState aButton,
|
---|
136 | ButtonState aState, ButtonState aStateAfter,
|
---|
137 | int aWheelDelta, Orientation aWheelDir);
|
---|
138 |
|
---|
139 | void emitKeyboardStateChanged() {
|
---|
140 | emit keyboardStateChanged (
|
---|
141 | (kbd_captured ? KeyboardCaptured : 0) |
|
---|
142 | (hostkey_pressed ? HostKeyPressed : 0));
|
---|
143 | }
|
---|
144 | void emitMouseStateChanged() {
|
---|
145 | emit mouseStateChanged ((mouse_captured ? MouseCaptured : 0) |
|
---|
146 | (mouse_absolute ? MouseAbsolute : 0) |
|
---|
147 | (!mouse_integration ? MouseAbsoluteDisabled : 0));
|
---|
148 | }
|
---|
149 |
|
---|
150 | // IConsoleCallback event handlers
|
---|
151 | void onStateChange (CEnums::MachineState state);
|
---|
152 |
|
---|
153 | void doRefresh();
|
---|
154 |
|
---|
155 | void viewportPaintEvent( QPaintEvent * );
|
---|
156 | #ifdef VBOX_GUI_USE_REFRESH_TIMER
|
---|
157 | void timerEvent( QTimerEvent * );
|
---|
158 | #endif
|
---|
159 |
|
---|
160 | void captureKbd (bool capture, bool emit_signal = true);
|
---|
161 | void captureMouse (bool capture, bool emit_signal = true);
|
---|
162 |
|
---|
163 | bool processHotKey (const QKeySequence &key, QMenuData *data);
|
---|
164 | void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
|
---|
165 |
|
---|
166 | void releaseAllKeysPressed (bool release_hostkey = true);
|
---|
167 | void saveKeyStates();
|
---|
168 | void sendChangedKeyStates();
|
---|
169 | void updateMouseClipping();
|
---|
170 |
|
---|
171 | void setPointerShape (MousePointerChangeEvent *me);
|
---|
172 |
|
---|
173 | bool isPaused() { return last_state == CEnums::Paused; }
|
---|
174 | bool isRunning() { return last_state == CEnums::Running; }
|
---|
175 |
|
---|
176 | static void dimImage (QImage &img);
|
---|
177 |
|
---|
178 | private slots:
|
---|
179 |
|
---|
180 | void exitFullScreen();
|
---|
181 |
|
---|
182 | void doResizeHint();
|
---|
183 | void normalizeGeo() { normalizeGeometry (true); }
|
---|
184 |
|
---|
185 | private:
|
---|
186 |
|
---|
187 | void maybeRestrictMinimumSize();
|
---|
188 |
|
---|
189 | VBoxConsoleWnd *mainwnd;
|
---|
190 |
|
---|
191 | CConsole cconsole;
|
---|
192 |
|
---|
193 | const VBoxGlobalSettings &gs;
|
---|
194 |
|
---|
195 | CEnums::MachineState last_state;
|
---|
196 |
|
---|
197 | bool attached : 1;
|
---|
198 | bool kbd_captured : 1;
|
---|
199 | bool mouse_captured : 1;
|
---|
200 | bool mouse_absolute : 1;
|
---|
201 | bool mouse_integration : 1;
|
---|
202 | QPoint last_pos;
|
---|
203 | QPoint captured_pos;
|
---|
204 |
|
---|
205 | enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
|
---|
206 | uint8_t keys_pressed[128];
|
---|
207 | uint8_t keys_pressed_copy[128];
|
---|
208 |
|
---|
209 | bool hostkey_pressed : 1;
|
---|
210 | bool hostkey_alone : 1;
|
---|
211 | /** kbd_captured value during the the last host key press or release */
|
---|
212 | bool hostkey_in_capture : 1;
|
---|
213 |
|
---|
214 | bool ignore_mainwnd_resize : 1;
|
---|
215 | bool mAutoresizeGuest : 1;
|
---|
216 |
|
---|
217 | bool mIsAdditionsActive : 1;
|
---|
218 |
|
---|
219 | bool mfNumLock : 1;
|
---|
220 | bool mfScrollLock : 1;
|
---|
221 | bool mfCapsLock : 1;
|
---|
222 | long muNumLockAdaptionCnt;
|
---|
223 | long muCapsLockAdaptionCnt;
|
---|
224 |
|
---|
225 | QTimer *resize_hint_timer;
|
---|
226 |
|
---|
227 | VBoxDefs::RenderMode mode;
|
---|
228 |
|
---|
229 | #if defined(Q_WS_WIN)
|
---|
230 | HCURSOR mAlphaCursor;
|
---|
231 | #endif
|
---|
232 |
|
---|
233 | #if defined(Q_WS_MAC)
|
---|
234 | # ifndef VBOX_WITH_HACKED_QT
|
---|
235 | /** Event handler reference. NULL if the handler isn't installed. */
|
---|
236 | EventHandlerRef m_darwinEventHandlerRef;
|
---|
237 | # endif
|
---|
238 | /** The current modifier key mask. Used to figure out which modifier
|
---|
239 | * key was pressed when we get a kEventRawKeyModifiersChanged event. */
|
---|
240 | UInt32 m_darwinKeyModifiers;
|
---|
241 | /** The darwin cursor handle (see DarwinCursor.h/.cpp). */
|
---|
242 | DARWINCURSOR m_darwinCursor;
|
---|
243 | #endif
|
---|
244 |
|
---|
245 | #if defined (VBOX_GUI_USE_REFRESH_TIMER)
|
---|
246 | QPixmap pm;
|
---|
247 | int tid; /**< Timer id */
|
---|
248 | #endif
|
---|
249 |
|
---|
250 | VBoxFrameBuffer *fb;
|
---|
251 | CConsoleCallback callback;
|
---|
252 |
|
---|
253 | friend class VBoxConsoleCallback;
|
---|
254 |
|
---|
255 | #if defined (Q_WS_WIN32)
|
---|
256 | static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
|
---|
257 | WPARAM wParam, LPARAM lParam);
|
---|
258 | #elif defined (Q_WS_MAC)
|
---|
259 | # ifndef VBOX_WITH_HACKED_QT
|
---|
260 | static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
|
---|
261 | EventRef inEvent, void *inUserData);
|
---|
262 | # else /* VBOX_WITH_HACKED_QT */
|
---|
263 | static bool macEventFilter (EventRef inEvent, void *inUserData);
|
---|
264 | # endif /* VBOX_WITH_HACKED_QT */
|
---|
265 | #endif
|
---|
266 |
|
---|
267 | QPixmap mPausedShot;
|
---|
268 | };
|
---|
269 |
|
---|
270 | #endif // __VBoxConsoleView_h__
|
---|
271 |
|
---|