VirtualBox

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

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

FE/Qt4: 3306: Seamless VM after restore incorrect size - fixed. Checked on windows & kde win managers.

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