VirtualBox

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

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

FE/Qt: improved heuristics for automatic maximum guest resolution

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