VirtualBox

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

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

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 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();
98
99 void setIgnoreMainwndResize (bool aYes) { mIgnoreMainwndResize = aYes; }
100
101 QRect getDesktopGeometry();
102
103 /* todo: This are some support functions for the qt4 port. Maybe we get rid
104 * of them some day. */
105 int contentsX() const { return horizontalScrollBar()->value(); }
106 int contentsY() const { return verticalScrollBar()->value(); }
107 int contentsWidth() const;
108 int contentsHeight() const;
109 int visibleWidth() const { return horizontalScrollBar()->pageStep(); }
110 int visibleHeight() const { return verticalScrollBar()->pageStep(); }
111 void scrollBy (int dx, int dy)
112 {
113 horizontalScrollBar()->setValue (horizontalScrollBar()->value() + dx);
114 verticalScrollBar()->setValue (verticalScrollBar()->value() + dy);
115 }
116 QPoint viewportToContents ( const QPoint & vp ) const
117 {
118 return QPoint (vp.x() + contentsX(),
119 vp.y() + contentsY());
120 }
121 void updateSliders();
122
123signals:
124
125 void keyboardStateChanged (int state);
126 void mouseStateChanged (int state);
127 void machineStateChanged (KMachineState state);
128 void additionsStateChanged (const QString &, bool, bool);
129 void mediaChanged (VBoxDefs::DiskType aType);
130 void networkStateChange();
131 void usbStateChange();
132 void sharedFoldersChanged();
133 void resizeHintDone();
134
135protected:
136
137 // events
138 bool event (QEvent *e);
139 bool eventFilter (QObject *watched, QEvent *e);
140
141#if defined(Q_WS_WIN32)
142 bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
143 bool winEvent (MSG *msg);
144#elif defined(Q_WS_PM)
145 bool pmEvent (QMSG *aMsg);
146#elif defined(Q_WS_X11)
147 bool x11Event (XEvent *event);
148#elif defined(Q_WS_MAC)
149 bool darwinKeyboardEvent (EventRef inEvent);
150 void darwinGrabKeyboardEvents (bool fGrab);
151#endif
152
153private:
154
155 /** Flags for keyEvent(). */
156 enum {
157 KeyExtended = 0x01,
158 KeyPressed = 0x02,
159 KeyPause = 0x04,
160 KeyPrint = 0x08,
161 };
162
163 void focusEvent (bool aHasFocus, bool aReleaseHostKey = true);
164 bool keyEvent (int aKey, uint8_t aScan, int aFlags,
165 wchar_t *aUniKey = NULL);
166 bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
167 Qt::ButtonState aButton,
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 void setDesktopGeometry(int minWidth, int minHeight);
218 void sendInitialSizeHint(void);
219 void maybeRestrictMinimumSize();
220
221 VBoxConsoleWnd *mMainWnd;
222
223 CConsole mConsole;
224
225 const VBoxGlobalSettings &gs;
226
227 KMachineState mLastState;
228
229 bool mAttached : 1;
230 bool mKbdCaptured : 1;
231 bool mMouseCaptured : 1;
232 bool mMouseAbsolute : 1;
233 bool mMouseIntegration : 1;
234 QPoint mLastPos;
235 QPoint mCapturedPos;
236
237 bool mDisableAutoCapture : 1;
238
239 enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
240 uint8_t mPressedKeys [128];
241 uint8_t mPressedKeysCopy [128];
242
243 bool mIsHostkeyPressed : 1;
244 bool mIsHostkeyAlone : 1;
245
246 /** mKbdCaptured value during the the last host key press or release */
247 bool hostkey_in_capture : 1;
248
249 bool mIgnoreMainwndResize : 1;
250 bool mAutoresizeGuest : 1;
251
252 bool mIsAdditionsActive : 1;
253
254 bool mNumLock : 1;
255 bool mScrollLock : 1;
256 bool mCapsLock : 1;
257 long muNumLockAdaptionCnt;
258 long muCapsLockAdaptionCnt;
259
260 QTimer *mToggleFSModeTimer;
261
262 VBoxDefs::RenderMode mode;
263
264 QRegion mLastVisibleRegion;
265 QSize mNormalSize;
266
267#if defined(Q_WS_WIN)
268 HCURSOR mAlphaCursor;
269#endif
270
271#if defined(Q_WS_MAC)
272# ifndef VBOX_WITH_HACKED_QT
273 /** Event handler reference. NULL if the handler isn't installed. */
274 EventHandlerRef mDarwinEventHandlerRef;
275# endif
276 /** The current modifier key mask. Used to figure out which modifier
277 * key was pressed when we get a kEventRawKeyModifiersChanged event. */
278 UInt32 mDarwinKeyModifiers;
279 /** The darwin cursor handle (see DarwinCursor.h/.cpp). */
280 DARWINCURSOR mDarwinCursor;
281#endif
282
283 VBoxFrameBuffer *mFrameBuf;
284 CConsoleCallback mCallback;
285
286 friend class VBoxConsoleCallback;
287
288#if defined (Q_WS_WIN32)
289 static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
290 WPARAM wParam, LPARAM lParam);
291#elif defined (Q_WS_MAC)
292# ifndef VBOX_WITH_HACKED_QT
293 static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
294 EventRef inEvent, void *inUserData);
295# else /* VBOX_WITH_HACKED_QT */
296 static bool macEventFilter (EventRef inEvent, void *inUserData);
297# endif /* VBOX_WITH_HACKED_QT */
298#endif
299
300 QPixmap mPausedShot;
301#if defined(Q_WS_MAC)
302 CGImageRef mVirtualBoxLogo;
303#endif
304 QSize mLastSizeHint;
305 QRect mDesktopGeometry;
306};
307
308#endif // __VBoxConsoleView_h__
309
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