VirtualBox

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

Last change on this file since 11971 was 11971, checked in by vboxsync, 17 years ago

FE/Qt4-OSX: Mouse cursor handling cleanup.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette