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