VirtualBox

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

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

1803: FE/Qt leaks memory on Windows

It looks like QCursor uses HCURSOR handle “as is” without copying, so it is not correct to destroy WinAPI HCURSOR just after setting cursor to console viewport.
Unfortunately QCursor will not destroy icon under HCURSOR handle during self-destruction so it is necessary:

  1. to make VBoxConsoleView class member – HCURSOR handle,
  2. to destroy HCURSOR handle after new cursor is set for viewport,
  3. to destroy HCURSOR handle if it is not required any more (upon VBoxConsoleView destruction).
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.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.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
38class VBoxConsoleWnd;
39class MousePointerChangeEvent;
40class VBoxFrameBuffer;
41
42class QPainter;
43class QLabel;
44class QMenuData;
45
46class VBoxConsoleView : public QScrollView
47{
48 Q_OBJECT
49
50public:
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
88signals:
89
90 void keyboardStateChanged (int state);
91 void mouseStateChanged (int state);
92 void machineStateChanged (CEnums::MachineState state);
93
94protected:
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
107private:
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
163private slots:
164
165 void doResizeHint();
166 void normalizeGeo() { normalizeGeometry(); }
167
168private:
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 : 1;
199 bool mfScrollLock : 1;
200 bool mfCapsLock : 1;
201 long muNumLockAdaptionCnt;
202 long muCapsLockAdaptionCnt;
203
204 QTimer *resize_hint_timer;
205
206 VBoxDefs::RenderMode mode;
207
208#if defined(Q_WS_WIN)
209 HCURSOR mAlphaCursor;
210#endif
211
212#if defined (VBOX_GUI_USE_REFRESH_TIMER)
213 QPixmap pm;
214 int tid; /**< Timer id */
215#endif
216
217 VBoxFrameBuffer *fb;
218 CConsoleCallback callback;
219
220 friend class VBoxConsoleCallback;
221
222#if defined (Q_WS_WIN32)
223 static LRESULT CALLBACK lowLevelKeyboardProc (int nCode,
224 WPARAM wParam, LPARAM lParam);
225#endif
226
227 QPixmap mPausedShot;
228};
229
230#endif // __VBoxConsoleView_h__
231
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