VirtualBox

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

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

FE/Qt4-OSX: make it more OSE compatible

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