VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h@ 19253

Last change on this file since 19253 was 18654, checked in by vboxsync, 16 years ago

crOpenGL-OSX: more fixes for clipping on the root window

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