VirtualBox

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

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

Main: Reworked enums to avoid 1) weird duplication of enum name when referring to enum values in cross-platform code; 2) possible clashes on Win32 due to putting identifiers like Paused or Disabled to the global namespace (via C enums). In the new style, enums are used like this: a) USBDeviceState_T v = USBDeviceState_Busy from cross-platform non-Qt code; b) KUSBDeviceState v = KUSBDeviceState_Busy from Qt code; c) USBDeviceState v = USBDeviceState_Busy from plain Win32 and d) PRUInt32 USBDeviceState v = USBDeviceState::Busy from plain XPCOM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxConsoleView class declaration
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
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
19#ifndef __VBoxConsoleView_h__
20#define __VBoxConsoleView_h__
21
22#include "COMDefs.h"
23
24#include "VBoxDefs.h"
25#include "VBoxGlobalSettings.h"
26
27#include <qdatetime.h>
28#include <qscrollview.h>
29#include <qpixmap.h>
30#include <qimage.h>
31
32#include <qkeysequence.h>
33
34#if defined (Q_WS_PM)
35#include "src/os2/VBoxHlp.h"
36#define UM_PREACCEL_CHAR WM_USER
37#endif
38
39#if defined (Q_WS_MAC)
40# include <Carbon/Carbon.h>
41# include "DarwinCursor.h"
42/** @todo remove this hack when somebody get around fixing the conflicting typedef/enum OSType. */
43# define OSType VBoxOSType
44#endif
45
46class VBoxConsoleWnd;
47class MousePointerChangeEvent;
48class VBoxFrameBuffer;
49
50class QPainter;
51class QLabel;
52class QMenuData;
53
54class VBoxConsoleView : public QScrollView
55{
56 Q_OBJECT
57
58public:
59
60 enum {
61 MouseCaptured = 0x01,
62 MouseAbsolute = 0x02,
63 MouseAbsoluteDisabled = 0x04,
64 MouseNeedsHostCursor = 0x08,
65 KeyboardCaptured = 0x01,
66 HostKeyPressed = 0x02,
67 };
68
69 VBoxConsoleView (VBoxConsoleWnd *mainWnd,
70 const CConsole &console,
71 VBoxDefs::RenderMode rm,
72 QWidget *parent = 0, const char *name = 0, WFlags f = 0);
73 ~VBoxConsoleView();
74
75 QSize sizeHint() const;
76
77 void attach();
78 void detach();
79 void refresh() { doRefresh(); }
80 void normalizeGeometry (bool adjustPosition = false);
81
82 CConsole &console() { return mConsole; }
83
84 bool pause (bool on);
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();
99
100 void setIgnoreMainwndResize (bool aYes) { mIgnoreMainwndResize = aYes; }
101
102signals:
103
104 void keyboardStateChanged (int state);
105 void mouseStateChanged (int state);
106 void machineStateChanged (KMachineState state);
107 void additionsStateChanged (const QString &, bool, bool);
108 void mediaChanged (VBoxDefs::DiskType aType);
109 void networkStateChange();
110 void usbStateChange();
111 void sharedFoldersChanged();
112 void resizeHintDone();
113
114protected:
115
116 // events
117 bool event (QEvent *e);
118 bool eventFilter (QObject *watched, QEvent *e);
119
120#if defined(Q_WS_WIN32)
121 bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
122 bool winEvent (MSG *msg);
123#elif defined(Q_WS_PM)
124 bool pmEvent (QMSG *aMsg);
125#elif defined(Q_WS_X11)
126 bool x11Event (XEvent *event);
127#elif defined(Q_WS_MAC)
128 bool darwinKeyboardEvent (EventRef inEvent);
129 void darwinGrabKeyboardEvents (bool fGrab);
130#endif
131
132private:
133
134 /** Flags for keyEvent(). */
135 enum {
136 KeyExtended = 0x01,
137 KeyPressed = 0x02,
138 KeyPause = 0x04,
139 KeyPrint = 0x08,
140 };
141
142 void focusEvent (bool aHasFocus, bool aReleaseHostKey = true);
143 bool keyEvent (int aKey, uint8_t aScan, int aFlags,
144 wchar_t *aUniKey = NULL);
145 bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
146 ButtonState aButton,
147 ButtonState aState, ButtonState aStateAfter,
148 int aWheelDelta, Orientation aWheelDir);
149
150 void emitKeyboardStateChanged()
151 {
152 emit keyboardStateChanged (
153 (mKbdCaptured ? KeyboardCaptured : 0) |
154 (mIsHostkeyPressed ? HostKeyPressed : 0));
155 }
156
157 void emitMouseStateChanged() {
158 emit mouseStateChanged ((mMouseCaptured ? MouseCaptured : 0) |
159 (mMouseAbsolute ? MouseAbsolute : 0) |
160 (!mMouseIntegration ? MouseAbsoluteDisabled : 0));
161 }
162
163 // IConsoleCallback event handlers
164 void onStateChange (KMachineState state);
165
166 void doRefresh();
167
168 void viewportPaintEvent( QPaintEvent * );
169#ifdef VBOX_GUI_USE_REFRESH_TIMER
170 void timerEvent( QTimerEvent * );
171#endif
172
173 void captureKbd (bool aCapture, bool aEmitSignal = true);
174 void captureMouse (bool aCapture, bool aEmitSignal = true);
175
176 bool processHotKey (const QKeySequence &key, QMenuData *data);
177 void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
178
179 void releaseAllPressedKeys (bool aReleaseHostKey = true);
180 void saveKeyStates();
181 void sendChangedKeyStates();
182 void updateMouseClipping();
183
184 void setPointerShape (MousePointerChangeEvent *me);
185
186 bool isPaused() { return mLastState == KMachineState_Paused; }
187 bool isRunning() { return mLastState == KMachineState_Running; }
188
189 static void dimImage (QImage &img);
190
191private slots:
192
193 void doResizeHint (const QSize &aSize = QSize());
194
195private:
196
197 void maybeRestrictMinimumSize();
198
199 VBoxConsoleWnd *mMainWnd;
200
201 CConsole mConsole;
202
203 const VBoxGlobalSettings &gs;
204
205 KMachineState mLastState;
206
207 bool mAttached : 1;
208 bool mKbdCaptured : 1;
209 bool mMouseCaptured : 1;
210 bool mMouseAbsolute : 1;
211 bool mMouseIntegration : 1;
212 QPoint mLastPos;
213 QPoint mCapturedPos;
214
215 bool mDisableAutoCapture : 1;
216
217 enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
218 uint8_t mPressedKeys [128];
219 uint8_t mPressedKeysCopy [128];
220
221 bool mIsHostkeyPressed : 1;
222 bool mIsHostkeyAlone : 1;
223
224 /** mKbdCaptured value during the the last host key press or release */
225 bool hostkey_in_capture : 1;
226
227 bool mIgnoreMainwndResize : 1;
228 bool mAutoresizeGuest : 1;
229
230 bool mIsAdditionsActive : 1;
231
232 bool mNumLock : 1;
233 bool mScrollLock : 1;
234 bool mCapsLock : 1;
235 long muNumLockAdaptionCnt;
236 long muCapsLockAdaptionCnt;
237
238 QTimer *resize_hint_timer;
239 QTimer *mToggleFSModeTimer;
240
241 VBoxDefs::RenderMode mode;
242
243 QRegion mLastVisibleRegion;
244 QSize mNormalSize;
245
246#if defined(Q_WS_WIN)
247 HCURSOR mAlphaCursor;
248#endif
249
250#if defined(Q_WS_MAC)
251# ifndef VBOX_WITH_HACKED_QT
252 /** Event handler reference. NULL if the handler isn't installed. */
253 EventHandlerRef mDarwinEventHandlerRef;
254# endif
255 /** The current modifier key mask. Used to figure out which modifier
256 * key was pressed when we get a kEventRawKeyModifiersChanged event. */
257 UInt32 mDarwinKeyModifiers;
258 /** The darwin cursor handle (see DarwinCursor.h/.cpp). */
259 DARWINCURSOR mDarwinCursor;
260#endif
261
262#if defined (VBOX_GUI_USE_REFRESH_TIMER)
263 QPixmap pm;
264 int tid; /**< Timer id */
265#endif
266
267 VBoxFrameBuffer *mFrameBuf;
268 CConsoleCallback mCallback;
269
270 friend class VBoxConsoleCallback;
271
272#if defined (Q_WS_WIN32)
273 static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
274 WPARAM wParam, LPARAM lParam);
275#elif defined (Q_WS_MAC)
276# ifndef VBOX_WITH_HACKED_QT
277 static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
278 EventRef inEvent, void *inUserData);
279# else /* VBOX_WITH_HACKED_QT */
280 static bool macEventFilter (EventRef inEvent, void *inUserData);
281# endif /* VBOX_WITH_HACKED_QT */
282#endif
283
284 QPixmap mPausedShot;
285#if defined(Q_WS_MAC)
286 CGImageRef mVirtualBoxLogo;
287#endif
288};
289
290#endif // __VBoxConsoleView_h__
291
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