VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleView.h@ 15164

Last change on this file since 15164 was 15164, checked in by vboxsync, 16 years ago

FE/Qt: pass Ctrl-Alt-Del to Windows guests if the user wishes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
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
44class VBoxConsoleWnd;
45class MousePointerChangeEvent;
46class VBoxFrameBuffer;
47
48class QPainter;
49class QLabel;
50class QMenuData;
51
52class VBoxConsoleView : public QAbstractScrollArea
53{
54 Q_OBJECT
55
56public:
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#endif
132
133signals:
134
135 void keyboardStateChanged (int state);
136 void mouseStateChanged (int state);
137 void machineStateChanged (KMachineState state);
138 void additionsStateChanged (const QString &, bool, bool, bool);
139 void mediaDriveChanged (VBoxDefs::MediaType aType);
140 void networkStateChange();
141 void usbStateChange();
142 void sharedFoldersChanged();
143 void resizeHintDone();
144
145protected:
146
147 // events
148 bool event (QEvent *e);
149 bool eventFilter (QObject *watched, QEvent *e);
150
151#if defined(Q_WS_WIN32)
152 bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
153 bool winEvent (MSG *aMsg, long *aResult);
154#elif defined(Q_WS_PM)
155 bool pmEvent (QMSG *aMsg);
156#elif defined(Q_WS_X11)
157 bool x11Event (XEvent *event);
158#elif defined(Q_WS_MAC)
159 bool darwinKeyboardEvent (EventRef inEvent);
160 void darwinGrabKeyboardEvents (bool fGrab);
161#endif
162
163private:
164
165 /** Flags for keyEvent(). */
166 enum {
167 KeyExtended = 0x01,
168 KeyPressed = 0x02,
169 KeyPause = 0x04,
170 KeyPrint = 0x08,
171 };
172
173 void focusEvent (bool aHasFocus, bool aReleaseHostKey = true);
174 bool keyEvent (int aKey, uint8_t aScan, int aFlags,
175 wchar_t *aUniKey = NULL);
176 bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
177 Qt::MouseButtons aButtons, Qt::KeyboardModifiers aModifiers,
178 int aWheelDelta, Qt::Orientation aWheelDir);
179
180 void emitKeyboardStateChanged()
181 {
182 emit keyboardStateChanged (
183 (mKbdCaptured ? KeyboardCaptured : 0) |
184 (mIsHostkeyPressed ? HostKeyPressed : 0));
185 }
186
187 void emitMouseStateChanged() {
188 emit mouseStateChanged ((mMouseCaptured ? MouseCaptured : 0) |
189 (mMouseAbsolute ? MouseAbsolute : 0) |
190 (!mMouseIntegration ? MouseAbsoluteDisabled : 0));
191 }
192
193 // IConsoleCallback event handlers
194 void onStateChange (KMachineState state);
195
196 void doRefresh();
197
198 void resizeEvent (QResizeEvent *);
199 void paintEvent (QPaintEvent *);
200
201 void captureKbd (bool aCapture, bool aEmitSignal = true);
202 void captureMouse (bool aCapture, bool aEmitSignal = true);
203
204 bool processHotKey (const QKeySequence &key, const QList<QAction*>& data);
205 void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
206
207 void releaseAllPressedKeys (bool aReleaseHostKey = true);
208 void saveKeyStates();
209 void sendChangedKeyStates();
210 void updateMouseClipping();
211
212 void setPointerShape (MousePointerChangeEvent *me);
213
214 bool isRunning() { return mLastState == KMachineState_Running; }
215
216 static void dimImage (QImage &img);
217
218private slots:
219
220 void doResizeHint (const QSize &aSize = QSize());
221 void doResizeDesktop (int);
222
223private:
224
225 enum DesktopGeo
226 {
227 DesktopGeo_Invalid = 0, DesktopGeo_Fixed,
228 DesktopGeo_Automatic, DesktopGeo_Any
229 };
230
231 void setDesktopGeometry (DesktopGeo aGeo, int aWidth, int aHeight);
232 void setDesktopGeoHint (int aWidth, int aHeight);
233 void calculateDesktopGeometry();
234 void maybeRestrictMinimumSize();
235
236 VBoxConsoleWnd *mMainWnd;
237
238 CConsole mConsole;
239
240 const VBoxGlobalSettings &gs;
241
242 KMachineState mLastState;
243
244 bool mAttached : 1;
245 bool mKbdCaptured : 1;
246 bool mMouseCaptured : 1;
247 bool mMouseAbsolute : 1;
248 bool mMouseIntegration : 1;
249 QPoint mLastPos;
250 QPoint mCapturedPos;
251
252 bool mDisableAutoCapture : 1;
253
254 enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
255 uint8_t mPressedKeys [128];
256 uint8_t mPressedKeysCopy [128];
257
258 bool mIsHostkeyPressed : 1;
259 bool mIsHostkeyAlone : 1;
260
261 /** mKbdCaptured value during the the last host key press or release */
262 bool hostkey_in_capture : 1;
263
264 bool mIgnoreMainwndResize : 1;
265 bool mAutoresizeGuest : 1;
266 bool mIgnoreFrameBufferResize : 1;
267
268 /**
269 * This flag indicates whether the last console resize should trigger
270 * a size hint to the guest. This is important particularly when
271 * enabling the autoresize feature to know whether to send a hint.
272 */
273 bool mDoResize : 1;
274
275 bool mGuestSupportsGraphics : 1;
276
277 bool mNumLock : 1;
278 bool mScrollLock : 1;
279 bool mCapsLock : 1;
280 long muNumLockAdaptionCnt;
281 long muCapsLockAdaptionCnt;
282
283
284 VBoxDefs::RenderMode mode;
285
286 QRegion mLastVisibleRegion;
287 QSize mNormalSize;
288
289#if defined(Q_WS_WIN)
290 HCURSOR mAlphaCursor;
291#endif
292
293#if defined(Q_WS_MAC)
294# ifndef VBOX_WITH_HACKED_QT
295 /** Event handler reference. NULL if the handler isn't installed. */
296 EventHandlerRef mDarwinEventHandlerRef;
297# endif
298 /** The current modifier key mask. Used to figure out which modifier
299 * key was pressed when we get a kEventRawKeyModifiersChanged event. */
300 UInt32 mDarwinKeyModifiers;
301#endif
302
303 VBoxFrameBuffer *mFrameBuf;
304 CConsoleCallback mCallback;
305
306 friend class VBoxConsoleCallback;
307
308#if defined (Q_WS_WIN32)
309 static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
310 WPARAM wParam, LPARAM lParam);
311#elif defined (Q_WS_MAC)
312 EventHandlerRef mDarwinWindowOverlayHandlerRef;
313# ifndef VBOX_WITH_HACKED_QT
314 static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
315 EventRef inEvent, void *inUserData);
316# else /* VBOX_WITH_HACKED_QT */
317 static bool macEventFilter (EventRef inEvent, void *inUserData);
318# endif /* VBOX_WITH_HACKED_QT */
319#endif
320
321 QPixmap mPausedShot;
322#if defined(Q_WS_MAC)
323 CGImageRef mVirtualBoxLogo;
324 bool mDockIconEnabled;
325#endif
326 DesktopGeo mDesktopGeo;
327 QRect mDesktopGeometry;
328 QRect mLastSizeHint;
329 bool mPassCAD;
330};
331
332#endif // __VBoxConsoleView_h__
333
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette