1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxConsoleView class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006 InnoTek Systemberatung 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 | #endif
|
---|
42 |
|
---|
43 | class VBoxConsoleWnd;
|
---|
44 | class MousePointerChangeEvent;
|
---|
45 | class VBoxFrameBuffer;
|
---|
46 |
|
---|
47 | class QPainter;
|
---|
48 | class QLabel;
|
---|
49 | class QMenuData;
|
---|
50 |
|
---|
51 | /** Auto-resize event.
|
---|
52 | * Useful for posting into events queue to be processed just after all
|
---|
53 | * QEvent::Resize & QEvent::WindowStateChange events currently posted.
|
---|
54 | * This is necessary due to these two events - QEvent::Resize &
|
---|
55 | * QEvent::WindowStateChange are processed in different sequence
|
---|
56 | * under Win32 and X11. */
|
---|
57 | class AutoResizeEvent : public QEvent
|
---|
58 | {
|
---|
59 | public:
|
---|
60 | AutoResizeEvent () :
|
---|
61 | QEvent ((QEvent::Type) VBoxDefs::AutoResizeEventType) {}
|
---|
62 | };
|
---|
63 |
|
---|
64 | class VBoxConsoleView : public QScrollView
|
---|
65 | {
|
---|
66 | Q_OBJECT
|
---|
67 |
|
---|
68 | public:
|
---|
69 |
|
---|
70 | enum {
|
---|
71 | MouseCaptured = 0x01,
|
---|
72 | MouseAbsolute = 0x02,
|
---|
73 | MouseAbsoluteDisabled = 0x04,
|
---|
74 | MouseNeedsHostCursor = 0x08,
|
---|
75 | KeyboardCaptured = 0x01,
|
---|
76 | HostKeyPressed = 0x02,
|
---|
77 | };
|
---|
78 |
|
---|
79 | VBoxConsoleView (VBoxConsoleWnd *mainWnd,
|
---|
80 | const CConsole &console,
|
---|
81 | VBoxDefs::RenderMode rm,
|
---|
82 | QWidget *parent = 0, const char *name = 0, WFlags f = 0);
|
---|
83 | ~VBoxConsoleView();
|
---|
84 |
|
---|
85 | QSize sizeHint() const;
|
---|
86 |
|
---|
87 | void attach();
|
---|
88 | void detach();
|
---|
89 | void refresh() { doRefresh(); }
|
---|
90 | void normalizeGeometry (bool adjustPosition = false);
|
---|
91 |
|
---|
92 | CConsole &console() { return cconsole; }
|
---|
93 |
|
---|
94 | bool pause (bool on);
|
---|
95 |
|
---|
96 | void setMouseIntegrationEnabled (bool enabled);
|
---|
97 |
|
---|
98 | bool isMouseAbsolute() const { return mouse_absolute; }
|
---|
99 |
|
---|
100 | void setAutoresizeGuest (bool on);
|
---|
101 |
|
---|
102 | void onFullscreenChange (bool on);
|
---|
103 |
|
---|
104 | void fixModifierState (LONG *codes, uint *count);
|
---|
105 |
|
---|
106 | signals:
|
---|
107 |
|
---|
108 | void keyboardStateChanged (int state);
|
---|
109 | void mouseStateChanged (int state);
|
---|
110 | void machineStateChanged (CEnums::MachineState state);
|
---|
111 | void additionsStateChanged (const QString &, bool);
|
---|
112 |
|
---|
113 | protected:
|
---|
114 |
|
---|
115 | // events
|
---|
116 | bool event( QEvent *e );
|
---|
117 | bool eventFilter( QObject *watched, QEvent *e );
|
---|
118 |
|
---|
119 | #if defined(Q_WS_WIN32)
|
---|
120 | bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
|
---|
121 | bool winEvent (MSG *msg);
|
---|
122 | #elif defined(Q_WS_X11)
|
---|
123 | bool x11Event (XEvent *event );
|
---|
124 | #elif defined(Q_WS_MAC)
|
---|
125 | bool darwinKeyboardEvent (EventRef inEvent);
|
---|
126 | void darwinGrabKeyboardEvents (bool fGrab);
|
---|
127 | #endif
|
---|
128 |
|
---|
129 | private:
|
---|
130 |
|
---|
131 | // flags for keyEvent()
|
---|
132 | enum {
|
---|
133 | KeyExtended = 0x01,
|
---|
134 | KeyPressed = 0x02,
|
---|
135 | KeyPause = 0x04,
|
---|
136 | KeyPrint = 0x08,
|
---|
137 | };
|
---|
138 |
|
---|
139 | void focusEvent (bool focus);
|
---|
140 | bool keyEvent (int key, uint8_t scan, int flags, wchar_t *aUniKey = NULL);
|
---|
141 | bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
|
---|
142 | ButtonState aButton,
|
---|
143 | ButtonState aState, ButtonState aStateAfter,
|
---|
144 | int aWheelDelta, Orientation aWheelDir);
|
---|
145 |
|
---|
146 | void emitKeyboardStateChanged() {
|
---|
147 | emit keyboardStateChanged (
|
---|
148 | (kbd_captured ? KeyboardCaptured : 0) |
|
---|
149 | (hostkey_pressed ? HostKeyPressed : 0));
|
---|
150 | }
|
---|
151 | void emitMouseStateChanged() {
|
---|
152 | emit mouseStateChanged ((mouse_captured ? MouseCaptured : 0) |
|
---|
153 | (mouse_absolute ? MouseAbsolute : 0) |
|
---|
154 | (!mouse_integration ? MouseAbsoluteDisabled : 0));
|
---|
155 | }
|
---|
156 |
|
---|
157 | // IConsoleCallback event handlers
|
---|
158 | void onStateChange (CEnums::MachineState state);
|
---|
159 |
|
---|
160 | void doRefresh();
|
---|
161 |
|
---|
162 | void viewportPaintEvent( QPaintEvent * );
|
---|
163 | #ifdef VBOX_GUI_USE_REFRESH_TIMER
|
---|
164 | void timerEvent( QTimerEvent * );
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | void captureKbd (bool capture, bool emit_signal = true);
|
---|
168 | void captureMouse (bool capture, bool emit_signal = true);
|
---|
169 |
|
---|
170 | bool processHotKey (const QKeySequence &key, QMenuData *data);
|
---|
171 | void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
|
---|
172 |
|
---|
173 | void releaseAllKeysPressed (bool release_hostkey = true);
|
---|
174 | void saveKeyStates();
|
---|
175 | void sendChangedKeyStates();
|
---|
176 | void updateMouseClipping();
|
---|
177 |
|
---|
178 | void setPointerShape (MousePointerChangeEvent *me);
|
---|
179 |
|
---|
180 | bool isPaused() { return last_state == CEnums::Paused; }
|
---|
181 | bool isRunning() { return last_state == CEnums::Running; }
|
---|
182 |
|
---|
183 | static void dimImage (QImage &img);
|
---|
184 |
|
---|
185 | void performAutoResize();
|
---|
186 |
|
---|
187 | private slots:
|
---|
188 |
|
---|
189 | void doResizeHint();
|
---|
190 | void normalizeGeo() { normalizeGeometry (true); }
|
---|
191 |
|
---|
192 | private:
|
---|
193 |
|
---|
194 | VBoxConsoleWnd *mainwnd;
|
---|
195 |
|
---|
196 | CConsole cconsole;
|
---|
197 |
|
---|
198 | const VBoxGlobalSettings &gs;
|
---|
199 |
|
---|
200 | CEnums::MachineState last_state;
|
---|
201 |
|
---|
202 | bool attached : 1;
|
---|
203 | bool kbd_captured : 1;
|
---|
204 | bool mouse_captured : 1;
|
---|
205 | bool mouse_absolute : 1;
|
---|
206 | bool mouse_integration : 1;
|
---|
207 | QPoint last_pos;
|
---|
208 | QPoint captured_pos;
|
---|
209 |
|
---|
210 | enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
|
---|
211 | uint8_t keys_pressed[128];
|
---|
212 | uint8_t keys_pressed_copy[128];
|
---|
213 |
|
---|
214 | bool hostkey_pressed : 1;
|
---|
215 | bool hostkey_alone : 1;
|
---|
216 | /** kbd_captured value during the the last host key press or release */
|
---|
217 | bool hostkey_in_capture : 1;
|
---|
218 |
|
---|
219 | bool ignore_mainwnd_resize : 1;
|
---|
220 | bool autoresize_guest : 1;
|
---|
221 |
|
---|
222 | bool mfNumLock : 1;
|
---|
223 | bool mfScrollLock : 1;
|
---|
224 | bool mfCapsLock : 1;
|
---|
225 | long muNumLockAdaptionCnt;
|
---|
226 | long muCapsLockAdaptionCnt;
|
---|
227 |
|
---|
228 | QTimer *resize_hint_timer;
|
---|
229 |
|
---|
230 | VBoxDefs::RenderMode mode;
|
---|
231 |
|
---|
232 | #if defined(Q_WS_WIN)
|
---|
233 | HCURSOR mAlphaCursor;
|
---|
234 | #endif
|
---|
235 |
|
---|
236 | #if defined(Q_WS_MAC)
|
---|
237 | # ifndef VBOX_WITH_HACKED_QT
|
---|
238 | /** Event handler reference. NULL if the handler isn't installed. */
|
---|
239 | EventHandlerRef m_darwinEventHandlerRef;
|
---|
240 | # endif
|
---|
241 | /** The current modifier key mask. Used to figure out which modifier
|
---|
242 | * key was pressed when we get a kEventRawKeyModifiersChanged event. */
|
---|
243 | UInt32 m_darwinKeyModifiers;
|
---|
244 | /** The darwin cursor handle (see DarwinCursor.h/.cpp). */
|
---|
245 | DARWINCURSOR m_darwinCursor;
|
---|
246 | #endif
|
---|
247 |
|
---|
248 | #if defined (VBOX_GUI_USE_REFRESH_TIMER)
|
---|
249 | QPixmap pm;
|
---|
250 | int tid; /**< Timer id */
|
---|
251 | #endif
|
---|
252 |
|
---|
253 | VBoxFrameBuffer *fb;
|
---|
254 | CConsoleCallback callback;
|
---|
255 |
|
---|
256 | friend class VBoxConsoleCallback;
|
---|
257 |
|
---|
258 | #if defined (Q_WS_WIN32)
|
---|
259 | static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
|
---|
260 | WPARAM wParam, LPARAM lParam);
|
---|
261 | #elif defined (Q_WS_MAC)
|
---|
262 | # ifndef VBOX_WITH_HACKED_QT
|
---|
263 | static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
|
---|
264 | EventRef inEvent, void *inUserData);
|
---|
265 | # else /* VBOX_WITH_HACKED_QT */
|
---|
266 | static bool macEventFilter (EventRef inEvent, void *inUserData);
|
---|
267 | # endif /* VBOX_WITH_HACKED_QT */
|
---|
268 | #endif
|
---|
269 |
|
---|
270 | QPixmap mPausedShot;
|
---|
271 | };
|
---|
272 |
|
---|
273 | #endif // __VBoxConsoleView_h__
|
---|
274 |
|
---|