VirtualBox

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

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

View HW Accel: guest ddraw command definitions, moved opengl framebuffer impl to a separate file

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