VirtualBox

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

Last change on this file since 22816 was 22816, checked in by vboxsync, 15 years ago

video 2d accel: move overlay functionality to a separate class/files, make it easy to reuse with different framebuffers

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