VirtualBox

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

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

FE/Qt4-OSX: added helper functions for the external window handling

  • 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#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
126signals:
127
128 void keyboardStateChanged (int state);
129 void mouseStateChanged (int state);
130 void machineStateChanged (KMachineState state);
131 void additionsStateChanged (const QString &, bool, bool, bool);
132 void mediaDriveChanged (VBoxDefs::MediaType aType);
133 void networkStateChange();
134 void usbStateChange();
135 void sharedFoldersChanged();
136 void resizeHintDone();
137
138protected:
139
140 // events
141 bool event (QEvent *e);
142 bool eventFilter (QObject *watched, QEvent *e);
143
144#if defined(Q_WS_WIN32)
145 bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
146 bool winEvent (MSG *aMsg, long *aResult);
147#elif defined(Q_WS_PM)
148 bool pmEvent (QMSG *aMsg);
149#elif defined(Q_WS_X11)
150 bool x11Event (XEvent *event);
151#elif defined(Q_WS_MAC)
152 bool darwinKeyboardEvent (EventRef inEvent);
153 void darwinGrabKeyboardEvents (bool fGrab);
154#endif
155
156private:
157
158 /** Flags for keyEvent(). */
159 enum {
160 KeyExtended = 0x01,
161 KeyPressed = 0x02,
162 KeyPause = 0x04,
163 KeyPrint = 0x08,
164 };
165
166 void focusEvent (bool aHasFocus, bool aReleaseHostKey = true);
167 bool keyEvent (int aKey, uint8_t aScan, int aFlags,
168 wchar_t *aUniKey = NULL);
169 bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
170 Qt::MouseButtons aButtons, Qt::KeyboardModifiers aModifiers,
171 int aWheelDelta, Qt::Orientation aWheelDir);
172
173 void emitKeyboardStateChanged()
174 {
175 emit keyboardStateChanged (
176 (mKbdCaptured ? KeyboardCaptured : 0) |
177 (mIsHostkeyPressed ? HostKeyPressed : 0));
178 }
179
180 void emitMouseStateChanged() {
181 emit mouseStateChanged ((mMouseCaptured ? MouseCaptured : 0) |
182 (mMouseAbsolute ? MouseAbsolute : 0) |
183 (!mMouseIntegration ? MouseAbsoluteDisabled : 0));
184 }
185
186 // IConsoleCallback event handlers
187 void onStateChange (KMachineState state);
188
189 void doRefresh();
190
191 void resizeEvent (QResizeEvent *);
192 void paintEvent (QPaintEvent *);
193
194 void captureKbd (bool aCapture, bool aEmitSignal = true);
195 void captureMouse (bool aCapture, bool aEmitSignal = true);
196
197 bool processHotKey (const QKeySequence &key, const QList<QAction*>& data);
198 void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
199
200 void releaseAllPressedKeys (bool aReleaseHostKey = true);
201 void saveKeyStates();
202 void sendChangedKeyStates();
203 void updateMouseClipping();
204
205 void setPointerShape (MousePointerChangeEvent *me);
206
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#endif
294
295 VBoxFrameBuffer *mFrameBuf;
296 CConsoleCallback mCallback;
297
298 friend class VBoxConsoleCallback;
299
300#if defined (Q_WS_WIN32)
301 static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
302 WPARAM wParam, LPARAM lParam);
303#elif defined (Q_WS_MAC)
304 EventHandlerRef mDarwinWindowOverlayHandlerRef;
305# ifndef VBOX_WITH_HACKED_QT
306 static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
307 EventRef inEvent, void *inUserData);
308# else /* VBOX_WITH_HACKED_QT */
309 static bool macEventFilter (EventRef inEvent, void *inUserData);
310# endif /* VBOX_WITH_HACKED_QT */
311#endif
312
313 QPixmap mPausedShot;
314#if defined(Q_WS_MAC)
315 CGImageRef mVirtualBoxLogo;
316#endif
317 DesktopGeo mDesktopGeo;
318 QRect mDesktopGeometry;
319 QRect mLastSizeHint;
320};
321
322#endif // __VBoxConsoleView_h__
323
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