VirtualBox

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

Last change on this file since 2077 was 2077, checked in by vboxsync, 18 years ago

FE/Qt: Applied temorary fix to avoud VM hangs when Auto Resize Guest is turned on and resizing is done using window borders instead of the size grip.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxConsoleView class declaration
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#ifndef __VBoxConsoleView_h__
24#define __VBoxConsoleView_h__
25
26#include "COMDefs.h"
27
28#include "VBoxDefs.h"
29#include "VMGlobalSettings.h"
30
31#include <qdatetime.h>
32#include <qscrollview.h>
33#include <qpixmap.h>
34#include <qimage.h>
35
36#include <qkeysequence.h>
37
38#if defined (Q_WS_MAC)
39# include <Carbon/Carbon.h>
40# include "DarwinCursor.h"
41#endif
42
43class VBoxConsoleWnd;
44class MousePointerChangeEvent;
45class VBoxFrameBuffer;
46
47class QPainter;
48class QLabel;
49class QMenuData;
50
51class VBoxConsoleView : public QScrollView
52{
53 Q_OBJECT
54
55public:
56
57 enum {
58 MouseCaptured = 0x01,
59 MouseAbsolute = 0x02,
60 MouseAbsoluteDisabled = 0x04,
61 MouseNeedsHostCursor = 0x08,
62 KeyboardCaptured = 0x01,
63 HostKeyPressed = 0x02,
64 };
65
66 VBoxConsoleView (VBoxConsoleWnd *mainWnd,
67 const CConsole &console,
68 VBoxDefs::RenderMode rm,
69 QWidget *parent = 0, const char *name = 0, WFlags f = 0);
70 ~VBoxConsoleView();
71
72 QSize sizeHint() const;
73
74 void attach();
75 void detach();
76 void refresh() { doRefresh(); }
77 void normalizeGeometry (bool adjustPosition = false);
78
79 CConsole &console() { return cconsole; }
80
81 bool pause (bool on);
82
83 void setMouseIntegrationEnabled (bool enabled);
84
85 bool isMouseAbsolute() const { return mouse_absolute; }
86
87 void setAutoresizeGuest (bool on);
88
89 void onFullscreenChange (bool on);
90
91 void fixModifierState (LONG *codes, uint *count);
92
93signals:
94
95 void keyboardStateChanged (int state);
96 void mouseStateChanged (int state);
97 void machineStateChanged (CEnums::MachineState state);
98
99protected:
100
101 // events
102 bool event( QEvent *e );
103 bool eventFilter( QObject *watched, QEvent *e );
104
105#if defined(Q_WS_WIN32)
106 bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
107 bool winEvent (MSG *msg);
108#elif defined(Q_WS_X11)
109 bool x11Event (XEvent *event );
110#elif defined(Q_WS_MAC)
111 bool darwinKeyboardEvent (EventRef inEvent);
112 void darwinGrabKeyboardEvents (bool fGrab);
113#endif
114
115private:
116
117 // flags for keyEvent()
118 enum {
119 KeyExtended = 0x01,
120 KeyPressed = 0x02,
121 KeyPause = 0x04,
122 KeyPrint = 0x08,
123 };
124
125 void focusEvent (bool focus);
126 bool keyEvent (int key, uint8_t scan, int flags, wchar_t *aUniKey = NULL);
127 bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
128 ButtonState aButton,
129 ButtonState aState, ButtonState aStateAfter,
130 int aWheelDelta, Orientation aWheelDir);
131
132 void emitKeyboardStateChanged() {
133 emit keyboardStateChanged (
134 (kbd_captured ? KeyboardCaptured : 0) |
135 (hostkey_pressed ? HostKeyPressed : 0));
136 }
137 void emitMouseStateChanged() {
138 emit mouseStateChanged ((mouse_captured ? MouseCaptured : 0) |
139 (mouse_absolute ? MouseAbsolute : 0) |
140 (!mouse_integration ? MouseAbsoluteDisabled : 0));
141 }
142
143 // IConsoleCallback event handlers
144 void onStateChange (CEnums::MachineState state);
145
146 void doRefresh();
147
148 void viewportPaintEvent( QPaintEvent * );
149#ifdef VBOX_GUI_USE_REFRESH_TIMER
150 void timerEvent( QTimerEvent * );
151#endif
152
153 void captureKbd (bool capture, bool emit_signal = true);
154 void captureMouse (bool capture, bool emit_signal = true);
155
156 bool processHotKey (const QKeySequence &key, QMenuData *data);
157 void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
158
159 void releaseAllKeysPressed (bool release_hostkey = true);
160 void saveKeyStates();
161 void sendChangedKeyStates();
162 void updateMouseClipping();
163
164 void setPointerShape (MousePointerChangeEvent *me);
165
166 bool isPaused() { return last_state == CEnums::Paused; }
167 bool isRunning() { return last_state == CEnums::Running; }
168
169 static void dimImage (QImage &img);
170
171private slots:
172
173 void doResizeHint();
174 void normalizeGeo() { normalizeGeometry(); }
175
176private:
177
178 VBoxConsoleWnd *mainwnd;
179
180 CConsole cconsole;
181
182 const VMGlobalSettings &gs;
183
184 CEnums::MachineState last_state;
185
186 bool attached : 1;
187 bool kbd_captured : 1;
188 bool mouse_captured : 1;
189 bool mouse_absolute : 1;
190 bool mouse_integration : 1;
191 QPoint last_pos;
192 QPoint captured_pos;
193
194 enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
195 uint8_t keys_pressed[128];
196 uint8_t keys_pressed_copy[128];
197
198 bool hostkey_pressed : 1;
199 bool hostkey_alone : 1;
200 /** kbd_captured value during the the last host key press or release */
201 bool hostkey_in_capture : 1;
202
203 bool ignore_mainwnd_resize : 1;
204 bool autoresize_guest : 1;
205 QSize autoresize_guest_hint;
206
207 bool mfNumLock : 1;
208 bool mfScrollLock : 1;
209 bool mfCapsLock : 1;
210 long muNumLockAdaptionCnt;
211 long muCapsLockAdaptionCnt;
212
213 QTimer *resize_hint_timer;
214
215 VBoxDefs::RenderMode mode;
216
217#if defined(Q_WS_WIN)
218 HCURSOR mAlphaCursor;
219#endif
220
221#if defined(Q_WS_MAC)
222# ifndef VBOX_WITH_HACKED_QT
223 /** Event handler reference. NULL if the handler isn't installed. */
224 EventHandlerRef m_darwinEventHandlerRef;
225# endif
226 /** The current modifier key mask. Used to figure out which modifier
227 * key was pressed when we get a kEventRawKeyModifiersChanged event. */
228 UInt32 m_darwinKeyModifiers;
229 /** The darwin cursor handle (see DarwinCursor.h/.cpp). */
230 DARWINCURSOR m_darwinCursor;
231#endif
232
233#if defined (VBOX_GUI_USE_REFRESH_TIMER)
234 QPixmap pm;
235 int tid; /**< Timer id */
236#endif
237
238 VBoxFrameBuffer *fb;
239 CConsoleCallback callback;
240
241 friend class VBoxConsoleCallback;
242
243#if defined (Q_WS_WIN32)
244 static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
245 WPARAM wParam, LPARAM lParam);
246#elif defined (Q_WS_MAC)
247# ifndef VBOX_WITH_HACKED_QT
248 static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
249 EventRef inEvent, void *inUserData);
250# else /* VBOX_WITH_HACKED_QT */
251 static bool macEventFilter (EventRef inEvent, void *inUserData);
252# endif /* VBOX_WITH_HACKED_QT */
253#endif
254
255 QPixmap mPausedShot;
256};
257
258#endif // __VBoxConsoleView_h__
259
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