1 | /* $Id: UISession.cpp 26754 2010-02-24 16:34:48Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UISession stuff implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | /* Global inclues */
|
---|
25 | #include <QApplication>
|
---|
26 | #include <QWidget>
|
---|
27 |
|
---|
28 | /* Local includes */
|
---|
29 | #include "UISession.h"
|
---|
30 |
|
---|
31 | #include "UIMachine.h"
|
---|
32 | #include "UIMachineLogic.h"
|
---|
33 | #include "UIMachineWindow.h"
|
---|
34 |
|
---|
35 | #include "VBoxUtils.h"
|
---|
36 |
|
---|
37 | /* Guest mouse pointer shape change event: */
|
---|
38 | class UIMousePointerShapeChangeEvent : public QEvent
|
---|
39 | {
|
---|
40 | public:
|
---|
41 |
|
---|
42 | UIMousePointerShapeChangeEvent(bool bIsVisible, bool bIsAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight, const uchar *pShape)
|
---|
43 | : QEvent((QEvent::Type)UIConsoleEventType_MousePointerShapeChange)
|
---|
44 | , m_bIsVisible(bIsVisible), m_bIsAlpha(bIsAlpha), m_uXHot(uXHot), m_uYHot(uYHot), m_uWidth(uWidth), m_uHeight(uHeight), m_pData(0)
|
---|
45 | {
|
---|
46 | uint dataSize = ((((m_uWidth + 7) / 8 * m_uHeight) + 3) & ~3) + m_uWidth * 4 * m_uHeight;
|
---|
47 | if (pShape)
|
---|
48 | {
|
---|
49 | m_pData = new uchar[dataSize];
|
---|
50 | memcpy((void*)m_pData, (void*)pShape, dataSize);
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | virtual ~UIMousePointerShapeChangeEvent()
|
---|
55 | {
|
---|
56 | if (m_pData) delete[] m_pData;
|
---|
57 | }
|
---|
58 |
|
---|
59 | bool isVisible() const { return m_bIsVisible; }
|
---|
60 | bool hasAlpha() const { return m_bIsAlpha; }
|
---|
61 | uint xHot() const { return m_uXHot; }
|
---|
62 | uint yHot() const { return m_uYHot; }
|
---|
63 | uint width() const { return m_uWidth; }
|
---|
64 | uint height() const { return m_uHeight; }
|
---|
65 | const uchar *shapeData() const { return m_pData; }
|
---|
66 |
|
---|
67 | private:
|
---|
68 |
|
---|
69 | bool m_bIsVisible, m_bIsAlpha;
|
---|
70 | uint m_uXHot, m_uYHot, m_uWidth, m_uHeight;
|
---|
71 | const uchar *m_pData;
|
---|
72 | };
|
---|
73 |
|
---|
74 | /* Guest mouse absolute positioning capability change event: */
|
---|
75 | class UIMouseCapabilityChangeEvent : public QEvent
|
---|
76 | {
|
---|
77 | public:
|
---|
78 |
|
---|
79 | UIMouseCapabilityChangeEvent(bool bSupportsAbsolute, bool bNeedsHostCursor)
|
---|
80 | : QEvent((QEvent::Type)UIConsoleEventType_MouseCapabilityChange)
|
---|
81 | , m_bSupportsAbsolute(bSupportsAbsolute), m_bNeedsHostCursor(bNeedsHostCursor) {}
|
---|
82 |
|
---|
83 | bool supportsAbsolute() const { return m_bSupportsAbsolute; }
|
---|
84 | bool needsHostCursor() const { return m_bNeedsHostCursor; }
|
---|
85 |
|
---|
86 | private:
|
---|
87 |
|
---|
88 | bool m_bSupportsAbsolute;
|
---|
89 | bool m_bNeedsHostCursor;
|
---|
90 | };
|
---|
91 |
|
---|
92 | /* Keyboard LEDs change event: */
|
---|
93 | class UIKeyboardLedsChangeEvent : public QEvent
|
---|
94 | {
|
---|
95 | public:
|
---|
96 |
|
---|
97 | UIKeyboardLedsChangeEvent(bool bNumLock, bool bCapsLock, bool bScrollLock)
|
---|
98 | : QEvent((QEvent::Type)UIConsoleEventType_KeyboardLedsChange)
|
---|
99 | , m_bNumLock(bNumLock), m_bCapsLock(bCapsLock), m_bScrollLock(bScrollLock) {}
|
---|
100 |
|
---|
101 | bool numLock() const { return m_bNumLock; }
|
---|
102 | bool capsLock() const { return m_bCapsLock; }
|
---|
103 | bool scrollLock() const { return m_bScrollLock; }
|
---|
104 |
|
---|
105 | private:
|
---|
106 |
|
---|
107 | bool m_bNumLock;
|
---|
108 | bool m_bCapsLock;
|
---|
109 | bool m_bScrollLock;
|
---|
110 | };
|
---|
111 |
|
---|
112 | /* Machine state change event: */
|
---|
113 | class UIStateChangeEvent : public QEvent
|
---|
114 | {
|
---|
115 | public:
|
---|
116 |
|
---|
117 | UIStateChangeEvent(KMachineState machineState)
|
---|
118 | : QEvent((QEvent::Type)UIConsoleEventType_StateChange)
|
---|
119 | , m_machineState(machineState) {}
|
---|
120 |
|
---|
121 | KMachineState machineState() const { return m_machineState; }
|
---|
122 |
|
---|
123 | private:
|
---|
124 |
|
---|
125 | KMachineState m_machineState;
|
---|
126 | };
|
---|
127 |
|
---|
128 | /* Guest Additions state change event: */
|
---|
129 | class UIAdditionsStateChangeEvent : public QEvent
|
---|
130 | {
|
---|
131 | public:
|
---|
132 |
|
---|
133 | UIAdditionsStateChangeEvent()
|
---|
134 | : QEvent((QEvent::Type)UIConsoleEventType_AdditionsStateChange) {}
|
---|
135 | };
|
---|
136 |
|
---|
137 | /* Network adapter change event: */
|
---|
138 | class UINetworkAdapterChangeEvent : public QEvent
|
---|
139 | {
|
---|
140 | public:
|
---|
141 |
|
---|
142 | UINetworkAdapterChangeEvent(const CNetworkAdapter &networkAdapter)
|
---|
143 | : QEvent((QEvent::Type)UIConsoleEventType_NetworkAdapterChange)
|
---|
144 | , m_networkAdapter(networkAdapter) {}
|
---|
145 |
|
---|
146 | const CNetworkAdapter& networkAdapter() { return m_networkAdapter; }
|
---|
147 |
|
---|
148 | private:
|
---|
149 |
|
---|
150 | const CNetworkAdapter &m_networkAdapter;
|
---|
151 | };
|
---|
152 |
|
---|
153 | /* Serial port change event: */
|
---|
154 | class UISerialPortChangeEvent : public QEvent
|
---|
155 | {
|
---|
156 | public:
|
---|
157 |
|
---|
158 | UISerialPortChangeEvent(const CSerialPort &serialPort)
|
---|
159 | : QEvent((QEvent::Type)UIConsoleEventType_SerialPortChange)
|
---|
160 | , m_serialPort(serialPort) {}
|
---|
161 |
|
---|
162 | const CSerialPort& serialPort() { return m_serialPort; }
|
---|
163 |
|
---|
164 | private:
|
---|
165 |
|
---|
166 | const CSerialPort &m_serialPort;
|
---|
167 | };
|
---|
168 |
|
---|
169 | /* Parallel port change event: */
|
---|
170 | class UIParallelPortChangeEvent : public QEvent
|
---|
171 | {
|
---|
172 | public:
|
---|
173 |
|
---|
174 | UIParallelPortChangeEvent(const CParallelPort ¶llelPort)
|
---|
175 | : QEvent((QEvent::Type)UIConsoleEventType_ParallelPortChange)
|
---|
176 | , m_parallelPort(parallelPort) {}
|
---|
177 |
|
---|
178 | const CParallelPort& parallelPort() { return m_parallelPort; }
|
---|
179 |
|
---|
180 | private:
|
---|
181 |
|
---|
182 | const CParallelPort &m_parallelPort;
|
---|
183 | };
|
---|
184 |
|
---|
185 | /* Storage controller change event: */
|
---|
186 | class UIStorageControllerChangeEvent : public QEvent
|
---|
187 | {
|
---|
188 | public:
|
---|
189 |
|
---|
190 | UIStorageControllerChangeEvent()
|
---|
191 | : QEvent((QEvent::Type)UIConsoleEventType_StorageControllerChange) {}
|
---|
192 | };
|
---|
193 |
|
---|
194 | /* Storage medium change event: */
|
---|
195 | class UIMediumChangeEvent : public QEvent
|
---|
196 | {
|
---|
197 | public:
|
---|
198 |
|
---|
199 | UIMediumChangeEvent(const CMediumAttachment &mediumAttachment)
|
---|
200 | : QEvent((QEvent::Type)UIConsoleEventType_MediumChange)
|
---|
201 | , m_mediumAttachment(mediumAttachment) {}
|
---|
202 | const CMediumAttachment& mediumAttahment() { return m_mediumAttachment; }
|
---|
203 |
|
---|
204 | private:
|
---|
205 |
|
---|
206 | const CMediumAttachment &m_mediumAttachment;
|
---|
207 | };
|
---|
208 |
|
---|
209 | /* CPU change event: */
|
---|
210 | class UICPUChangeEvent : public QEvent
|
---|
211 | {
|
---|
212 | public:
|
---|
213 |
|
---|
214 | UICPUChangeEvent(ulong uCPU, bool bRemove)
|
---|
215 | : QEvent((QEvent::Type)UIConsoleEventType_CPUChange)
|
---|
216 | , m_uCPU(uCPU), m_bRemove(bRemove) {}
|
---|
217 |
|
---|
218 | ulong cpu() const { return m_uCPU; }
|
---|
219 | bool remove() const { return m_bRemove; }
|
---|
220 |
|
---|
221 | private:
|
---|
222 |
|
---|
223 | ulong m_uCPU;
|
---|
224 | bool m_bRemove;
|
---|
225 | };
|
---|
226 |
|
---|
227 | /* VRDP server change event: */
|
---|
228 | class UIVRDPServerChangeEvent : public QEvent
|
---|
229 | {
|
---|
230 | public:
|
---|
231 |
|
---|
232 | UIVRDPServerChangeEvent()
|
---|
233 | : QEvent((QEvent::Type)UIConsoleEventType_VRDPServerChange) {}
|
---|
234 | };
|
---|
235 |
|
---|
236 | /* Remote display info change event: */
|
---|
237 | class UIRemoteDisplayInfoChangeEvent : public QEvent
|
---|
238 | {
|
---|
239 | public:
|
---|
240 |
|
---|
241 | UIRemoteDisplayInfoChangeEvent()
|
---|
242 | : QEvent((QEvent::Type)UIConsoleEventType_RemoteDisplayInfoChange) {}
|
---|
243 | };
|
---|
244 |
|
---|
245 | /* USB controller change event: */
|
---|
246 | class UIUSBControllerChangeEvent : public QEvent
|
---|
247 | {
|
---|
248 | public:
|
---|
249 |
|
---|
250 | UIUSBControllerChangeEvent()
|
---|
251 | : QEvent((QEvent::Type)UIConsoleEventType_USBControllerChange) {}
|
---|
252 | };
|
---|
253 |
|
---|
254 | /* USB device state change event: */
|
---|
255 | class UIUSBDeviceUIStateChangeEvent : public QEvent
|
---|
256 | {
|
---|
257 | public:
|
---|
258 |
|
---|
259 | UIUSBDeviceUIStateChangeEvent(const CUSBDevice &device, bool bAttached, const CVirtualBoxErrorInfo &error)
|
---|
260 | : QEvent((QEvent::Type)UIConsoleEventType_USBDeviceStateChange)
|
---|
261 | , m_device(device), m_bAttached(bAttached), m_error(error) {}
|
---|
262 |
|
---|
263 | const CUSBDevice& device() const { return m_device; }
|
---|
264 | bool attached() const { return m_bAttached; }
|
---|
265 | const CVirtualBoxErrorInfo& error() const { return m_error; }
|
---|
266 |
|
---|
267 | private:
|
---|
268 |
|
---|
269 | const CUSBDevice &m_device;
|
---|
270 | bool m_bAttached;
|
---|
271 | const CVirtualBoxErrorInfo &m_error;
|
---|
272 | };
|
---|
273 |
|
---|
274 | /* Shared folder change event: */
|
---|
275 | class UISharedFolderChangeEvent : public QEvent
|
---|
276 | {
|
---|
277 | public:
|
---|
278 |
|
---|
279 | UISharedFolderChangeEvent()
|
---|
280 | : QEvent((QEvent::Type)UIConsoleEventType_SharedFolderChange) {}
|
---|
281 | };
|
---|
282 |
|
---|
283 | /* VM Runtime error event: */
|
---|
284 | class UIRuntimeErrorEvent : public QEvent
|
---|
285 | {
|
---|
286 | public:
|
---|
287 |
|
---|
288 | UIRuntimeErrorEvent(bool bFatal, const QString &strErrorID, const QString &strMessage)
|
---|
289 | : QEvent((QEvent::Type)UIConsoleEventType_RuntimeError)
|
---|
290 | , m_bFatal(bFatal), m_strErrorID(strErrorID), m_strMessage(strMessage) {}
|
---|
291 |
|
---|
292 | bool fatal() const { return m_bFatal; }
|
---|
293 | QString errorID() const { return m_strErrorID; }
|
---|
294 | QString message() const { return m_strMessage; }
|
---|
295 |
|
---|
296 | private:
|
---|
297 |
|
---|
298 | bool m_bFatal;
|
---|
299 | QString m_strErrorID;
|
---|
300 | QString m_strMessage;
|
---|
301 | };
|
---|
302 |
|
---|
303 | /* Can show window event: */
|
---|
304 | class UICanUIShowWindowEvent : public QEvent
|
---|
305 | {
|
---|
306 | public:
|
---|
307 |
|
---|
308 | UICanUIShowWindowEvent()
|
---|
309 | : QEvent((QEvent::Type)UIConsoleEventType_CanShowWindow) {}
|
---|
310 | };
|
---|
311 |
|
---|
312 | /* Show window event: */
|
---|
313 | class UIShowWindowEvent : public QEvent
|
---|
314 | {
|
---|
315 | public:
|
---|
316 |
|
---|
317 | UIShowWindowEvent()
|
---|
318 | : QEvent((QEvent::Type)UIConsoleEventType_ShowWindow) {}
|
---|
319 | };
|
---|
320 |
|
---|
321 | class UIConsoleCallback : VBOX_SCRIPTABLE_IMPL(IConsoleCallback)
|
---|
322 | {
|
---|
323 | public:
|
---|
324 |
|
---|
325 | UIConsoleCallback(UISession *pEventHandler)
|
---|
326 | : m_pEventHandler(pEventHandler)
|
---|
327 | #if defined (Q_WS_WIN)
|
---|
328 | , m_iRefCount(0)
|
---|
329 | #endif
|
---|
330 | {
|
---|
331 | }
|
---|
332 |
|
---|
333 | virtual ~UIConsoleCallback()
|
---|
334 | {
|
---|
335 | }
|
---|
336 |
|
---|
337 | NS_DECL_ISUPPORTS
|
---|
338 |
|
---|
339 | #if defined (Q_WS_WIN)
|
---|
340 | STDMETHOD_(ULONG, AddRef)()
|
---|
341 | {
|
---|
342 | return ::InterlockedIncrement(&m_iRefCount);
|
---|
343 | }
|
---|
344 | STDMETHOD_(ULONG, Release)()
|
---|
345 | {
|
---|
346 | long iCount = ::InterlockedDecrement(&m_iRefCount);
|
---|
347 | if (iCount == 0)
|
---|
348 | delete this;
|
---|
349 | return iCount;
|
---|
350 | }
|
---|
351 | #endif
|
---|
352 |
|
---|
353 | VBOX_SCRIPTABLE_DISPATCH_IMPL(IConsoleCallback)
|
---|
354 |
|
---|
355 | STDMETHOD(OnMousePointerShapeChange)(BOOL bIsVisible, BOOL bAlpha, ULONG uXHot, ULONG uYHot, ULONG uWidth, ULONG uHeight, BYTE *pShape)
|
---|
356 | {
|
---|
357 | QApplication::postEvent(m_pEventHandler, new UIMousePointerShapeChangeEvent(bIsVisible, bAlpha, uXHot, uYHot, uWidth, uHeight, pShape));
|
---|
358 | return S_OK;
|
---|
359 | }
|
---|
360 |
|
---|
361 | STDMETHOD(OnMouseCapabilityChange)(BOOL bSupportsAbsolute, BOOL bNeedHostCursor)
|
---|
362 | {
|
---|
363 | QApplication::postEvent(m_pEventHandler, new UIMouseCapabilityChangeEvent(bSupportsAbsolute, bNeedHostCursor));
|
---|
364 | return S_OK;
|
---|
365 | }
|
---|
366 |
|
---|
367 | STDMETHOD(OnKeyboardLedsChange)(BOOL bNumLock, BOOL bCapsLock, BOOL bScrollLock)
|
---|
368 | {
|
---|
369 | QApplication::postEvent(m_pEventHandler, new UIKeyboardLedsChangeEvent(bNumLock, bCapsLock, bScrollLock));
|
---|
370 | return S_OK;
|
---|
371 | }
|
---|
372 |
|
---|
373 | STDMETHOD(OnStateChange)(MachineState_T machineState)
|
---|
374 | {
|
---|
375 | QApplication::postEvent(m_pEventHandler, new UIStateChangeEvent((KMachineState)machineState));
|
---|
376 | return S_OK;
|
---|
377 | }
|
---|
378 |
|
---|
379 | STDMETHOD(OnAdditionsStateChange)()
|
---|
380 | {
|
---|
381 | QApplication::postEvent(m_pEventHandler, new UIAdditionsStateChangeEvent);
|
---|
382 | return S_OK;
|
---|
383 | }
|
---|
384 |
|
---|
385 | STDMETHOD(OnNetworkAdapterChange)(INetworkAdapter *pNetworkAdapter)
|
---|
386 | {
|
---|
387 | QApplication::postEvent(m_pEventHandler, new UINetworkAdapterChangeEvent(CNetworkAdapter(pNetworkAdapter)));
|
---|
388 | return S_OK;
|
---|
389 | }
|
---|
390 |
|
---|
391 | STDMETHOD(OnSerialPortChange)(ISerialPort *pSerialPort)
|
---|
392 | {
|
---|
393 | QApplication::postEvent(m_pEventHandler, new UISerialPortChangeEvent(CSerialPort(pSerialPort)));
|
---|
394 | return S_OK;
|
---|
395 | }
|
---|
396 |
|
---|
397 | STDMETHOD(OnParallelPortChange)(IParallelPort *pParallelPort)
|
---|
398 | {
|
---|
399 | QApplication::postEvent(m_pEventHandler, new UIParallelPortChangeEvent(CParallelPort(pParallelPort)));
|
---|
400 | return S_OK;
|
---|
401 | }
|
---|
402 |
|
---|
403 | STDMETHOD(OnStorageControllerChange)()
|
---|
404 | {
|
---|
405 | QApplication::postEvent(m_pEventHandler, new UIStorageControllerChangeEvent);
|
---|
406 | return S_OK;
|
---|
407 | }
|
---|
408 |
|
---|
409 | STDMETHOD(OnMediumChange)(IMediumAttachment *pMediumAttachment)
|
---|
410 | {
|
---|
411 | QApplication::postEvent(m_pEventHandler, new UIMediumChangeEvent(CMediumAttachment(pMediumAttachment)));
|
---|
412 | return S_OK;
|
---|
413 | }
|
---|
414 |
|
---|
415 | STDMETHOD(OnCPUChange)(ULONG uCPU, BOOL bRemove)
|
---|
416 | {
|
---|
417 | QApplication::postEvent(m_pEventHandler, new UICPUChangeEvent(uCPU, bRemove));
|
---|
418 | return S_OK;
|
---|
419 | }
|
---|
420 |
|
---|
421 | STDMETHOD(OnVRDPServerChange)()
|
---|
422 | {
|
---|
423 | QApplication::postEvent(m_pEventHandler, new UIVRDPServerChangeEvent);
|
---|
424 | return S_OK;
|
---|
425 | }
|
---|
426 |
|
---|
427 | STDMETHOD(OnRemoteDisplayInfoChange)()
|
---|
428 | {
|
---|
429 | QApplication::postEvent(m_pEventHandler, new UIRemoteDisplayInfoChangeEvent);
|
---|
430 | return S_OK;
|
---|
431 | }
|
---|
432 |
|
---|
433 | STDMETHOD(OnUSBControllerChange)()
|
---|
434 | {
|
---|
435 | QApplication::postEvent(m_pEventHandler, new UIUSBControllerChangeEvent);
|
---|
436 | return S_OK;
|
---|
437 | }
|
---|
438 |
|
---|
439 | STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *pDevice, BOOL bAttached, IVirtualBoxErrorInfo *pError)
|
---|
440 | {
|
---|
441 | QApplication::postEvent(m_pEventHandler, new UIUSBDeviceUIStateChangeEvent(CUSBDevice(pDevice), bAttached, CVirtualBoxErrorInfo(pError)));
|
---|
442 | return S_OK;
|
---|
443 | }
|
---|
444 |
|
---|
445 | STDMETHOD(OnSharedFolderChange)(Scope_T scope)
|
---|
446 | {
|
---|
447 | NOREF(scope);
|
---|
448 | QApplication::postEvent(m_pEventHandler, new UISharedFolderChangeEvent);
|
---|
449 | return S_OK;
|
---|
450 | }
|
---|
451 |
|
---|
452 | STDMETHOD(OnRuntimeError)(BOOL bFatal, IN_BSTR strId, IN_BSTR strMessage)
|
---|
453 | {
|
---|
454 | QApplication::postEvent(m_pEventHandler, new UIRuntimeErrorEvent(bFatal, QString::fromUtf16(strId), QString::fromUtf16(strMessage)));
|
---|
455 | return S_OK;
|
---|
456 | }
|
---|
457 |
|
---|
458 | STDMETHOD(OnCanShowWindow)(BOOL *pbCanShow)
|
---|
459 | {
|
---|
460 | if (!pbCanShow)
|
---|
461 | return E_POINTER;
|
---|
462 |
|
---|
463 | *pbCanShow = TRUE;
|
---|
464 | return S_OK;
|
---|
465 | }
|
---|
466 |
|
---|
467 | STDMETHOD(OnShowWindow)(ULONG64 *puWinId)
|
---|
468 | {
|
---|
469 | if (!puWinId)
|
---|
470 | return E_POINTER;
|
---|
471 |
|
---|
472 | #if defined (Q_WS_MAC)
|
---|
473 | /* Let's try the simple approach first - grab the focus.
|
---|
474 | * Getting a window out of the dock (minimized or whatever it's called)
|
---|
475 | * needs to be done on the GUI thread, so post it a note: */
|
---|
476 | *puWinId = 0;
|
---|
477 | if (!m_pEventHandler)
|
---|
478 | return S_OK;
|
---|
479 |
|
---|
480 | if (::darwinSetFrontMostProcess())
|
---|
481 | QApplication::postEvent(m_pEventHandler, new UIShowWindowEvent);
|
---|
482 | else
|
---|
483 | {
|
---|
484 | /* It failed for some reason, send the other process our PSN so it can try.
|
---|
485 | * (This is just a precaution should Mac OS X start imposing the same sensible
|
---|
486 | * focus stealing restrictions that other window managers implement). */
|
---|
487 | *puWinId = ::darwinGetCurrentProcessId();
|
---|
488 | }
|
---|
489 | #else
|
---|
490 | /* Return the ID of the top-level console window. */
|
---|
491 | *puWinId = m_pEventHandler->winId();
|
---|
492 | #endif
|
---|
493 |
|
---|
494 | return S_OK;
|
---|
495 | }
|
---|
496 |
|
---|
497 | private:
|
---|
498 |
|
---|
499 | UISession *m_pEventHandler;
|
---|
500 |
|
---|
501 | #if defined (Q_WS_WIN)
|
---|
502 | long m_iRefCount;
|
---|
503 | #endif
|
---|
504 | };
|
---|
505 |
|
---|
506 | #if !defined (Q_WS_WIN)
|
---|
507 | NS_DECL_CLASSINFO(UIConsoleCallback)
|
---|
508 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI(UIConsoleCallback, IConsoleCallback)
|
---|
509 | #endif
|
---|
510 |
|
---|
511 | UISession::UISession(UIMachine *pMachine, const CSession &session)
|
---|
512 | : QObject(pMachine)
|
---|
513 | , m_pMachine(pMachine)
|
---|
514 | , m_session(session)
|
---|
515 | , m_pCallback(new UIConsoleCallback(this))
|
---|
516 | , m_callback(CConsoleCallback(m_pCallback))
|
---|
517 | {
|
---|
518 | /* Check CSession object */
|
---|
519 | AssertMsg(!m_session.isNull(), ("CSession is not set!\n"));
|
---|
520 |
|
---|
521 | /* Register console callback: */
|
---|
522 | m_session.GetConsole().RegisterCallback(m_callback);
|
---|
523 | }
|
---|
524 |
|
---|
525 | UISession::~UISession()
|
---|
526 | {
|
---|
527 | /* Unregister console callback: */
|
---|
528 | m_session.GetConsole().UnregisterCallback(m_callback);
|
---|
529 | delete m_pCallback;
|
---|
530 | m_pCallback = 0;
|
---|
531 | }
|
---|
532 |
|
---|
533 | bool UISession::event(QEvent *pEvent)
|
---|
534 | {
|
---|
535 | switch (pEvent->type())
|
---|
536 | {
|
---|
537 | case UIConsoleEventType_MousePointerShapeChange:
|
---|
538 | {
|
---|
539 | UIMousePointerShapeChangeEvent *pConsoleEvent = static_cast<UIMousePointerShapeChangeEvent*>(pEvent);
|
---|
540 | emit sigMousePointerShapeChange(pConsoleEvent->isVisible(), pConsoleEvent->hasAlpha(),
|
---|
541 | pConsoleEvent->xHot(), pConsoleEvent->yHot(),
|
---|
542 | pConsoleEvent->width(), pConsoleEvent->height(),
|
---|
543 | pConsoleEvent->shapeData());
|
---|
544 | return true;
|
---|
545 | }
|
---|
546 |
|
---|
547 | case UIConsoleEventType_MouseCapabilityChange:
|
---|
548 | {
|
---|
549 | UIMouseCapabilityChangeEvent *pConsoleEvent = static_cast<UIMouseCapabilityChangeEvent*>(pEvent);
|
---|
550 | emit sigMouseCapabilityChange(pConsoleEvent->supportsAbsolute(), pConsoleEvent->needsHostCursor());
|
---|
551 | return true;
|
---|
552 | }
|
---|
553 |
|
---|
554 | case UIConsoleEventType_KeyboardLedsChange:
|
---|
555 | {
|
---|
556 | UIKeyboardLedsChangeEvent *pConsoleEvent = static_cast<UIKeyboardLedsChangeEvent*>(pEvent);
|
---|
557 | emit sigKeyboardLedsChange(pConsoleEvent->numLock(), pConsoleEvent->capsLock(), pConsoleEvent->scrollLock());
|
---|
558 | return true;
|
---|
559 | }
|
---|
560 |
|
---|
561 | case UIConsoleEventType_StateChange:
|
---|
562 | {
|
---|
563 | UIStateChangeEvent *pConsoleEvent = static_cast<UIStateChangeEvent*>(pEvent);
|
---|
564 | emit sigStateChange(pConsoleEvent->machineState());
|
---|
565 | return true;
|
---|
566 | }
|
---|
567 |
|
---|
568 | case UIConsoleEventType_AdditionsStateChange:
|
---|
569 | {
|
---|
570 | emit sigAdditionsStateChange();
|
---|
571 | return true;
|
---|
572 | }
|
---|
573 |
|
---|
574 | case UIConsoleEventType_NetworkAdapterChange:
|
---|
575 | {
|
---|
576 | UINetworkAdapterChangeEvent *pConsoleEvent = static_cast<UINetworkAdapterChangeEvent*>(pEvent);
|
---|
577 | emit sigNetworkAdapterChange(pConsoleEvent->networkAdapter());
|
---|
578 | return true;
|
---|
579 | }
|
---|
580 |
|
---|
581 | case UIConsoleEventType_SerialPortChange:
|
---|
582 | {
|
---|
583 | UISerialPortChangeEvent *pConsoleEvent = static_cast<UISerialPortChangeEvent*>(pEvent);
|
---|
584 | emit sigSerialPortChange(pConsoleEvent->serialPort());
|
---|
585 | return true;
|
---|
586 | }
|
---|
587 |
|
---|
588 | case UIConsoleEventType_ParallelPortChange:
|
---|
589 | {
|
---|
590 | UIParallelPortChangeEvent *pConsoleEvent = static_cast<UIParallelPortChangeEvent*>(pEvent);
|
---|
591 | emit sigParallelPortChange(pConsoleEvent->parallelPort());
|
---|
592 | return true;
|
---|
593 | }
|
---|
594 |
|
---|
595 | case UIConsoleEventType_StorageControllerChange:
|
---|
596 | {
|
---|
597 | emit sigStorageControllerChange();
|
---|
598 | return true;
|
---|
599 | }
|
---|
600 |
|
---|
601 | case UIConsoleEventType_MediumChange:
|
---|
602 | {
|
---|
603 | UIMediumChangeEvent *pConsoleEvent = static_cast<UIMediumChangeEvent*>(pEvent);
|
---|
604 | emit sigMediumChange(pConsoleEvent->mediumAttahment());
|
---|
605 | return true;
|
---|
606 | }
|
---|
607 |
|
---|
608 | case UIConsoleEventType_CPUChange:
|
---|
609 | {
|
---|
610 | UICPUChangeEvent *pConsoleEvent = static_cast<UICPUChangeEvent*>(pEvent);
|
---|
611 | emit sigCPUChange(pConsoleEvent->cpu(), pConsoleEvent->remove());
|
---|
612 | return true;
|
---|
613 | }
|
---|
614 |
|
---|
615 | case UIConsoleEventType_VRDPServerChange:
|
---|
616 | {
|
---|
617 | emit sigVRDPServerChange();
|
---|
618 | return true;
|
---|
619 | }
|
---|
620 |
|
---|
621 | case UIConsoleEventType_RemoteDisplayInfoChange:
|
---|
622 | {
|
---|
623 | emit sigRemoteDisplayInfoChange();
|
---|
624 | return true;
|
---|
625 | }
|
---|
626 |
|
---|
627 | case UIConsoleEventType_USBControllerChange:
|
---|
628 | {
|
---|
629 | emit sigUSBControllerChange();
|
---|
630 | return true;
|
---|
631 | }
|
---|
632 |
|
---|
633 | case UIConsoleEventType_USBDeviceStateChange:
|
---|
634 | {
|
---|
635 | UIUSBDeviceUIStateChangeEvent *pConsoleEvent = static_cast<UIUSBDeviceUIStateChangeEvent*>(pEvent);
|
---|
636 | emit sigUSBDeviceStateChange(pConsoleEvent->device(), pConsoleEvent->attached(), pConsoleEvent->error());
|
---|
637 | return true;
|
---|
638 | }
|
---|
639 |
|
---|
640 | case UIConsoleEventType_SharedFolderChange:
|
---|
641 | {
|
---|
642 | emit sigSharedFolderChange();
|
---|
643 | return true;
|
---|
644 | }
|
---|
645 |
|
---|
646 | case UIConsoleEventType_RuntimeError:
|
---|
647 | {
|
---|
648 | UIRuntimeErrorEvent *pConsoleEvent = static_cast<UIRuntimeErrorEvent*>(pEvent);
|
---|
649 | emit sigRuntimeError(pConsoleEvent->fatal(), pConsoleEvent->errorID(), pConsoleEvent->message());
|
---|
650 | return true;
|
---|
651 | }
|
---|
652 |
|
---|
653 | #ifdef Q_WS_MAC
|
---|
654 | /* posted OnShowWindow */
|
---|
655 | case UIConsoleEventType_ShowWindow:
|
---|
656 | {
|
---|
657 | /* Dunno what Qt3 thinks a window that has minimized to the dock
|
---|
658 | * should be - it is not hidden, neither is it minimized. OTOH it is
|
---|
659 | * marked shown and visible, but not activated. This latter isn't of
|
---|
660 | * much help though, since at this point nothing is marked activated.
|
---|
661 | * I might have overlooked something, but I'm buggered what if I know
|
---|
662 | * what. So, I'll just always show & activate the stupid window to
|
---|
663 | * make it get out of the dock when the user wishes to show a VM. */
|
---|
664 | #if 0
|
---|
665 | // TODO_NEW_CORE
|
---|
666 | window()->show();
|
---|
667 | window()->activateWindow();
|
---|
668 | #endif
|
---|
669 | return true;
|
---|
670 | }
|
---|
671 | #endif
|
---|
672 |
|
---|
673 | default:
|
---|
674 | break;
|
---|
675 | }
|
---|
676 | return QObject::event(pEvent);
|
---|
677 | }
|
---|
678 |
|
---|
679 | qulonglong UISession::winId() const
|
---|
680 | {
|
---|
681 | return machine()->machineLogic()->machineWindowWrapper()->machineWindow()->winId();
|
---|
682 | }
|
---|
683 |
|
---|