1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxConsoleView class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
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 | /* Qt includes */
|
---|
32 | #include <QAbstractScrollArea>
|
---|
33 | #include <QScrollBar>
|
---|
34 |
|
---|
35 | #if defined (Q_WS_PM)
|
---|
36 | #include "src/os2/VBoxHlp.h"
|
---|
37 | #define UM_PREACCEL_CHAR WM_USER
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | #if defined (Q_WS_MAC)
|
---|
41 | # include <ApplicationServices/ApplicationServices.h>
|
---|
42 | # ifndef QT_MAC_USE_COCOA
|
---|
43 | # include <Carbon/Carbon.h>
|
---|
44 | # endif /* !QT_MAC_USE_COCOA */
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | class VBoxConsoleWnd;
|
---|
48 | class MousePointerChangeEvent;
|
---|
49 | class VBoxFrameBuffer;
|
---|
50 | class VBoxDockIconPreview;
|
---|
51 |
|
---|
52 | class QPainter;
|
---|
53 | class QLabel;
|
---|
54 | class QMenuData;
|
---|
55 |
|
---|
56 | class VBoxConsoleView : public QAbstractScrollArea
|
---|
57 | {
|
---|
58 | Q_OBJECT
|
---|
59 |
|
---|
60 | public:
|
---|
61 |
|
---|
62 | enum {
|
---|
63 | MouseCaptured = 0x01,
|
---|
64 | MouseAbsolute = 0x02,
|
---|
65 | MouseAbsoluteDisabled = 0x04,
|
---|
66 | MouseNeedsHostCursor = 0x08,
|
---|
67 | KeyboardCaptured = 0x01,
|
---|
68 | HostKeyPressed = 0x02,
|
---|
69 | };
|
---|
70 |
|
---|
71 | VBoxConsoleView (VBoxConsoleWnd *mainWnd,
|
---|
72 | const CConsole &console,
|
---|
73 | VBoxDefs::RenderMode rm,
|
---|
74 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
75 | bool accelerate2DVideo,
|
---|
76 | #endif
|
---|
77 | QWidget *parent = 0);
|
---|
78 | ~VBoxConsoleView();
|
---|
79 |
|
---|
80 | QSize sizeHint() const;
|
---|
81 |
|
---|
82 | void attach();
|
---|
83 | void detach();
|
---|
84 | void refresh() { doRefresh(); }
|
---|
85 | void normalizeGeometry (bool adjustPosition = false);
|
---|
86 |
|
---|
87 | CConsole &console() { return mConsole; }
|
---|
88 |
|
---|
89 | bool pause (bool on);
|
---|
90 | bool isPaused() { return mLastState == KMachineState_Paused; }
|
---|
91 | const QPixmap& pauseShot() const { return mPausedShot; }
|
---|
92 |
|
---|
93 | void setMouseIntegrationEnabled (bool enabled);
|
---|
94 |
|
---|
95 | bool isMouseAbsolute() const { return mMouseAbsolute; }
|
---|
96 |
|
---|
97 | bool shouldHideHostPointer() const
|
---|
98 | { return mMouseCaptured || (mMouseAbsolute && mHideHostPointer); }
|
---|
99 |
|
---|
100 | void setAutoresizeGuest (bool on);
|
---|
101 |
|
---|
102 | void onFullscreenChange (bool on);
|
---|
103 |
|
---|
104 | void onViewOpened();
|
---|
105 |
|
---|
106 | void fixModifierState (LONG *codes, uint *count);
|
---|
107 |
|
---|
108 | void toggleFSMode (const QSize &aSize = QSize());
|
---|
109 |
|
---|
110 | void setIgnoreMainwndResize (bool aYes) { mIgnoreMainwndResize = aYes; }
|
---|
111 |
|
---|
112 | QRect desktopGeometry();
|
---|
113 |
|
---|
114 | QRegion lastVisibleRegion() const;
|
---|
115 |
|
---|
116 | bool isAutoresizeGuestActive();
|
---|
117 |
|
---|
118 | /* todo: This are some support functions for the qt4 port. Maybe we get rid
|
---|
119 | * of them some day. */
|
---|
120 | int contentsX() const { return horizontalScrollBar()->value(); }
|
---|
121 | int contentsY() const { return verticalScrollBar()->value(); }
|
---|
122 | int contentsWidth() const;
|
---|
123 | int contentsHeight() const;
|
---|
124 | int visibleWidth() const { return horizontalScrollBar()->pageStep(); }
|
---|
125 | int visibleHeight() const { return verticalScrollBar()->pageStep(); }
|
---|
126 | void scrollBy (int dx, int dy)
|
---|
127 | {
|
---|
128 | horizontalScrollBar()->setValue (horizontalScrollBar()->value() + dx);
|
---|
129 | verticalScrollBar()->setValue (verticalScrollBar()->value() + dy);
|
---|
130 | }
|
---|
131 | QPoint viewportToContents ( const QPoint & vp ) const
|
---|
132 | {
|
---|
133 | return QPoint (vp.x() + contentsX(),
|
---|
134 | vp.y() + contentsY());
|
---|
135 | }
|
---|
136 | void updateSliders();
|
---|
137 |
|
---|
138 | void requestToResize (const QSize &aSize);
|
---|
139 |
|
---|
140 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
141 | void scrollContentsBy (int dx, int dy);
|
---|
142 | #endif
|
---|
143 |
|
---|
144 | #if defined(Q_WS_MAC)
|
---|
145 | void updateDockIcon();
|
---|
146 | void updateDockOverlay();
|
---|
147 | void setDockIconEnabled (bool aOn) { mDockIconEnabled = aOn; };
|
---|
148 | void setMouseCoalescingEnabled (bool aOn);
|
---|
149 | #endif
|
---|
150 |
|
---|
151 | signals:
|
---|
152 |
|
---|
153 | void keyboardStateChanged (int state);
|
---|
154 | void mouseStateChanged (int state);
|
---|
155 | void machineStateChanged (KMachineState state);
|
---|
156 | void additionsStateChanged (const QString &, bool, bool, bool);
|
---|
157 | void mediaDriveChanged (VBoxDefs::MediumType aType);
|
---|
158 | void networkStateChange();
|
---|
159 | void usbStateChange();
|
---|
160 | void sharedFoldersChanged();
|
---|
161 | void resizeHintDone();
|
---|
162 |
|
---|
163 | protected:
|
---|
164 |
|
---|
165 | // events
|
---|
166 | bool event (QEvent *e);
|
---|
167 | bool eventFilter (QObject *watched, QEvent *e);
|
---|
168 |
|
---|
169 | #if defined(Q_WS_WIN32)
|
---|
170 | bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
|
---|
171 | bool winEvent (MSG *aMsg, long *aResult);
|
---|
172 | #elif defined(Q_WS_PM)
|
---|
173 | bool pmEvent (QMSG *aMsg);
|
---|
174 | #elif defined(Q_WS_X11)
|
---|
175 | bool x11Event (XEvent *event);
|
---|
176 | #elif defined(Q_WS_MAC)
|
---|
177 | bool darwinKeyboardEvent (const void *pvCocoaEvent, EventRef inEvent);
|
---|
178 | void darwinGrabKeyboardEvents (bool fGrab);
|
---|
179 | #endif
|
---|
180 |
|
---|
181 | private:
|
---|
182 |
|
---|
183 | /** Flags for keyEvent(). */
|
---|
184 | enum {
|
---|
185 | KeyExtended = 0x01,
|
---|
186 | KeyPressed = 0x02,
|
---|
187 | KeyPause = 0x04,
|
---|
188 | KeyPrint = 0x08,
|
---|
189 | };
|
---|
190 |
|
---|
191 | void focusEvent (bool aHasFocus, bool aReleaseHostKey = true);
|
---|
192 | bool keyEvent (int aKey, uint8_t aScan, int aFlags,
|
---|
193 | wchar_t *aUniKey = NULL);
|
---|
194 | bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
|
---|
195 | Qt::MouseButtons aButtons, Qt::KeyboardModifiers aModifiers,
|
---|
196 | int aWheelDelta, Qt::Orientation aWheelDir);
|
---|
197 |
|
---|
198 | void emitKeyboardStateChanged()
|
---|
199 | {
|
---|
200 | emit keyboardStateChanged (
|
---|
201 | (mKbdCaptured ? KeyboardCaptured : 0) |
|
---|
202 | (mIsHostkeyPressed ? HostKeyPressed : 0));
|
---|
203 | }
|
---|
204 |
|
---|
205 | void emitMouseStateChanged() {
|
---|
206 | emit mouseStateChanged ((mMouseCaptured ? MouseCaptured : 0) |
|
---|
207 | (mMouseAbsolute ? MouseAbsolute : 0) |
|
---|
208 | (!mMouseIntegration ? MouseAbsoluteDisabled : 0));
|
---|
209 | }
|
---|
210 |
|
---|
211 | // IConsoleCallback event handlers
|
---|
212 | void onStateChange (KMachineState state);
|
---|
213 |
|
---|
214 | void doRefresh();
|
---|
215 |
|
---|
216 | void resizeEvent (QResizeEvent *);
|
---|
217 | void moveEvent (QMoveEvent *);
|
---|
218 | void paintEvent (QPaintEvent *);
|
---|
219 |
|
---|
220 | void captureKbd (bool aCapture, bool aEmitSignal = true);
|
---|
221 | void captureMouse (bool aCapture, bool aEmitSignal = true);
|
---|
222 |
|
---|
223 | bool processHotKey (const QKeySequence &key, const QList<QAction*>& data);
|
---|
224 | void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
|
---|
225 |
|
---|
226 | void releaseAllPressedKeys (bool aReleaseHostKey = true);
|
---|
227 | void saveKeyStates();
|
---|
228 | void sendChangedKeyStates();
|
---|
229 | void updateMouseClipping();
|
---|
230 |
|
---|
231 | void setPointerShape (MousePointerChangeEvent *me);
|
---|
232 |
|
---|
233 | bool isRunning() { return mLastState == KMachineState_Running; }
|
---|
234 |
|
---|
235 | static void dimImage (QImage &img);
|
---|
236 |
|
---|
237 | private slots:
|
---|
238 |
|
---|
239 | void doResizeHint (const QSize &aSize = QSize());
|
---|
240 | void doResizeDesktop (int);
|
---|
241 |
|
---|
242 | private:
|
---|
243 |
|
---|
244 | enum DesktopGeo
|
---|
245 | {
|
---|
246 | DesktopGeo_Invalid = 0, DesktopGeo_Fixed,
|
---|
247 | DesktopGeo_Automatic, DesktopGeo_Any
|
---|
248 | };
|
---|
249 |
|
---|
250 | void setDesktopGeometry (DesktopGeo aGeo, int aWidth, int aHeight);
|
---|
251 | void setDesktopGeoHint (int aWidth, int aHeight);
|
---|
252 | void calculateDesktopGeometry();
|
---|
253 | void maybeRestrictMinimumSize();
|
---|
254 |
|
---|
255 | VBoxConsoleWnd *mMainWnd;
|
---|
256 |
|
---|
257 | CConsole mConsole;
|
---|
258 |
|
---|
259 | const VBoxGlobalSettings &gs;
|
---|
260 |
|
---|
261 | KMachineState mLastState;
|
---|
262 |
|
---|
263 | bool mAttached : 1;
|
---|
264 | bool mKbdCaptured : 1;
|
---|
265 | bool mMouseCaptured : 1;
|
---|
266 | bool mMouseAbsolute : 1;
|
---|
267 | bool mMouseIntegration : 1;
|
---|
268 | QPoint mLastPos;
|
---|
269 | QPoint mCapturedPos;
|
---|
270 |
|
---|
271 | bool mDisableAutoCapture : 1;
|
---|
272 |
|
---|
273 | enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
|
---|
274 | uint8_t mPressedKeys [128];
|
---|
275 | uint8_t mPressedKeysCopy [128];
|
---|
276 |
|
---|
277 | bool mIsHostkeyPressed : 1;
|
---|
278 | bool mIsHostkeyAlone : 1;
|
---|
279 |
|
---|
280 | /** mKbdCaptured value during the the last host key press or release */
|
---|
281 | bool hostkey_in_capture : 1;
|
---|
282 |
|
---|
283 | bool mIgnoreMainwndResize : 1;
|
---|
284 | bool mAutoresizeGuest : 1;
|
---|
285 | bool mIgnoreFrameBufferResize : 1;
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * This flag indicates whether the last console resize should trigger
|
---|
289 | * a size hint to the guest. This is important particularly when
|
---|
290 | * enabling the autoresize feature to know whether to send a hint.
|
---|
291 | */
|
---|
292 | bool mDoResize : 1;
|
---|
293 |
|
---|
294 | bool mGuestSupportsGraphics : 1;
|
---|
295 |
|
---|
296 | bool mNumLock : 1;
|
---|
297 | bool mScrollLock : 1;
|
---|
298 | bool mCapsLock : 1;
|
---|
299 | long muNumLockAdaptionCnt;
|
---|
300 | long muCapsLockAdaptionCnt;
|
---|
301 |
|
---|
302 |
|
---|
303 | VBoxDefs::RenderMode mode;
|
---|
304 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
305 | bool mAccelerate2DVideo;
|
---|
306 | #endif
|
---|
307 |
|
---|
308 | QRegion mLastVisibleRegion;
|
---|
309 | QSize mNormalSize;
|
---|
310 |
|
---|
311 | #if defined(Q_WS_WIN)
|
---|
312 | HCURSOR mAlphaCursor;
|
---|
313 | #endif
|
---|
314 |
|
---|
315 | #if defined(Q_WS_MAC)
|
---|
316 | # if !defined (VBOX_WITH_HACKED_QT) && !defined (QT_MAC_USE_COCOA)
|
---|
317 | /** Event handler reference. NULL if the handler isn't installed. */
|
---|
318 | EventHandlerRef mDarwinEventHandlerRef;
|
---|
319 | # endif
|
---|
320 | /** The current modifier key mask. Used to figure out which modifier
|
---|
321 | * key was pressed when we get a kEventRawKeyModifiersChanged event. */
|
---|
322 | UInt32 mDarwinKeyModifiers;
|
---|
323 | bool mKeyboardGrabbed;
|
---|
324 | #endif
|
---|
325 |
|
---|
326 | VBoxFrameBuffer *mFrameBuf;
|
---|
327 | CConsoleCallback mCallback;
|
---|
328 |
|
---|
329 | friend class VBoxConsoleCallback;
|
---|
330 |
|
---|
331 | #if defined (Q_WS_WIN32)
|
---|
332 | static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
|
---|
333 | WPARAM wParam, LPARAM lParam);
|
---|
334 | #elif defined (Q_WS_MAC)
|
---|
335 | # if defined (QT_MAC_USE_COCOA)
|
---|
336 | static bool darwinEventHandlerProc (const void *pvCocoaEvent, const
|
---|
337 | void *pvCarbonEvent, void *pvUser);
|
---|
338 | # elif !defined (VBOX_WITH_HACKED_QT)
|
---|
339 | static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
|
---|
340 | EventRef inEvent, void *inUserData);
|
---|
341 | # else /* VBOX_WITH_HACKED_QT */
|
---|
342 | static bool macEventFilter (EventRef inEvent, void *inUserData);
|
---|
343 | # endif /* VBOX_WITH_HACKED_QT */
|
---|
344 | #endif
|
---|
345 |
|
---|
346 | QPixmap mPausedShot;
|
---|
347 | #if defined(Q_WS_MAC)
|
---|
348 | # if !defined (QT_MAC_USE_COCOA)
|
---|
349 | EventHandlerRef mDarwinWindowOverlayHandlerRef;
|
---|
350 | # endif
|
---|
351 | VBoxDockIconPreview *mDockIconPreview;
|
---|
352 | bool mDockIconEnabled;
|
---|
353 | #endif
|
---|
354 | DesktopGeo mDesktopGeo;
|
---|
355 | QRect mDesktopGeometry;
|
---|
356 | QRect mLastSizeHint;
|
---|
357 | bool mPassCAD;
|
---|
358 | bool mHideHostPointer;
|
---|
359 | QCursor mLastCursor;
|
---|
360 | };
|
---|
361 |
|
---|
362 | #endif // !___VBoxConsoleView_h___
|
---|
363 |
|
---|