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.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 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 | class VBoxConsoleWnd;
|
---|
39 | class MousePointerChangeEvent;
|
---|
40 | class VBoxFrameBuffer;
|
---|
41 |
|
---|
42 | class QPainter;
|
---|
43 | class QLabel;
|
---|
44 | class QMenuData;
|
---|
45 |
|
---|
46 | class VBoxConsoleView : public QScrollView
|
---|
47 | {
|
---|
48 | Q_OBJECT
|
---|
49 |
|
---|
50 | public:
|
---|
51 |
|
---|
52 | enum {
|
---|
53 | MouseCaptured = 0x01,
|
---|
54 | MouseAbsolute = 0x02,
|
---|
55 | MouseAbsoluteDisabled = 0x04,
|
---|
56 | MouseNeedsHostCursor = 0x08,
|
---|
57 | KeyboardCaptured = 0x01,
|
---|
58 | HostKeyPressed = 0x02,
|
---|
59 | };
|
---|
60 |
|
---|
61 | VBoxConsoleView (VBoxConsoleWnd *mainWnd,
|
---|
62 | const CConsole &console,
|
---|
63 | VBoxDefs::RenderMode rm,
|
---|
64 | QWidget *parent = 0, const char *name = 0, WFlags f = 0);
|
---|
65 | ~VBoxConsoleView();
|
---|
66 |
|
---|
67 | QSize sizeHint() const;
|
---|
68 |
|
---|
69 | void attach();
|
---|
70 | void detach();
|
---|
71 | void refresh() { doRefresh(); }
|
---|
72 | void normalizeGeometry (bool adjustPosition = false);
|
---|
73 |
|
---|
74 | CConsole &console() { return cconsole; }
|
---|
75 |
|
---|
76 | bool pause (bool on);
|
---|
77 |
|
---|
78 | void setMouseIntegrationEnabled (bool enabled);
|
---|
79 |
|
---|
80 | bool isMouseAbsolute() const { return mouse_absolute; }
|
---|
81 |
|
---|
82 | void setAutoresizeGuest (bool on);
|
---|
83 |
|
---|
84 | void onFullscreenChange (bool on);
|
---|
85 |
|
---|
86 | void FixModifierState (LONG *codes, uint *count);
|
---|
87 |
|
---|
88 | signals:
|
---|
89 |
|
---|
90 | void keyboardStateChanged (int state);
|
---|
91 | void mouseStateChanged (int state);
|
---|
92 | void machineStateChanged (CEnums::MachineState state);
|
---|
93 |
|
---|
94 | protected:
|
---|
95 |
|
---|
96 | // events
|
---|
97 | bool event( QEvent *e );
|
---|
98 | bool eventFilter( QObject *watched, QEvent *e );
|
---|
99 |
|
---|
100 | #if defined(Q_WS_WIN32)
|
---|
101 | bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
|
---|
102 | bool winEvent (MSG *msg);
|
---|
103 | #elif defined(Q_WS_X11)
|
---|
104 | bool x11Event (XEvent *event );
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | private:
|
---|
108 |
|
---|
109 | // flags for keyEvent()
|
---|
110 | enum {
|
---|
111 | KeyExtended = 0x01,
|
---|
112 | KeyPressed = 0x02,
|
---|
113 | KeyPause = 0x04,
|
---|
114 | KeyPrint = 0x08,
|
---|
115 | };
|
---|
116 |
|
---|
117 | void focusEvent (bool focus);
|
---|
118 | bool keyEvent (int key, uint8_t scan, int flags);
|
---|
119 | bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
|
---|
120 | ButtonState aButton,
|
---|
121 | ButtonState aState, ButtonState aStateAfter,
|
---|
122 | int aWheelDelta, Orientation aWheelDir);
|
---|
123 |
|
---|
124 | void emitKeyboardStateChanged() {
|
---|
125 | emit keyboardStateChanged (
|
---|
126 | (kbd_captured ? KeyboardCaptured : 0) |
|
---|
127 | (hostkey_pressed ? HostKeyPressed : 0));
|
---|
128 | }
|
---|
129 | void emitMouseStateChanged() {
|
---|
130 | emit mouseStateChanged ((mouse_captured ? MouseCaptured : 0) |
|
---|
131 | (mouse_absolute ? MouseAbsolute : 0) |
|
---|
132 | (!mouse_integration ? MouseAbsoluteDisabled : 0));
|
---|
133 | }
|
---|
134 |
|
---|
135 | // IConsoleCallback event handlers
|
---|
136 | void onStateChange (CEnums::MachineState state);
|
---|
137 |
|
---|
138 | void doRefresh();
|
---|
139 |
|
---|
140 | void viewportPaintEvent( QPaintEvent * );
|
---|
141 | #ifdef VBOX_GUI_USE_REFRESH_TIMER
|
---|
142 | void timerEvent( QTimerEvent * );
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | void captureKbd (bool capture, bool emit_signal = true);
|
---|
146 | void captureMouse (bool capture, bool emit_signal = true);
|
---|
147 |
|
---|
148 | bool processHotKey (const QKeySequence &key, QMenuData *data);
|
---|
149 | void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
|
---|
150 |
|
---|
151 | void releaseAllKeysPressed (bool release_hostkey = true);
|
---|
152 | void saveKeyStates();
|
---|
153 | void sendChangedKeyStates();
|
---|
154 | void updateMouseClipping();
|
---|
155 |
|
---|
156 | void setPointerShape (MousePointerChangeEvent *me);
|
---|
157 |
|
---|
158 | bool isPaused() { return last_state == CEnums::Paused; }
|
---|
159 | bool isRunning() { return last_state == CEnums::Running; }
|
---|
160 |
|
---|
161 | static void dimImage (QImage &img);
|
---|
162 |
|
---|
163 | private slots:
|
---|
164 |
|
---|
165 | void doResizeHint();
|
---|
166 | void normalizeGeo() { normalizeGeometry(); }
|
---|
167 |
|
---|
168 | private:
|
---|
169 |
|
---|
170 | VBoxConsoleWnd *mainwnd;
|
---|
171 |
|
---|
172 | CConsole cconsole;
|
---|
173 |
|
---|
174 | const VMGlobalSettings &gs;
|
---|
175 |
|
---|
176 | CEnums::MachineState last_state;
|
---|
177 |
|
---|
178 | bool attached : 1;
|
---|
179 | bool kbd_captured : 1;
|
---|
180 | bool mouse_captured : 1;
|
---|
181 | bool mouse_absolute : 1;
|
---|
182 | bool mouse_integration : 1;
|
---|
183 | QPoint last_pos;
|
---|
184 | QPoint captured_pos;
|
---|
185 |
|
---|
186 | enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
|
---|
187 | uint8_t keys_pressed[128];
|
---|
188 | uint8_t keys_pressed_copy[128];
|
---|
189 |
|
---|
190 | bool hostkey_pressed : 1;
|
---|
191 | bool hostkey_alone : 1;
|
---|
192 | /** kbd_captured value during the the last host key press or release */
|
---|
193 | bool hostkey_in_capture : 1;
|
---|
194 |
|
---|
195 | bool ignore_mainwnd_resize : 1;
|
---|
196 | bool autoresize_guest : 1;
|
---|
197 |
|
---|
198 | bool mfNumLock;
|
---|
199 | bool mfScrollLock;
|
---|
200 | bool mfCapsLock;
|
---|
201 | long muNumLockAdaptionCnt;
|
---|
202 |
|
---|
203 | QTimer *resize_hint_timer;
|
---|
204 |
|
---|
205 | VBoxDefs::RenderMode mode;
|
---|
206 |
|
---|
207 | #if defined (VBOX_GUI_USE_REFRESH_TIMER)
|
---|
208 | QPixmap pm;
|
---|
209 | int tid; /**< Timer id */
|
---|
210 | #endif
|
---|
211 |
|
---|
212 | VBoxFrameBuffer *fb;
|
---|
213 | CConsoleCallback callback;
|
---|
214 |
|
---|
215 | friend class VBoxConsoleCallback;
|
---|
216 |
|
---|
217 | #if defined (Q_WS_WIN32)
|
---|
218 | static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
|
---|
219 | WPARAM wParam, LPARAM lParam);
|
---|
220 | #endif
|
---|
221 |
|
---|
222 | QPixmap mPausedShot;
|
---|
223 | };
|
---|
224 |
|
---|
225 | #endif // __VBoxConsoleView_h__
|
---|
226 |
|
---|