VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp@ 6455

Last change on this file since 6455 was 6455, checked in by vboxsync, 17 years ago

FE/Qt: ungrab the keyboard when we loose the focus

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 110.0 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxConsoleView class implementation
5 */
6
7/*
8 * Copyright (C) 22006-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 (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "VBoxConsoleView.h"
20#include "VBoxConsoleWnd.h"
21#include "VBoxUtils.h"
22
23#include "VBoxFrameBuffer.h"
24#include "VBoxGlobal.h"
25#include "VBoxProblemReporter.h"
26
27#ifdef Q_WS_PM
28#include "QIHotKeyEdit.h"
29#endif
30
31#include <qapplication.h>
32#include <qstatusbar.h>
33#include <qlabel.h>
34#include <qpainter.h>
35#include <qpixmap.h>
36#include <qimage.h>
37#include <qbitmap.h>
38#include <qcursor.h>
39#include <qthread.h>
40
41#include <qmenudata.h>
42#include <qmenubar.h>
43#include <qwidgetlist.h>
44#include <qtimer.h>
45
46#ifdef Q_WS_WIN
47// VBox/cdefs.h defines these:
48#undef LOWORD
49#undef HIWORD
50#undef LOBYTE
51#undef HIBYTE
52#include <windows.h>
53#endif
54
55#ifdef Q_WS_X11
56// We need to capture some X11 events directly which
57// requires the XEvent structure to be defined. However,
58// including the Xlib header file will cause some nasty
59// conflicts with Qt. Therefore we use the following hack
60// to redefine those conflicting identifiers.
61#define XK_XKB_KEYS
62#define XK_MISCELLANY
63#include <X11/Xlib.h>
64#include <X11/Xutil.h>
65#include <X11/XKBlib.h>
66#include <X11/keysym.h>
67#ifdef KeyPress
68const int XFocusOut = FocusOut;
69const int XFocusIn = FocusIn;
70const int XKeyPress = KeyPress;
71const int XKeyRelease = KeyRelease;
72#undef KeyRelease
73#undef KeyPress
74#undef FocusOut
75#undef FocusIn
76#endif
77#include "XKeyboard.h"
78#ifndef VBOX_WITHOUT_XCURSOR
79# include <X11/Xcursor/Xcursor.h>
80#endif
81#endif // Q_WS_X11
82
83#if defined (Q_WS_MAC)
84# include "DarwinKeyboard.h"
85# include "DarwinCursor.h"
86# ifdef VBOX_WITH_HACKED_QT
87# include "QIApplication.h"
88# endif
89# include <VBox/err.h>
90#endif /* defined (Q_WS_MAC) */
91
92#if defined (VBOX_GUI_USE_REFRESH_TIMER)
93enum { UPDATE_FREQ = 1000 / 60 }; // a-la 60Hz
94#endif
95
96#if defined (Q_WS_WIN32)
97
98static HHOOK g_kbdhook = NULL;
99static VBoxConsoleView *g_view = 0;
100
101LRESULT CALLBACK VBoxConsoleView::lowLevelKeyboardProc (int nCode,
102 WPARAM wParam, LPARAM lParam)
103{
104 Assert (g_view);
105 if (g_view && nCode == HC_ACTION &&
106 g_view->winLowKeyboardEvent (wParam, *(KBDLLHOOKSTRUCT *) lParam))
107 return 1;
108
109 return CallNextHookEx (NULL, nCode, wParam, lParam);
110}
111
112#endif
113
114#if defined (Q_WS_MAC)
115
116# ifndef VBOX_WITH_HACKED_QT
117/**
118 * Event handler callback for Mac OS X.
119 */
120/* static */
121pascal OSStatus VBoxConsoleView::darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
122 EventRef inEvent, void *inUserData)
123{
124 VBoxConsoleView *view = (VBoxConsoleView *)inUserData;
125 UInt32 EventClass = ::GetEventClass (inEvent);
126 if (EventClass == kEventClassKeyboard)
127 {
128 if (view->darwinKeyboardEvent (inEvent))
129 return 0;
130 }
131 /*
132 * Command-H and Command-Q aren't properly disabled yet, and it's still
133 * possible to use the left command key to invoke them when the keyboard
134 * is captured. We discard the events these if the keyboard is captured
135 * as a half measure to prevent unexpected behaviour. However, we don't
136 * get any key down/up events, so these combinations are dead to the guest...
137 */
138 else if (EventClass == kEventClassCommand)
139 {
140 if (view->mKbdCaptured)
141 return 0;
142 }
143 return ::CallNextEventHandler (inHandlerCallRef, inEvent);
144}
145
146# else /* VBOX_WITH_HACKED_QT */
147
148/**
149 * Event handler callback for Mac OS X.
150 */
151/* static */
152bool VBoxConsoleView::macEventFilter (EventRef inEvent, void *inUserData)
153{
154 VBoxConsoleView *view = (VBoxConsoleView *)inUserData;
155 UInt32 EventClass = ::GetEventClass (inEvent);
156 if (EventClass == kEventClassKeyboard)
157 {
158 if (view->darwinKeyboardEvent (inEvent))
159 return true;
160 }
161 return false;
162}
163# endif /* VBOX_WITH_HACKED_QT */
164
165#endif /* Q_WS_MAC */
166
167/** Guest mouse pointer shape change event. */
168class MousePointerChangeEvent : public QEvent
169{
170public:
171 MousePointerChangeEvent (bool visible, bool alpha, uint xhot, uint yhot,
172 uint width, uint height,
173 const uchar *shape) :
174 QEvent ((QEvent::Type) VBoxDefs::MousePointerChangeEventType),
175 vis (visible), alph (alpha), xh (xhot), yh (yhot), w (width), h (height),
176 data (NULL)
177 {
178 // make a copy of shape
179 uint dataSize = ((((width + 7) / 8 * height) + 3) & ~3) + width * 4 * height;
180
181 if (shape) {
182 data = new uchar [dataSize];
183 memcpy ((void *) data, (void *) shape, dataSize);
184 }
185 }
186 ~MousePointerChangeEvent()
187 {
188 if (data) delete[] data;
189 }
190 bool isVisible() const { return vis; }
191 bool hasAlpha() const { return alph; }
192 uint xHot() const { return xh; }
193 uint yHot() const { return yh; }
194 uint width() const { return w; }
195 uint height() const { return h; }
196 const uchar *shapeData() const { return data; }
197private:
198 bool vis, alph;
199 uint xh, yh, w, h;
200 const uchar *data;
201};
202
203/** Guest mouse absolute positioning capability change event. */
204class MouseCapabilityEvent : public QEvent
205{
206public:
207 MouseCapabilityEvent (bool supportsAbsolute, bool needsHostCursor) :
208 QEvent ((QEvent::Type) VBoxDefs::MouseCapabilityEventType),
209 can_abs (supportsAbsolute),
210 needs_host_cursor (needsHostCursor) {}
211 bool supportsAbsolute() const { return can_abs; }
212 bool needsHostCursor() const { return needs_host_cursor; }
213private:
214 bool can_abs;
215 bool needs_host_cursor;
216};
217
218/** Machine state change. */
219class StateChangeEvent : public QEvent
220{
221public:
222 StateChangeEvent (CEnums::MachineState state) :
223 QEvent ((QEvent::Type) VBoxDefs::MachineStateChangeEventType),
224 s (state) {}
225 CEnums::MachineState machineState() const { return s; }
226private:
227 CEnums::MachineState s;
228};
229
230/** Guest Additions property changes. */
231class GuestAdditionsEvent : public QEvent
232{
233public:
234 GuestAdditionsEvent (const QString &aOsTypeId,
235 const QString &aAddVersion,
236 bool aAddActive,
237 bool aSupportsSeamless) :
238 QEvent ((QEvent::Type) VBoxDefs::AdditionsStateChangeEventType),
239 mOsTypeId (aOsTypeId), mAddVersion (aAddVersion),
240 mAddActive (aAddActive), mSupportsSeamless (aSupportsSeamless) {}
241 const QString &osTypeId() const { return mOsTypeId; }
242 const QString &additionVersion() const { return mAddVersion; }
243 bool additionActive() const { return mAddActive; }
244 bool supportsSeamless() const { return mSupportsSeamless; }
245private:
246 QString mOsTypeId;
247 QString mAddVersion;
248 bool mAddActive;
249 bool mSupportsSeamless;
250};
251
252/** DVD/FD change event */
253class MediaChangeEvent : public QEvent
254{
255public:
256 MediaChangeEvent (VBoxDefs::DiskType aType)
257 : QEvent ((QEvent::Type) VBoxDefs::MediaChangeEventType)
258 , mType (aType) {}
259 VBoxDefs::DiskType diskType() const { return mType; }
260private:
261 VBoxDefs::DiskType mType;
262};
263
264/** Menu activation event */
265class ActivateMenuEvent : public QEvent
266{
267public:
268 ActivateMenuEvent (QMenuData *menuData, uint index) :
269 QEvent ((QEvent::Type) VBoxDefs::ActivateMenuEventType),
270 md (menuData), i (index) {}
271 QMenuData *menuData() const { return md; }
272 uint index() const { return i; }
273private:
274 QMenuData *md;
275 uint i;
276};
277
278/** VM Runtime error event */
279class RuntimeErrorEvent : public QEvent
280{
281public:
282 RuntimeErrorEvent (bool aFatal, const QString &aErrorID,
283 const QString &aMessage) :
284 QEvent ((QEvent::Type) VBoxDefs::RuntimeErrorEventType),
285 mFatal (aFatal), mErrorID (aErrorID), mMessage (aMessage) {}
286 bool fatal() const { return mFatal; }
287 QString errorID() const { return mErrorID; }
288 QString message() const { return mMessage; }
289private:
290 bool mFatal;
291 QString mErrorID;
292 QString mMessage;
293};
294
295/** Modifier key change event */
296class ModifierKeyChangeEvent : public QEvent
297{
298public:
299 ModifierKeyChangeEvent (bool fNumLock, bool fCapsLock, bool fScrollLock) :
300 QEvent ((QEvent::Type) VBoxDefs::ModifierKeyChangeEventType),
301 mNumLock (fNumLock), mCapsLock (fCapsLock), mScrollLock (fScrollLock) {}
302 bool numLock() const { return mNumLock; }
303 bool capsLock() const { return mCapsLock; }
304 bool scrollLock() const { return mScrollLock; }
305private:
306 bool mNumLock, mCapsLock, mScrollLock;
307};
308
309/** Network adapter change event */
310class NetworkAdapterChangeEvent : public QEvent
311{
312public:
313 NetworkAdapterChangeEvent (INetworkAdapter *aAdapter) :
314 QEvent ((QEvent::Type) VBoxDefs::NetworkAdapterChangeEventType),
315 mAdapter (aAdapter) {}
316 INetworkAdapter* networkAdapter() { return mAdapter; }
317private:
318 INetworkAdapter *mAdapter;
319};
320
321/** USB controller state change event */
322class USBControllerStateChangeEvent : public QEvent
323{
324public:
325 USBControllerStateChangeEvent()
326 : QEvent ((QEvent::Type) VBoxDefs::USBCtlStateChangeEventType) {}
327};
328
329/** USB device state change event */
330class USBDeviceStateChangeEvent : public QEvent
331{
332public:
333 USBDeviceStateChangeEvent (const CUSBDevice &aDevice, bool aAttached,
334 const CVirtualBoxErrorInfo &aError) :
335 QEvent ((QEvent::Type) VBoxDefs::USBDeviceStateChangeEventType),
336 mDevice (aDevice), mAttached (aAttached), mError (aError) {}
337 CUSBDevice device() const { return mDevice; }
338 bool attached() const { return mAttached; }
339 CVirtualBoxErrorInfo error() const { return mError; }
340private:
341 CUSBDevice mDevice;
342 bool mAttached;
343 CVirtualBoxErrorInfo mError;
344};
345
346//
347// VBoxConsoleCallback class
348/////////////////////////////////////////////////////////////////////////////
349
350class VBoxConsoleCallback : public IConsoleCallback
351{
352public:
353
354 VBoxConsoleCallback (VBoxConsoleView *v) {
355#if defined (Q_WS_WIN)
356 mRefCnt = 0;
357#endif
358 mView = v;
359 }
360
361 virtual ~VBoxConsoleCallback() {}
362
363 NS_DECL_ISUPPORTS
364
365#if defined (Q_WS_WIN)
366 STDMETHOD_(ULONG, AddRef)() {
367 return ::InterlockedIncrement (&mRefCnt);
368 }
369 STDMETHOD_(ULONG, Release)()
370 {
371 long cnt = ::InterlockedDecrement (&mRefCnt);
372 if (cnt == 0)
373 delete this;
374 return cnt;
375 }
376 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
377 {
378 if (riid == IID_IUnknown) {
379 *ppObj = this;
380 AddRef();
381 return S_OK;
382 }
383 if (riid == IID_IConsoleCallback) {
384 *ppObj = this;
385 AddRef();
386 return S_OK;
387 }
388 *ppObj = NULL;
389 return E_NOINTERFACE;
390 }
391#endif
392
393 STDMETHOD(OnMousePointerShapeChange) (BOOL visible, BOOL alpha,
394 ULONG xhot, ULONG yhot,
395 ULONG width, ULONG height,
396 BYTE *shape)
397 {
398 QApplication::postEvent (mView,
399 new MousePointerChangeEvent (visible, alpha,
400 xhot, yhot,
401 width, height, shape));
402 return S_OK;
403 }
404
405 STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL needsHostCursor)
406 {
407 QApplication::postEvent (mView,
408 new MouseCapabilityEvent (supportsAbsolute,
409 needsHostCursor));
410 return S_OK;
411 }
412
413 STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
414 {
415 QApplication::postEvent (mView,
416 new ModifierKeyChangeEvent (fNumLock, fCapsLock,
417 fScrollLock));
418 return S_OK;
419 }
420
421 STDMETHOD(OnStateChange)(MachineState_T machineState)
422 {
423 LogFlowFunc (("machineState=%d\n", machineState));
424 QApplication::postEvent (mView,
425 new StateChangeEvent (
426 (CEnums::MachineState) machineState));
427 return S_OK;
428 }
429
430 STDMETHOD(OnAdditionsStateChange)()
431 {
432 CGuest guest = mView->console().GetGuest();
433 LogFlowFunc (("ver=%s, active=%d\n",
434 guest.GetAdditionsVersion().latin1(),
435 guest.GetAdditionsActive()));
436 QApplication::postEvent (mView,
437 new GuestAdditionsEvent (
438 guest.GetOSTypeId(),
439 guest.GetAdditionsVersion(),
440 guest.GetAdditionsActive(),
441 guest.GetSupportsSeamless()));
442 return S_OK;
443 }
444
445 STDMETHOD(OnDVDDriveChange)()
446 {
447 LogFlowFunc (("DVD Drive changed\n"));
448 QApplication::postEvent (mView, new MediaChangeEvent (VBoxDefs::CD));
449 return S_OK;
450 }
451
452 STDMETHOD(OnFloppyDriveChange)()
453 {
454 LogFlowFunc (("Floppy Drive changed\n"));
455 QApplication::postEvent (mView, new MediaChangeEvent (VBoxDefs::FD));
456 return S_OK;
457 }
458
459 STDMETHOD(OnNetworkAdapterChange) (INetworkAdapter *aNetworkAdapter)
460 {
461 QApplication::postEvent (mView,
462 new NetworkAdapterChangeEvent (aNetworkAdapter));
463 return S_OK;
464 }
465
466 STDMETHOD(OnSerialPortChange) (ISerialPort *aSerialPort)
467 {
468 NOREF(aSerialPort);
469 return S_OK;
470 }
471
472 STDMETHOD(OnParallelPortChange) (IParallelPort *aParallelPort)
473 {
474 NOREF(aParallelPort);
475 return S_OK;
476 }
477
478 STDMETHOD(OnVRDPServerChange)()
479 {
480 return S_OK;
481 }
482
483 STDMETHOD(OnUSBControllerChange)()
484 {
485 QApplication::postEvent (mView,
486 new USBControllerStateChangeEvent());
487 return S_OK;
488 }
489
490 STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *aDevice, BOOL aAttached,
491 IVirtualBoxErrorInfo *aError)
492 {
493 QApplication::postEvent (mView,
494 new USBDeviceStateChangeEvent (
495 CUSBDevice (aDevice),
496 bool (aAttached),
497 CVirtualBoxErrorInfo (aError)));
498 return S_OK;
499 }
500
501 STDMETHOD(OnSharedFolderChange) (Scope_T aScope)
502 {
503 NOREF(aScope);
504 QApplication::postEvent (mView,
505 new QEvent ((QEvent::Type)
506 VBoxDefs::SharedFolderChangeEventType));
507 return S_OK;
508 }
509
510 STDMETHOD(OnRuntimeError)(BOOL fatal, IN_BSTRPARAM id, IN_BSTRPARAM message)
511 {
512 QApplication::postEvent (mView,
513 new RuntimeErrorEvent (!!fatal,
514 QString::fromUcs2 (id),
515 QString::fromUcs2 (message)));
516 return S_OK;
517 }
518
519 STDMETHOD(OnCanShowWindow) (BOOL *canShow)
520 {
521 if (!canShow)
522 return E_POINTER;
523
524 /* as long as there is VBoxConsoleView (which creates/destroys us), it
525 * can be shown */
526 *canShow = TRUE;
527 return S_OK;
528 }
529
530 STDMETHOD(OnShowWindow) (ULONG64 *winId)
531 {
532 if (!winId)
533 return E_POINTER;
534
535#if defined (Q_WS_MAC)
536 /*
537 * Let's try the simple approach first - grab the focus.
538 * Getting a window out of the dock (minimized or whatever it's called)
539 * needs to be done on the GUI thread, so post it a note.
540 */
541 *winId = 0;
542 if (!mView)
543 return S_OK;
544
545 ProcessSerialNumber psn = { 0, kCurrentProcess };
546 OSErr rc = ::SetFrontProcess (&psn);
547 if (!rc)
548 QApplication::postEvent (mView, new QEvent ((QEvent::Type)VBoxDefs::ShowWindowEventType));
549 else
550 {
551 /*
552 * It failed for some reason, send the other process our PSN so it can try.
553 * (This is just a precaution should Mac OS X start imposing the same sensible
554 * focus stealing restrictions that other window managers implement.)
555 */
556 AssertMsgFailed(("SetFrontProcess -> %#x\n", rc));
557 if (::GetCurrentProcess (&psn))
558 *winId = RT_MAKE_U64 (psn.lowLongOfPSN, psn.highLongOfPSN);
559 }
560
561#else
562 /* Return the ID of the top-level console window. */
563 *winId = (ULONG64) mView->topLevelWidget()->winId();
564#endif
565
566 return S_OK;
567 }
568
569protected:
570
571 VBoxConsoleView *mView;
572
573#if defined (Q_WS_WIN)
574private:
575 long mRefCnt;
576#endif
577};
578
579#if !defined (Q_WS_WIN)
580NS_DECL_CLASSINFO (VBoxConsoleCallback)
581NS_IMPL_THREADSAFE_ISUPPORTS1_CI (VBoxConsoleCallback, IConsoleCallback)
582#endif
583
584//
585// VBoxConsoleView class
586/////////////////////////////////////////////////////////////////////////////
587
588/** @class VBoxConsoleView
589 *
590 * The VBoxConsoleView class is a widget that implements a console
591 * for the running virtual machine.
592 */
593
594VBoxConsoleView::VBoxConsoleView (VBoxConsoleWnd *mainWnd,
595 const CConsole &console,
596 VBoxDefs::RenderMode rm,
597 QWidget *parent, const char *name, WFlags f)
598 : QScrollView (parent, name, f | WStaticContents | WNoAutoErase)
599 , mMainWnd (mainWnd)
600 , mConsole (console)
601 , gs (vboxGlobal().settings())
602 , mAttached (false)
603 , mKbdCaptured (false)
604 , mMouseCaptured (false)
605 , mMouseAbsolute (false)
606 , mMouseIntegration (true)
607 , mDisableAutoCapture (false)
608 , mIsHostkeyPressed (false)
609 , mIsHostkeyAlone (false)
610 , mIgnoreMainwndResize (true)
611 , mAutoresizeGuest (false)
612 , mIsAdditionsActive (false)
613 , mNumLock (false)
614 , mScrollLock (false)
615 , mCapsLock (false)
616 , muNumLockAdaptionCnt (2)
617 , muCapsLockAdaptionCnt (2)
618 , mode (rm)
619#if defined(Q_WS_WIN)
620 , mAlphaCursor (NULL)
621#endif
622#if defined(Q_WS_MAC)
623# ifndef VBOX_WITH_HACKED_QT
624 , mDarwinEventHandlerRef (NULL)
625# endif
626 , mDarwinKeyModifiers (0)
627#endif
628{
629 Assert (!mConsole.isNull() &&
630 !mConsole.GetDisplay().isNull() &&
631 !mConsole.GetKeyboard().isNull() &&
632 !mConsole.GetMouse().isNull());
633
634 /* enable MouseMove events */
635 viewport()->setMouseTracking (true);
636
637 /*
638 * QScrollView does the below on its own, but let's do it anyway
639 * for the case it will not do it in the future.
640 */
641 viewport()->installEventFilter (this);
642
643 /* to fix some focus issues */
644 mMainWnd->menuBar()->installEventFilter (this);
645
646 /* we want to be notified on some parent's events */
647 mMainWnd->installEventFilter (this);
648
649#ifdef Q_WS_X11
650 /* initialize the X keyboard subsystem */
651 initXKeyboard (this->x11Display());
652#endif
653
654 ::memset (mPressedKeys, 0, SIZEOF_ARRAY (mPressedKeys));
655
656 resize_hint_timer = new QTimer (this);
657 connect (resize_hint_timer, SIGNAL (timeout()),
658 this, SLOT (doResizeHint()));
659
660 mToggleFSModeTimer = new QTimer (this);
661 connect (mToggleFSModeTimer, SIGNAL (timeout()),
662 this, SIGNAL (resizeHintDone()));
663
664 /* setup rendering */
665
666 CDisplay display = mConsole.GetDisplay();
667 Assert (!display.isNull());
668
669#if defined (VBOX_GUI_USE_REFRESH_TIMER)
670 tid = 0;
671#endif
672 mFrameBuf = 0;
673
674 LogFlowFunc (("Rendering mode: %d\n", mode));
675
676 switch (mode)
677 {
678#if defined (VBOX_GUI_USE_REFRESH_TIMER)
679 case VBoxDefs::TimerMode:
680 display.SetupInternalFramebuffer (32);
681 tid = startTimer (UPDATE_FREQ);
682 break;
683#endif
684#if defined (VBOX_GUI_USE_QIMAGE)
685 case VBoxDefs::QImageMode:
686 mFrameBuf = new VBoxQImageFrameBuffer (this);
687 break;
688#endif
689#if defined (VBOX_GUI_USE_SDL)
690 case VBoxDefs::SDLMode:
691# ifdef Q_WS_X11
692 /* This is somehow necessary to prevent strange X11 warnings on
693 * i386 and segfaults on x86_64. */
694 XFlush(this->x11Display());
695# endif
696 mFrameBuf = new VBoxSDLFrameBuffer (this);
697 /*
698 * disable scrollbars because we cannot correctly draw in a
699 * scrolled window using SDL
700 */
701 horizontalScrollBar()->setEnabled (false);
702 verticalScrollBar()->setEnabled (false);
703 break;
704#endif
705#if defined (VBOX_GUI_USE_DDRAW)
706 case VBoxDefs::DDRAWMode:
707 mFrameBuf = new VBoxDDRAWFrameBuffer (this);
708 break;
709#endif
710 default:
711 AssertReleaseMsgFailed (("Render mode must be valid: %d\n", mode));
712 LogRel (("Invalid render mode: %d\n", mode));
713 qApp->exit (1);
714 break;
715 }
716
717#if defined (VBOX_GUI_USE_DDRAW)
718 if (!mFrameBuf || mFrameBuf->address () == NULL)
719 {
720 if (mFrameBuf)
721 delete mFrameBuf;
722 mode = VBoxDefs::QImageMode;
723 mFrameBuf = new VBoxQImageFrameBuffer (this);
724 }
725#endif
726
727 if (mFrameBuf)
728 {
729 mFrameBuf->AddRef();
730 display.RegisterExternalFramebuffer (CFramebuffer (mFrameBuf));
731 }
732
733 /* setup the callback */
734 mCallback = CConsoleCallback (new VBoxConsoleCallback (this));
735 mConsole.RegisterCallback (mCallback);
736 AssertWrapperOk (mConsole);
737
738 viewport()->setEraseColor (black);
739
740 setSizePolicy (QSizePolicy (QSizePolicy::Maximum, QSizePolicy::Maximum));
741 setMaximumSize (sizeHint());
742
743 setFocusPolicy (WheelFocus);
744
745#if defined (VBOX_GUI_DEBUG) && defined (VBOX_GUI_FRAMEBUF_STAT)
746 VMCPUTimer::calibrate (200);
747#endif
748
749#if defined (Q_WS_WIN)
750 g_view = this;
751#endif
752
753#ifdef Q_WS_MAC
754 DarwinCursorClearHandle (&mDarwinCursor);
755#endif
756}
757
758VBoxConsoleView::~VBoxConsoleView()
759{
760#if defined (Q_WS_WIN)
761 if (g_kbdhook)
762 UnhookWindowsHookEx (g_kbdhook);
763 g_view = 0;
764 if (mAlphaCursor)
765 DestroyIcon (mAlphaCursor);
766#endif
767
768#if defined (VBOX_GUI_USE_REFRESH_TIMER)
769 if (tid)
770 killTimer (tid);
771#endif
772 if (mFrameBuf)
773 {
774 /* detach our framebuffer from Display */
775 CDisplay display = mConsole.GetDisplay();
776 Assert (!display.isNull());
777 display.SetupInternalFramebuffer (0);
778 /* release the reference */
779 mFrameBuf->Release();
780 }
781
782 mConsole.UnregisterCallback (mCallback);
783}
784
785//
786// Public members
787/////////////////////////////////////////////////////////////////////////////
788
789QSize VBoxConsoleView::sizeHint() const
790{
791#if defined (VBOX_GUI_USE_REFRESH_TIMER)
792 if (mode == VBoxDefs::TimerMode)
793 {
794 CDisplay display = mConsole.GetDisplay();
795 return QSize (display.GetWidth() + frameWidth() * 2,
796 display.GetHeight() + frameWidth() * 2);
797 }
798 else
799#endif
800 {
801 return QSize (mFrameBuf->width() + frameWidth() * 2,
802 mFrameBuf->height() + frameWidth() * 2);
803 }
804}
805
806/**
807 * Attaches this console view to the managed virtual machine.
808 *
809 * @note This method is not really necessary these days -- the only place where
810 * it gets called is VBoxConsole::openView(), right after powering the
811 * VM up. We leave it as is just in case attaching/detaching will become
812 * necessary some day (there are useful attached checks everywhere in the
813 * code).
814 */
815void VBoxConsoleView::attach()
816{
817 if (!mAttached)
818 {
819 mAttached = true;
820 }
821}
822
823/**
824 * Detaches this console view from the VM. Must be called to indicate
825 * that the virtual machine managed by this instance will be no more valid
826 * after this call.
827 *
828 * @note This method is not really necessary these days -- the only place where
829 * it gets called is VBoxConsole::closeView(), when the VM is powered
830 * down, before deleting VBoxConsoleView. We leave it as is just in case
831 * attaching/detaching will become necessary some day (there are useful
832 * attached checks everywhere in the code).
833 */
834void VBoxConsoleView::detach()
835{
836 if (mAttached)
837 {
838 /* reuse the focus event handler to uncapture everything */
839 focusEvent (false);
840 mAttached = false;
841 }
842}
843
844/**
845 * Resizes the toplevel widget to fit the console view w/o scrollbars.
846 * If adjustPosition is true and such resize is not possible (because the
847 * console view size is lagrer then the available screen space) the toplevel
848 * widget is resized and moved to become as large as possible while staying
849 * fully visible.
850 */
851void VBoxConsoleView::normalizeGeometry (bool adjustPosition /* = false */)
852{
853 /* Make no normalizeGeometry in case we are in manual resize
854 * mode or main window is maximized */
855 if (mMainWnd->isMaximized() || mMainWnd->isFullScreen())
856 return;
857
858 QWidget *tlw = topLevelWidget();
859
860 /* calculate client window offsets */
861 QRect fr = tlw->frameGeometry();
862 QRect r = tlw->geometry();
863 int dl = r.left() - fr.left();
864 int dt = r.top() - fr.top();
865 int dr = fr.right() - r.right();
866 int db = fr.bottom() - r.bottom();
867
868 /* get the best size w/o scroll bars */
869 QSize s = tlw->sizeHint();
870
871 /* resize the frame to fit the contents */
872 s -= tlw->size();
873 fr.rRight() += s.width();
874 fr.rBottom() += s.height();
875
876 if (adjustPosition)
877 {
878 QRect ar = QApplication::desktop()->availableGeometry (tlw->pos());
879 fr = VBoxGlobal::normalizeGeometry (
880 fr, ar, mode != VBoxDefs::SDLMode /* canResize */);
881 }
882
883#if 0
884 /* center the frame on the desktop */
885 fr.moveCenter (ar.center());
886#endif
887
888 /* finally, set the frame geometry */
889 tlw->setGeometry (fr.left() + dl, fr.top() + dt,
890 fr.width() - dl - dr, fr.height() - dt - db);
891}
892
893/**
894 * Pauses or resumes the VM execution.
895 */
896bool VBoxConsoleView::pause (bool on)
897{
898 /* QAction::setOn() emits the toggled() signal, so avoid recursion when
899 * QAction::setOn() is called from VBoxConsoleWnd::updateMachineState() */
900 if (isPaused() == on)
901 return true;
902
903 if (on)
904 mConsole.Pause();
905 else
906 mConsole.Resume();
907
908 bool ok = mConsole.isOk();
909 if (!ok)
910 {
911 if (on)
912 vboxProblem().cannotPauseMachine (mConsole);
913 else
914 vboxProblem().cannotResumeMachine (mConsole);
915 }
916
917 return ok;
918}
919
920/**
921 * Temporarily disables the mouse integration (or enables it back).
922 */
923void VBoxConsoleView::setMouseIntegrationEnabled (bool enabled)
924{
925 if (mMouseIntegration == enabled)
926 return;
927
928 if (mMouseAbsolute)
929 captureMouse (!enabled, false);
930
931 /* Hiding host cursor in case we are entering mouse integration
932 * mode until it's shape is set to the guest cursor shape in
933 * OnMousePointerShapeChange event handler.
934 *
935 * This is necessary to avoid double-cursor issue when both the
936 * guest and the host cursors are displayed in one place one-above-one.
937 *
938 * This is a workaround because the correct decision is to notify
939 * the Guest Additions about we are entering the mouse integration
940 * mode. The GuestOS should hide it's cursor to allow using of
941 * host cursor for the guest's manipulation.
942 *
943 * This notification is not possible right now due to there is
944 * no the required API. */
945 if (enabled)
946 viewport()->setCursor (QCursor (BlankCursor));
947
948 mMouseIntegration = enabled;
949
950 emitMouseStateChanged();
951}
952
953void VBoxConsoleView::setAutoresizeGuest (bool on)
954{
955 if (mAutoresizeGuest != on)
956 {
957 mAutoresizeGuest = on;
958
959 maybeRestrictMinimumSize();
960
961 if (mIsAdditionsActive && mAutoresizeGuest)
962 doResizeHint();
963 }
964}
965
966/**
967 * This method is called by VBoxConsoleWnd after it does everything necessary
968 * on its side to go to or from fullscreen, but before it is shown.
969 */
970void VBoxConsoleView::onFullscreenChange (bool /* on */)
971{
972 /* Nothing to do here so far */
973}
974
975/**
976 * Notify the console scroll-view about the console-window is opened.
977 */
978void VBoxConsoleView::onViewOpened()
979{
980 /* Variable mIgnoreMainwndResize was initially "true" to ignore QT
981 * initial resize event in case of auto-resize feature is on.
982 * Currently, initial resize event is already processed, so we set
983 * mIgnoreMainwndResize to "false" to process all further resize
984 * events as user-initiated window resize events. */
985 mIgnoreMainwndResize = false;
986}
987
988//
989// Protected Events
990/////////////////////////////////////////////////////////////////////////////
991
992bool VBoxConsoleView::event (QEvent *e)
993{
994 if (mAttached)
995 {
996 switch (e->type())
997 {
998 case QEvent::FocusIn:
999 {
1000 if (isRunning())
1001 focusEvent (true);
1002 break;
1003 }
1004 case QEvent::FocusOut:
1005 {
1006 if (isRunning())
1007 focusEvent (false);
1008 else
1009 {
1010 /* release the host key even when paused */
1011 mIsHostkeyPressed = false;
1012 emitKeyboardStateChanged();
1013 }
1014 break;
1015 }
1016
1017 case VBoxDefs::ResizeEventType:
1018 {
1019 bool oldIgnoreMainwndResize = mIgnoreMainwndResize;
1020 mIgnoreMainwndResize = true;
1021
1022 VBoxResizeEvent *re = (VBoxResizeEvent *) e;
1023 LogFlow (("VBoxDefs::ResizeEventType: %d x %d x %d bpp\n",
1024 re->width(), re->height(), re->bitsPerPixel()));
1025
1026 if (mToggleFSModeTimer->isActive())
1027 mToggleFSModeTimer->stop();
1028
1029 /* do frame buffer dependent resize */
1030 mFrameBuf->resizeEvent (re);
1031 viewport()->unsetCursor();
1032
1033 /* This event appears in case of guest video was changed
1034 * for somehow even without video resolution change.
1035 * In this last case the host VM window will not be resized
1036 * according this event and the host mouse cursor which was
1037 * unset to default here will not be hidden in capture state.
1038 * So it is necessary to perform updateMouseClipping() for
1039 * the guest resize event if the mouse cursor was captured. */
1040 if (mMouseCaptured)
1041 updateMouseClipping();
1042
1043 /* apply maximum size restriction */
1044 setMaximumSize (sizeHint());
1045
1046 maybeRestrictMinimumSize();
1047
1048 /* resize the guest canvas */
1049 resizeContents (re->width(), re->height());
1050 /* let our toplevel widget calculate its sizeHint properly */
1051 QApplication::sendPostedEvents (0, QEvent::LayoutHint);
1052
1053 normalizeGeometry (true /* adjustPosition */);
1054
1055 /* report to the VM thread that we finished resizing */
1056 mConsole.GetDisplay().ResizeCompleted (0);
1057
1058 mIgnoreMainwndResize = oldIgnoreMainwndResize;
1059
1060 /* update geometry after entering fullscreen | seamless */
1061 if (mMainWnd->isTrueFullscreen() || mMainWnd->isTrueSeamless())
1062 updateGeometry();
1063
1064 /* make sure that all posted signals are processed */
1065 qApp->processEvents();
1066
1067 /* emit a signal about guest was resized */
1068 emit resizeHintDone();
1069
1070 return true;
1071 }
1072
1073#if !defined (Q_WS_WIN) && !defined (Q_WS_PM)
1074 /* see VBox[QImage|SDL]FrameBuffer::NotifyUpdate(). */
1075 case VBoxDefs::RepaintEventType:
1076 {
1077 VBoxRepaintEvent *re = (VBoxRepaintEvent *) e;
1078 viewport()->repaint (re->x() - contentsX(),
1079 re->y() - contentsY(),
1080 re->width(), re->height(), false);
1081 /* mConsole.GetDisplay().UpdateCompleted(); - the event was acked already */
1082 return true;
1083 }
1084#endif
1085
1086 case VBoxDefs::SetRegionEventType:
1087 {
1088 VBoxSetRegionEvent *sre = (VBoxSetRegionEvent*) e;
1089 if (mMainWnd->isTrueSeamless() &&
1090 sre->region() != mLastVisibleRegion)
1091 {
1092 mLastVisibleRegion = sre->region();
1093 mMainWnd->setMask (sre->region());
1094 }
1095 else if (!mLastVisibleRegion.isNull() &&
1096 !mMainWnd->isTrueSeamless())
1097 mLastVisibleRegion = QRegion();
1098 return true;
1099 }
1100
1101 case VBoxDefs::MousePointerChangeEventType:
1102 {
1103 MousePointerChangeEvent *me = (MousePointerChangeEvent *) e;
1104 /* change cursor shape only when mouse integration is
1105 * supported (change mouse shape type event may arrive after
1106 * mouse capability change that disables integration */
1107 if (mMouseAbsolute)
1108 setPointerShape (me);
1109 return true;
1110 }
1111 case VBoxDefs::MouseCapabilityEventType:
1112 {
1113 MouseCapabilityEvent *me = (MouseCapabilityEvent *) e;
1114 if (mMouseAbsolute != me->supportsAbsolute())
1115 {
1116 mMouseAbsolute = me->supportsAbsolute();
1117 /* correct the mouse capture state and reset the cursor
1118 * to the default shape if necessary */
1119 if (mMouseAbsolute)
1120 {
1121 CMouse mouse = mConsole.GetMouse();
1122 mouse.PutMouseEventAbsolute (-1, -1, 0, 0);
1123 captureMouse (false, false);
1124 }
1125 else
1126 viewport()->unsetCursor();
1127 emitMouseStateChanged();
1128 vboxProblem().remindAboutMouseIntegration (mMouseAbsolute);
1129 }
1130 if (me->needsHostCursor())
1131 mMainWnd->setMouseIntegrationLocked (false);
1132 return true;
1133 }
1134
1135 case VBoxDefs::ModifierKeyChangeEventType:
1136 {
1137 ModifierKeyChangeEvent *me = (ModifierKeyChangeEvent* )e;
1138 if (me->numLock() != mNumLock)
1139 muNumLockAdaptionCnt = 2;
1140 if (me->capsLock() != mCapsLock)
1141 muCapsLockAdaptionCnt = 2;
1142 mNumLock = me->numLock();
1143 mCapsLock = me->capsLock();
1144 mScrollLock = me->scrollLock();
1145 return true;
1146 }
1147
1148 case VBoxDefs::MachineStateChangeEventType:
1149 {
1150 StateChangeEvent *me = (StateChangeEvent *) e;
1151 LogFlowFunc (("MachineStateChangeEventType: state=%d\n",
1152 me->machineState()));
1153 onStateChange (me->machineState());
1154 emit machineStateChanged (me->machineState());
1155 return true;
1156 }
1157
1158 case VBoxDefs::AdditionsStateChangeEventType:
1159 {
1160 GuestAdditionsEvent *ge = (GuestAdditionsEvent *) e;
1161 LogFlowFunc (("AdditionsStateChangeEventType\n"));
1162
1163 mIsAdditionsActive = ge->additionActive();
1164
1165 maybeRestrictMinimumSize();
1166
1167 emit additionsStateChanged (ge->additionVersion(),
1168 ge->additionActive(),
1169 ge->supportsSeamless());
1170 return true;
1171 }
1172
1173 case VBoxDefs::MediaChangeEventType:
1174 {
1175 MediaChangeEvent *mce = (MediaChangeEvent *) e;
1176 LogFlowFunc (("MediaChangeEvent\n"));
1177
1178 emit mediaChanged (mce->diskType());
1179 return true;
1180 }
1181
1182 case VBoxDefs::ActivateMenuEventType:
1183 {
1184 ActivateMenuEvent *ame = (ActivateMenuEvent *) e;
1185 ame->menuData()->activateItemAt (ame->index());
1186
1187 /*
1188 * The main window and its children can be destroyed at this
1189 * point (if, for example, the activated menu item closes the
1190 * main window). Detect this situation to prevent calls to
1191 * destroyed widgets.
1192 */
1193 QWidgetList *list = QApplication::topLevelWidgets ();
1194 bool destroyed = list->find (mMainWnd) < 0;
1195 delete list;
1196 if (!destroyed && mMainWnd->statusBar())
1197 mMainWnd->statusBar()->clear();
1198
1199 return true;
1200 }
1201
1202 case VBoxDefs::NetworkAdapterChangeEventType:
1203 {
1204 /* no specific adapter information stored in this
1205 * event is currently used */
1206 emit networkStateChange();
1207 return true;
1208 }
1209
1210 case VBoxDefs::USBCtlStateChangeEventType:
1211 {
1212 emit usbStateChange();
1213 return true;
1214 }
1215
1216 case VBoxDefs::USBDeviceStateChangeEventType:
1217 {
1218 USBDeviceStateChangeEvent *ue = (USBDeviceStateChangeEvent *)e;
1219
1220 bool success = ue->error().isNull();
1221
1222 if (!success)
1223 {
1224 if (ue->attached())
1225 vboxProblem().cannotAttachUSBDevice (
1226 mConsole,
1227 vboxGlobal().details (ue->device()), ue->error());
1228 else
1229 vboxProblem().cannotDetachUSBDevice (
1230 mConsole,
1231 vboxGlobal().details (ue->device()), ue->error());
1232 }
1233
1234 emit usbStateChange();
1235
1236 return true;
1237 }
1238
1239 case VBoxDefs::SharedFolderChangeEventType:
1240 {
1241 emit sharedFoldersChanged();
1242 return true;
1243 }
1244
1245 case VBoxDefs::RuntimeErrorEventType:
1246 {
1247 RuntimeErrorEvent *ee = (RuntimeErrorEvent *) e;
1248 vboxProblem().showRuntimeError (mConsole, ee->fatal(),
1249 ee->errorID(), ee->message());
1250 return true;
1251 }
1252
1253 case QEvent::KeyPress:
1254 {
1255 QKeyEvent *ke = (QKeyEvent *) e;
1256 if (mIsHostkeyPressed)
1257 {
1258 if (ke->key() >= Key_F1 && ke->key() <= Key_F12)
1259 {
1260 LONG combo [6];
1261 combo [0] = 0x1d; /* Ctrl down */
1262 combo [1] = 0x38; /* Alt down */
1263 combo [4] = 0xb8; /* Alt up */
1264 combo [5] = 0x9d; /* Ctrl up */
1265 if (ke->key() >= Key_F1 && ke->key() <= Key_F10)
1266 {
1267 combo [2] = 0x3b + (ke->key() - Key_F1); /* F1-F10 down */
1268 combo [3] = 0xbb + (ke->key() - Key_F1); /* F1-F10 up */
1269 }
1270 /* some scan slice */
1271 else if (ke->key() >= Key_F11 && ke->key() <= Key_F12)
1272 {
1273 combo [2] = 0x57 + (ke->key() - Key_F11); /* F11-F12 down */
1274 combo [3] = 0xd7 + (ke->key() - Key_F11); /* F11-F12 up */
1275 }
1276 else
1277 Assert (0);
1278
1279 CKeyboard keyboard = mConsole.GetKeyboard();
1280 Assert (!keyboard.isNull());
1281 keyboard.PutScancodes (combo, 6);
1282 }
1283 else if (ke->key() == Key_Home)
1284 {
1285 /* activate the main menu */
1286 if (mMainWnd->isTrueSeamless() || mMainWnd->isTrueFullscreen())
1287 mMainWnd->popupMainMenu (mMouseCaptured);
1288 else
1289 mMainWnd->menuBar()->setFocus();
1290 }
1291 else
1292 {
1293 /* process hot keys not processed in keyEvent()
1294 * (as in case of non-alphanumeric keys) */
1295 processHotKey (QKeySequence (ke->key()),
1296 mMainWnd->menuBar());
1297 }
1298 }
1299 else
1300 {
1301 if (isPaused())
1302 {
1303 /* if the reminder is disabled we pass the event to
1304 * Qt to enable normal keyboard functionality
1305 * (for example, menu access with Alt+Letter) */
1306 if (!vboxProblem().remindAboutPausedVMInput())
1307 break;
1308 }
1309 }
1310 ke->accept();
1311 return true;
1312 }
1313
1314#ifdef Q_WS_MAC
1315 /* posted OnShowWindow */
1316 case VBoxDefs::ShowWindowEventType:
1317 {
1318 /*
1319 * Dunno what Qt3 thinks a window that has minimized to the dock
1320 * should be - it is not hidden, neither is it minimized. OTOH it is
1321 * marked shown and visible, but not activated. This latter isn't of
1322 * much help though, since at this point nothing is marked activated.
1323 * I might have overlooked something, but I'm buggered what if I know
1324 * what. So, I'll just always show & activate the stupid window to
1325 * make it get out of the dock when the user wishes to show a VM.
1326 */
1327 topLevelWidget()->show();
1328 topLevelWidget()->setActiveWindow();
1329 return true;
1330 }
1331#endif
1332 default:
1333 break;
1334 }
1335 }
1336
1337 return QScrollView::event (e);
1338}
1339
1340bool VBoxConsoleView::eventFilter (QObject *watched, QEvent *e)
1341{
1342 if (mAttached && watched == viewport())
1343 {
1344 switch (e->type())
1345 {
1346 case QEvent::MouseMove:
1347 case QEvent::MouseButtonPress:
1348 case QEvent::MouseButtonDblClick:
1349 case QEvent::MouseButtonRelease:
1350 {
1351 QMouseEvent *me = (QMouseEvent *) e;
1352 if (mouseEvent (me->type(), me->pos(), me->globalPos(),
1353 me->button(), me->state(), me->stateAfter(),
1354 0, Horizontal))
1355 return true; /* stop further event handling */
1356 break;
1357 }
1358 case QEvent::Wheel:
1359 {
1360 QWheelEvent *we = (QWheelEvent *) e;
1361 if (mouseEvent (we->type(), we->pos(), we->globalPos(),
1362 NoButton, we->state(), we->state(),
1363 we->delta(), we->orientation()))
1364 return true; /* stop further event handling */
1365 break;
1366 }
1367 case QEvent::Resize:
1368 {
1369 if (mMouseCaptured)
1370 updateMouseClipping();
1371 }
1372 default:
1373 break;
1374 }
1375 }
1376 else if (watched == mMainWnd)
1377 {
1378 switch (e->type())
1379 {
1380#if defined (Q_WS_WIN32)
1381#if defined (VBOX_GUI_USE_DDRAW)
1382 case QEvent::Move:
1383 {
1384 /*
1385 * notification from our parent that it has moved. We need this
1386 * in order to possibly adjust the direct screen blitting.
1387 */
1388 if (mFrameBuf)
1389 mFrameBuf->moveEvent ((QMoveEvent *) e);
1390 break;
1391 }
1392#endif
1393 /*
1394 * install/uninstall low-level kbd hook on every
1395 * activation/deactivation to:
1396 * a) avoid excess hook calls when we're not active and
1397 * b) be always in front of any other possible hooks
1398 */
1399 case QEvent::WindowActivate:
1400 {
1401 g_kbdhook = SetWindowsHookEx (WH_KEYBOARD_LL, lowLevelKeyboardProc,
1402 GetModuleHandle (NULL), 0);
1403 AssertMsg (g_kbdhook, ("SetWindowsHookEx(): err=%d", GetLastError()));
1404 break;
1405 }
1406 case QEvent::WindowDeactivate:
1407 {
1408 if (g_kbdhook)
1409 {
1410 UnhookWindowsHookEx (g_kbdhook);
1411 g_kbdhook = NULL;
1412 }
1413 break;
1414 }
1415#endif /* defined (Q_WS_WIN32) */
1416#if defined (Q_WS_MAC)
1417 /*
1418 * Install/remove the keyboard event handler.
1419 */
1420 case QEvent::WindowActivate:
1421 darwinGrabKeyboardEvents (true);
1422 break;
1423 case QEvent::WindowDeactivate:
1424 darwinGrabKeyboardEvents (false);
1425 break;
1426#endif /* defined (Q_WS_MAC) */
1427 case QEvent::Resize:
1428 {
1429 if (!mIgnoreMainwndResize &&
1430 mIsAdditionsActive && mAutoresizeGuest)
1431 resize_hint_timer->start (300, TRUE);
1432 break;
1433 }
1434
1435 default:
1436 break;
1437 }
1438 }
1439 else if (watched == mMainWnd->menuBar())
1440 {
1441 /*
1442 * sometimes when we press ESC in the menu it brings the
1443 * focus away (Qt bug?) causing no widget to have a focus,
1444 * or holds the focus itself, instead of returning the focus
1445 * to the console window. here we fix this.
1446 */
1447 switch (e->type())
1448 {
1449 case QEvent::FocusOut:
1450 {
1451 if (qApp->focusWidget() == 0)
1452 setFocus();
1453 break;
1454 }
1455 case QEvent::KeyPress:
1456 {
1457 QKeyEvent *ke = (QKeyEvent *) e;
1458 if (ke->key() == Key_Escape && !(ke->state() & KeyButtonMask))
1459 if (mMainWnd->menuBar()->hasFocus())
1460 setFocus();
1461 break;
1462 }
1463 default:
1464 break;
1465 }
1466 }
1467
1468 return QScrollView::eventFilter (watched, e);
1469}
1470
1471#if defined(Q_WS_WIN32)
1472
1473/**
1474 * Low-level keyboard event handler,
1475 * @return
1476 * true to indicate that the message is processed and false otherwise
1477 */
1478bool VBoxConsoleView::winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event)
1479{
1480#if 0
1481 LogFlow (("### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X (mKbdCaptured=%d)\n",
1482 event.vkCode, event.scanCode, event.flags, event.dwExtraInfo, mKbdCaptured));
1483 char buf [256];
1484 sprintf (buf, "### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X",
1485 event.vkCode, event.scanCode, event.flags, event.dwExtraInfo);
1486 mMainWnd->statusBar()->message (buf);
1487#endif
1488
1489 /* Sometimes it happens that Win inserts additional events on some key
1490 * press/release. For example, it prepends ALT_GR in German layout with
1491 * the VK_LCONTROL vkey with curious 0x21D scan code (seems to be necessary
1492 * to specially treat ALT_GR to enter additional chars to regular apps).
1493 * These events are definitely unwanted in VM, so filter them out. */
1494 if (hasFocus() && (event.scanCode & ~0xFF))
1495 return true;
1496
1497 if (!mKbdCaptured)
1498 return false;
1499
1500 /* it's possible that a key has been pressed while the keyboard was not
1501 * captured, but is being released under the capture. Detect this situation
1502 * and return false to let Windows process the message normally and update
1503 * its key state table (to avoid the stuck key effect). */
1504 uint8_t what_pressed = (event.flags & 0x01) && (event.vkCode != VK_RSHIFT)
1505 ? IsExtKeyPressed
1506 : IsKeyPressed;
1507 if ((event.flags & 0x80) /* released */ &&
1508 ((event.vkCode == gs.hostKey() && !hostkey_in_capture) ||
1509 (mPressedKeys [event.scanCode] & (IsKbdCaptured | what_pressed)) == what_pressed))
1510 return false;
1511
1512 MSG message;
1513 message.hwnd = winId();
1514 message.message = msg;
1515 message.wParam = event.vkCode;
1516 message.lParam =
1517 1 |
1518 (event.scanCode & 0xFF) << 16 |
1519 (event.flags & 0xFF) << 24;
1520
1521 /* Windows sets here the extended bit when the Right Shift key is pressed,
1522 * which is totally wrong. Undo it. */
1523 if (event.vkCode == VK_RSHIFT)
1524 message.lParam &= ~0x1000000;
1525
1526 /* we suppose here that this hook is always called on the main GUI thread */
1527 return winEvent (&message);
1528}
1529
1530/**
1531 * Get Win32 messages before they are passed to Qt. This allows us to get
1532 * the keyboard events directly and bypass the harmful Qt translation. A
1533 * return value of @c true indicates to Qt that the event has been handled.
1534 */
1535bool VBoxConsoleView::winEvent (MSG *msg)
1536{
1537 if (!mAttached || ! (
1538 msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
1539 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP
1540 ))
1541 return false;
1542
1543 /* check for the special flag possibly set at the end of this function */
1544 if ((msg->lParam >> 25) & 0x1)
1545 return false;
1546
1547#if 0
1548 char buf [256];
1549 sprintf (buf, "WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d rzv=%01X ctx=%01d prev=%01d tran=%01d",
1550 msg->message, msg->wParam,
1551 (msg->lParam & 0xFFFF),
1552 ((msg->lParam >> 16) & 0xFF),
1553 ((msg->lParam >> 24) & 0x1),
1554 ((msg->lParam >> 25) & 0xF),
1555 ((msg->lParam >> 29) & 0x1),
1556 ((msg->lParam >> 30) & 0x1),
1557 ((msg->lParam >> 31) & 0x1));
1558 mMainWnd->statusBar()->message (buf);
1559 LogFlow (("%s\n", buf));
1560#endif
1561
1562 int scan = (msg->lParam >> 16) & 0x7F;
1563 /* scancodes 0x80 and 0x00 are ignored */
1564 if (!scan)
1565 return true;
1566
1567 int vkey = msg->wParam;
1568
1569 /* When one of the SHIFT keys is held and one of the cursor movement
1570 * keys is pressed, Windows duplicates SHIFT press/release messages,
1571 * but with the virtual key code set to 0xFF. These virtual keys are also
1572 * sent in some other situations (Pause, PrtScn, etc.). Ignore such
1573 * messages. */
1574 if (vkey == 0xFF)
1575 return true;
1576
1577 int flags = 0;
1578 if (msg->lParam & 0x1000000)
1579 flags |= KeyExtended;
1580 if (!(msg->lParam & 0x80000000))
1581 flags |= KeyPressed;
1582
1583 switch (vkey)
1584 {
1585 case VK_SHIFT:
1586 case VK_CONTROL:
1587 case VK_MENU:
1588 {
1589 /* overcome stupid Win32 modifier key generalization */
1590 int keyscan = scan;
1591 if (flags & KeyExtended)
1592 keyscan |= 0xE000;
1593 switch (keyscan)
1594 {
1595 case 0x002A: vkey = VK_LSHIFT; break;
1596 case 0x0036: vkey = VK_RSHIFT; break;
1597 case 0x001D: vkey = VK_LCONTROL; break;
1598 case 0xE01D: vkey = VK_RCONTROL; break;
1599 case 0x0038: vkey = VK_LMENU; break;
1600 case 0xE038: vkey = VK_RMENU; break;
1601 }
1602 break;
1603 }
1604 case VK_NUMLOCK:
1605 /* Win32 sets the extended bit for the NumLock key. Reset it. */
1606 flags &= ~KeyExtended;
1607 break;
1608 case VK_SNAPSHOT:
1609 flags |= KeyPrint;
1610 break;
1611 case VK_PAUSE:
1612 flags |= KeyPause;
1613 break;
1614 }
1615
1616 bool result = keyEvent (vkey, scan, flags);
1617 if (!result && mKbdCaptured)
1618 {
1619 /* keyEvent() returned that it didn't process the message, but since the
1620 * keyboard is captured, we don't want to pass it to Windows. We just want
1621 * to let Qt process the message (to handle non-alphanumeric <HOST>+key
1622 * shortcuts for example). So send it direcltly to the window with the
1623 * special flag in the reserved area of lParam (to avoid recursion). */
1624 ::SendMessage (msg->hwnd, msg->message,
1625 msg->wParam, msg->lParam | (0x1 << 25));
1626 return true;
1627 }
1628
1629 /* These special keys have to be handled by Windows as well to update the
1630 * internal modifier state and to enable/disable the keyboard LED */
1631 if (vkey == VK_NUMLOCK || vkey == VK_CAPITAL)
1632 return false;
1633
1634 return result;
1635}
1636
1637#elif defined (Q_WS_PM)
1638
1639/**
1640 * Get PM messages before they are passed to Qt. This allows us to get
1641 * the keyboard events directly and bypass the harmful Qt translation. A
1642 * return value of @c true indicates to Qt that the event has been handled.
1643 */
1644bool VBoxConsoleView::pmEvent (QMSG *aMsg)
1645{
1646 if (!mAttached || aMsg->msg != WM_CHAR)
1647 return false;
1648
1649 /* check for the special flag possibly set at the end of this function */
1650 if (SHORT2FROMMP (aMsg->mp2) & 0x8000)
1651 return false;
1652
1653#if 0
1654 {
1655 char buf [256];
1656 sprintf (buf, "*** WM_CHAR: f=%04X rep=%03d scan=%02X ch=%04X vk=%04X",
1657 SHORT1FROMMP (aMsg->mp1), CHAR3FROMMP (aMsg->mp1),
1658 CHAR4FROMMP (aMsg->mp1), SHORT1FROMMP (aMsg->mp2),
1659 SHORT2FROMMP (aMsg->mp2));
1660 mMainWnd->statusBar()->message (buf);
1661 LogFlow (("%s\n", buf));
1662 }
1663#endif
1664
1665 USHORT ch = SHORT1FROMMP (aMsg->mp2);
1666 USHORT f = SHORT1FROMMP (aMsg->mp1);
1667
1668 int scan = (unsigned int) CHAR4FROMMP (aMsg->mp1);
1669 if (!scan || scan > 0x7F)
1670 return true;
1671
1672 int vkey = QIHotKeyEdit::virtualKey (aMsg);
1673
1674 int flags = 0;
1675
1676 if ((ch & 0xFF) == 0xE0)
1677 {
1678 flags |= KeyExtended;
1679 scan = ch >> 8;
1680 }
1681 else if (scan == 0x5C && (ch & 0xFF) == '/')
1682 {
1683 /* this is the '/' key on the keypad */
1684 scan = 0x35;
1685 flags |= KeyExtended;
1686 }
1687 else
1688 {
1689 /* For some keys, the scan code passed in QMSG is a pseudo scan
1690 * code. We replace it with a real hardware scan code, according to
1691 * http://www.computer-engineering.org/ps2keyboard/scancodes1.html.
1692 * Also detect Pause and PrtScn and set flags. */
1693 switch (vkey)
1694 {
1695 case VK_ENTER: scan = 0x1C; flags |= KeyExtended; break;
1696 case VK_CTRL: scan = 0x1D; flags |= KeyExtended; break;
1697 case VK_ALTGRAF: scan = 0x38; flags |= KeyExtended; break;
1698 case VK_LWIN: scan = 0x5B; flags |= KeyExtended; break;
1699 case VK_RWIN: scan = 0x5C; flags |= KeyExtended; break;
1700 case VK_WINMENU: scan = 0x5D; flags |= KeyExtended; break;
1701 case VK_FORWARD: scan = 0x69; flags |= KeyExtended; break;
1702 case VK_BACKWARD: scan = 0x6A; flags |= KeyExtended; break;
1703#if 0
1704 /// @todo this would send 0xE0 0x46 0xE0 0xC6. It's not fully
1705 // clear what is more correct
1706 case VK_BREAK: scan = 0x46; flags |= KeyExtended; break;
1707#else
1708 case VK_BREAK: scan = 0; flags |= KeyPause; break;
1709#endif
1710 case VK_PAUSE: scan = 0; flags |= KeyPause; break;
1711 case VK_PRINTSCRN: scan = 0; flags |= KeyPrint; break;
1712 default:;
1713 }
1714 }
1715
1716 if (!(f & KC_KEYUP))
1717 flags |= KeyPressed;
1718
1719 bool result = keyEvent (vkey, scan, flags);
1720 if (!result && mKbdCaptured)
1721 {
1722 /* keyEvent() returned that it didn't process the message, but since the
1723 * keyboard is captured, we don't want to pass it to PM. We just want
1724 * to let Qt process the message (to handle non-alphanumeric <HOST>+key
1725 * shortcuts for example). So send it direcltly to the window with the
1726 * special flag in the reserved area of lParam (to avoid recursion). */
1727 ::WinSendMsg (aMsg->hwnd, aMsg->msg,
1728 aMsg->mp1,
1729 MPFROM2SHORT (SHORT1FROMMP (aMsg->mp2),
1730 SHORT2FROMMP (aMsg->mp2) | 0x8000));
1731 return true;
1732 }
1733 return result;
1734}
1735
1736#elif defined(Q_WS_X11)
1737
1738/**
1739 * This routine gets X11 events before they are processed by Qt. This is
1740 * used for our platform specific keyboard implementation. A return value
1741 * of TRUE indicates that the event has been processed by us.
1742 */
1743bool VBoxConsoleView::x11Event (XEvent *event)
1744{
1745 static WINEKEYBOARDINFO wineKeyboardInfo;
1746
1747 switch (event->type)
1748 {
1749 /* We have to handle XFocusOut right here as this event is not passed
1750 * to VBoxConsoleView::event(). Handling this event is important for
1751 * releasing the keyboard before the screen saver gets active. */
1752 case XFocusOut:
1753 if (isRunning ())
1754 focusEvent (false);
1755 return false;
1756 case XKeyPress:
1757 case XKeyRelease:
1758 if (mAttached)
1759 break;
1760 /* else fall through */
1761 /// @todo (AH) later, we might want to handle these as well
1762 case KeymapNotify:
1763 case MappingNotify:
1764 default:
1765 return false; /* pass the event to Qt */
1766 }
1767
1768 /* perform the mega-complex translation using the wine algorithms */
1769 handleXKeyEvent (this->x11Display(), event, &wineKeyboardInfo);
1770
1771#if 0
1772 char buf [256];
1773 sprintf (buf, "pr=%d kc=%08X st=%08X fl=%08lX scan=%04X",
1774 event->type == XKeyPress ? 1 : 0, event->xkey.keycode,
1775 event->xkey.state, wineKeyboardInfo.dwFlags, wineKeyboardInfo.wScan);
1776 mMainWnd->statusBar()->message (buf);
1777 LogFlow (("### %s\n", buf));
1778#endif
1779
1780 int scan = wineKeyboardInfo.wScan & 0x7F;
1781 // scancodes 0x00 (no valid translation) and 0x80 are ignored
1782 if (!scan)
1783 return true;
1784
1785 KeySym ks = ::XKeycodeToKeysym (event->xkey.display, event->xkey.keycode, 0);
1786
1787 int flags = 0;
1788 if (wineKeyboardInfo.dwFlags & 0x0001)
1789 flags |= KeyExtended;
1790 if (event->type == XKeyPress)
1791 flags |= KeyPressed;
1792
1793 switch (ks)
1794 {
1795 case XK_Num_Lock:
1796 // Wine sets the extended bit for the NumLock key. Reset it.
1797 flags &= ~KeyExtended;
1798 break;
1799 case XK_Print:
1800 flags |= KeyPrint;
1801 break;
1802 case XK_Pause:
1803 flags |= KeyPause;
1804 break;
1805 }
1806
1807 return keyEvent (ks, scan, flags);
1808}
1809
1810#elif defined (Q_WS_MAC)
1811
1812/**
1813 * Invoked by VBoxConsoleView::darwinEventHandlerProc / VBoxConsoleView::macEventFilter when
1814 * it receives a raw keyboard event.
1815 *
1816 * @param inEvent The keyboard event.
1817 *
1818 * @return true if the key was processed, false if it wasn't processed and should be passed on.
1819 */
1820bool VBoxConsoleView::darwinKeyboardEvent (EventRef inEvent)
1821{
1822 bool ret = false;
1823 UInt32 EventKind = ::GetEventKind (inEvent);
1824 if (EventKind != kEventRawKeyModifiersChanged)
1825 {
1826 /* convert keycode to set 1 scan code. */
1827 UInt32 keyCode = ~0U;
1828 ::GetEventParameter (inEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof (keyCode), NULL, &keyCode);
1829 unsigned scanCode = ::DarwinKeycodeToSet1Scancode (keyCode);
1830 if (scanCode)
1831 {
1832 /* calc flags. */
1833 int flags = 0;
1834 if (EventKind != kEventRawKeyUp)
1835 flags |= KeyPressed;
1836 if (scanCode & VBOXKEY_EXTENDED)
1837 flags |= KeyExtended;
1838 /** @todo KeyPause, KeyPrint. */
1839 scanCode &= VBOXKEY_SCANCODE_MASK;
1840
1841 /* get the unicode string (if present). */
1842 AssertCompileSize (wchar_t, 2);
1843 AssertCompileSize (UniChar, 2);
1844 UInt32 cbWritten = 0;
1845 wchar_t ucs[8];
1846 if (::GetEventParameter (inEvent, kEventParamKeyUnicodes, typeUnicodeText, NULL,
1847 sizeof (ucs), &cbWritten, &ucs[0]) != 0)
1848 cbWritten = 0;
1849 ucs[cbWritten / sizeof(wchar_t)] = 0; /* The api doesn't terminate it. */
1850
1851 ret = keyEvent (keyCode, scanCode, flags, ucs[0] ? ucs : NULL);
1852 }
1853 }
1854 else
1855 {
1856 /* May contain multiple modifier changes, kind of annoying. */
1857 UInt32 newMask = 0;
1858 ::GetEventParameter (inEvent, kEventParamKeyModifiers, typeUInt32, NULL,
1859 sizeof (newMask), NULL, &newMask);
1860 newMask = ::DarwinAdjustModifierMask (newMask);
1861 UInt32 changed = newMask ^ mDarwinKeyModifiers;
1862 if (changed)
1863 {
1864 for (UInt32 bit = 0; bit < 32; bit++)
1865 {
1866 if (!(changed & (1 << bit)))
1867 continue;
1868 unsigned scanCode = ::DarwinModifierMaskToSet1Scancode (1 << bit);
1869 if (!scanCode)
1870 continue;
1871 unsigned keyCode = ::DarwinModifierMaskToDarwinKeycode (1 << bit);
1872 Assert (keyCode);
1873
1874 if (!(scanCode & VBOXKEY_LOCK))
1875 {
1876 unsigned flags = (newMask & (1 << bit)) ? KeyPressed : 0;
1877 if (scanCode & VBOXKEY_EXTENDED)
1878 flags |= KeyExtended;
1879 scanCode &= VBOXKEY_SCANCODE_MASK;
1880 ret |= keyEvent (keyCode, scanCode & 0xff, flags);
1881 }
1882 else
1883 {
1884 unsigned flags = 0;
1885 if (scanCode & VBOXKEY_EXTENDED)
1886 flags |= KeyExtended;
1887 scanCode &= VBOXKEY_SCANCODE_MASK;
1888 keyEvent (keyCode, scanCode, flags | KeyPressed);
1889 keyEvent (keyCode, scanCode, flags);
1890 }
1891 }
1892 }
1893
1894 mDarwinKeyModifiers = newMask;
1895
1896 /* Always return true here because we'll otherwise getting a Qt event
1897 we don't want and that will only cause the Pause warning to pop up. */
1898 ret = true;
1899 }
1900
1901 return ret;
1902}
1903
1904
1905/**
1906 * Installs or removes the keyboard event handler.
1907 *
1908 * @param fGrab True if we're to grab the events, false if we're not to.
1909 */
1910void VBoxConsoleView::darwinGrabKeyboardEvents (bool fGrab)
1911{
1912 if (fGrab)
1913 {
1914 ::SetMouseCoalescingEnabled (false, NULL); //??
1915 ::CGSetLocalEventsSuppressionInterval (0.0); //??
1916
1917#ifndef VBOX_WITH_HACKED_QT
1918
1919 EventTypeSpec eventTypes[6];
1920 eventTypes[0].eventClass = kEventClassKeyboard;
1921 eventTypes[0].eventKind = kEventRawKeyDown;
1922 eventTypes[1].eventClass = kEventClassKeyboard;
1923 eventTypes[1].eventKind = kEventRawKeyUp;
1924 eventTypes[2].eventClass = kEventClassKeyboard;
1925 eventTypes[2].eventKind = kEventRawKeyRepeat;
1926 eventTypes[3].eventClass = kEventClassKeyboard;
1927 eventTypes[3].eventKind = kEventRawKeyModifiersChanged;
1928 /* For ignorning Command-H and Command-Q which aren't affected by the
1929 * global hotkey stuff (doesn't work well): */
1930 eventTypes[4].eventClass = kEventClassCommand;
1931 eventTypes[4].eventKind = kEventCommandProcess;
1932 eventTypes[5].eventClass = kEventClassCommand;
1933 eventTypes[5].eventKind = kEventCommandUpdateStatus;
1934
1935 EventHandlerUPP eventHandler = ::NewEventHandlerUPP (VBoxConsoleView::darwinEventHandlerProc);
1936
1937 mDarwinEventHandlerRef = NULL;
1938 ::InstallApplicationEventHandler (eventHandler, RT_ELEMENTS (eventTypes), &eventTypes[0],
1939 this, &mDarwinEventHandlerRef);
1940 ::DisposeEventHandlerUPP (eventHandler);
1941
1942#else /* VBOX_WITH_HACKED_QT */
1943 ((QIApplication *)qApp)->setEventFilter (VBoxConsoleView::macEventFilter, this);
1944#endif /* VBOX_WITH_HACKED_QT */
1945
1946 ::DarwinGrabKeyboard (false);
1947 }
1948 else
1949 {
1950 ::DarwinReleaseKeyboard ();
1951#ifndef VBOX_WITH_HACKED_QT
1952 if (mDarwinEventHandlerRef)
1953 {
1954 ::RemoveEventHandler (mDarwinEventHandlerRef);
1955 mDarwinEventHandlerRef = NULL;
1956 }
1957#else
1958 ((QIApplication *)qApp)->setEventFilter (NULL, NULL);
1959#endif
1960 }
1961}
1962
1963#endif // defined (Q_WS_WIN)
1964
1965//
1966// Private members
1967/////////////////////////////////////////////////////////////////////////////
1968
1969/**
1970 * Called on every focus change and also to forcibly capture/uncapture the
1971 * input in situations similar to gaining or losing focus.
1972 *
1973 * @param aHasFocus true if the window got focus and false otherwise.
1974 * @param aReleaseHostKey true to release the host key (used only when
1975 * @a aHasFocus is false.
1976 */
1977void VBoxConsoleView::focusEvent (bool aHasFocus,
1978 bool aReleaseHostKey /* = true */)
1979{
1980 if (aHasFocus)
1981 {
1982#ifdef RT_OS_WINDOWS
1983 if ( !mDisableAutoCapture && gs.autoCapture()
1984 && GetAncestor (winId(), GA_ROOT) == GetForegroundWindow())
1985#else
1986 if (!mDisableAutoCapture && gs.autoCapture())
1987#endif /* RT_OS_WINDOWS */
1988 {
1989 captureKbd (true);
1990/// @todo (dmik)
1991// the below is for the mouse auto-capture. disabled for now. in order to
1992// properly support it, we need to know when *all* mouse buttons are
1993// released after we got focus, and grab the mouse only after then.
1994// btw, the similar would be good the for keyboard auto-capture, too.
1995// if (!(mMouseAbsolute && mMouseIntegration))
1996// captureMouse (true);
1997 }
1998
1999 /* reset the single-time disable capture flag */
2000 if (mDisableAutoCapture)
2001 mDisableAutoCapture = false;
2002 }
2003 else
2004 {
2005 captureMouse (false);
2006 captureKbd (false, false);
2007 releaseAllPressedKeys (aReleaseHostKey);
2008 }
2009}
2010
2011/**
2012 * Synchronize the views of the host and the guest to the modifier keys.
2013 * This function will add up to 6 additional keycodes to codes.
2014 *
2015 * @param codes pointer to keycodes which are sent to the keyboard
2016 * @param count pointer to the keycodes counter
2017 */
2018void VBoxConsoleView::fixModifierState(LONG *codes, uint *count)
2019{
2020#if defined(Q_WS_X11)
2021
2022 Window wDummy1, wDummy2;
2023 int iDummy3, iDummy4, iDummy5, iDummy6;
2024 unsigned uMask;
2025 unsigned uKeyMaskNum = 0, uKeyMaskCaps = 0, uKeyMaskScroll = 0;
2026
2027 uKeyMaskCaps = LockMask;
2028 XModifierKeymap* map = XGetModifierMapping(qt_xdisplay());
2029 KeyCode keyCodeNum = XKeysymToKeycode(qt_xdisplay(), XK_Num_Lock);
2030 KeyCode keyCodeScroll = XKeysymToKeycode(qt_xdisplay(), XK_Scroll_Lock);
2031
2032 for (int i = 0; i < 8; i++)
2033 {
2034 if ( keyCodeNum != NoSymbol
2035 && map->modifiermap[map->max_keypermod * i] == keyCodeNum)
2036 uKeyMaskNum = 1 << i;
2037 else if ( keyCodeScroll != NoSymbol
2038 && map->modifiermap[map->max_keypermod * i] == keyCodeScroll)
2039 uKeyMaskScroll = 1 << i;
2040 }
2041 XQueryPointer(qt_xdisplay(), DefaultRootWindow(qt_xdisplay()), &wDummy1, &wDummy2,
2042 &iDummy3, &iDummy4, &iDummy5, &iDummy6, &uMask);
2043 XFreeModifiermap(map);
2044
2045 if (muNumLockAdaptionCnt && (mNumLock ^ !!(uMask & uKeyMaskNum)))
2046 {
2047 muNumLockAdaptionCnt--;
2048 codes[(*count)++] = 0x45;
2049 codes[(*count)++] = 0x45 | 0x80;
2050 }
2051 if (muCapsLockAdaptionCnt && (mCapsLock ^ !!(uMask & uKeyMaskCaps)))
2052 {
2053 muCapsLockAdaptionCnt--;
2054 codes[(*count)++] = 0x3a;
2055 codes[(*count)++] = 0x3a | 0x80;
2056 }
2057
2058#elif defined(Q_WS_WIN32)
2059
2060 if (muNumLockAdaptionCnt && (mNumLock ^ !!(GetKeyState(VK_NUMLOCK))))
2061 {
2062 muNumLockAdaptionCnt--;
2063 codes[(*count)++] = 0x45;
2064 codes[(*count)++] = 0x45 | 0x80;
2065 }
2066 if (muCapsLockAdaptionCnt && (mCapsLock ^ !!(GetKeyState(VK_CAPITAL))))
2067 {
2068 muCapsLockAdaptionCnt--;
2069 codes[(*count)++] = 0x3a;
2070 codes[(*count)++] = 0x3a | 0x80;
2071 }
2072
2073#elif defined(Q_WS_MAC)
2074
2075 /* if (muNumLockAdaptionCnt) ... - NumLock isn't implemented by Mac OS X so ignore it. */
2076 if (muCapsLockAdaptionCnt && (mCapsLock ^ !!(::GetCurrentEventKeyModifiers() & alphaLock)))
2077 {
2078 muCapsLockAdaptionCnt--;
2079 codes[(*count)++] = 0x3a;
2080 codes[(*count)++] = 0x3a | 0x80;
2081 }
2082
2083#else
2084
2085#warning Adapt VBoxConsoleView::fixModifierState
2086
2087#endif
2088
2089
2090}
2091
2092/**
2093 * Called on enter/exit seamless/fullscreen mode.
2094 */
2095void VBoxConsoleView::toggleFSMode()
2096{
2097 if (mIsAdditionsActive && mAutoresizeGuest)
2098 {
2099 QSize newSize = QSize();
2100 if (mMainWnd->isTrueFullscreen() || mMainWnd->isTrueSeamless())
2101 {
2102 mNormalSize = frameSize();
2103 newSize = maximumSize();
2104 }
2105 else
2106 newSize = mNormalSize;
2107 doResizeHint (newSize);
2108 }
2109 mToggleFSModeTimer->start (400, true);
2110}
2111
2112/**
2113 * Called on every key press and release (while in focus).
2114 *
2115 * @param aKey virtual scan code (virtual key on Win32 and KeySym on X11)
2116 * @param aScan hardware scan code
2117 * @param aFlags flags, a combination of Key* constants
2118 * @param aUniKey Unicode translation of the key. Optional.
2119 *
2120 * @return true to consume the event and false to pass it to Qt
2121 */
2122bool VBoxConsoleView::keyEvent (int aKey, uint8_t aScan, int aFlags,
2123 wchar_t *aUniKey/* = NULL*/)
2124{
2125#if 0
2126 {
2127 char buf [256];
2128 sprintf (buf, "aKey=%08X aScan=%02X aFlags=%08X",
2129 aKey, aScan, aFlags);
2130 mMainWnd->statusBar()->message (buf);
2131 }
2132#endif
2133
2134 const bool isHostKey = aKey == gs.hostKey();
2135
2136 LONG buf [16];
2137 LONG *codes = buf;
2138 uint count = 0;
2139 uint8_t whatPressed = 0;
2140
2141 if (!isHostKey)
2142 {
2143 if (aFlags & KeyPrint)
2144 {
2145 static LONG PrintMake[] = { 0xE0, 0x2A, 0xE0, 0x37 };
2146 static LONG PrintBreak[] = { 0xE0, 0xB7, 0xE0, 0xAA };
2147 if (aFlags & KeyPressed)
2148 {
2149 codes = PrintMake;
2150 count = SIZEOF_ARRAY (PrintMake);
2151 }
2152 else
2153 {
2154 codes = PrintBreak;
2155 count = SIZEOF_ARRAY (PrintBreak);
2156 }
2157 }
2158 else if (aFlags & KeyPause)
2159 {
2160 if (aFlags & KeyPressed)
2161 {
2162 static LONG Pause[] = { 0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5 };
2163 codes = Pause;
2164 count = SIZEOF_ARRAY (Pause);
2165 }
2166 else
2167 {
2168 /* Pause shall not produce a break code */
2169 return true;
2170 }
2171 }
2172 else
2173 {
2174 if (aFlags & KeyPressed)
2175 {
2176 /* Check if the guest has the same view on the modifier keys (NumLock,
2177 * CapsLock, ScrollLock) as the X server. If not, send KeyPress events
2178 * to synchronize the state. */
2179 fixModifierState (codes, &count);
2180 }
2181
2182 /* Check if it's C-A-D */
2183 if (aScan == 0x53 /* Del */ &&
2184 ((mPressedKeys [0x38] & IsKeyPressed) /* Alt */ ||
2185 (mPressedKeys [0x38] & IsExtKeyPressed)) &&
2186 ((mPressedKeys [0x1d] & IsKeyPressed) /* Ctrl */ ||
2187 (mPressedKeys [0x1d] & IsExtKeyPressed)))
2188 {
2189 /* Use the C-A-D combination as a last resort to get the
2190 * keyboard and mouse back to the host when the user forgets
2191 * the Host Key. Note that it's always possible to send C-A-D
2192 * to the guest using the Host+Del combination. BTW, it would
2193 * be preferrable to completely ignore C-A-D in guests, but
2194 * that's not possible because we cannot predict what other
2195 * keys will be pressed next when one of C, A, D is held. */
2196
2197 if (isRunning() && mKbdCaptured)
2198 {
2199 captureKbd (false);
2200 if (!(mMouseAbsolute && mMouseIntegration))
2201 captureMouse (false);
2202 }
2203
2204 return true;
2205 }
2206
2207 /* process the scancode and update the table of pressed keys */
2208 whatPressed = IsKeyPressed;
2209
2210 if (aFlags & KeyExtended)
2211 {
2212 codes [count++] = 0xE0;
2213 whatPressed = IsExtKeyPressed;
2214 }
2215
2216 if (aFlags & KeyPressed)
2217 {
2218 codes [count++] = aScan;
2219 mPressedKeys [aScan] |= whatPressed;
2220 }
2221 else
2222 {
2223 /* if we haven't got this key's press message, we ignore its
2224 * release */
2225 if (!(mPressedKeys [aScan] & whatPressed))
2226 return true;
2227 codes [count++] = aScan | 0x80;
2228 mPressedKeys [aScan] &= ~whatPressed;
2229 }
2230
2231 if (mKbdCaptured)
2232 mPressedKeys [aScan] |= IsKbdCaptured;
2233 else
2234 mPressedKeys [aScan] &= ~IsKbdCaptured;
2235 }
2236 }
2237 else
2238 {
2239 /* currently this is used in winLowKeyboardEvent() only */
2240 hostkey_in_capture = mKbdCaptured;
2241 }
2242
2243 bool emitSignal = false;
2244 int hotkey = 0;
2245
2246 /* process the host key */
2247 if (aFlags & KeyPressed)
2248 {
2249 if (isHostKey)
2250 {
2251 if (!mIsHostkeyPressed)
2252 {
2253 mIsHostkeyPressed = mIsHostkeyAlone = true;
2254 if (isRunning())
2255 saveKeyStates();
2256 emitSignal = true;
2257 }
2258 }
2259 else
2260 {
2261 if (mIsHostkeyPressed)
2262 {
2263 if (mIsHostkeyAlone)
2264 {
2265 hotkey = aKey;
2266 mIsHostkeyAlone = false;
2267 }
2268 }
2269 }
2270 }
2271 else
2272 {
2273 if (isHostKey)
2274 {
2275 if (mIsHostkeyPressed)
2276 {
2277 mIsHostkeyPressed = false;
2278
2279 if (mIsHostkeyAlone)
2280 {
2281 if (isPaused())
2282 {
2283 vboxProblem().remindAboutPausedVMInput();
2284 }
2285 else
2286 if (isRunning())
2287 {
2288 bool captured = mKbdCaptured;
2289 bool ok = true;
2290 if (!captured)
2291 {
2292 /* temporarily disable auto capture that will take
2293 * place after this dialog is dismissed because
2294 * the capture state is to be defined by the
2295 * dialog result itself */
2296 mDisableAutoCapture = true;
2297 bool autoConfirmed = false;
2298 ok = vboxProblem().confirmInputCapture (&autoConfirmed);
2299 if (autoConfirmed)
2300 mDisableAutoCapture = false;
2301 /* otherwise, the disable flag will be reset in
2302 * the next console view's foucs in event (since
2303 * may happen asynchronously on some platforms,
2304 * after we return from this code) */
2305 }
2306
2307 if (ok)
2308 {
2309 captureKbd (!captured, false);
2310 if (!(mMouseAbsolute && mMouseIntegration))
2311 captureMouse (mKbdCaptured);
2312 }
2313 }
2314 }
2315
2316 if (isRunning())
2317 sendChangedKeyStates();
2318
2319 emitSignal = true;
2320 }
2321 }
2322 else
2323 {
2324 if (mIsHostkeyPressed)
2325 mIsHostkeyAlone = false;
2326 }
2327 }
2328
2329 /* emit the keyboard state change signal */
2330 if (emitSignal)
2331 emitKeyboardStateChanged();
2332
2333 /* process HOST+<key> shortcuts. currently, <key> is limited to
2334 * alphanumeric chars. */
2335 if (hotkey)
2336 {
2337 bool processed = false;
2338#if defined (Q_WS_WIN32)
2339 NOREF(aUniKey);
2340 int n = GetKeyboardLayoutList (0, NULL);
2341 Assert (n);
2342 HKL *list = new HKL [n];
2343 GetKeyboardLayoutList (n, list);
2344 for (int i = 0; i < n && !processed; i++)
2345 {
2346 wchar_t ch;
2347 static BYTE keys [256] = {0};
2348 if (!ToUnicodeEx (hotkey, 0, keys, &ch, 1, 0, list [i]) == 1)
2349 ch = 0;
2350 if (ch)
2351 processed = processHotKey (QKeySequence (UNICODE_ACCEL +
2352 QChar (ch).upper().unicode()),
2353 mMainWnd->menuBar());
2354 }
2355 delete[] list;
2356#elif defined (Q_WS_X11)
2357 NOREF(aUniKey);
2358 Display *display = x11Display();
2359 int keysyms_per_keycode = getKeysymsPerKeycode();
2360 KeyCode kc = XKeysymToKeycode (display, aKey);
2361 // iterate over the first level (not shifted) keysyms in every group
2362 for (int i = 0; i < keysyms_per_keycode && !processed; i += 2)
2363 {
2364 KeySym ks = XKeycodeToKeysym (display, kc, i);
2365 char ch = 0;
2366 if (!XkbTranslateKeySym (display, &ks, 0, &ch, 1, NULL) == 1)
2367 ch = 0;
2368 if (ch)
2369 {
2370 QChar c = QString::fromLocal8Bit (&ch, 1) [0];
2371 processed = processHotKey (QKeySequence (UNICODE_ACCEL +
2372 c.upper().unicode()),
2373 mMainWnd->menuBar());
2374 }
2375 }
2376#elif defined (Q_WS_MAC)
2377 if (aUniKey && aUniKey [0] && !aUniKey [1])
2378 processed = processHotKey (QKeySequence (UNICODE_ACCEL +
2379 QChar (aUniKey [0]).upper().unicode()),
2380 mMainWnd->menuBar());
2381
2382 /* Don't consider the hot key as pressed since the guest never saw
2383 * it. (probably a generic thing) */
2384 mPressedKeys [aScan] &= ~whatPressed;
2385#endif
2386
2387 /* grab the key from Qt if processed, or pass it to Qt otherwise
2388 * in order to process non-alphanumeric keys in event(), after they are
2389 * converted to Qt virtual keys. */
2390 return processed;
2391 }
2392
2393 /* no more to do, if the host key is in action or the VM is paused */
2394 if (mIsHostkeyPressed || isHostKey || isPaused())
2395 {
2396 /* grab the key from Qt and from VM if it's a host key,
2397 * otherwise just pass it to Qt */
2398 return isHostKey;
2399 }
2400
2401 CKeyboard keyboard = mConsole.GetKeyboard();
2402 Assert (!keyboard.isNull());
2403
2404#if defined (Q_WS_WIN32)
2405 /* send pending WM_PAINT events */
2406 ::UpdateWindow (viewport()->winId());
2407#endif
2408
2409#if 0
2410 {
2411 char buf [256];
2412 sprintf (buf, "*** SCANS: ");
2413 for (uint i = 0; i < count; ++ i)
2414 sprintf (buf + strlen (buf), "%02X ", codes [i]);
2415 mMainWnd->statusBar()->message (buf);
2416 LogFlow (("%s\n", buf));
2417 }
2418#endif
2419
2420 keyboard.PutScancodes (codes, count);
2421
2422 /* grab the key from Qt */
2423 return true;
2424}
2425
2426/**
2427 * Called on every mouse/wheel move and button press/release.
2428 *
2429 * @return true to consume the event and false to pass it to Qt
2430 */
2431bool VBoxConsoleView::mouseEvent (int aType, const QPoint &aPos,
2432 const QPoint &aGlobalPos, ButtonState aButton,
2433 ButtonState aState, ButtonState aStateAfter,
2434 int aWheelDelta, Orientation aWheelDir)
2435{
2436#if 0
2437 char buf [256];
2438 sprintf (buf,
2439 "MOUSE: type=%03d x=%03d y=%03d btn=%03d st=%08X stAfter=%08X "
2440 "wdelta=%03d wdir=%03d",
2441 aType, aPos.x(), aPos.y(), aButton, aState, aStateAfter,
2442 aWheelDelta, aWheelDir);
2443 mMainWnd->statusBar()->message (buf);
2444#else
2445 Q_UNUSED (aButton);
2446 Q_UNUSED (aState);
2447#endif
2448
2449 int state = 0;
2450 if (aStateAfter & LeftButton)
2451 state |= CEnums::LeftButton;
2452 if (aStateAfter & RightButton)
2453 state |= CEnums::RightButton;
2454 if (aStateAfter & MidButton)
2455 state |= CEnums::MiddleButton;
2456
2457 int wheel = 0;
2458 if (aWheelDir == Vertical)
2459 {
2460 /* the absolute value of wheel delta is 120 units per every wheel
2461 * move; positive deltas correspond to counterclockwize rotations
2462 * (usually up), negative -- to clockwize (usually down). */
2463 wheel = - (aWheelDelta / 120);
2464 }
2465
2466 if (mMouseCaptured)
2467 {
2468#ifdef Q_WS_WIN32
2469 /* send pending WM_PAINT events */
2470 ::UpdateWindow (viewport()->winId());
2471#endif
2472
2473 CMouse mouse = mConsole.GetMouse();
2474 mouse.PutMouseEvent (aGlobalPos.x() - mLastPos.x(),
2475 aGlobalPos.y() - mLastPos.y(),
2476 wheel, state);
2477
2478#if defined (Q_WS_MAC)
2479 /*
2480 * Keep the mouse from leaving the widget.
2481 *
2482 * This is a bit tricky to get right because if it escapes we won't necessarily
2483 * get mouse events any longer and can warp it back. So, we keep safety zone
2484 * of up to 300 pixels around the borders of the widget to prevent this from
2485 * happening. Also, the mouse is warped back to the center of the widget.
2486 *
2487 * (Note, aPos seems to be unreliable, it caused endless recursion here at one points...)
2488 * (Note, synergy and other remote clients might not like this cursor warping.)
2489 */
2490 QRect rect = viewport()->visibleRect();
2491 QPoint pw = viewport()->mapToGlobal (viewport()->pos());
2492 rect.moveBy (pw.x(), pw.y());
2493
2494 QRect dpRect = QApplication::desktop()->screenGeometry (viewport());
2495 if (rect.intersects (dpRect))
2496 rect = rect.intersect (dpRect);
2497
2498 int wsafe = rect.width() / 6;
2499 rect.setWidth (rect.width() - wsafe * 2);
2500 rect.setLeft (rect.left() + wsafe);
2501
2502 int hsafe = rect.height() / 6;
2503 rect.setWidth (rect.height() - hsafe * 2);
2504 rect.setTop (rect.top() + hsafe);
2505
2506 if (rect.contains (aGlobalPos, true))
2507 mLastPos = aGlobalPos;
2508 else
2509 {
2510 mLastPos = rect.center();
2511 QCursor::setPos (mLastPos);
2512 }
2513
2514#else /* !Q_WS_MAC */
2515
2516 /* "jerk" the mouse by bringing it to the opposite side
2517 * to simulate the endless moving */
2518
2519#ifdef Q_WS_WIN32
2520 int we = viewport()->width() - 1;
2521 int he = viewport()->height() - 1;
2522 QPoint p = aPos;
2523 if (aPos.x() == 0)
2524 p.setX (we - 1);
2525 else if (aPos.x() == we)
2526 p.setX (1);
2527 if (aPos.y() == 0 )
2528 p.setY (he - 1);
2529 else if (aPos.y() == he)
2530 p.setY (1);
2531
2532 if (p != aPos)
2533 {
2534 mLastPos = viewport()->mapToGlobal (p);
2535 QCursor::setPos (mLastPos);
2536 }
2537 else
2538 {
2539 mLastPos = aGlobalPos;
2540 }
2541#else
2542 int we = QApplication::desktop()->width() - 1;
2543 int he = QApplication::desktop()->height() - 1;
2544 QPoint p = aGlobalPos;
2545 if (aGlobalPos.x() == 0)
2546 p.setX (we - 1);
2547 else if (aGlobalPos.x() == we)
2548 p.setX( 1 );
2549 if (aGlobalPos.y() == 0)
2550 p.setY (he - 1);
2551 else if (aGlobalPos.y() == he)
2552 p.setY (1);
2553
2554 if (p != aGlobalPos)
2555 {
2556 mLastPos = p;
2557 QCursor::setPos (mLastPos);
2558 }
2559 else
2560 {
2561 mLastPos = aGlobalPos;
2562 }
2563#endif
2564#endif /* !Q_WS_MAC */
2565 return true; /* stop further event handling */
2566 }
2567 else /* !mMouseCaptured */
2568 {
2569#ifdef Q_WS_MAC
2570 /* Update the mouse cursor; this is a bit excessive really... */
2571 if (!DarwinCursorIsNull (&mDarwinCursor))
2572 DarwinCursorSet (&mDarwinCursor);
2573#endif
2574 if (mMainWnd->isTrueFullscreen())
2575 {
2576 if (mode != VBoxDefs::SDLMode)
2577 {
2578 /* try to automatically scroll the guest canvas if the
2579 * mouse is on the screen border */
2580 /// @todo (r=dmik) better use a timer for autoscroll
2581 QRect scrGeo = QApplication::desktop()->screenGeometry (this);
2582 int dx = 0, dy = 0;
2583 if (scrGeo.width() < contentsWidth())
2584 {
2585 if (scrGeo.rLeft() == aGlobalPos.x()) dx = -1;
2586 if (scrGeo.rRight() == aGlobalPos.x()) dx = +1;
2587 }
2588 if (scrGeo.height() < contentsHeight())
2589 {
2590 if (scrGeo.rTop() == aGlobalPos.y()) dy = -1;
2591 if (scrGeo.rBottom() == aGlobalPos.y()) dy = +1;
2592 }
2593 if (dx || dy)
2594 scrollBy (dx, dy);
2595 }
2596 }
2597
2598 if (mMouseAbsolute && mMouseIntegration)
2599 {
2600 int cw = contentsWidth(), ch = contentsHeight();
2601 int vw = visibleWidth(), vh = visibleHeight();
2602
2603 if (mode != VBoxDefs::SDLMode)
2604 {
2605 /* try to automatically scroll the guest canvas if the
2606 * mouse goes outside its visible part */
2607
2608 int dx = 0;
2609 if (aPos.x() > vw) dx = aPos.x() - vw;
2610 else if (aPos.x() < 0) dx = aPos.x();
2611 int dy = 0;
2612 if (aPos.y() > vh) dy = aPos.y() - vh;
2613 else if (aPos.y() < 0) dy = aPos.y();
2614 if (dx != 0 || dy != 0) scrollBy (dx, dy);
2615 }
2616
2617 QPoint cpnt = viewportToContents (aPos);
2618 if (cpnt.x() < 0) cpnt.setX (0);
2619 else if (cpnt.x() >= cw) cpnt.setX (cw - 1);
2620 if (cpnt.y() < 0) cpnt.setY (0);
2621 else if (cpnt.y() >= ch) cpnt.setY (ch - 1);
2622
2623 CMouse mouse = mConsole.GetMouse();
2624 mouse.PutMouseEventAbsolute (cpnt.x() + 1, cpnt.y() + 1,
2625 wheel, state);
2626 return true; /* stop further event handling */
2627 }
2628 else
2629 {
2630 if (hasFocus() &&
2631 (aType == QEvent::MouseButtonRelease &&
2632 !aStateAfter))
2633 {
2634 if (isPaused())
2635 {
2636 vboxProblem().remindAboutPausedVMInput();
2637 }
2638 else if (isRunning())
2639 {
2640 /* temporarily disable auto capture that will take
2641 * place after this dialog is dismissed because
2642 * the capture state is to be defined by the
2643 * dialog result itself */
2644 mDisableAutoCapture = true;
2645 bool autoConfirmed = false;
2646 bool ok = vboxProblem().confirmInputCapture (&autoConfirmed);
2647 if (autoConfirmed)
2648 mDisableAutoCapture = false;
2649 /* otherwise, the disable flag will be reset in
2650 * the next console view's foucs in event (since
2651 * may happen asynchronously on some platforms,
2652 * after we return from this code) */
2653
2654 if (ok)
2655 {
2656 captureKbd (true);
2657 captureMouse (true);
2658 }
2659 }
2660 }
2661 }
2662 }
2663
2664 return false;
2665}
2666
2667void VBoxConsoleView::onStateChange (CEnums::MachineState state)
2668{
2669 switch (state)
2670 {
2671 case CEnums::Paused:
2672 {
2673 if (mode != VBoxDefs::TimerMode && mFrameBuf)
2674 {
2675 /*
2676 * Take a screen snapshot. Note that TakeScreenShot() always
2677 * needs a 32bpp image
2678 */
2679 QImage shot = QImage (mFrameBuf->width(), mFrameBuf->height(), 32, 0);
2680 CDisplay dsp = mConsole.GetDisplay();
2681 dsp.TakeScreenShot (shot.bits(), shot.width(), shot.height());
2682 /*
2683 * TakeScreenShot() may fail if, e.g. the Paused notification
2684 * was delivered after the machine execution was resumed. It's
2685 * not fatal.
2686 */
2687 if (dsp.isOk())
2688 {
2689 dimImage (shot);
2690 mPausedShot = shot;
2691 /* fully repaint to pick up mPausedShot */
2692 viewport()->repaint();
2693 }
2694 }
2695 /* fall through */
2696 }
2697 case CEnums::Stuck:
2698 {
2699 /* reuse the focus event handler to uncapture everything */
2700 if (hasFocus())
2701 focusEvent (false /* aHasFocus*/, false /* aReleaseHostKey */);
2702 break;
2703 }
2704 case CEnums::Running:
2705 {
2706 if (mLastState == CEnums::Paused)
2707 {
2708 if (mode != VBoxDefs::TimerMode && mFrameBuf)
2709 {
2710 /* reset the pixmap to free memory */
2711 mPausedShot.resize (0, 0);
2712 /*
2713 * ask for full guest display update (it will also update
2714 * the viewport through IFramebuffer::NotifyUpdate)
2715 */
2716 CDisplay dsp = mConsole.GetDisplay();
2717 dsp.InvalidateAndUpdate();
2718 }
2719 }
2720 /* reuse the focus event handler to capture input */
2721 if (hasFocus())
2722 focusEvent (true /* aHasFocus */);
2723 break;
2724 }
2725 default:
2726 break;
2727 }
2728
2729 mLastState = state;
2730}
2731
2732void VBoxConsoleView::doRefresh()
2733{
2734#if defined (VBOX_GUI_USE_REFRESH_TIMER)
2735 if (mode == VBoxDefs::TimerMode)
2736 {
2737 FRAMEBUF_DEBUG_START (xxx);
2738 QSize last_sz = pm.size();
2739 bool rc = display_to_pixmap (mConsole, pm);
2740 if (rc)
2741 {
2742 if (pm.size() != last_sz)
2743 {
2744 int pw = pm.width(), ph = pm.height();
2745 resizeContents (pw, ph);
2746 updateGeometry();
2747 setMaximumSize (sizeHint());
2748 /* let our toplevel widget calculate its sizeHint properly */
2749 QApplication::sendPostedEvents (0, QEvent::LayoutHint);
2750 normalizeGeometry();
2751 }
2752 else
2753 {
2754 /* the alternative is to update, so we will be repainted
2755 * on the next event loop iteration. currently disabled.
2756 * updateContents(); */
2757 repaintContents (false);
2758 }
2759 }
2760 if (rc)
2761 FRAMEBUF_DEBUG_STOP (xxx, pm.width(), pm.height());
2762 }
2763 else
2764#endif
2765 repaintContents (false);
2766}
2767
2768void VBoxConsoleView::viewportPaintEvent (QPaintEvent *pe)
2769{
2770#if defined (VBOX_GUI_USE_REFRESH_TIMER)
2771 if (mode == VBoxDefs::TimerMode)
2772 {
2773 if (!pm.isNull())
2774 {
2775 /* draw a part of vbuf */
2776 const QRect &r = pe->rect();
2777 ::bitBlt (viewport(), r.x(), r.y(),
2778 &pm, r.x() + contentsX(), r.y() + contentsY(),
2779 r.width(), r.height(),
2780 CopyROP, TRUE);
2781 }
2782 else
2783 {
2784 viewport()->erase (pe->rect());
2785 }
2786 }
2787 else
2788#endif
2789 {
2790 if (mPausedShot.isNull())
2791 {
2792 /* delegate the paint function to the VBoxFrameBuffer interface */
2793 mFrameBuf->paintEvent (pe);
2794#ifdef Q_WS_MAC
2795 /* Update the dock icon if we are in the running state */
2796 if(isRunning())
2797 SetApplicationDockTileImage(::DarwinCreateDockPreview(mFrameBuf));
2798#endif
2799
2800 return;
2801 }
2802
2803 /* we have a snapshot for the paused state */
2804 QRect r = pe->rect().intersect (viewport()->rect());
2805 QPainter pnt (viewport());
2806 pnt.drawPixmap (r.x(), r.y(), mPausedShot,
2807 r.x() + contentsX(), r.y() + contentsY(),
2808 r.width(), r.height());
2809 }
2810}
2811
2812#ifdef VBOX_GUI_USE_REFRESH_TIMER
2813void VBoxConsoleView::timerEvent( QTimerEvent * )
2814{
2815 doRefresh();
2816}
2817#endif
2818
2819/**
2820 * Captures the keyboard. When captured, no keyboard input reaches the host
2821 * system (including most system combinations like Alt-Tab).
2822 *
2823 * @param aCapture true to capture, false to uncapture.
2824 * @param aEmitSignal Whether to emit keyboardStateChanged() or not.
2825 */
2826void VBoxConsoleView::captureKbd (bool aCapture, bool aEmitSignal /* = true */)
2827{
2828 AssertMsg (mAttached, ("Console must be attached"));
2829
2830 if (mKbdCaptured == aCapture)
2831 return;
2832
2833 /* On Win32, keyboard grabbing is ineffective, a low-level keyboard hook is
2834 * used instead. On X11, we use XGrabKey instead of XGrabKeyboard (called
2835 * by QWidget::grabKeyboard()) because the latter causes problems under
2836 * metacity 2.16 (in particular, due to a bug, a window cannot be moved
2837 * using the mouse if it is currently grabing the keyboard). On Mac OS X,
2838 * we use the Qt methods + disabling global hot keys + watching modifiers
2839 * (for right/left separation). */
2840#if defined (Q_WS_WIN32)
2841 /**/
2842#elif defined (Q_WS_X11)
2843 if (aCapture)
2844 XGrabKey (x11Display(), AnyKey, AnyModifier,
2845 topLevelWidget()->winId(), False,
2846 GrabModeAsync, GrabModeAsync);
2847 else
2848 XUngrabKey (x11Display(), AnyKey, AnyModifier,
2849 topLevelWidget()->winId());
2850#elif defined (Q_WS_MAC)
2851 if (aCapture)
2852 {
2853 ::DarwinDisableGlobalHotKeys (true);
2854 grabKeyboard();
2855 }
2856 else
2857 {
2858 ::DarwinDisableGlobalHotKeys (false);
2859 releaseKeyboard();
2860 }
2861#else
2862 if (aCapture)
2863 grabKeyboard();
2864 else
2865 releaseKeyboard();
2866#endif
2867
2868 mKbdCaptured = aCapture;
2869
2870 if (aEmitSignal)
2871 emitKeyboardStateChanged ();
2872}
2873
2874/**
2875 * Captures the host mouse pointer. When captured, the mouse pointer is
2876 * unavailable to the host applications.
2877 *
2878 * @param aCapture true to capture, false to uncapture.
2879 * @param aEmitSignal Whether to emit mouseStateChanged() or not.
2880 */
2881void VBoxConsoleView::captureMouse (bool aCapture, bool aEmitSignal /* = true */)
2882{
2883 AssertMsg (mAttached, ("Console must be attached"));
2884
2885 if (mMouseCaptured == aCapture)
2886 return;
2887
2888 if (aCapture)
2889 {
2890 /* memorize the host position where the cursor was captured */
2891 mCapturedPos = QCursor::pos();
2892#ifdef Q_WS_WIN32
2893 viewport()->setCursor (QCursor (BlankCursor));
2894 /* move the mouse to the center of the visible area */
2895 QCursor::setPos (mapToGlobal (visibleRect().center()));
2896 mLastPos = QCursor::pos();
2897#elif defined (Q_WS_MAC)
2898 /* move the mouse to the center of the visible area */
2899 mLastPos = mapToGlobal (visibleRect().center());
2900 QCursor::setPos (mLastPos);
2901 /* grab all mouse events. */
2902 viewport()->grabMouse();
2903#else
2904 viewport()->grabMouse();
2905 mLastPos = QCursor::pos();
2906#endif
2907 }
2908 else
2909 {
2910#ifndef Q_WS_WIN32
2911 viewport()->releaseMouse();
2912#endif
2913 /* release mouse buttons */
2914 CMouse mouse = mConsole.GetMouse();
2915 mouse.PutMouseEvent (0, 0, 0, 0);
2916 }
2917
2918 mMouseCaptured = aCapture;
2919
2920 updateMouseClipping();
2921
2922 if (aEmitSignal)
2923 emitMouseStateChanged ();
2924}
2925
2926/**
2927 * Searches for a menu item with a given hot key (shortcut). If the item
2928 * is found, activates it and returns true. Otherwise returns false.
2929 */
2930bool VBoxConsoleView::processHotKey (const QKeySequence &key, QMenuData *data)
2931{
2932 if (!data) return false;
2933
2934 /*
2935 * Note: below, we use the internal class QMenuItem, that is subject
2936 * to change w/o notice... (the alternative would be to explicitly assign
2937 * specific IDs to all popup submenus in VBoxConsoleWnd and then
2938 * look through its children in order to find a popup with a given ID,
2939 * which is unconvenient).
2940 */
2941
2942 for (uint i = 0; i < data->count(); i++)
2943 {
2944 int id = data->idAt (i);
2945 QMenuItem *item = data->findItem (id);
2946 if (item->popup())
2947 {
2948 if (processHotKey (key, item->popup()))
2949 return true;
2950 }
2951 else
2952 {
2953 QStringList list = QStringList::split ("\tHost+", data->text (id));
2954 if (list.count() == 2)
2955 {
2956 if (key.matches (QKeySequence (list[1])) == Identical)
2957 {
2958 /*
2959 * we asynchronously post a special event instead of calling
2960 * data->activateItemAt (i) directly, to let key presses
2961 * and releases be processed correctly by Qt first.
2962 * Note: we assume that nobody will delete the menu item
2963 * corresponding to the key sequence, so that the pointer to
2964 * menu data posted along with the event will remain valid in
2965 * the event handler, at least until the main window is closed.
2966 */
2967
2968 QApplication::postEvent (this,
2969 new ActivateMenuEvent (data, i));
2970 return true;
2971 }
2972 }
2973 }
2974 }
2975
2976 return false;
2977}
2978
2979/**
2980 * Send the KEY BREAK code to the VM for all currently pressed keys.
2981 *
2982 * @param aReleaseHostKey @c true to set the host key state to unpressed.
2983 */
2984void VBoxConsoleView::releaseAllPressedKeys (bool aReleaseHostKey)
2985{
2986 AssertMsg (mAttached, ("Console must be attached"));
2987
2988 CKeyboard keyboard = mConsole.GetKeyboard();
2989 bool fSentRESEND = false;
2990
2991 /* send a dummy scan code (RESEND) to prevent the guest OS from recognizing
2992 * a single key click (for ex., Alt) and performing an unwanted action
2993 * (for ex., activating the menu) when we release all pressed keys below.
2994 * Note, that it's just a guess that sending RESEND will give the desired
2995 * effect :), but at least it works with NT and W2k guests. */
2996
2997 /// @todo Sending 0xFE is responsible for the warning
2998 //
2999 // ``atkbd.c: Spurious NAK on isa0060/serio0. Some program might
3000 // be trying access hardware directly''
3001 //
3002 // on Linux guests (#1944). It might also be responsible for #1949. Don't
3003 // send this command unless we really have to release any key modifier.
3004 // --frank
3005
3006 for (uint i = 0; i < SIZEOF_ARRAY (mPressedKeys); i++)
3007 {
3008 if (mPressedKeys [i] & IsKeyPressed)
3009 {
3010 if (!fSentRESEND)
3011 {
3012 keyboard.PutScancode (0xFE);
3013 fSentRESEND = true;
3014 }
3015 keyboard.PutScancode (i | 0x80);
3016 }
3017 else if (mPressedKeys [i] & IsExtKeyPressed)
3018 {
3019 if (!fSentRESEND)
3020 {
3021 keyboard.PutScancode (0xFE);
3022 fSentRESEND = true;
3023 }
3024 LONG codes [2];
3025 codes[0] = 0xE0;
3026 codes[1] = i | 0x80;
3027 keyboard.PutScancodes (codes, 2);
3028 }
3029 mPressedKeys [i] = 0;
3030 }
3031
3032 if (aReleaseHostKey)
3033 mIsHostkeyPressed = false;
3034
3035#ifdef Q_WS_MAC
3036 /* clear most of the modifiers. */
3037 mDarwinKeyModifiers &=
3038 alphaLock | kEventKeyModifierNumLockMask |
3039 (aReleaseHostKey ? 0 : ::DarwinKeyCodeToDarwinModifierMask (gs.hostKey()));
3040#endif
3041
3042 emitKeyboardStateChanged ();
3043}
3044
3045void VBoxConsoleView::saveKeyStates()
3046{
3047 ::memcpy (mPressedKeysCopy, mPressedKeys,
3048 SIZEOF_ARRAY (mPressedKeys));
3049}
3050
3051void VBoxConsoleView::sendChangedKeyStates()
3052{
3053 AssertMsg (mAttached, ("Console must be attached"));
3054
3055 LONG codes [2];
3056 CKeyboard keyboard = mConsole.GetKeyboard();
3057 for (uint i = 0; i < SIZEOF_ARRAY (mPressedKeys); ++ i)
3058 {
3059 uint8_t os = mPressedKeysCopy [i];
3060 uint8_t ns = mPressedKeys [i];
3061 if ((os & IsKeyPressed) != (ns & IsKeyPressed))
3062 {
3063 codes [0] = i;
3064 if (!(ns & IsKeyPressed))
3065 codes[0] |= 0x80;
3066 keyboard.PutScancode (codes[0]);
3067 }
3068 else if ((os & IsExtKeyPressed) != (ns & IsExtKeyPressed))
3069 {
3070 codes [0] = 0xE0;
3071 codes [1] = i;
3072 if (!(ns & IsExtKeyPressed))
3073 codes [1] |= 0x80;
3074 keyboard.PutScancodes (codes, 2);
3075 }
3076 }
3077}
3078
3079void VBoxConsoleView::updateMouseClipping()
3080{
3081 AssertMsg (mAttached, ("Console must be attached"));
3082
3083 if (mMouseCaptured)
3084 {
3085 viewport()->setCursor (QCursor (BlankCursor));
3086#ifdef Q_WS_WIN32
3087 QRect r = viewport()->rect();
3088 r.moveTopLeft (viewport()->mapToGlobal (QPoint (0, 0)));
3089 RECT rect = { r.left(), r.top(), r.right() + 1, r.bottom() + 1 };
3090 ::ClipCursor (&rect);
3091#endif
3092 }
3093 else
3094 {
3095#ifdef Q_WS_WIN32
3096 ::ClipCursor (NULL);
3097#endif
3098 /* return the cursor to where it was when we captured it and show it */
3099 QCursor::setPos (mCapturedPos);
3100 viewport()->unsetCursor();
3101 }
3102}
3103
3104void VBoxConsoleView::setPointerShape (MousePointerChangeEvent *me)
3105{
3106 if (me->shapeData () != NULL)
3107 {
3108 bool ok = false;
3109
3110 const uchar *srcAndMaskPtr = me->shapeData();
3111 uint andMaskSize = (me->width() + 7) / 8 * me->height();
3112 const uchar *srcShapePtr = me->shapeData() + ((andMaskSize + 3) & ~3);
3113 uint srcShapePtrScan = me->width() * 4;
3114
3115#if defined (Q_WS_WIN)
3116
3117 BITMAPV5HEADER bi;
3118 HBITMAP hBitmap;
3119 void *lpBits;
3120
3121 ::ZeroMemory (&bi, sizeof (BITMAPV5HEADER));
3122 bi.bV5Size = sizeof (BITMAPV5HEADER);
3123 bi.bV5Width = me->width();
3124 bi.bV5Height = - (LONG) me->height();
3125 bi.bV5Planes = 1;
3126 bi.bV5BitCount = 32;
3127 bi.bV5Compression = BI_BITFIELDS;
3128 // specifiy a supported 32 BPP alpha format for Windows XP
3129 bi.bV5RedMask = 0x00FF0000;
3130 bi.bV5GreenMask = 0x0000FF00;
3131 bi.bV5BlueMask = 0x000000FF;
3132 if (me->hasAlpha())
3133 bi.bV5AlphaMask = 0xFF000000;
3134 else
3135 bi.bV5AlphaMask = 0;
3136
3137 HDC hdc = GetDC (NULL);
3138
3139 // create the DIB section with an alpha channel
3140 hBitmap = CreateDIBSection (hdc, (BITMAPINFO *) &bi, DIB_RGB_COLORS,
3141 (void **) &lpBits, NULL, (DWORD) 0);
3142
3143 ReleaseDC (NULL, hdc);
3144
3145 HBITMAP hMonoBitmap = NULL;
3146 if (me->hasAlpha())
3147 {
3148 // create an empty mask bitmap
3149 hMonoBitmap = CreateBitmap (me->width(), me->height(), 1, 1, NULL);
3150 }
3151 else
3152 {
3153 /* Word aligned AND mask. Will be allocated and created if necessary. */
3154 uint8_t *pu8AndMaskWordAligned = NULL;
3155
3156 /* Width in bytes of the original AND mask scan line. */
3157 uint32_t cbAndMaskScan = (me->width() + 7) / 8;
3158
3159 if (cbAndMaskScan & 1)
3160 {
3161 /* Original AND mask is not word aligned. */
3162
3163 /* Allocate memory for aligned AND mask. */
3164 pu8AndMaskWordAligned = (uint8_t *)RTMemTmpAllocZ ((cbAndMaskScan + 1) * me->height());
3165
3166 Assert(pu8AndMaskWordAligned);
3167
3168 if (pu8AndMaskWordAligned)
3169 {
3170 /* According to MSDN the padding bits must be 0.
3171 * Compute the bit mask to set padding bits to 0 in the last byte of original AND mask.
3172 */
3173 uint32_t u32PaddingBits = cbAndMaskScan * 8 - me->width();
3174 Assert(u32PaddingBits < 8);
3175 uint8_t u8LastBytesPaddingMask = (uint8_t)(0xFF << u32PaddingBits);
3176
3177 Log(("u8LastBytesPaddingMask = %02X, aligned w = %d, width = %d, cbAndMaskScan = %d\n",
3178 u8LastBytesPaddingMask, (cbAndMaskScan + 1) * 8, me->width(), cbAndMaskScan));
3179
3180 uint8_t *src = (uint8_t *)srcAndMaskPtr;
3181 uint8_t *dst = pu8AndMaskWordAligned;
3182
3183 unsigned i;
3184 for (i = 0; i < me->height(); i++)
3185 {
3186 memcpy (dst, src, cbAndMaskScan);
3187
3188 dst[cbAndMaskScan - 1] &= u8LastBytesPaddingMask;
3189
3190 src += cbAndMaskScan;
3191 dst += cbAndMaskScan + 1;
3192 }
3193 }
3194 }
3195
3196 /* create the AND mask bitmap */
3197 hMonoBitmap = ::CreateBitmap (me->width(), me->height(), 1, 1,
3198 pu8AndMaskWordAligned? pu8AndMaskWordAligned: srcAndMaskPtr);
3199
3200 if (pu8AndMaskWordAligned)
3201 {
3202 RTMemTmpFree (pu8AndMaskWordAligned);
3203 }
3204 }
3205
3206 Assert (hBitmap);
3207 Assert (hMonoBitmap);
3208 if (hBitmap && hMonoBitmap)
3209 {
3210 DWORD *dstShapePtr = (DWORD *) lpBits;
3211
3212 for (uint y = 0; y < me->height(); y ++)
3213 {
3214 memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
3215 srcShapePtr += srcShapePtrScan;
3216 dstShapePtr += me->width();
3217 }
3218
3219 ICONINFO ii;
3220 ii.fIcon = FALSE;
3221 ii.xHotspot = me->xHot();
3222 ii.yHotspot = me->yHot();
3223 ii.hbmMask = hMonoBitmap;
3224 ii.hbmColor = hBitmap;
3225
3226 HCURSOR hAlphaCursor = CreateIconIndirect (&ii);
3227 Assert (hAlphaCursor);
3228 if (hAlphaCursor)
3229 {
3230 viewport()->setCursor (QCursor (hAlphaCursor));
3231 ok = true;
3232 if (mAlphaCursor)
3233 DestroyIcon (mAlphaCursor);
3234 mAlphaCursor = hAlphaCursor;
3235 }
3236 }
3237
3238 if (hMonoBitmap)
3239 DeleteObject (hMonoBitmap);
3240 if (hBitmap)
3241 DeleteObject (hBitmap);
3242
3243#elif defined (Q_WS_X11) && !defined (VBOX_WITHOUT_XCURSOR)
3244
3245 XcursorImage *img = XcursorImageCreate (me->width(), me->height());
3246 Assert (img);
3247 if (img)
3248 {
3249 img->xhot = me->xHot();
3250 img->yhot = me->yHot();
3251
3252 XcursorPixel *dstShapePtr = img->pixels;
3253
3254 for (uint y = 0; y < me->height(); y ++)
3255 {
3256 memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
3257
3258 if (!me->hasAlpha())
3259 {
3260 /* convert AND mask to the alpha channel */
3261 uchar byte = 0;
3262 for (uint x = 0; x < me->width(); x ++)
3263 {
3264 if (!(x % 8))
3265 byte = *(srcAndMaskPtr ++);
3266 else
3267 byte <<= 1;
3268
3269 if (byte & 0x80)
3270 {
3271 /* Linux doesn't support inverted pixels (XOR ops,
3272 * to be exact) in cursor shapes, so we detect such
3273 * pixels and always replace them with black ones to
3274 * make them visible at least over light colors */
3275 if (dstShapePtr [x] & 0x00FFFFFF)
3276 dstShapePtr [x] = 0xFF000000;
3277 else
3278 dstShapePtr [x] = 0x00000000;
3279 }
3280 else
3281 dstShapePtr [x] |= 0xFF000000;
3282 }
3283 }
3284
3285 srcShapePtr += srcShapePtrScan;
3286 dstShapePtr += me->width();
3287 }
3288
3289 Cursor cur = XcursorImageLoadCursor (x11Display(), img);
3290 Assert (cur);
3291 if (cur)
3292 {
3293 viewport()->setCursor (QCursor (cur));
3294 ok = true;
3295 }
3296
3297 XcursorImageDestroy (img);
3298 }
3299
3300#elif defined(Q_WS_MAC)
3301
3302 /*
3303 * Qt3/Mac only supports black/white cursors and it offers no way
3304 * to create your own cursors here unlike on X11 and Windows.
3305 * Which means we're pretty much forced to do it our own way.
3306 */
3307 int rc;
3308
3309 /* dispose of the old cursor. */
3310 if (!DarwinCursorIsNull (&mDarwinCursor))
3311 {
3312 rc = DarwinCursorDestroy (&mDarwinCursor);
3313 AssertRC (rc);
3314 }
3315
3316 /* create the new cursor */
3317 rc = DarwinCursorCreate (me->width(), me->height(), me->xHot(), me->yHot(), me->hasAlpha(),
3318 srcAndMaskPtr, srcShapePtr, &mDarwinCursor);
3319 AssertRC (rc);
3320 if (VBOX_SUCCESS (rc))
3321 {
3322 /** @todo check current mouse coordinates. */
3323 rc = DarwinCursorSet (&mDarwinCursor);
3324 AssertRC (rc);
3325 }
3326 ok = VBOX_SUCCESS (rc);
3327 NOREF (srcShapePtrScan);
3328
3329#else
3330
3331# warning "port me"
3332
3333#endif
3334 if (!ok)
3335 viewport()->unsetCursor();
3336 }
3337 else
3338 {
3339 /*
3340 * We did not get any shape data
3341 */
3342 if (me->isVisible ())
3343 {
3344 /*
3345 * We're supposed to make the last shape we got visible.
3346 * We don't support that for now...
3347 */
3348 /// @todo viewport()->setCursor (QCursor());
3349 }
3350 else
3351 {
3352 viewport()->setCursor (QCursor::BlankCursor);
3353 }
3354 }
3355}
3356
3357inline QRgb qRgbIntensity (QRgb rgb, int mul, int div)
3358{
3359 int r = qRed (rgb);
3360 int g = qGreen (rgb);
3361 int b = qBlue (rgb);
3362 return qRgb (mul * r / div, mul * g / div, mul * b / div);
3363}
3364
3365/* static */
3366void VBoxConsoleView::dimImage (QImage &img)
3367{
3368 for (int y = 0; y < img.height(); y ++) {
3369 if (y % 2) {
3370 if (img.depth() == 32) {
3371 for (int x = 0; x < img.width(); x ++) {
3372 int gray = qGray (img.pixel (x, y)) / 2;
3373 img.setPixel (x, y, qRgb (gray, gray, gray));
3374// img.setPixel (x, y, qRgbIntensity (img.pixel (x, y), 1, 2));
3375 }
3376 } else {
3377 ::memset (img.scanLine (y), 0, img.bytesPerLine());
3378 }
3379 } else {
3380 if (img.depth() == 32) {
3381 for (int x = 0; x < img.width(); x ++) {
3382 int gray = (2 * qGray (img.pixel (x, y))) / 3;
3383 img.setPixel (x, y, qRgb (gray, gray, gray));
3384// img.setPixel (x, y, qRgbIntensity (img.pixel(x, y), 2, 3));
3385 }
3386 }
3387 }
3388 }
3389}
3390
3391void VBoxConsoleView::doResizeHint (const QSize &aToSize)
3392{
3393 if (mIsAdditionsActive && mAutoresizeGuest)
3394 {
3395 /* If this slot is invoked directly then use the passed size
3396 * otherwise get the available size for the guest display.
3397 * We assume here that the centralWidget() contains this view only
3398 * and gives it all available space. */
3399 QSize sz (aToSize.isValid() ? aToSize : mMainWnd->centralWidget()->size());
3400 if (!aToSize.isValid())
3401 sz -= QSize (frameWidth() * 2, frameWidth() * 2);
3402 LogFlowFunc (("Will suggest %d x %d\n", sz.width(), sz.height()));
3403
3404 mConsole.GetDisplay().SetVideoModeHint (sz.width(), sz.height(), 0, 0);
3405 }
3406}
3407
3408/**
3409 * Sets the the minimum size restriction depending on the auto-resize feature
3410 * state and the current rendering mode.
3411 *
3412 * Currently, the restriction is set only in SDL mode and only when the
3413 * auto-resize feature is inactive. We need to do that because we cannot
3414 * correctly draw in a scrolled window in SDL mode.
3415 *
3416 * In all other modes, or when auto-resize is in force, this function does
3417 * nothing.
3418 */
3419void VBoxConsoleView::maybeRestrictMinimumSize()
3420{
3421 if (mode == VBoxDefs::SDLMode)
3422 {
3423 if (!mIsAdditionsActive || !mAutoresizeGuest)
3424 setMinimumSize (sizeHint());
3425 else
3426 setMinimumSize (0, 0);
3427 }
3428}
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