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