VirtualBox

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

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

FE/Qt4: 3616: Guru meditation triggers VM window resize: Ignoring initial VGA resize request in case of GM.

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