VirtualBox

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

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

Darwin: fixed the screen update issue and started implementing the keyboard stuff.

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