VirtualBox

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

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

FE/Qt4-OSX: new look of the dock preview icon

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 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#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 (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 paintEvent (QPaintEvent *);
203
204 void captureKbd (bool aCapture, bool aEmitSignal = true);
205 void captureMouse (bool aCapture, bool aEmitSignal = true);
206
207 bool processHotKey (const QKeySequence &key, const QList<QAction*>& data);
208 void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
209
210 void releaseAllPressedKeys (bool aReleaseHostKey = true);
211 void saveKeyStates();
212 void sendChangedKeyStates();
213 void updateMouseClipping();
214
215 void setPointerShape (MousePointerChangeEvent *me);
216
217 bool isRunning() { return mLastState == KMachineState_Running; }
218
219 static void dimImage (QImage &img);
220
221private slots:
222
223 void doResizeHint (const QSize &aSize = QSize());
224 void doResizeDesktop (int);
225
226private:
227
228 enum DesktopGeo
229 {
230 DesktopGeo_Invalid = 0, DesktopGeo_Fixed,
231 DesktopGeo_Automatic, DesktopGeo_Any
232 };
233
234 void setDesktopGeometry (DesktopGeo aGeo, int aWidth, int aHeight);
235 void setDesktopGeoHint (int aWidth, int aHeight);
236 void calculateDesktopGeometry();
237 void maybeRestrictMinimumSize();
238
239 VBoxConsoleWnd *mMainWnd;
240
241 CConsole mConsole;
242
243 const VBoxGlobalSettings &gs;
244
245 KMachineState mLastState;
246
247 bool mAttached : 1;
248 bool mKbdCaptured : 1;
249 bool mMouseCaptured : 1;
250 bool mMouseAbsolute : 1;
251 bool mMouseIntegration : 1;
252 QPoint mLastPos;
253 QPoint mCapturedPos;
254
255 bool mDisableAutoCapture : 1;
256
257 enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
258 uint8_t mPressedKeys [128];
259 uint8_t mPressedKeysCopy [128];
260
261 bool mIsHostkeyPressed : 1;
262 bool mIsHostkeyAlone : 1;
263
264 /** mKbdCaptured value during the the last host key press or release */
265 bool hostkey_in_capture : 1;
266
267 bool mIgnoreMainwndResize : 1;
268 bool mAutoresizeGuest : 1;
269 bool mIgnoreFrameBufferResize : 1;
270
271 /**
272 * This flag indicates whether the last console resize should trigger
273 * a size hint to the guest. This is important particularly when
274 * enabling the autoresize feature to know whether to send a hint.
275 */
276 bool mDoResize : 1;
277
278 bool mGuestSupportsGraphics : 1;
279
280 bool mNumLock : 1;
281 bool mScrollLock : 1;
282 bool mCapsLock : 1;
283 long muNumLockAdaptionCnt;
284 long muCapsLockAdaptionCnt;
285
286
287 VBoxDefs::RenderMode mode;
288
289 QRegion mLastVisibleRegion;
290 QSize mNormalSize;
291
292#if defined(Q_WS_WIN)
293 HCURSOR mAlphaCursor;
294#endif
295
296#if defined(Q_WS_MAC)
297# ifndef VBOX_WITH_HACKED_QT
298 /** Event handler reference. NULL if the handler isn't installed. */
299 EventHandlerRef mDarwinEventHandlerRef;
300# endif
301 /** The current modifier key mask. Used to figure out which modifier
302 * key was pressed when we get a kEventRawKeyModifiersChanged event. */
303 UInt32 mDarwinKeyModifiers;
304 bool mKeyboardGrabbed;
305#endif
306
307 VBoxFrameBuffer *mFrameBuf;
308 CConsoleCallback mCallback;
309
310 friend class VBoxConsoleCallback;
311
312#if defined (Q_WS_WIN32)
313 static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
314 WPARAM wParam, LPARAM lParam);
315#elif defined (Q_WS_MAC)
316 EventHandlerRef mDarwinWindowOverlayHandlerRef;
317# ifndef VBOX_WITH_HACKED_QT
318 static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
319 EventRef inEvent, void *inUserData);
320# else /* VBOX_WITH_HACKED_QT */
321 static bool macEventFilter (EventRef inEvent, void *inUserData);
322# endif /* VBOX_WITH_HACKED_QT */
323#endif
324
325 QPixmap mPausedShot;
326#if defined(Q_WS_MAC)
327 VBoxDockIconPreview *mDockIconPreview;
328 bool mDockIconEnabled;
329#endif
330 DesktopGeo mDesktopGeo;
331 QRect mDesktopGeometry;
332 QRect mLastSizeHint;
333 bool mPassCAD;
334};
335
336#endif // __VBoxConsoleView_h__
337
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