VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h@ 20048

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

HGSMI: post host VBVA commands to display; Video HW Accel: mechanism for passing/processing commands to framebuffer

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