VirtualBox

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

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

Qt4Gui: Carbon -> Coca; make it build. (darwin/amd64)

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