VirtualBox

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

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

FE/Qt: OS/2: Implemented keyboard input to the VM.

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