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