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