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 (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef __VBoxConsoleView_h__
|
---|
20 | #define __VBoxConsoleView_h__
|
---|
21 |
|
---|
22 | #include "COMDefs.h"
|
---|
23 |
|
---|
24 | #include "VBoxDefs.h"
|
---|
25 | #include "VBoxGlobalSettings.h"
|
---|
26 |
|
---|
27 | #include <qdatetime.h>
|
---|
28 | #include <q3scrollview.h>
|
---|
29 | #include <qpixmap.h>
|
---|
30 | #include <qimage.h>
|
---|
31 |
|
---|
32 | #include <qkeysequence.h>
|
---|
33 | //Added by qt3to4:
|
---|
34 | #include <QTimerEvent>
|
---|
35 | #include <QPaintEvent>
|
---|
36 | #include <QLabel>
|
---|
37 | #include <QEvent>
|
---|
38 |
|
---|
39 | #if defined (Q_WS_PM)
|
---|
40 | #include "src/os2/VBoxHlp.h"
|
---|
41 | #define UM_PREACCEL_CHAR WM_USER
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | #if defined (Q_WS_MAC)
|
---|
45 | # include <Carbon/Carbon.h>
|
---|
46 | # include "DarwinCursor.h"
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | class VBoxConsoleWnd;
|
---|
50 | class MousePointerChangeEvent;
|
---|
51 | class VBoxFrameBuffer;
|
---|
52 |
|
---|
53 | class QPainter;
|
---|
54 | class QLabel;
|
---|
55 | class QMenuData;
|
---|
56 |
|
---|
57 | class VBoxConsoleView : public Q3ScrollView
|
---|
58 | {
|
---|
59 | Q_OBJECT
|
---|
60 |
|
---|
61 | public:
|
---|
62 |
|
---|
63 | enum {
|
---|
64 | MouseCaptured = 0x01,
|
---|
65 | MouseAbsolute = 0x02,
|
---|
66 | MouseAbsoluteDisabled = 0x04,
|
---|
67 | MouseNeedsHostCursor = 0x08,
|
---|
68 | KeyboardCaptured = 0x01,
|
---|
69 | HostKeyPressed = 0x02,
|
---|
70 | };
|
---|
71 |
|
---|
72 | VBoxConsoleView (VBoxConsoleWnd *mainWnd,
|
---|
73 | const CConsole &console,
|
---|
74 | VBoxDefs::RenderMode rm,
|
---|
75 | QWidget *parent = 0, const char *name = 0, Qt::WFlags f = 0);
|
---|
76 | ~VBoxConsoleView();
|
---|
77 |
|
---|
78 | QSize sizeHint() const;
|
---|
79 |
|
---|
80 | void attach();
|
---|
81 | void detach();
|
---|
82 | void refresh() { doRefresh(); }
|
---|
83 | void normalizeGeometry (bool adjustPosition = false);
|
---|
84 |
|
---|
85 | CConsole &console() { return mConsole; }
|
---|
86 |
|
---|
87 | bool pause (bool on);
|
---|
88 |
|
---|
89 | void setMouseIntegrationEnabled (bool enabled);
|
---|
90 |
|
---|
91 | bool isMouseAbsolute() const { return mMouseAbsolute; }
|
---|
92 |
|
---|
93 | void setAutoresizeGuest (bool on);
|
---|
94 |
|
---|
95 | void onFullscreenChange (bool on);
|
---|
96 |
|
---|
97 | void onViewOpened();
|
---|
98 |
|
---|
99 | void fixModifierState (LONG *codes, uint *count);
|
---|
100 |
|
---|
101 | void toggleFSMode();
|
---|
102 |
|
---|
103 | void setIgnoreMainwndResize (bool aYes) { mIgnoreMainwndResize = aYes; }
|
---|
104 |
|
---|
105 | signals:
|
---|
106 |
|
---|
107 | void keyboardStateChanged (int state);
|
---|
108 | void mouseStateChanged (int state);
|
---|
109 | void machineStateChanged (KMachineState state);
|
---|
110 | void additionsStateChanged (const QString &, bool, bool);
|
---|
111 | void mediaChanged (VBoxDefs::DiskType aType);
|
---|
112 | void networkStateChange();
|
---|
113 | void usbStateChange();
|
---|
114 | void sharedFoldersChanged();
|
---|
115 | void resizeHintDone();
|
---|
116 |
|
---|
117 | protected:
|
---|
118 |
|
---|
119 | // events
|
---|
120 | bool event (QEvent *e);
|
---|
121 | bool eventFilter (QObject *watched, QEvent *e);
|
---|
122 |
|
---|
123 | #if defined(Q_WS_WIN32)
|
---|
124 | bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
|
---|
125 | bool winEvent (MSG *msg);
|
---|
126 | #elif defined(Q_WS_PM)
|
---|
127 | bool pmEvent (QMSG *aMsg);
|
---|
128 | #elif defined(Q_WS_X11)
|
---|
129 | bool x11Event (XEvent *event);
|
---|
130 | #elif defined(Q_WS_MAC)
|
---|
131 | bool darwinKeyboardEvent (EventRef inEvent);
|
---|
132 | void darwinGrabKeyboardEvents (bool fGrab);
|
---|
133 | #endif
|
---|
134 |
|
---|
135 | private:
|
---|
136 |
|
---|
137 | /** Flags for keyEvent(). */
|
---|
138 | enum {
|
---|
139 | KeyExtended = 0x01,
|
---|
140 | KeyPressed = 0x02,
|
---|
141 | KeyPause = 0x04,
|
---|
142 | KeyPrint = 0x08,
|
---|
143 | };
|
---|
144 |
|
---|
145 | void focusEvent (bool aHasFocus, bool aReleaseHostKey = true);
|
---|
146 | bool keyEvent (int aKey, uint8_t aScan, int aFlags,
|
---|
147 | wchar_t *aUniKey = NULL);
|
---|
148 | bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
|
---|
149 | Qt::ButtonState aButton,
|
---|
150 | Qt::ButtonState aState, Qt::ButtonState aStateAfter,
|
---|
151 | int aWheelDelta, Qt::Orientation aWheelDir);
|
---|
152 |
|
---|
153 | void emitKeyboardStateChanged()
|
---|
154 | {
|
---|
155 | emit keyboardStateChanged (
|
---|
156 | (mKbdCaptured ? KeyboardCaptured : 0) |
|
---|
157 | (mIsHostkeyPressed ? HostKeyPressed : 0));
|
---|
158 | }
|
---|
159 |
|
---|
160 | void emitMouseStateChanged() {
|
---|
161 | emit mouseStateChanged ((mMouseCaptured ? MouseCaptured : 0) |
|
---|
162 | (mMouseAbsolute ? MouseAbsolute : 0) |
|
---|
163 | (!mMouseIntegration ? MouseAbsoluteDisabled : 0));
|
---|
164 | }
|
---|
165 |
|
---|
166 | // IConsoleCallback event handlers
|
---|
167 | void onStateChange (KMachineState state);
|
---|
168 |
|
---|
169 | void doRefresh();
|
---|
170 |
|
---|
171 | void viewportPaintEvent( QPaintEvent * );
|
---|
172 | #ifdef VBOX_GUI_USE_REFRESH_TIMER
|
---|
173 | void timerEvent( QTimerEvent * );
|
---|
174 | #endif
|
---|
175 |
|
---|
176 | void captureKbd (bool aCapture, bool aEmitSignal = true);
|
---|
177 | void captureMouse (bool aCapture, bool aEmitSignal = true);
|
---|
178 |
|
---|
179 | bool processHotKey (const QKeySequence &key, QMenuData *data);
|
---|
180 | void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
|
---|
181 |
|
---|
182 | void releaseAllPressedKeys (bool aReleaseHostKey = true);
|
---|
183 | void saveKeyStates();
|
---|
184 | void sendChangedKeyStates();
|
---|
185 | void updateMouseClipping();
|
---|
186 |
|
---|
187 | void setPointerShape (MousePointerChangeEvent *me);
|
---|
188 |
|
---|
189 | bool isPaused() { return mLastState == KMachineState_Paused; }
|
---|
190 | bool isRunning() { return mLastState == KMachineState_Running; }
|
---|
191 |
|
---|
192 | static void dimImage (QImage &img);
|
---|
193 |
|
---|
194 | private slots:
|
---|
195 |
|
---|
196 | void doResizeHint (const QSize &aSize = QSize());
|
---|
197 |
|
---|
198 | private:
|
---|
199 |
|
---|
200 | void maybeRestrictMinimumSize();
|
---|
201 |
|
---|
202 | VBoxConsoleWnd *mMainWnd;
|
---|
203 |
|
---|
204 | CConsole mConsole;
|
---|
205 |
|
---|
206 | const VBoxGlobalSettings &gs;
|
---|
207 |
|
---|
208 | KMachineState mLastState;
|
---|
209 |
|
---|
210 | bool mAttached : 1;
|
---|
211 | bool mKbdCaptured : 1;
|
---|
212 | bool mMouseCaptured : 1;
|
---|
213 | bool mMouseAbsolute : 1;
|
---|
214 | bool mMouseIntegration : 1;
|
---|
215 | QPoint mLastPos;
|
---|
216 | QPoint mCapturedPos;
|
---|
217 |
|
---|
218 | bool mDisableAutoCapture : 1;
|
---|
219 |
|
---|
220 | enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
|
---|
221 | uint8_t mPressedKeys [128];
|
---|
222 | uint8_t mPressedKeysCopy [128];
|
---|
223 |
|
---|
224 | bool mIsHostkeyPressed : 1;
|
---|
225 | bool mIsHostkeyAlone : 1;
|
---|
226 |
|
---|
227 | /** mKbdCaptured value during the the last host key press or release */
|
---|
228 | bool hostkey_in_capture : 1;
|
---|
229 |
|
---|
230 | bool mIgnoreMainwndResize : 1;
|
---|
231 | bool mAutoresizeGuest : 1;
|
---|
232 |
|
---|
233 | bool mIsAdditionsActive : 1;
|
---|
234 |
|
---|
235 | bool mNumLock : 1;
|
---|
236 | bool mScrollLock : 1;
|
---|
237 | bool mCapsLock : 1;
|
---|
238 | long muNumLockAdaptionCnt;
|
---|
239 | long muCapsLockAdaptionCnt;
|
---|
240 |
|
---|
241 | QTimer *resize_hint_timer;
|
---|
242 | QTimer *mToggleFSModeTimer;
|
---|
243 |
|
---|
244 | VBoxDefs::RenderMode mode;
|
---|
245 |
|
---|
246 | QRegion mLastVisibleRegion;
|
---|
247 | QSize mNormalSize;
|
---|
248 |
|
---|
249 | #if defined(Q_WS_WIN)
|
---|
250 | HCURSOR mAlphaCursor;
|
---|
251 | #endif
|
---|
252 |
|
---|
253 | #if defined(Q_WS_MAC)
|
---|
254 | # ifndef VBOX_WITH_HACKED_QT
|
---|
255 | /** Event handler reference. NULL if the handler isn't installed. */
|
---|
256 | EventHandlerRef mDarwinEventHandlerRef;
|
---|
257 | # endif
|
---|
258 | /** The current modifier key mask. Used to figure out which modifier
|
---|
259 | * key was pressed when we get a kEventRawKeyModifiersChanged event. */
|
---|
260 | UInt32 mDarwinKeyModifiers;
|
---|
261 | /** The darwin cursor handle (see DarwinCursor.h/.cpp). */
|
---|
262 | DARWINCURSOR mDarwinCursor;
|
---|
263 | #endif
|
---|
264 |
|
---|
265 | #if defined (VBOX_GUI_USE_REFRESH_TIMER)
|
---|
266 | QPixmap pm;
|
---|
267 | int tid; /**< Timer id */
|
---|
268 | #endif
|
---|
269 |
|
---|
270 | VBoxFrameBuffer *mFrameBuf;
|
---|
271 | CConsoleCallback mCallback;
|
---|
272 |
|
---|
273 | friend class VBoxConsoleCallback;
|
---|
274 |
|
---|
275 | #if defined (Q_WS_WIN32)
|
---|
276 | static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
|
---|
277 | WPARAM wParam, LPARAM lParam);
|
---|
278 | #elif defined (Q_WS_MAC)
|
---|
279 | # ifndef VBOX_WITH_HACKED_QT
|
---|
280 | static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
|
---|
281 | EventRef inEvent, void *inUserData);
|
---|
282 | # else /* VBOX_WITH_HACKED_QT */
|
---|
283 | static bool macEventFilter (EventRef inEvent, void *inUserData);
|
---|
284 | # endif /* VBOX_WITH_HACKED_QT */
|
---|
285 | #endif
|
---|
286 |
|
---|
287 | QPixmap mPausedShot;
|
---|
288 | #if defined(Q_WS_MAC)
|
---|
289 | CGImageRef mVirtualBoxLogo;
|
---|
290 | #endif
|
---|
291 | };
|
---|
292 |
|
---|
293 | #endif // __VBoxConsoleView_h__
|
---|
294 |
|
---|