Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 26753)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 26754)
@@ -403,4 +403,8 @@
     connect(uisession(), SIGNAL(sigStateChange(KMachineState)), this, SLOT(sltMachineStateChanged(KMachineState)));
     connect(uisession(), SIGNAL(sigAdditionsStateChange()), this, SLOT(sltAdditionsStateChanged()));
+    connect(uisession(), SIGNAL(sigUSBDeviceStateChange(const CUSBDevice &, bool, const CVirtualBoxErrorInfo &)),
+            this, SLOT(sltUSBDeviceStateChange(const CUSBDevice &, bool, const CVirtualBoxErrorInfo &)));
+    connect(uisession(), SIGNAL(sigRuntimeError(bool, const QString &, const QString &)),
+            this, SLOT(sltRuntimeError(bool, const QString &, const QString &)));
 }
 
@@ -800,4 +804,22 @@
 }
 
+void UIMachineLogic::sltUSBDeviceStateChange(const CUSBDevice &device, bool bIsAttached, const CVirtualBoxErrorInfo &error)
+{
+    bool success = error.isNull();
+
+    if (!success)
+    {
+        if (bIsAttached)
+            vboxProblem().cannotAttachUSBDevice(session().GetConsole(), vboxGlobal().details(device), error);
+        else
+            vboxProblem().cannotDetachUSBDevice(session().GetConsole(), vboxGlobal().details(device), error);
+    }
+}
+
+void UIMachineLogic::sltRuntimeError(bool bIsFatal, const QString &strErrorId, const QString &strMessage)
+{
+    vboxProblem().showRuntimeError(session().GetConsole(), bIsFatal, strErrorId, strMessage);
+}
+
 void UIMachineLogic::sltToggleGuestAutoresize(bool /* bEnabled */)
 {
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 26753)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 26754)
@@ -77,9 +77,9 @@
 
     /* Cleanup helpers: */
-    void saveLogicSettings();
-    //void cleanupRequiredFeatures();
-    //void cleanupActionConnections();
-    //void cleanupActionGroups();
-    //void cleanupConsoleConnections();
+    virtual void saveLogicSettings();
+    //virtual void cleanupRequiredFeatures();
+    //virtual void cleanupActionConnections();
+    //virtual void cleanupActionGroups();
+    //virtual void cleanupConsoleConnections();
 
     /* Protected getters: */
@@ -105,4 +105,6 @@
     void sltMachineStateChanged(KMachineState newMachineState);
     void sltAdditionsStateChanged();
+    void sltUSBDeviceStateChange(const CUSBDevice &device, bool bIsAttached, const CVirtualBoxErrorInfo &error);
+    void sltRuntimeError(bool bIsFatal, const QString &strErrorId, const QString &strMessage);
 
     /* "Machine" menu funtionality */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 26753)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 26754)
@@ -119,4 +119,7 @@
 };
 
+enum { KeyExtended = 0x01, KeyPressed = 0x02, KeyPause = 0x04, KeyPrint = 0x08 };
+enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
+
 UIMachineView* UIMachineView::create(  UIMachineWindow *pMachineWindow
                                      , VBoxDefs::RenderMode renderMode
@@ -197,14 +200,17 @@
                             )
     : QAbstractScrollArea(pMachineWindow->machineWindow())
-    /* Protected members: */
-    , mode(renderMode)
-    , m_bIsGuestSupportsGraphics(false)
     /* Private members: */
     , m_pMachineWindow(pMachineWindow)
     , m_console(pMachineWindow->machineLogic()->uisession()->session().GetConsole())
+    , m_mode(renderMode)
     , m_globalSettings(vboxGlobal().settings())
+    , m_machineState(KMachineState_Null)
+    , m_pFrameBuffer(0)
+#if defined(Q_WS_WIN)
+    , m_alphaCursor(0)
+#endif
     , m_iLastMouseWheelDelta(0)
-    , muNumLockAdaptionCnt(2)
-    , muCapsLockAdaptionCnt(2)
+    , m_uNumLockAdaptionCnt(2)
+    , m_uCapsLockAdaptionCnt(2)
     , m_bIsAutoCaptureDisabled(false)
     , m_bIsKeyboardCaptured(false)
@@ -214,29 +220,29 @@
     , m_bIsHostkeyPressed(false)
     , m_bIsHostkeyAlone (false)
+    , m_bIsGuestSupportsGraphics(false)
     , m_bIsMachineWindowResizeIgnored(true)
     , m_bIsFrameBufferResizeIgnored(false)
     , m_bIsGuestResizeIgnored(false)
+    , m_numLock(false)
+    , m_scrollLock(false)
+    , m_capsLock(false)
+    , m_fPassCAD (false)
+    , m_fHideHostPointer(true)
+#ifdef VBOX_WITH_VIDEOHWACCEL
+    , m_fAccelerate2DVideo(bAccelerate2DVideo)
+#endif
+#if 0 // TODO: Do we need this?
     , mDoResize(false)
-    , mNumLock(false)
-    , mScrollLock(false)
-    , mCapsLock(false)
-#ifdef VBOX_WITH_VIDEOHWACCEL
-    , mAccelerate2DVideo(bAccelerate2DVideo)
-#endif
-#if defined(Q_WS_WIN)
-    , mAlphaCursor (NULL)
 #endif
 #if defined(Q_WS_MAC)
 # ifndef QT_MAC_USE_COCOA
-    , mDarwinEventHandlerRef (NULL)
+    , m_darwinEventHandlerRef(NULL)
 # endif /* !QT_MAC_USE_COCOA */
-    , mDarwinKeyModifiers (0)
-    , mKeyboardGrabbed (false)
+    , m_darwinKeyModifiers (0)
+    , m_fKeyboardGrabbed (false)
     , mDockIconEnabled (true)
 #endif
-    , mDesktopGeo (DesktopGeo_Invalid)
-    , mPassCAD (false)
+    , m_desktopGeometryType(DesktopGeo_Invalid)
       /* Don't show a hardware pointer until we have one to show */
-    , mHideHostPointer (true)
 {
 }
@@ -252,10 +258,10 @@
     /* HACK ALERT! Really ugly workaround for the resizing to 9x1 done
      *             by DevVGA if provoked before power on. */
-    QSize fb(mFrameBuf->width(), mFrameBuf->height());
+    QSize fb(m_pFrameBuffer->width(), m_pFrameBuffer->height());
     if ((fb.width() < 16 || fb.height() < 16) && (vboxGlobal().isStartPausedEnabled() || vboxGlobal().isDebuggerAutoShowEnabled()))
         fb = QSize(640, 480);
     return QSize(fb.width() + frameWidth() * 2, fb.height() + frameWidth() * 2);
 #else
-    return QSize(mFrameBuf->width() + frameWidth() * 2, mFrameBuf->height() + frameWidth() * 2);
+    return QSize(m_pFrameBuffer->width() + frameWidth() * 2, m_pFrameBuffer->height() + frameWidth() * 2);
 #endif
 }
@@ -273,10 +279,10 @@
 int UIMachineView::contentsWidth() const
 {
-    return mFrameBuf->width();
+    return m_pFrameBuffer->width();
 }
 
 int UIMachineView::contentsHeight() const
 {
-    return mFrameBuf->height();
+    return m_pFrameBuffer->height();
 }
 
@@ -291,10 +297,30 @@
 }
 
+QRect UIMachineView::desktopGeometry() const
+{
+    QRect geometry;
+    switch (m_desktopGeometryType)
+    {
+        case DesktopGeo_Fixed:
+        case DesktopGeo_Automatic:
+            geometry = QRect(0, 0,
+                            qMax(m_desktopGeometry.width(), m_storedConsoleSize.width()),
+                            qMax(m_desktopGeometry.height(), m_storedConsoleSize.height()));
+            break;
+        case DesktopGeo_Any:
+            geometry = QRect(0, 0, 0, 0);
+            break;
+        default:
+            AssertMsgFailed(("Bad geometry type %d!\n", m_desktopGeometryType));
+    }
+    return geometry;
+}
+
 void UIMachineView::calculateDesktopGeometry()
 {
-    /* This method should not get called until we have initially set up the mDesktopGeo: */
-    Assert((mDesktopGeo != DesktopGeo_Invalid));
+    /* This method should not get called until we have initially set up the m_desktopGeometryType: */
+    Assert((m_desktopGeometryType != DesktopGeo_Invalid));
     /* If we are not doing automatic geometry calculation then there is nothing to do: */
-    if (DesktopGeo_Automatic == mDesktopGeo)
+    if (DesktopGeo_Automatic == m_desktopGeometryType)
     {
         /* Available geometry of the desktop.  If the desktop is a single
@@ -303,8 +329,8 @@
          * complex case of a desktop spanning multiple screens: */
         QRect desktop = availableGeometry();
-        /* The area taken up by the console window on the desktop,
-         * including window frame, title and menu bar and whatnot. */
+        /* The area taken up by the machine window on the desktop,
+         * including window frame, title and menu bar and whatnot: */
         QRect frame = machineWindowWrapper()->machineWindow()->frameGeometry();
-        /* The area taken up by the console window, minus all decorations. */
+        /* The area taken up by the machine view, so excluding all decorations: */
         QRect window = geometry();
         /* To work out how big we can make the console window while still
@@ -312,27 +338,47 @@
          * This works because the difference between frame and window
          * (or at least its width and height) is a constant. */
-        mDesktopGeometry = QRect(0, 0, desktop.width() - frame.width() + window.width(),
+        m_desktopGeometry = QRect(0, 0, desktop.width() - frame.width() + window.width(),
                                        desktop.height() - frame.height() + window.height());
     }
 }
 
-QRect UIMachineView::desktopGeometry() const
-{
-    QRect rc;
-    switch (mDesktopGeo)
+void UIMachineView::setDesktopGeometry(DesktopGeo aGeo, int aWidth, int aHeight)
+{
+    switch (aGeo)
     {
         case DesktopGeo_Fixed:
+            m_desktopGeometryType = DesktopGeo_Fixed;
+            if (aWidth != 0 && aHeight != 0)
+                m_desktopGeometry = QRect(0, 0, aWidth, aHeight);
+            else
+                m_desktopGeometry = QRect(0, 0, 0, 0);
+            storeConsoleSize(0, 0);
+            break;
         case DesktopGeo_Automatic:
-            rc = QRect(0, 0,
-                       qMax(mDesktopGeometry.width(), mStoredConsoleSize.width()),
-                       qMax(mDesktopGeometry.height(), mStoredConsoleSize.height()));
+            m_desktopGeometryType = DesktopGeo_Automatic;
+            m_desktopGeometry = QRect(0, 0, 0, 0);
+            storeConsoleSize(0, 0);
             break;
         case DesktopGeo_Any:
-            rc = QRect(0, 0, 0, 0);
+            m_desktopGeometryType = DesktopGeo_Any;
+            m_desktopGeometry = QRect(0, 0, 0, 0);
             break;
         default:
-            AssertMsgFailed(("Bad geometry type %d\n", mDesktopGeo));
-    }
-    return rc;
+            AssertMsgFailed(("Invalid desktop geometry type %d\n", aGeo));
+            m_desktopGeometryType = DesktopGeo_Invalid;
+    }
+}
+
+void UIMachineView::storeConsoleSize(int aWidth, int aHeight)
+{
+    LogFlowThisFunc(("aWidth=%d, aHeight=%d\n", aWidth, aHeight));
+    m_storedConsoleSize = QRect(0, 0, aWidth, aHeight);
+}
+
+QRect UIMachineView::availableGeometry()
+{
+    return machineWindowWrapper()->machineWindow()->isFullScreen() ?
+           QApplication::desktop()->screenGeometry(this) :
+           QApplication::desktop()->availableGeometry(this);
 }
 
@@ -341,7 +387,7 @@
     CDisplay display = m_console.GetDisplay();
     Assert(!display.isNull());
-    mFrameBuf = NULL;
-
-    switch (mode)
+    m_pFrameBuffer = NULL;
+
+    switch (mode())
     {
 #if defined (VBOX_GUI_USE_QIMAGE)
@@ -349,10 +395,10 @@
 #if 0 // TODO: Enable QImage + Video Acceleration!
 # ifdef VBOX_WITH_VIDEOHWACCEL
-            mFrameBuf = mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<UIFrameBufferQImage>(this, &machineWindowWrapper()->session()) : new UIFrameBufferQImage(this);
+            m_pFrameBuffer = m_fAccelerate2DVideo ? new VBoxOverlayFrameBuffer<UIFrameBufferQImage>(this, &machineWindowWrapper()->session()) : new UIFrameBufferQImage(this);
 # else
-            mFrameBuf = new UIFrameBufferQImage(this);
+            m_pFrameBuffer = new UIFrameBufferQImage(this);
 # endif
 #endif
-            mFrameBuf = new UIFrameBufferQImage(this);
+            m_pFrameBuffer = new UIFrameBufferQImage(this);
             break;
 #endif
@@ -360,8 +406,8 @@
 #if defined (VBOX_GUI_USE_QGL)
         case VBoxDefs::QGLMode:
-            mFrameBuf = new UIQGLFrameBuffer(this);
+            m_pFrameBuffer = new UIQGLFrameBuffer(this);
             break;
         case VBoxDefs::QGLOverlayMode:
-            mFrameBuf = new UIQGLOverlayFrameBuffer(this);
+            m_pFrameBuffer = new UIQGLOverlayFrameBuffer(this);
             break;
 #endif
@@ -377,7 +423,7 @@
 # endif
 # if defined(VBOX_WITH_VIDEOHWACCEL) && defined(DEBUG_misha) /* not tested yet */
-            mFrameBuf = mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<UISDLFrameBuffer> (this, &machineWindowWrapper()->session()) : new UISDLFrameBuffer(this);
+            m_pFrameBuffer = m_fAccelerate2DVideo ? new VBoxOverlayFrameBuffer<UISDLFrameBuffer> (this, &machineWindowWrapper()->session()) : new UISDLFrameBuffer(this);
 # else
-            mFrameBuf = new UISDLFrameBuffer(this);
+            m_pFrameBuffer = new UISDLFrameBuffer(this);
 # endif
             /* Disable scrollbars because we cannot correctly draw in a scrolled window using SDL: */
@@ -390,11 +436,11 @@
 #if defined (VBOX_GUI_USE_DDRAW)
         case VBoxDefs::DDRAWMode:
-            mFrameBuf = new UIDDRAWFrameBuffer(this);
-            if (!mFrameBuf || mFrameBuf->address() == NULL)
-            {
-                if (mFrameBuf)
-                    delete mFrameBuf;
-                mode = VBoxDefs::QImageMode;
-                mFrameBuf = new UIFrameBufferQImage(this);
+            m_pFrameBuffer = new UIDDRAWFrameBuffer(this);
+            if (!m_pFrameBuffer || m_pFrameBuffer->address() == NULL)
+            {
+                if (m_pFrameBuffer)
+                    delete m_pFrameBuffer;
+                m_mode = VBoxDefs::QImageMode;
+                m_pFrameBuffer = new UIFrameBufferQImage(this);
             }
             break;
@@ -407,7 +453,7 @@
             pViewport->setAttribute(Qt::WA_PaintOnScreen);
 # ifdef VBOX_WITH_VIDEOHWACCEL
-            mFrameBuf = mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQuartz2DFrameBuffer>(this, &machineWindowWrapper()->session()) : new UIFrameBufferQuartz2D(this);
+            m_pFrameBuffer = m_fAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQuartz2DFrameBuffer>(this, &machineWindowWrapper()->session()) : new UIFrameBufferQuartz2D(this);
 # else
-            mFrameBuf = new UIFrameBufferQuartz2D(this);
+            m_pFrameBuffer = new UIFrameBufferQuartz2D(this);
 # endif
             break;
@@ -415,13 +461,13 @@
 #endif
         default:
-            AssertReleaseMsgFailed(("Render mode must be valid: %d\n", mode));
-            LogRel(("Invalid render mode: %d\n", mode));
+            AssertReleaseMsgFailed(("Render mode must be valid: %d\n", mode()));
+            LogRel(("Invalid render mode: %d\n", mode()));
             qApp->exit(1);
             break;
     }
-    if (mFrameBuf)
-    {
-        mFrameBuf->AddRef();
-        display.SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, CFramebuffer(mFrameBuf));
+    if (m_pFrameBuffer)
+    {
+        m_pFrameBuffer->AddRef();
+        display.SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, CFramebuffer(m_pFrameBuffer));
     }
 }
@@ -433,10 +479,10 @@
 
     /* Pressed keys: */
-    ::memset(mPressedKeys, 0, sizeof(mPressedKeys));
+    ::memset(m_pressedKeys, 0, sizeof(m_pressedKeys));
 
     /* Prepare viewport: */
 #ifdef VBOX_GUI_USE_QGL
     QWidget *pViewport;
-    switch (mode)
+    switch (mode())
     {
 #if 0 // TODO: Create Open GL viewport!
@@ -521,9 +567,17 @@
     viewport()->installEventFilter(this);
 
-    /* To fix some focus issues: */
-    //qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->menuBar()->installEventFilter(this);
-
     /* We want to be notified on some parent's events: */
     machineWindowWrapper()->machineWindow()->installEventFilter(this);
+}
+
+void UIMachineView::prepareConsoleConnections()
+{
+    UISession *sender = machineWindowWrapper()->machineLogic()->uisession();
+    connect(sender, SIGNAL(sigMousePointerShapeChange(bool, bool, uint, uint, uint, uint, const uchar *)),
+            this, SLOT(sltMousePointerShapeChange(bool, bool, uint, uint, uint, uint, const uchar *)));
+    connect(sender, SIGNAL(sigMouseCapabilityChange(bool, bool)), this, SLOT(sltMouseCapabilityChange(bool, bool)));
+    connect(sender, SIGNAL(sigKeyboardLedsChange(bool, bool, bool)), this, SLOT(sltKeyboardLedsChange(bool, bool, bool)));
+    connect(sender, SIGNAL(sigStateChange(KMachineState)), this, SLOT(sltStateChange(KMachineState)));
+    connect(sender, SIGNAL(sigAdditionsStateChange()), this, SLOT(sltAdditionsStateChange()));
 }
 
@@ -558,5 +612,5 @@
         QString passCAD = m_console.GetMachine().GetExtraData(VBoxDefs::GUI_PassCAD);
         if (!passCAD.isEmpty() && ((passCAD != "false") || (passCAD != "no")))
-            mPassCAD = true;
+            m_fPassCAD = true;
     }
 }
@@ -574,6 +628,6 @@
         UnhookWindowsHookEx(gKbdHook);
     gView = 0;
-    if (mAlphaCursor)
-        DestroyIcon(mAlphaCursor);
+    if (m_alphaCursor)
+        DestroyIcon(m_alphaCursor);
 #endif
 
@@ -594,5 +648,5 @@
 {
     /* Cleanup: */
-    if (mFrameBuf)
+    if (m_pFrameBuffer)
     {
         /* Detach framebuffer from Display: */
@@ -600,7 +654,138 @@
         display.SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, CFramebuffer(NULL));
         /* Release the reference: */
-        mFrameBuf->Release();
-        mFrameBuf = NULL;
-    }
+        m_pFrameBuffer->Release();
+        m_pFrameBuffer = NULL;
+    }
+}
+
+void UIMachineView::sltMousePointerShapeChange(bool fIsVisible, bool fHasAlpha,
+                                               uint uXHot, uint uYHot, uint uWidth, uint uHeight,
+                                               const uchar *pShapeData)
+{
+    if (m_bIsMouseAbsolute)
+    {
+        /* Do we have new shape data? */
+        if (pShapeData)
+            setPointerShape(pShapeData, fHasAlpha, uXHot, uYHot, uWidth, uHeight);
+
+        /* Should we hide/show pointer? */
+        if (fIsVisible)
+            viewport()->setCursor(m_lastCursor);
+        else
+            viewport()->setCursor(Qt::BlankCursor);
+    }
+    m_fHideHostPointer = !fIsVisible;
+}
+
+void UIMachineView::sltMouseCapabilityChange(bool bIsSupportsAbsolute, bool bNeedsHostCursor)
+{
+    if (m_bIsMouseAbsolute != bIsSupportsAbsolute)
+    {
+        m_bIsMouseAbsolute = bIsSupportsAbsolute;
+        /* Correct the mouse capture state and reset the cursor to the default shape if necessary: */
+        if (m_bIsMouseAbsolute)
+        {
+            CMouse mouse = m_console.GetMouse();
+            mouse.PutMouseEventAbsolute(-1, -1, 0, 0 /* Horizontal wheel */, 0);
+            captureMouse(false, false);
+        }
+        else
+            viewport()->unsetCursor();
+        emitMouseStateChanged();
+        vboxProblem().remindAboutMouseIntegration(m_bIsMouseAbsolute);
+    }
+    if (bNeedsHostCursor)
+        setMouseIntegrationLocked(false);
+    else
+        setMouseIntegrationLocked(true);
+}
+
+void UIMachineView::sltKeyboardLedsChange(bool bNumLock, bool bCapsLock, bool bScrollLock)
+{
+    if (bNumLock != m_numLock)
+        m_uNumLockAdaptionCnt = 2;
+    if (bCapsLock != m_capsLock)
+        m_uCapsLockAdaptionCnt = 2;
+    m_numLock    = bNumLock;
+    m_capsLock   = bCapsLock;
+    m_scrollLock = bScrollLock;
+}
+
+void UIMachineView::sltStateChange(KMachineState state)
+{
+    switch (state)
+    {
+        case KMachineState_Paused:
+        case KMachineState_TeleportingPausedVM:
+        {
+            if (mode() != VBoxDefs::TimerMode &&  m_pFrameBuffer &&
+                (state != KMachineState_TeleportingPausedVM || m_machineState != KMachineState_Teleporting))
+            {
+                /* Take a screen snapshot. Note that TakeScreenShot() always needs a 32bpp image: */
+                QImage shot = QImage(m_pFrameBuffer->width(), m_pFrameBuffer->height(), QImage::Format_RGB32);
+                CDisplay dsp = m_console.GetDisplay();
+                dsp.TakeScreenShot(shot.bits(), shot.width(), shot.height());
+                /* TakeScreenShot() may fail if, e.g. the Paused notification was delivered
+                 * after the machine execution was resumed. It's not fatal: */
+                if (dsp.isOk())
+                {
+                    dimImage(shot);
+                    m_pauseShot = QPixmap::fromImage(shot);
+                    /* Fully repaint to pick up m_pauseShot: */
+                    repaint();
+                }
+            }
+        }
+        case KMachineState_Stuck:
+        {
+            /* Reuse the focus event handler to uncapture everything: */
+            if (hasFocus())
+                focusEvent(false /* aHasFocus*/, false /* aReleaseHostKey */);
+            break;
+        }
+        case KMachineState_Running:
+        {
+            if (m_machineState == KMachineState_Paused || m_machineState == KMachineState_TeleportingPausedVM)
+            {
+                if (mode() != VBoxDefs::TimerMode && m_pFrameBuffer)
+                {
+                    /* Reset the pixmap to free memory: */
+                    m_pauseShot = QPixmap();
+                    /* Ask for full guest display update (it will also update
+                     * the viewport through IFramebuffer::NotifyUpdate): */
+                    CDisplay dsp = m_console.GetDisplay();
+                    dsp.InvalidateAndUpdate();
+                }
+            }
+            /* Reuse the focus event handler to capture input: */
+            if (hasFocus())
+                focusEvent(true /* aHasFocus */);
+            break;
+        }
+        default:
+            break;
+    }
+
+    m_machineState = state;
+}
+
+void UIMachineView::sltAdditionsStateChange()
+{
+    CGuest guest = console().GetGuest();
+    bool fIsGuestSupportsGraphics = guest.GetSupportsGraphics();
+
+#if 0 // TODO: Do we need this?
+    if (!mDoResize && !isGuestSupportsGraphics() && fIsGuestSupportsGraphics &&
+        (machineWindowWrapper()->isTrueSeamless() || machineWindowWrapper()->isTrueFullscreen()))
+        mDoResize = true;
+#endif
+    m_bIsGuestSupportsGraphics = fIsGuestSupportsGraphics;
+
+    maybeRestrictMinimumSize();
+
+#if 0 // TODO: Do we need this?
+    /* This will only be acted upon if mDoResize is true: */
+    doResizeHint();
+#endif
 }
 
@@ -639,391 +824,338 @@
 #endif
 
-bool UIMachineView::event(QEvent *e)
-{
-    //if (m_bIsAttached)
-    {
-        switch (e->type())
-        {
-            case QEvent::FocusIn:
-            {
-                if (isRunning())
-                    focusEvent (true);
-                break;
-            }
-            case QEvent::FocusOut:
-            {
-                if (isRunning())
-                    focusEvent (false);
+bool UIMachineView::event(QEvent *pEvent)
+{
+    switch (pEvent->type())
+    {
+        case QEvent::FocusIn:
+        {
+            if (isRunning())
+                focusEvent(true);
+            break;
+        }
+        case QEvent::FocusOut:
+        {
+            if (isRunning())
+                focusEvent(false);
+            else
+            {
+                /* Release the host key and all other pressed keys too even when paused (otherwise, we will get stuck
+                 * keys in the guest when doing sendChangedKeyStates() on resume because key presses were already
+                 * recorded in m_pressedKeys but key releases will most likely not reach us but the new focus window instead): */
+                releaseAllPressedKeys(true /* fReleaseHostKey */);
+            }
+            break;
+        }
+
+        case VBoxDefs::ResizeEventType:
+        {
+            /* Some situations require initial VGA Resize Request
+             * to be ignored at all, leaving previous framebuffer,
+             * machine view and machine window sizes preserved: */
+            if (m_bIsGuestResizeIgnored)
+                return true;
+
+            bool oldIgnoreMainwndResize = m_bIsMachineWindowResizeIgnored;
+            m_bIsMachineWindowResizeIgnored = true;
+
+            UIResizeEvent *pResizeEvent = static_cast<UIResizeEvent*>(pEvent);
+
+            /* Store the new size to prevent unwanted resize hints being sent back. */
+            storeConsoleSize(pResizeEvent->width(), pResizeEvent->height());
+
+            /* Unfortunately restoreOverrideCursor() is broken in Qt 4.4.0 if WA_PaintOnScreen widgets are present.
+             * This is the case on linux with SDL. As workaround we save/restore the arrow cursor manually.
+             * See http://trolltech.com/developer/task-tracker/index_html?id=206165&method=entry for details.
+             * Moreover the current cursor, which could be set by the guest, should be restored after resize: */
+            QCursor cursor;
+            if (shouldHideHostPointer())
+                cursor = QCursor(Qt::BlankCursor);
+            else
+                cursor = viewport()->cursor();
+            m_pFrameBuffer->resizeEvent(pResizeEvent);
+            viewport()->setCursor(cursor);
+
+#ifdef Q_WS_MAC
+            mDockIconPreview->setOriginalSize(pResizeEvent->width(), pResizeEvent->height());
+#endif /* Q_WS_MAC */
+
+            /* This event appears in case of guest video was changed for somehow even without video resolution change.
+             * In this last case the host VM window will not be resized according this event and the host mouse cursor
+             * which was unset to default here will not be hidden in capture state. So it is necessary to perform
+             * updateMouseClipping() for the guest resize event if the mouse cursor was captured: */
+            if (m_bIsMouseCaptured)
+                updateMouseClipping();
+
+            /* Apply maximum size restriction: */
+            setMaximumSize(sizeHint());
+
+            /* May be we have to restrict minimum size? */
+            maybeRestrictMinimumSize();
+
+            /* Resize the guest canvas: */
+            if (!m_bIsFrameBufferResizeIgnored)
+                resize(pResizeEvent->width(), pResizeEvent->height());
+            updateSliders();
+
+            /* Let our toplevel widget calculate its sizeHint properly. */
+#ifdef Q_WS_X11
+            /* We use processEvents rather than sendPostedEvents & set the time out value to max cause on X11 otherwise
+             * the layout isn't calculated correctly. Dosn't find the bug in Qt, but this could be triggered through
+             * the async nature of the X11 window event system. */
+            QCoreApplication::processEvents(QEventLoop::AllEvents, INT_MAX);
+#else /* Q_WS_X11 */
+            QCoreApplication::sendPostedEvents(0, QEvent::LayoutRequest);
+#endif /* Q_WS_X11 */
+
+            if (!m_bIsFrameBufferResizeIgnored)
+                normalizeGeometry(true /* adjustPosition */);
+
+            /* Report to the VM thread that we finished resizing */
+            m_console.GetDisplay().ResizeCompleted(0);
+
+            m_bIsMachineWindowResizeIgnored = oldIgnoreMainwndResize;
+
+            /* Make sure that all posted signals are processed: */
+            qApp->processEvents();
+
+            /* Emit a signal about guest was resized: */
+            emit resizeHintDone();
+
+            /* We also recalculate the desktop geometry if this is determined
+             * automatically.  In fact, we only need this on the first resize,
+             * but it is done every time to keep the code simpler. */
+            calculateDesktopGeometry();
+
+            /* Enable frame-buffer resize watching only now: */
+            if (m_bIsFrameBufferResizeIgnored)
+                m_bIsFrameBufferResizeIgnored = false;
+
+            return true;
+        }
+
+        /* See VBox[QImage|SDL]FrameBuffer::NotifyUpdate(): */
+        case VBoxDefs::RepaintEventType:
+        {
+            UIRepaintEvent *pPaintEvent = static_cast<UIRepaintEvent*>(pEvent);
+            viewport()->repaint(pPaintEvent->x() - contentsX(), pPaintEvent->y() - contentsY(),
+                                pPaintEvent->width(), pPaintEvent->height());
+            /* m_console.GetDisplay().UpdateCompleted(); - the event was acked already */
+            return true;
+        }
+
+#ifdef VBOX_WITH_VIDEOHWACCEL
+        case VBoxDefs::VHWACommandProcessType:
+        {
+            m_pFrameBuffer->doProcessVHWACommand(pEvent);
+            return true;
+        }
+#endif
+
+#if 0 // TODO: Move that to seamless mode event hadler!
+        case VBoxDefs::SetRegionEventType:
+        {
+            VBoxSetRegionEvent *sre = (VBoxSetRegionEvent*) pEvent;
+            if (machineWindowWrapper()->isTrueSeamless() && sre->region() != mLastVisibleRegion)
+            {
+                mLastVisibleRegion = sre->region();
+                machineWindowWrapper()->setMask (sre->region());
+            }
+            else if (!mLastVisibleRegion.isEmpty() && !machineWindowWrapper()->isTrueSeamless())
+                mLastVisibleRegion = QRegion();
+            return true;
+        }
+#endif
+
+#if 0 // TODO: Move that to specific event handler!
+        case VBoxDefs::ActivateMenuEventType:
+        {
+            ActivateMenuEvent *pMenuEvent = static_cast<ActivateMenuEvent*>(pEvent);
+            pMenuEvent->action()->trigger();
+
+            /* The main window and its children can be destroyed at this point (if, for example, the activated menu
+             * item closes the main window). Detect this situation to prevent calls to destroyed widgets: */
+            QWidgetList list = QApplication::topLevelWidgets();
+            bool destroyed = list.indexOf(machineWindowWrapper()->machineWindow()) < 0;
+            if (!destroyed && machineWindowWrapper()->machineWindow()->statusBar())
+                machineWindowWrapper()->machineWindow()->statusBar()->clearMessage();
+
+            return true;
+        }
+#endif
+
+        case QEvent::KeyPress:
+        case QEvent::KeyRelease:
+        {
+            QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
+
+#ifdef Q_WS_PM
+            // TODO: that a temporary solution to send Alt+Tab and friends to the guest.
+            // The proper solution is to write a keyboard driver that will steal these combos from the host
+            // (it's impossible to do so using hooks on OS/2):
+
+            if (m_bIsHostkeyPressed)
+            {
+                bool pressed = pEvent->type() == QEvent::KeyPress;
+                CKeyboard keyboard = m_console.GetKeyboard();
+
+                /* Whether the host key is Shift so that it will modify the hot key values?
+                 * Note that we don't distinguish between left and right shift here (too much hassle): */
+                const bool kShift = (m_globalSettings.hostKey() == VK_SHIFT ||
+                                    m_globalSettings.hostKey() == VK_LSHIFT) &&
+                                    (pKeyEvent->state() & Qt::ShiftModifier);
+                /* define hot keys according to the Shift state */
+                const int kAltTab      = kShift ? Qt::Key_Exclam     : Qt::Key_1;
+                const int kAltShiftTab = kShift ? Qt::Key_At         : Qt::Key_2;
+                const int kCtrlEsc     = kShift ? Qt::Key_AsciiTilde : Qt::Key_QuoteLeft;
+
+                /* Simulate Alt+Tab on Host+1 and Alt+Shift+Tab on Host+2 */
+                if (pKeyEvent->key() == kAltTab || pKeyEvent->key() == kAltShiftTab)
+                {
+                    if (pressed)
+                    {
+                        /* Send the Alt press to the guest */
+                        if (!(m_pressedKeysCopy[0x38] & IsKeyPressed))
+                        {
+                            /* Store the press in *Copy to have it automatically
+                             * released when the Host key is released: */
+                            m_pressedKeysCopy[0x38] |= IsKeyPressed;
+                            keyboard.PutScancode(0x38);
+                        }
+
+                        /* Make sure Shift is pressed if it's Key_2 and released if it's Key_1: */
+                        if (pKeyEvent->key() == kAltTab &&
+                            (m_pressedKeysCopy[0x2A] & IsKeyPressed))
+                        {
+                            m_pressedKeysCopy[0x2A] &= ~IsKeyPressed;
+                            keyboard.PutScancode(0xAA);
+                        }
+                        else
+                        if (pKeyEvent->key() == kAltShiftTab &&
+                            !(m_pressedKeysCopy[0x2A] & IsKeyPressed))
+                        {
+                            m_pressedKeysCopy[0x2A] |= IsKeyPressed;
+                            keyboard.PutScancode(0x2A);
+                        }
+                    }
+
+                    keyboard.PutScancode(pressed ? 0x0F : 0x8F);
+
+                    pKeyEvent->accept();
+                    return true;
+                }
+
+                /* Simulate Ctrl+Esc on Host+Tilde */
+                if (pKeyEvent->key() == kCtrlEsc)
+                {
+                    /* Send the Ctrl press to the guest */
+                    if (pressed && !(m_pressedKeysCopy[0x1d] & IsKeyPressed))
+                    {
+                        /* store the press in *Copy to have it automatically
+                         * released when the Host key is released */
+                        m_pressedKeysCopy[0x1d] |= IsKeyPressed;
+                        keyboard.PutScancode(0x1d);
+                    }
+
+                    keyboard.PutScancode(pressed ? 0x01 : 0x81);
+
+                    pKeyEvent->accept();
+                    return true;
+                }
+            }
+#endif /* Q_WS_PM */
+
+            if (m_bIsHostkeyPressed && pEvent->type() == QEvent::KeyPress)
+            {
+                if (pKeyEvent->key() >= Qt::Key_F1 && pKeyEvent->key() <= Qt::Key_F12)
+                {
+                    QVector <LONG> combo(6);
+                    combo[0] = 0x1d; /* Ctrl down */
+                    combo[1] = 0x38; /* Alt  down */
+                    combo[4] = 0xb8; /* Alt  up   */
+                    combo[5] = 0x9d; /* Ctrl up   */
+                    if (pKeyEvent->key() >= Qt::Key_F1 && pKeyEvent->key() <= Qt::Key_F10)
+                    {
+                        combo[2] = 0x3b + (pKeyEvent->key() - Qt::Key_F1); /* F1-F10 down */
+                        combo[3] = 0xbb + (pKeyEvent->key() - Qt::Key_F1); /* F1-F10 up   */
+                    }
+                    /* some scan slice */
+                    else if (pKeyEvent->key() >= Qt::Key_F11 && pKeyEvent->key() <= Qt::Key_F12)
+                    {
+                        combo[2] = 0x57 + (pKeyEvent->key() - Qt::Key_F11); /* F11-F12 down */
+                        combo[3] = 0xd7 + (pKeyEvent->key() - Qt::Key_F11); /* F11-F12 up   */
+                    }
+                    else
+                        Assert(0);
+
+                    CKeyboard keyboard = m_console.GetKeyboard();
+                    keyboard.PutScancodes(combo);
+                }
+
+#if 0 // TODO: Divide tha code to specific parts and move it there:
+                if (pKeyEvent->key() == Qt::Key_Home)
+                {
+                    /* Activate the main menu */
+                    if (machineWindowWrapper()->isTrueSeamless() || machineWindowWrapper()->isTrueFullscreen())
+                        machineWindowWrapper()->popupMainMenu (m_bIsMouseCaptured);
+                    else
+                    {
+                        /* In Qt4 it is not enough to just set the focus to menu-bar.
+                         * So to get the menu-bar we have to send Qt::Key_Alt press/release events directly: */
+                        QKeyEvent e1(QEvent::KeyPress, Qt::Key_Alt, Qt::NoModifier);
+                        QKeyEvent e2(QEvent::KeyRelease, Qt::Key_Alt, Qt::NoModifier);
+                        QApplication::sendEvent(machineWindowWrapper()->menuBar(), &e1);
+                        QApplication::sendEvent(machineWindowWrapper()->menuBar(), &e2);
+                    }
+                }
                 else
                 {
-                    /* release the host key and all other pressed keys too even
-                     * when paused (otherwise, we will get stuck keys in the
-                     * guest when doing sendChangedKeyStates() on resume because
-                     * key presses were already recorded in mPressedKeys but key
-                     * releases will most likely not reach us but the new focus
-                     * window instead). */
-                    releaseAllPressedKeys (true /* aReleaseHostKey */);
+                    /* Process hot keys not processed in keyEvent() (as in case of non-alphanumeric keys): */
+                    processHotKey(QKeySequence (pKeyEvent->key()), machineWindowWrapper()->menuBar()->actions());
                 }
-                break;
-            }
-
-            case VBoxDefs::ResizeEventType:
-            {
-                /* Some situations require initial VGA Resize Request
-                 * to be ignored at all, leaving previous framebuffer,
-                 * console widget and vm window size preserved. */
-                if (m_bIsGuestResizeIgnored)
-                    return true;
-
-                bool oldIgnoreMainwndResize = m_bIsMachineWindowResizeIgnored;
-                m_bIsMachineWindowResizeIgnored = true;
-
-                UIResizeEvent *re = (UIResizeEvent *) e;
-                LogFlow (("VBoxDefs::ResizeEventType: %d x %d x %d bpp\n",
-                          re->width(), re->height(), re->bitsPerPixel()));
-#ifdef DEBUG_michael
-                LogRel (("Resize event from guest: %d x %d x %d bpp\n",
-                         re->width(), re->height(), re->bitsPerPixel()));
-#endif
-
-                /* Store the new size to prevent unwanted resize hints being
-                 * sent back. */
-                storeConsoleSize(re->width(), re->height());
-                /* do frame buffer dependent resize */
-
-                /* restoreOverrideCursor() is broken in Qt 4.4.0 if WA_PaintOnScreen
-                 * widgets are present. This is the case on linux with SDL. As
-                 * workaround we save/restore the arrow cursor manually. See
-                 * http://trolltech.com/developer/task-tracker/index_html?id=206165&method=entry
-                 * for details.
-                 *
-                 * Moreover the current cursor, which could be set by the guest,
-                 * should be restored after resize.
-                 */
-                QCursor cursor;
-                if (shouldHideHostPointer())
-                    cursor = QCursor (Qt::BlankCursor);
-                else
-                    cursor = viewport()->cursor();
-                mFrameBuf->resizeEvent (re);
-                viewport()->setCursor (cursor);
+#endif
+            }
+            else if (!m_bIsHostkeyPressed && pEvent->type() == QEvent::KeyRelease)
+            {
+                /* Show a possible warning on key release which seems to be more expected by the end user: */
+                if (machineWindowWrapper()->machineLogic()->isPaused())
+                {
+                    /* Iif the reminder is disabled we pass the event to Qt to enable normal
+                     * keyboard functionality (for example, menu access with Alt+Letter): */
+                    if (!vboxProblem().remindAboutPausedVMInput())
+                        break;
+                }
+            }
+
+            pKeyEvent->accept();
+            return true;
+        }
 
 #ifdef Q_WS_MAC
-                mDockIconPreview->setOriginalSize (re->width(), re->height());
-#endif /* Q_WS_MAC */
-
-                /* This event appears in case of guest video was changed
-                 * for somehow even without video resolution change.
-                 * In this last case the host VM window will not be resized
-                 * according this event and the host mouse cursor which was
-                 * unset to default here will not be hidden in capture state.
-                 * So it is necessary to perform updateMouseClipping() for
-                 * the guest resize event if the mouse cursor was captured. */
-                if (m_bIsMouseCaptured)
-                    updateMouseClipping();
-
-                /* apply maximum size restriction */
-                setMaximumSize (sizeHint());
-
-                maybeRestrictMinimumSize();
-
-                /* resize the guest canvas */
-                if (!m_bIsFrameBufferResizeIgnored)
-                    resize (re->width(), re->height());
-                updateSliders();
-                /* Let our toplevel widget calculate its sizeHint properly. */
-#ifdef Q_WS_X11
-                /* We use processEvents rather than sendPostedEvents & set the
-                 * time out value to max cause on X11 otherwise the layout
-                 * isn't calculated correctly. Dosn't find the bug in Qt, but
-                 * this could be triggered through the async nature of the X11
-                 * window event system. */
-                QCoreApplication::processEvents (QEventLoop::AllEvents, INT_MAX);
-#else /* Q_WS_X11 */
-                QCoreApplication::sendPostedEvents (0, QEvent::LayoutRequest);
-#endif /* Q_WS_X11 */
-
-                if (!m_bIsFrameBufferResizeIgnored)
-                    normalizeGeometry (true /* adjustPosition */);
-
-                /* report to the VM thread that we finished resizing */
-                m_console.GetDisplay().ResizeCompleted (0);
-
-                m_bIsMachineWindowResizeIgnored = oldIgnoreMainwndResize;
-
-                /* update geometry after entering fullscreen | seamless */
-                // if (machineWindowWrapper()->isTrueFullscreen() || machineWindowWrapper()->isTrueSeamless()) TODO check that!
-                    updateGeometry();
-
-                /* make sure that all posted signals are processed */
-                qApp->processEvents();
-
-                /* emit a signal about guest was resized */
-                emit resizeHintDone();
-
-                /* We also recalculate the desktop geometry if this is determined
-                 * automatically.  In fact, we only need this on the first resize,
-                 * but it is done every time to keep the code simpler. */
-                calculateDesktopGeometry();
-
-                /* Enable frame-buffer resize watching. */
-                if (m_bIsFrameBufferResizeIgnored)
-                {
-                    m_bIsFrameBufferResizeIgnored = false;
-                }
-
-                // machineWindowWrapper()->onDisplayResize (re->width(), re->height()); TODO check that!
-
-                return true;
-            }
-
-            /* See VBox[QImage|SDL]FrameBuffer::NotifyUpdate(). */
-            case VBoxDefs::RepaintEventType:
-            {
-                UIRepaintEvent *re = (UIRepaintEvent *) e;
-                viewport()->repaint (re->x() - contentsX(),
-                                     re->y() - contentsY(),
-                                     re->width(), re->height());
-                /* m_console.GetDisplay().UpdateCompleted(); - the event was acked already */
-                return true;
-            }
-
-#ifdef VBOX_WITH_VIDEOHWACCEL
-            case VBoxDefs::VHWACommandProcessType:
-            {
-                mFrameBuf->doProcessVHWACommand(e);
-                return true;
-            }
-#endif
-
-            #if 0
-            // TODO check that!
-            case VBoxDefs::SetRegionEventType:
-            {
-                VBoxSetRegionEvent *sre = (VBoxSetRegionEvent*) e;
-                if (machineWindowWrapper()->isTrueSeamless() && sre->region() != mLastVisibleRegion)
-                {
-                    mLastVisibleRegion = sre->region();
-                    machineWindowWrapper()->setMask (sre->region());
-                }
-                else if (!mLastVisibleRegion.isEmpty() && !machineWindowWrapper()->isTrueSeamless())
-                    mLastVisibleRegion = QRegion();
-                return true;
-            }
-            #endif
-
-            #if 0
-            case VBoxDefs::ActivateMenuEventType:
-            {
-                ActivateMenuEvent *ame = (ActivateMenuEvent *) e;
-                ame->action()->trigger();
-
-                /*
-                 *  The main window and its children can be destroyed at this
-                 *  point (if, for example, the activated menu item closes the
-                 *  main window). Detect this situation to prevent calls to
-                 *  destroyed widgets.
-                 */
-                QWidgetList list = QApplication::topLevelWidgets();
-                bool destroyed = list.indexOf (machineWindowWrapper()->machineWindow()) < 0;
-                if (!destroyed && machineWindowWrapper()->machineWindow()->statusBar())
-                    machineWindowWrapper()->machineWindow()->statusBar()->clearMessage();
-
-                return true;
-            }
-            #endif
-
-            case QEvent::KeyPress:
-            case QEvent::KeyRelease:
-            {
-                QKeyEvent *ke = (QKeyEvent *) e;
-
-#ifdef Q_WS_PM
-                /// @todo temporary solution to send Alt+Tab and friends to
-                //  the guest. The proper solution is to write a keyboard
-                //  driver that will steal these combos from the host (it's
-                //  impossible to do so using hooks on OS/2).
-
-                if (m_bIsHostkeyPressed)
-                {
-                    bool pressed = e->type() == QEvent::KeyPress;
-                    CKeyboard keyboard = m_console.GetKeyboard();
-
-                    /* whether the host key is Shift so that it will modify
-                     * the hot key values? Note that we don't distinguish
-                     * between left and right shift here (too much hassle) */
-                    const bool kShift = (m_globalSettings.hostKey() == VK_SHIFT ||
-                                        m_globalSettings.hostKey() == VK_LSHIFT) &&
-                                        (ke->state() & Qt::ShiftModifier);
-                    /* define hot keys according to the Shift state */
-                    const int kAltTab      = kShift ? Qt::Key_Exclam     : Qt::Key_1;
-                    const int kAltShiftTab = kShift ? Qt::Key_At         : Qt::Key_2;
-                    const int kCtrlEsc     = kShift ? Qt::Key_AsciiTilde : Qt::Key_QuoteLeft;
-
-                    /* Simulate Alt+Tab on Host+1 and Alt+Shift+Tab on Host+2 */
-                    if (ke->key() == kAltTab || ke->key() == kAltShiftTab)
-                    {
-                        if (pressed)
-                        {
-                            /* Send the Alt press to the guest */
-                            if (!(mPressedKeysCopy [0x38] & IsKeyPressed))
-                            {
-                                /* store the press in *Copy to have it automatically
-                                 * released when the Host key is released */
-                                mPressedKeysCopy [0x38] |= IsKeyPressed;
-                                keyboard.PutScancode (0x38);
-                            }
-
-                            /* Make sure Shift is pressed if it's Key_2 and released
-                             * if it's Key_1 */
-                            if (ke->key() == kAltTab &&
-                                (mPressedKeysCopy [0x2A] & IsKeyPressed))
-                            {
-                                mPressedKeysCopy [0x2A] &= ~IsKeyPressed;
-                                keyboard.PutScancode (0xAA);
-                            }
-                            else
-                            if (ke->key() == kAltShiftTab &&
-                                !(mPressedKeysCopy [0x2A] & IsKeyPressed))
-                            {
-                                mPressedKeysCopy [0x2A] |= IsKeyPressed;
-                                keyboard.PutScancode (0x2A);
-                            }
-                        }
-
-                        keyboard.PutScancode (pressed ? 0x0F : 0x8F);
-
-                        ke->accept();
-                        return true;
-                    }
-
-                    /* Simulate Ctrl+Esc on Host+Tilde */
-                    if (ke->key() == kCtrlEsc)
-                    {
-                        /* Send the Ctrl press to the guest */
-                        if (pressed && !(mPressedKeysCopy [0x1d] & IsKeyPressed))
-                        {
-                            /* store the press in *Copy to have it automatically
-                             * released when the Host key is released */
-                            mPressedKeysCopy [0x1d] |= IsKeyPressed;
-                            keyboard.PutScancode (0x1d);
-                        }
-
-                        keyboard.PutScancode (pressed ? 0x01 : 0x81);
-
-                        ke->accept();
-                        return true;
-                    }
-                }
-
-                /* fall through to normal processing */
-
-#endif /* Q_WS_PM */
-
-                if (m_bIsHostkeyPressed && e->type() == QEvent::KeyPress)
-                {
-                    if (ke->key() >= Qt::Key_F1 && ke->key() <= Qt::Key_F12)
-                    {
-                        QVector <LONG> combo (6);
-                        combo [0] = 0x1d; /* Ctrl down */
-                        combo [1] = 0x38; /* Alt  down */
-                        combo [4] = 0xb8; /* Alt  up   */
-                        combo [5] = 0x9d; /* Ctrl up   */
-                        if (ke->key() >= Qt::Key_F1 && ke->key() <= Qt::Key_F10)
-                        {
-                            combo [2] = 0x3b + (ke->key() - Qt::Key_F1); /* F1-F10 down */
-                            combo [3] = 0xbb + (ke->key() - Qt::Key_F1); /* F1-F10 up   */
-                        }
-                        /* some scan slice */
-                        else if (ke->key() >= Qt::Key_F11 && ke->key() <= Qt::Key_F12)
-                        {
-                            combo [2] = 0x57 + (ke->key() - Qt::Key_F11); /* F11-F12 down */
-                            combo [3] = 0xd7 + (ke->key() - Qt::Key_F11); /* F11-F12 up   */
-                        }
-                        else
-                            Assert (0);
-
-                        CKeyboard keyboard = m_console.GetKeyboard();
-                        keyboard.PutScancodes (combo);
-                    }
-                    #if 0
-                    // TODO check that!
-                    else if (ke->key() == Qt::Key_Home)
-                    {
-                        /* Activate the main menu */
-                        if (machineWindowWrapper()->isTrueSeamless() || machineWindowWrapper()->isTrueFullscreen())
-                            machineWindowWrapper()->popupMainMenu (m_bIsMouseCaptured);
-                        else
-                        {
-                            /* In Qt4 it is not enough to just set the focus to
-                             * menu-bar. So to get the menu-bar we have to send
-                             * Qt::Key_Alt press/release events directly. */
-                            QKeyEvent e1 (QEvent::KeyPress, Qt::Key_Alt,
-                                          Qt::NoModifier);
-                            QKeyEvent e2 (QEvent::KeyRelease, Qt::Key_Alt,
-                                          Qt::NoModifier);
-                            QApplication::sendEvent (machineWindowWrapper()->menuBar(), &e1);
-                            QApplication::sendEvent (machineWindowWrapper()->menuBar(), &e2);
-                        }
-                    }
-                    else
-                    {
-                        /* process hot keys not processed in keyEvent()
-                         * (as in case of non-alphanumeric keys) */
-                        processHotKey (QKeySequence (ke->key()),
-                                       machineWindowWrapper()->menuBar()->actions());
-                    }
-                    #endif
-                }
-                else if (!m_bIsHostkeyPressed && e->type() == QEvent::KeyRelease)
-                {
-                    /* Show a possible warning on key release which seems to
-                     * be more expected by the end user */
-
-                    if (machineWindowWrapper()->machineLogic()->isPaused())
-                    {
-                        /* if the reminder is disabled we pass the event to
-                         * Qt to enable normal keyboard functionality
-                         * (for example, menu access with Alt+Letter) */
-                        if (!vboxProblem().remindAboutPausedVMInput())
-                            break;
-                    }
-                }
-
-                ke->accept();
-                return true;
-            }
-
-#ifdef Q_WS_MAC
-            /* posted OnShowWindow */
-            case VBoxDefs::ShowWindowEventType:
-            {
-                /*
-                 *  Dunno what Qt3 thinks a window that has minimized to the dock
-                 *  should be - it is not hidden, neither is it minimized. OTOH it is
-                 *  marked shown and visible, but not activated. This latter isn't of
-                 *  much help though, since at this point nothing is marked activated.
-                 *  I might have overlooked something, but I'm buggered what if I know
-                 *  what. So, I'll just always show & activate the stupid window to
-                 *  make it get out of the dock when the user wishes to show a VM.
-                 */
-                window()->show();
-                window()->activateWindow();
-                return true;
-            }
-#endif
-            default:
-                break;
-        }
-    }
-
-    return QAbstractScrollArea::event (e);
-}
-
-bool UIMachineView::eventFilter(QObject *watched, QEvent *e)
-{
-    if (watched == viewport())
-    {
-        switch (e->type())
+        /* posted OnShowWindow */
+        case VBoxDefs::ShowWindowEventType:
+        {
+            /* Dunno what Qt3 thinks a window that has minimized to the dock should be - it is not hidden,
+             * neither is it minimized. OTOH it is marked shown and visible, but not activated.
+             * This latter isn't of much help though, since at this point nothing is marked activated.
+             * I might have overlooked something, but I'm buggered what if I know what. So, I'll just always
+             * show & activate the stupid window to make it get out of the dock when the user wishes to show a VM: */
+            window()->show();
+            window()->activateWindow();
+            return true;
+        }
+#endif
+
+        default:
+            break;
+    }
+
+    return QAbstractScrollArea::event(pEvent);
+}
+
+bool UIMachineView::eventFilter(QObject *pWatched, QEvent *pEvent)
+{
+    if (pWatched == viewport())
+    {
+        switch (pEvent->type())
         {
             case QEvent::MouseMove:
@@ -1032,22 +1164,20 @@
             case QEvent::MouseButtonRelease:
             {
-                QMouseEvent *me = (QMouseEvent *) e;
+                QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(pEvent);
                 m_iLastMouseWheelDelta = 0;
-                if (mouseEvent (me->type(), me->pos(), me->globalPos(),
-                                me->buttons(), me->modifiers(),
-                                0, Qt::Horizontal))
-                    return true; /* stop further event handling */
+                if (mouseEvent(pMouseEvent->type(), pMouseEvent->pos(), pMouseEvent->globalPos(),
+                               pMouseEvent->buttons(), pMouseEvent->modifiers(), 0, Qt::Horizontal))
+                    return true;
                 break;
             }
             case QEvent::Wheel:
             {
-                QWheelEvent *we = (QWheelEvent *) e;
-                /* There are pointing devices which send smaller values for the
-                 * delta than 120. Here we sum them up until we are greater
-                 * than 120. This allows to have finer control over the speed
-                 * acceleration & enables such devices to send a valid wheel
-                 * event to our guest mouse device at all. */
+                QWheelEvent *pWheelEvent = static_cast<QWheelEvent*>(pEvent);
+                /* There are pointing devices which send smaller values for the delta than 120.
+                 * Here we sum them up until we are greater than 120. This allows to have finer control
+                 * over the speed acceleration & enables such devices to send a valid wheel event to our
+                 * guest mouse device at all: */
                 int iDelta = 0;
-                m_iLastMouseWheelDelta += we->delta();
+                m_iLastMouseWheelDelta += pWheelEvent->delta();
                 if (qAbs(m_iLastMouseWheelDelta) >= 120)
                 {
@@ -1055,18 +1185,16 @@
                     m_iLastMouseWheelDelta = m_iLastMouseWheelDelta % 120;
                 }
-                if (mouseEvent (we->type(), we->pos(), we->globalPos(),
+                if (mouseEvent(pWheelEvent->type(), pWheelEvent->pos(), pWheelEvent->globalPos(),
 #ifdef QT_MAC_USE_COCOA
-                                /* Qt Cocoa is buggy. It always reports a left
-                                 * button pressed when the mouse wheel event
-                                 * occurs. A workaround is to ask the
-                                 * application which buttons are pressed
-                                 * currently. */
+                                /* Qt Cocoa is buggy. It always reports a left button pressed when the
+                                 * mouse wheel event occurs. A workaround is to ask the application which
+                                 * buttons are pressed currently: */
                                 QApplication::mouseButtons(),
 #else /* QT_MAC_USE_COCOA */
-                                we->buttons(),
+                                pWheelEvent->buttons(),
 #endif /* QT_MAC_USE_COCOA */
-                                we->modifiers(),
-                                iDelta, we->orientation()))
-                    return true; /* stop further event handling */
+                                pWheelEvent->modifiers(),
+                                iDelta, pWheelEvent->orientation()))
+                    return true;
                 break;
             }
@@ -1074,16 +1202,14 @@
             case QEvent::Leave:
             {
-                /* Enable mouse event compression if we leave the VM view. This
-                   is necessary for having smooth resizing of the VM/other
-                   windows. */
-                setMouseCoalescingEnabled (true);
+                /* Enable mouse event compression if we leave the VM view. This is necessary for
+                 * having smooth resizing of the VM/other windows: */
+                setMouseCoalescingEnabled(true);
                 break;
             }
             case QEvent::Enter:
             {
-                /* Disable mouse event compression if we enter the VM view. So
-                   all mouse events are registered in the VM. Only do this if
-                   the keyboard/mouse is grabbed (this is when we have a valid
-                   event handler). */
+                /* Disable mouse event compression if we enter the VM view. So all mouse events are
+                 * registered in the VM. Only do this if the keyboard/mouse is grabbed (this is when
+                 * we have a valid event handler): */
                 setMouseCoalescingEnabled (false);
                 break;
@@ -1095,7 +1221,7 @@
                     updateMouseClipping();
 #ifdef VBOX_WITH_VIDEOHWACCEL
-                if (mFrameBuf)
+                if (m_pFrameBuffer)
                 {
-                    mFrameBuf->viewportResized((QResizeEvent*)e);
+                    m_pFrameBuffer->viewportResized(static_cast<QResizeEvent*>(pEvent));
                 }
 #endif
@@ -1106,74 +1232,25 @@
         }
     }
-    else if (watched == machineWindowWrapper()->machineWindow())
-    {
-        switch (e->type())
-        {
-#if defined (Q_WS_WIN32)
-#if defined (VBOX_GUI_USE_DDRAW)
-            case QEvent::Move:
-            {
-                /*
-                 *  notification from our parent that it has moved. We need this
-                 *  in order to possibly adjust the direct screen blitting.
-                 */
-                if (mFrameBuf)
-                    mFrameBuf->moveEvent ((QMoveEvent *) e);
+    else if (pWatched == machineWindowWrapper()->machineWindow())
+    {
+        switch (pEvent->type())
+        {
+#if 0 // TODO Move to normal specific event handler:
+            case QEvent::Resize:
+            {
+                /* Set the "guest needs to resize" hint. This hint is acted upon when (and only when)
+                 * the autoresize property is "true": */
+                mDoResize = isGuestSupportsGraphics() || machineWindowWrapper()->isTrueFullscreen();
+                if (!m_bIsMachineWindowResizeIgnored && isGuestSupportsGraphics() && m_bIsGuestAutoresizeEnabled)
+                    QTimer::singleShot(300, this, SLOT(doResizeHint()));
                 break;
             }
 #endif
-            /*
-             *  install/uninstall low-level kbd hook on every
-             *  activation/deactivation to:
-             *  a) avoid excess hook calls when we're not active and
-             *  b) be always in front of any other possible hooks
-             */
-            case QEvent::WindowActivate:
-            {
-                gKbdHook = SetWindowsHookEx (WH_KEYBOARD_LL, lowLevelKeyboardProc,
-                                              GetModuleHandle (NULL), 0);
-                AssertMsg (gKbdHook, ("SetWindowsHookEx(): err=%d", GetLastError()));
-                break;
-            }
-            case QEvent::WindowDeactivate:
-            {
-                if (gKbdHook)
-                {
-                    UnhookWindowsHookEx (gKbdHook);
-                    gKbdHook = NULL;
-                }
-                break;
-            }
-#endif /* defined (Q_WS_WIN32) */
-#if defined (Q_WS_MAC)
-            /*
-             *  Install/remove the keyboard event handler.
-             */
-            case QEvent::WindowActivate:
-                darwinGrabKeyboardEvents (true);
-                break;
-            case QEvent::WindowDeactivate:
-                darwinGrabKeyboardEvents (false);
-                break;
-#endif /* defined (Q_WS_MAC) */
-            #if 0
-            // TODO check that!
-            case QEvent::Resize:
-            {
-                /* Set the "guest needs to resize" hint.  This hint is acted upon
-                 * when (and only when) the autoresize property is "true". */
-                mDoResize = m_bIsGuestSupportsGraphics || machineWindowWrapper()->isTrueFullscreen();
-                if (!m_bIsMachineWindowResizeIgnored &&
-                    m_bIsGuestSupportsGraphics && m_bIsGuestAutoresizeEnabled)
-                    QTimer::singleShot (300, this, SLOT (doResizeHint()));
-                break;
-            }
-            #endif
             case QEvent::WindowStateChange:
             {
                 /* During minimizing and state restoring machineWindowWrapper() gets the focus
                  * which belongs to console view window, so returning it properly. */
-                QWindowStateChangeEvent *ev = static_cast <QWindowStateChangeEvent*> (e);
-                if (ev->oldState() & Qt::WindowMinimized)
+                QWindowStateChangeEvent *pWindowEvent = static_cast<QWindowStateChangeEvent*>(pEvent);
+                if (pWindowEvent->oldState() & Qt::WindowMinimized)
                 {
                     if (QApplication::focusWidget())
@@ -1182,23 +1259,58 @@
                         qApp->processEvents();
                     }
-                    QTimer::singleShot (0, this, SLOT (setFocus()));
+                    QTimer::singleShot(0, this, SLOT(setFocus()));
                 }
                 break;
             }
-
+#if defined (Q_WS_WIN32)
+#if defined (VBOX_GUI_USE_DDRAW)
+            case QEvent::Move:
+            {
+                /* Notification from our parent that it has moved. We need this in order
+                 * to possibly adjust the direct screen blitting: */
+                if (m_pFrameBuffer)
+                    m_pFrameBuffer->moveEvent(static_cast<QMoveEvent*>(pEvent));
+                break;
+            }
+#endif
+            /* Install/uninstall low-level kbd hook on every activation/deactivation to:
+             * a) avoid excess hook calls when we're not active and
+             * b) be always in front of any other possible hooks */
+            case QEvent::WindowActivate:
+            {
+                gKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, lowLevelKeyboardProc, GetModuleHandle(NULL), 0);
+                AssertMsg(gKbdHook, ("SetWindowsHookEx(): err=%d", GetLastError()));
+                break;
+            }
+            case QEvent::WindowDeactivate:
+            {
+                if (gKbdHook)
+                {
+                    UnhookWindowsHookEx(gKbdHook);
+                    gKbdHook = NULL;
+                }
+                break;
+            }
+#endif /* defined (Q_WS_WIN32) */
+#if defined (Q_WS_MAC)
+            /* Install/remove the keyboard event handler: */
+            case QEvent::WindowActivate:
+                darwinGrabKeyboardEvents(true);
+                break;
+            case QEvent::WindowDeactivate:
+                darwinGrabKeyboardEvents(false);
+                break;
+#endif /* defined (Q_WS_MAC) */
             default:
                 break;
         }
     }
-    #if 0 // TODO check that
-    else if (watched == machineWindowWrapper()->menuBar())
-    {
-        /*
-         *  sometimes when we press ESC in the menu it brings the
-         *  focus away (Qt bug?) causing no widget to have a focus,
-         *  or holds the focus itself, instead of returning the focus
-         *  to the console window. here we fix this.
-         */
-        switch (e->type())
+#if 0 // TODO Move to normal specific event handler:
+    else if (pWatched == machineWindowWrapper()->menuBar())
+    {
+        /* Sometimes when we press ESC in the menu it brings the focus away (Qt bug?)
+         * causing no widget to have a focus, or holds the focus itself, instead of
+         * returning the focus to the console window. Here we fix this: */
+        switch (pEvent->type())
         {
             case QEvent::FocusOut:
@@ -1210,6 +1322,6 @@
             case QEvent::KeyPress:
             {
-                QKeyEvent *ke = (QKeyEvent *) e;
-                if (ke->key() == Qt::Key_Escape && (ke->modifiers() == Qt::NoModifier))
+                QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
+                if (pKeyEvent->key() == Qt::Key_Escape && (pKeyEvent->modifiers() == Qt::NoModifier))
                     if (machineWindowWrapper()->menuBar()->hasFocus())
                         setFocus();
@@ -1220,544 +1332,23 @@
         }
     }
-    #endif
-
-    return QAbstractScrollArea::eventFilter (watched, e);
-}
-
-#if defined(Q_WS_WIN32)
-
-bool UIMachineView::winLowKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event)
-{
-    /* Sometimes it happens that Win inserts additional events on some key
-     * press/release. For example, it prepends ALT_GR in German layout with
-     * the VK_LCONTROL vkey with curious 0x21D scan code (seems to be necessary
-     * to specially treat ALT_GR to enter additional chars to regular apps).
-     * These events are definitely unwanted in VM, so filter them out. */
-    /* Note (michael): it also sometimes sends the VK_CAPITAL vkey with scan
-     * code 0x23a. If this is not passed through then it is impossible to
-     * cancel CapsLock on a French keyboard.  I didn't find any other examples
-     * of these strange events.  Let's hope we are not missing anything else
-     * of importance! */
-    if (hasFocus() && (event.scanCode & ~0xFF))
-    {
-        if (event.vkCode == VK_CAPITAL)
-            return false;
-        else
-            return true;
-    }
-
-    if (!m_bIsKeyboardCaptured)
-        return false;
-
-    /* it's possible that a key has been pressed while the keyboard was not
-     * captured, but is being released under the capture. Detect this situation
-     * and return false to let Windows process the message normally and update
-     * its key state table (to avoid the stuck key effect). */
-    uint8_t what_pressed = (event.flags & 0x01) && (event.vkCode != VK_RSHIFT) ? IsExtKeyPressed : IsKeyPressed;
-    if ((event.flags & 0x80) /* released */ &&
-        ((event.vkCode == m_globalSettings.hostKey() && !hostkey_in_capture) ||
-         (mPressedKeys [event.scanCode] & (IsKbdCaptured | what_pressed)) == what_pressed))
-        return false;
-
-    MSG message;
-    message.hwnd = winId();
-    message.message = msg;
-    message.wParam = event.vkCode;
-    message.lParam = 1 | (event.scanCode & 0xFF) << 16 | (event.flags & 0xFF) << 24;
-
-    /* Windows sets here the extended bit when the Right Shift key is pressed,
-     * which is totally wrong. Undo it. */
-    if (event.vkCode == VK_RSHIFT)
-        message.lParam &= ~0x1000000;
-
-    /* we suppose here that this hook is always called on the main GUI thread */
-    long dummyResult;
-    return winEvent(&message, &dummyResult);
-}
-
-bool UIMachineView::winEvent(MSG *aMsg, long* /* aResult */)
-{
-    if (!(aMsg->message == WM_KEYDOWN || aMsg->message == WM_SYSKEYDOWN ||
-          aMsg->message == WM_KEYUP || aMsg->message == WM_SYSKEYUP))
-        return false;
-
-    /* Check for the special flag possibly set at the end of this function */
-    if (aMsg->lParam & (0x1 << 25))
-    {
-        aMsg->lParam &= ~(0x1 << 25);
-        return false;
-    }
-
-    int scan = (aMsg->lParam >> 16) & 0x7F;
-    /* scancodes 0x80 and 0x00 are ignored */
-    if (!scan)
-        return true;
-
-    int vkey = aMsg->wParam;
-
-    /* When one of the SHIFT keys is held and one of the cursor movement
-     * keys is pressed, Windows duplicates SHIFT press/release messages,
-     * but with the virtual key code set to 0xFF. These virtual keys are also
-     * sent in some other situations (Pause, PrtScn, etc.). Ignore such
-     * messages. */
-    if (vkey == 0xFF)
-        return true;
-
-    int flags = 0;
-    if (aMsg->lParam & 0x1000000)
-        flags |= KeyExtended;
-    if (!(aMsg->lParam & 0x80000000))
-        flags |= KeyPressed;
-
-    switch (vkey)
-    {
-        case VK_SHIFT:
-        case VK_CONTROL:
-        case VK_MENU:
-        {
-            /* overcome stupid Win32 modifier key generalization */
-            int keyscan = scan;
-            if (flags & KeyExtended)
-                keyscan |= 0xE000;
-            switch (keyscan)
-            {
-                case 0x002A: vkey = VK_LSHIFT; break;
-                case 0x0036: vkey = VK_RSHIFT; break;
-                case 0x001D: vkey = VK_LCONTROL; break;
-                case 0xE01D: vkey = VK_RCONTROL; break;
-                case 0x0038: vkey = VK_LMENU; break;
-                case 0xE038: vkey = VK_RMENU; break;
-            }
-            break;
-        }
-        case VK_NUMLOCK:
-            /* Win32 sets the extended bit for the NumLock key. Reset it. */
-            flags &= ~KeyExtended;
-            break;
-        case VK_SNAPSHOT:
-            flags |= KeyPrint;
-            break;
-        case VK_PAUSE:
-            flags |= KeyPause;
-            break;
-    }
-
-    bool result = keyEvent(vkey, scan, flags);
-    if (!result && m_bIsKeyboardCaptured)
-    {
-        /* keyEvent() returned that it didn't process the message, but since the
-         * keyboard is captured, we don't want to pass it to Windows. We just want
-         * to let Qt process the message (to handle non-alphanumeric <HOST>+key
-         * shortcuts for example). So send it direcltly to the window with the
-         * special flag in the reserved area of lParam (to avoid recursion). */
-        ::SendMessage(aMsg->hwnd, aMsg->message,
-                      aMsg->wParam, aMsg->lParam | (0x1 << 25));
-        return true;
-    }
-
-    /* These special keys have to be handled by Windows as well to update the
-     * internal modifier state and to enable/disable the keyboard LED */
-    if (vkey == VK_NUMLOCK || vkey == VK_CAPITAL || vkey == VK_LSHIFT || vkey == VK_RSHIFT)
-        return false;
-
-    return result;
-}
-
-#elif defined (Q_WS_PM)
-
-bool UIMachineView::pmEvent(QMSG *aMsg)
-{
-    if (aMsg->msg == UM_PREACCEL_CHAR)
-    {
-        /* We are inside the input hook
-         * let the message go through the normal system pipeline. */
-        if (!m_bIsKeyboardCaptured)
-            return false;
-    }
-
-    if (aMsg->msg != WM_CHAR && aMsg->msg != UM_PREACCEL_CHAR)
-        return false;
-
-    /* check for the special flag possibly set at the end of this function */
-    if (SHORT2FROMMP(aMsg->mp2) & 0x8000)
-    {
-        aMsg->mp2 = MPFROM2SHORT(SHORT1FROMMP(aMsg->mp2), SHORT2FROMMP(aMsg->mp2) & ~0x8000);
-        return false;
-    }
-
-    USHORT ch = SHORT1FROMMP(aMsg->mp2);
-    USHORT f = SHORT1FROMMP(aMsg->mp1);
-
-    int scan = (unsigned int)CHAR4FROMMP(aMsg->mp1);
-    if (!scan || scan > 0x7F)
-        return true;
-
-    int vkey = QIHotKeyEdit::virtualKey(aMsg);
-
-    int flags = 0;
-
-    if ((ch & 0xFF) == 0xE0)
-    {
-        flags |= KeyExtended;
-        scan = ch >> 8;
-    }
-    else if (scan == 0x5C && (ch & 0xFF) == '/')
-    {
-        /* this is the '/' key on the keypad */
-        scan = 0x35;
-        flags |= KeyExtended;
-    }
-    else
-    {
-        /* For some keys, the scan code passed in QMSG is a pseudo scan
-         * code. We replace it with a real hardware scan code, according to
-         * http://www.computer-engineering.org/ps2keyboard/scancodes1.html.
-         * Also detect Pause and PrtScn and set flags. */
-        switch (vkey)
-        {
-            case VK_ENTER:     scan = 0x1C; flags |= KeyExtended; break;
-            case VK_CTRL:      scan = 0x1D; flags |= KeyExtended; break;
-            case VK_ALTGRAF:   scan = 0x38; flags |= KeyExtended; break;
-            case VK_LWIN:      scan = 0x5B; flags |= KeyExtended; break;
-            case VK_RWIN:      scan = 0x5C; flags |= KeyExtended; break;
-            case VK_WINMENU:   scan = 0x5D; flags |= KeyExtended; break;
-            case VK_FORWARD:   scan = 0x69; flags |= KeyExtended; break;
-            case VK_BACKWARD:  scan = 0x6A; flags |= KeyExtended; break;
-#if 0
-            /// @todo this would send 0xE0 0x46 0xE0 0xC6. It's not fully
-            // clear what is more correct
-            case VK_BREAK:     scan = 0x46; flags |= KeyExtended; break;
-#else
-            case VK_BREAK:     scan = 0;    flags |= KeyPause; break;
-#endif
-            case VK_PAUSE:     scan = 0;    flags |= KeyPause;    break;
-            case VK_PRINTSCRN: scan = 0;    flags |= KeyPrint;    break;
-            default:;
-        }
-    }
-
-    if (!(f & KC_KEYUP))
-        flags |= KeyPressed;
-
-    bool result = keyEvent (vkey, scan, flags);
-    if (!result && m_bIsKeyboardCaptured)
-    {
-        /* keyEvent() returned that it didn't process the message, but since the
-         * keyboard is captured, we don't want to pass it to PM. We just want
-         * to let Qt process the message (to handle non-alphanumeric <HOST>+key
-         * shortcuts for example). So send it direcltly to the window with the
-         * special flag in the reserved area of lParam (to avoid recursion). */
-        ::WinSendMsg (aMsg->hwnd, WM_CHAR, aMsg->mp1,
-                      MPFROM2SHORT (SHORT1FROMMP (aMsg->mp2), SHORT2FROMMP (aMsg->mp2) | 0x8000));
-        return true;
-    }
-    return result;
-}
-
-#elif defined(Q_WS_X11)
-
-static Bool VBoxConsoleViewCompEvent(Display *, XEvent *pEvent, XPointer pvArg)
-{
-    XEvent *pKeyEvent = (XEvent *) pvArg;
-    if ((pEvent->type == XKeyPress) && (pEvent->xkey.keycode == pKeyEvent->xkey.keycode))
-        return True;
-    else
-        return False;
-}
-
-bool UIMachineView::x11Event(XEvent *event)
-{
-    switch (event->type)
-    {
-        /* We have to handle XFocusOut right here as this event is not passed
-         * to UIMachineView::event(). Handling this event is important for
-         * releasing the keyboard before the screen saver gets active. */
-        case XFocusOut:
-        case XFocusIn:
-            if (isRunning())
-                focusEvent(event->type == XFocusIn);
-            return false;
-        case XKeyPress:
-        case XKeyRelease:
-            break;
-        default:
-            return false; /* pass the event to Qt */
-    }
-
-    /* Translate the keycode to a PC scan code. */
-    unsigned scan = handleXKeyEvent(event);
-
-    // scancodes 0x00 (no valid translation) and 0x80 are ignored
-    if (!scan & 0x7F)
-        return true;
-
-    /* Fix for http://www.virtualbox.org/ticket/1296:
-     * when X11 sends events for repeated keys, it always inserts an
-     * XKeyRelease before the XKeyPress. */
-    XEvent returnEvent;
-    if ((event->type == XKeyRelease) && (XCheckIfEvent(event->xkey.display, &returnEvent,
-        VBoxConsoleViewCompEvent, (XPointer) event) == True))
-    {
-        XPutBackEvent(event->xkey.display, &returnEvent);
-        /* Discard it, don't pass it to Qt. */
-        return true;
-    }
-
-    KeySym ks = ::XKeycodeToKeysym(event->xkey.display, event->xkey.keycode, 0);
-
-    int flags = 0;
-    if (scan >> 8)
-        flags |= KeyExtended;
-    if (event->type == XKeyPress)
-        flags |= KeyPressed;
-
-    /* Remove the extended flag */
-    scan &= 0x7F;
-
-    switch (ks)
-    {
-        case XK_Print:
-            flags |= KeyPrint;
-            break;
-        case XK_Pause:
-            flags |= KeyPause;
-            break;
-    }
-
-    return keyEvent(ks, scan, flags);
-}
-
-#elif defined (Q_WS_MAC)
-
-bool UIMachineView::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)
-{
-    bool ret = false;
-    UInt32 EventKind = ::GetEventKind(inEvent);
-    if (EventKind != kEventRawKeyModifiersChanged)
-    {
-        /* convert keycode to set 1 scan code. */
-        UInt32 keyCode = ~0U;
-        ::GetEventParameter(inEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof (keyCode), NULL, &keyCode);
-        unsigned scanCode = ::DarwinKeycodeToSet1Scancode(keyCode);
-        if (scanCode)
-        {
-            /* calc flags. */
-            int flags = 0;
-            if (EventKind != kEventRawKeyUp)
-                flags |= KeyPressed;
-            if (scanCode & VBOXKEY_EXTENDED)
-                flags |= KeyExtended;
-            /** @todo KeyPause, KeyPrint. */
-            scanCode &= VBOXKEY_SCANCODE_MASK;
-
-            /* get the unicode string (if present). */
-            AssertCompileSize(wchar_t, 2);
-            AssertCompileSize(UniChar, 2);
-            ByteCount cbWritten = 0;
-            wchar_t ucs[8];
-            if (::GetEventParameter(inEvent, kEventParamKeyUnicodes, typeUnicodeText, NULL,
-                                    sizeof(ucs), &cbWritten, &ucs[0]) != 0)
-                cbWritten = 0;
-            ucs[cbWritten / sizeof(wchar_t)] = 0; /* The api doesn't terminate it. */
-
-            ret = keyEvent(keyCode, scanCode, flags, ucs[0] ? ucs : NULL);
-        }
-    }
-    else
-    {
-        /* May contain multiple modifier changes, kind of annoying. */
-        UInt32 newMask = 0;
-        ::GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL,
-                            sizeof(newMask), NULL, &newMask);
-        newMask = ::DarwinAdjustModifierMask(newMask, pvCocoaEvent);
-        UInt32 changed = newMask ^ mDarwinKeyModifiers;
-        if (changed)
-        {
-            for (UInt32 bit = 0; bit < 32; bit++)
-            {
-                if (!(changed & (1 << bit)))
-                    continue;
-                unsigned scanCode = ::DarwinModifierMaskToSet1Scancode(1 << bit);
-                if (!scanCode)
-                    continue;
-                unsigned keyCode = ::DarwinModifierMaskToDarwinKeycode(1 << bit);
-                Assert(keyCode);
-
-                if (!(scanCode & VBOXKEY_LOCK))
-                {
-                    unsigned flags = (newMask & (1 << bit)) ? KeyPressed : 0;
-                    if (scanCode & VBOXKEY_EXTENDED)
-                        flags |= KeyExtended;
-                    scanCode &= VBOXKEY_SCANCODE_MASK;
-                    ret |= keyEvent(keyCode, scanCode & 0xff, flags);
-                }
-                else
-                {
-                    unsigned flags = 0;
-                    if (scanCode & VBOXKEY_EXTENDED)
-                        flags |= KeyExtended;
-                    scanCode &= VBOXKEY_SCANCODE_MASK;
-                    keyEvent(keyCode, scanCode, flags | KeyPressed);
-                    keyEvent(keyCode, scanCode, flags);
-                }
-            }
-        }
-
-        mDarwinKeyModifiers = newMask;
-
-        /* Always return true here because we'll otherwise getting a Qt event
-           we don't want and that will only cause the Pause warning to pop up. */
-        ret = true;
-    }
-
-    return ret;
-}
-
-void UIMachineView::darwinGrabKeyboardEvents(bool fGrab)
-{
-    mKeyboardGrabbed = fGrab;
-    if (fGrab)
-    {
-        /* Disable mouse and keyboard event compression/delaying to make sure we *really* get all of the events. */
-        ::CGSetLocalEventsSuppressionInterval(0.0);
-        setMouseCoalescingEnabled(false);
-
-        /* Register the event callback/hook and grab the keyboard. */
-# ifdef QT_MAC_USE_COCOA
-        ::VBoxCocoaApplication_setCallback (UINT32_MAX, /** @todo fix mask */
-                                            UIMachineView::darwinEventHandlerProc, this);
-
-# else /* QT_MAC_USE_COCOA */
-        EventTypeSpec eventTypes[6];
-        eventTypes[0].eventClass = kEventClassKeyboard;
-        eventTypes[0].eventKind  = kEventRawKeyDown;
-        eventTypes[1].eventClass = kEventClassKeyboard;
-        eventTypes[1].eventKind  = kEventRawKeyUp;
-        eventTypes[2].eventClass = kEventClassKeyboard;
-        eventTypes[2].eventKind  = kEventRawKeyRepeat;
-        eventTypes[3].eventClass = kEventClassKeyboard;
-        eventTypes[3].eventKind  = kEventRawKeyModifiersChanged;
-        /* For ignorning Command-H and Command-Q which aren't affected by the
-         * global hotkey stuff (doesn't work well): */
-        eventTypes[4].eventClass = kEventClassCommand;
-        eventTypes[4].eventKind  = kEventCommandProcess;
-        eventTypes[5].eventClass = kEventClassCommand;
-        eventTypes[5].eventKind  = kEventCommandUpdateStatus;
-
-        EventHandlerUPP eventHandler = ::NewEventHandlerUPP(UIMachineView::darwinEventHandlerProc);
-
-        mDarwinEventHandlerRef = NULL;
-        ::InstallApplicationEventHandler(eventHandler, RT_ELEMENTS (eventTypes), &eventTypes[0],
-                                         this, &mDarwinEventHandlerRef);
-        ::DisposeEventHandlerUPP(eventHandler);
-# endif /* !QT_MAC_USE_COCOA */
-
-        ::DarwinGrabKeyboard (false);
-    }
-    else
-    {
-        ::DarwinReleaseKeyboard();
-# ifdef QT_MAC_USE_COCOA
-        ::VBoxCocoaApplication_unsetCallback(UINT32_MAX, /** @todo fix mask */
-                                             UIMachineView::darwinEventHandlerProc, this);
-# else /* QT_MAC_USE_COCOA */
-        if (mDarwinEventHandlerRef)
-        {
-            ::RemoveEventHandler(mDarwinEventHandlerRef);
-            mDarwinEventHandlerRef = NULL;
-        }
-# endif /* !QT_MAC_USE_COCOA */
-    }
-}
-
-#endif
-
-#if defined (Q_WS_WIN32)
-static HHOOK gKbdHook = NULL;
-static UIMachineView *gView = 0;
-LRESULT CALLBACK UIMachineView::lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
-{
-    Assert (gView);
-    if (gView && nCode == HC_ACTION &&
-            gView->winLowKeyboardEvent (wParam, *(KBDLLHOOKSTRUCT *) lParam))
-        return 1;
-
-    return CallNextHookEx (NULL, nCode, wParam, lParam);
-}
-#endif
-
-#if defined (Q_WS_MAC)
-# ifdef QT_MAC_USE_COCOA
-bool UIMachineView::darwinEventHandlerProc (const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
-{
-    UIMachineView *view = (UIMachineView*)pvUser;
-    EventRef inEvent = (EventRef)pvCarbonEvent;
-    UInt32 eventClass = ::GetEventClass(inEvent);
-
-    /* Check if this is an application key combo. In that case we will not pass
-       the event to the guest, but let the host process it. */
-    if (VBoxCocoaApplication_isApplicationCommand(pvCocoaEvent))
-        return false;
-
-    /* All keyboard class events needs to be handled. */
-    if (eventClass == kEventClassKeyboard)
-    {
-        if (view->darwinKeyboardEvent (pvCocoaEvent, inEvent))
-            return true;
-    }
-    /* Pass the event along. */
-    return false;
-}
-
-# else /* QT_MAC_USE_COCOA */
-
-pascal OSStatus UIMachineView::darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
-{
-    UIMachineView *view = static_cast<UIMachineView *> (inUserData);
-    UInt32 eventClass = ::GetEventClass (inEvent);
-
-    /* Not sure but this seems an triggered event if the spotlight searchbar is
-     * displayed. So flag that the host key isn't pressed alone. */
-    if (eventClass == 'cgs ' && view->m_bIsHostkeyPressed && ::GetEventKind (inEvent) == 0x15)
-        view->m_bIsHostkeyAlone = false;
-
-    if (eventClass == kEventClassKeyboard)
-    {
-        if (view->darwinKeyboardEvent (NULL, inEvent))
-            return 0;
-    }
-
-    /*
-     * Command-H and Command-Q aren't properly disabled yet, and it's still
-     * possible to use the left command key to invoke them when the keyboard
-     * is captured. We discard the events these if the keyboard is captured
-     * as a half measure to prevent unexpected behaviour. However, we don't
-     * get any key down/up events, so these combinations are dead to the guest...
-     */
-    else if (eventClass == kEventClassCommand)
-    {
-        if (view->m_bIsKeyboardCaptured)
-            return 0;
-    }
-    return ::CallNextEventHandler(inHandlerCallRef, inEvent);
-}
-# endif /* !QT_MAC_USE_COCOA */
-
-#endif /* Q_WS_MAC */
-
-void UIMachineView::focusEvent(bool aHasFocus, bool aReleaseHostKey /* = true */)
-{
-    if (aHasFocus)
-    {
-#ifdef RT_OS_WINDOWS
+#endif
+
+    return QAbstractScrollArea::eventFilter (pWatched, pEvent);
+}
+
+void UIMachineView::focusEvent(bool fHasFocus, bool fReleaseHostKey /* = true */)
+{
+    if (fHasFocus)
+    {
+#ifdef Q_WS_WIN32
         if (!m_bIsAutoCaptureDisabled && m_globalSettings.autoCapture() && GetAncestor(winId(), GA_ROOT) == GetForegroundWindow())
 #else
         if (!m_bIsAutoCaptureDisabled && m_globalSettings.autoCapture())
-#endif /* RT_OS_WINDOWS */
+#endif
         {
             captureKbd(true);
         }
 
-        /* reset the single-time disable capture flag */
+        /* Reset the single-time disable capture flag: */
         if (m_bIsAutoCaptureDisabled)
             m_bIsAutoCaptureDisabled = false;
@@ -1767,11 +1358,11 @@
         captureMouse(false);
         captureKbd(false, false);
-        releaseAllPressedKeys(aReleaseHostKey);
-    }
-}
-
-bool UIMachineView::keyEvent(int aKey, uint8_t aScan, int aFlags, wchar_t *aUniKey /* = NULL */)
-{
-    const bool isHostKey = aKey == m_globalSettings.hostKey();
+        releaseAllPressedKeys(fReleaseHostKey);
+    }
+}
+
+bool UIMachineView::keyEvent(int iKey, uint8_t uScan, int fFlags, wchar_t *pUniKey /* = NULL */)
+{
+    const bool isHostKey = iKey == m_globalSettings.hostKey();
 
     LONG buf[16];
@@ -1782,9 +1373,9 @@
     if (!isHostKey && !m_bIsHostkeyPressed)
     {
-        if (aFlags & KeyPrint)
+        if (fFlags & KeyPrint)
         {
             static LONG PrintMake[] = { 0xE0, 0x2A, 0xE0, 0x37 };
             static LONG PrintBreak[] = { 0xE0, 0xB7, 0xE0, 0xAA };
-            if (aFlags & KeyPressed)
+            if (fFlags & KeyPressed)
             {
                 codes = PrintMake;
@@ -1797,7 +1388,7 @@
             }
         }
-        else if (aFlags & KeyPause)
-        {
-            if (aFlags & KeyPressed)
+        else if (fFlags & KeyPause)
+        {
+            if (fFlags & KeyPressed)
             {
                 static LONG Pause[] = { 0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5 };
@@ -1813,5 +1404,5 @@
         else
         {
-            if (aFlags & KeyPressed)
+            if (fFlags & KeyPressed)
             {
                 /* Check if the guest has the same view on the modifier keys (NumLock,
@@ -1822,10 +1413,10 @@
 
             /* Check if it's C-A-D and GUI/PassCAD is not true */
-            if (!mPassCAD &&
-                aScan == 0x53 /* Del */ &&
-                ((mPressedKeys [0x38] & IsKeyPressed) /* Alt */ ||
-                 (mPressedKeys [0x38] & IsExtKeyPressed)) &&
-                ((mPressedKeys [0x1d] & IsKeyPressed) /* Ctrl */ ||
-                 (mPressedKeys [0x1d] & IsExtKeyPressed)))
+            if (!m_fPassCAD &&
+                uScan == 0x53 /* Del */ &&
+                ((m_pressedKeys[0x38] & IsKeyPressed) /* Alt */ ||
+                 (m_pressedKeys[0x38] & IsExtKeyPressed)) &&
+                ((m_pressedKeys[0x1d] & IsKeyPressed) /* Ctrl */ ||
+                 (m_pressedKeys[0x1d] & IsExtKeyPressed)))
             {
                 /* Use the C-A-D combination as a last resort to get the
@@ -1836,5 +1427,4 @@
                  * that's not possible because we cannot predict what other
                  * keys will be pressed next when one of C, A, D is held. */
-
                 if (isRunning() && m_bIsKeyboardCaptured)
                 {
@@ -1847,8 +1437,8 @@
             }
 
-            /* process the scancode and update the table of pressed keys */
+            /* Process the scancode and update the table of pressed keys: */
             whatPressed = IsKeyPressed;
 
-            if (aFlags & KeyExtended)
+            if (fFlags & KeyExtended)
             {
                 codes[count++] = 0xE0;
@@ -1856,29 +1446,28 @@
             }
 
-            if (aFlags & KeyPressed)
-            {
-                codes[count++] = aScan;
-                mPressedKeys[aScan] |= whatPressed;
+            if (fFlags & KeyPressed)
+            {
+                codes[count++] = uScan;
+                m_pressedKeys[uScan] |= whatPressed;
             }
             else
             {
-                /* if we haven't got this key's press message, we ignore its
-                 * release */
-                if (!(mPressedKeys [aScan] & whatPressed))
+                /* If we haven't got this key's press message, we ignore its release: */
+                if (!(m_pressedKeys[uScan] & whatPressed))
                     return true;
-                codes[count++] = aScan | 0x80;
-                mPressedKeys[aScan] &= ~whatPressed;
+                codes[count++] = uScan | 0x80;
+                m_pressedKeys[uScan] &= ~whatPressed;
             }
 
             if (m_bIsKeyboardCaptured)
-                mPressedKeys[aScan] |= IsKbdCaptured;
+                m_pressedKeys[uScan] |= IsKbdCaptured;
             else
-                mPressedKeys[aScan] &= ~IsKbdCaptured;
+                m_pressedKeys[uScan] &= ~IsKbdCaptured;
         }
     }
     else
     {
-        /* currently this is used in winLowKeyboardEvent() only */
-        hostkey_in_capture = m_bIsKeyboardCaptured;
+        /* Currently this is used in winLowKeyboardEvent() only: */
+        m_bHostkeyInCapture = m_bIsKeyboardCaptured;
     }
 
@@ -1886,6 +1475,6 @@
     int hotkey = 0;
 
-    /* process the host key */
-    if (aFlags & KeyPressed)
+    /* Process the host key: */
+    if (fFlags & KeyPressed)
     {
         if (isHostKey)
@@ -1905,5 +1494,5 @@
                 if (m_bIsHostkeyAlone)
                 {
-                    hotkey = aKey;
+                    hotkey = iKey;
                     m_bIsHostkeyAlone = false;
                 }
@@ -1987,51 +1576,46 @@
         bool processed = false;
 #if defined (Q_WS_WIN32)
-        NOREF(aUniKey);
-        int n = GetKeyboardLayoutList (0, NULL);
+        NOREF(pUniKey);
+        int n = GetKeyboardLayoutList(0, NULL);
         Assert (n);
-        HKL *list = new HKL [n];
-        GetKeyboardLayoutList (n, list);
+        HKL *list = new HKL[n];
+        GetKeyboardLayoutList(n, list);
         for (int i = 0; i < n && !processed; i++)
         {
             wchar_t ch;
-            static BYTE keys [256] = {0};
-            if (!ToUnicodeEx (hotkey, 0, keys, &ch, 1, 0, list [i]) == 1)
+            static BYTE keys[256] = {0};
+            if (!ToUnicodeEx(hotkey, 0, keys, &ch, 1, 0, list[i]) == 1)
                 ch = 0;
             if (ch)
-                processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL +
-                                                QChar (ch).toUpper().unicode()),
-                                           machineWindowWrapper()->menuBar()->actions());
+                processed = processHotKey(QKeySequence(Qt::UNICODE_ACCEL + QChar(ch).toUpper().unicode()),
+                                          machineWindowWrapper()->menuBar()->actions());
         }
         delete[] list;
 #elif defined (Q_WS_X11)
-        NOREF(aUniKey);
+        NOREF(pUniKey);
         Display *display = QX11Info::display();
         int keysyms_per_keycode = getKeysymsPerKeycode();
-        KeyCode kc = XKeysymToKeycode (display, aKey);
-        // iterate over the first level (not shifted) keysyms in every group
+        KeyCode kc = XKeysymToKeycode (display, iKey);
         for (int i = 0; i < keysyms_per_keycode && !processed; i += 2)
         {
-            KeySym ks = XKeycodeToKeysym (display, kc, i);
+            KeySym ks = XKeycodeToKeysym(display, kc, i);
             char ch = 0;
-            if (!XkbTranslateKeySym (display, &ks, 0, &ch, 1, NULL) == 1)
+            if (!XkbTranslateKeySym(display, &ks, 0, &ch, 1, NULL) == 1)
                 ch = 0;
             if (ch)
-            {
-                QChar c = QString::fromLocal8Bit (&ch, 1) [0];
-            }
+                QChar c = QString::fromLocal8Bit(&ch, 1)[0];
         }
 #elif defined (Q_WS_MAC)
         // TODO_NEW_CORE
-//        if (aUniKey && aUniKey [0] && !aUniKey [1])
-//            processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL +
-//                                                     QChar (aUniKey [0]).toUpper().unicode()),
-//                                       machineWindowWrapper()->menuBar()->actions());
+//        if (pUniKey && pUniKey [0] && !pUniKey [1])
+//            processed = processHotKey(QKeySequence (Qt::UNICODE_ACCEL + QChar(pUniKey[0]).toUpper().unicode()),
+//                                      machineWindowWrapper()->menuBar()->actions());
 
         /* Don't consider the hot key as pressed since the guest never saw
          * it. (probably a generic thing) */
-        mPressedKeys [aScan] &= ~whatPressed;
-#endif
-
-        /* grab the key from Qt if processed, or pass it to Qt otherwise
+        m_pressedKeys[uScan] &= ~whatPressed;
+#endif
+
+        /* Grab the key from Qt if processed, or pass it to Qt otherwise
          * in order to process non-alphanumeric keys in event(), after they are
          * converted to Qt virtual keys. */
@@ -2039,8 +1623,8 @@
     }
 
-    /* no more to do, if the host key is in action or the VM is paused */
+    /* No more to do, if the host key is in action or the VM is paused: */
     if (m_bIsHostkeyPressed || isHostKey || machineWindowWrapper()->machineLogic()->isPaused())
     {
-        /* grab the key from Qt and from VM if it's a host key,
+        /* Grab the key from Qt and from VM if it's a host key,
          * otherwise just pass it to Qt */
         return isHostKey;
@@ -2048,15 +1632,15 @@
 
     CKeyboard keyboard = m_console.GetKeyboard();
-    Assert (!keyboard.isNull());
+    Assert(!keyboard.isNull());
 
 #if defined (Q_WS_WIN32)
     /* send pending WM_PAINT events */
-    ::UpdateWindow (viewport()->winId());
+    ::UpdateWindow(viewport()->winId());
 #endif
 
     std::vector <LONG> scancodes(codes, &codes[count]);
-    keyboard.PutScancodes (QVector<LONG>::fromStdVector(scancodes));
-
-    /* grab the key from Qt */
+    keyboard.PutScancodes(QVector<LONG>::fromStdVector(scancodes));
+
+    /* Grab the key from Qt: */
     return true;
 }
@@ -2066,5 +1650,5 @@
                                int aWheelDelta, Qt::Orientation aWheelDir)
 {
-#if 1
+#if 0
     LogRel3(("%s: type=%03d x=%03d y=%03d btns=%08X wdelta=%03d wdir=%s\n",
              __PRETTY_FUNCTION__ , aType, aPos.x(), aPos.y(),
@@ -2123,7 +1707,7 @@
 
         CMouse mouse = m_console.GetMouse();
-        mouse.PutMouseEvent (aGlobalPos.x() - mLastPos.x(),
-                             aGlobalPos.y() - mLastPos.y(),
-                             wheelVertical, wheelHorizontal, state);
+        mouse.PutMouseEvent(aGlobalPos.x() - m_lastMousePos.x(),
+                            aGlobalPos.y() - m_lastMousePos.y(),
+                            wheelVertical, wheelHorizontal, state);
 
 #if defined (Q_WS_MAC)
@@ -2156,11 +1740,10 @@
 
         if (rect.contains (aGlobalPos, true))
-            mLastPos = aGlobalPos;
+            m_lastMousePos = aGlobalPos;
         else
         {
-            mLastPos = rect.center();
-            QCursor::setPos (mLastPos);
-        }
-
+            m_lastMousePos = rect.center();
+            QCursor::setPos (m_lastMousePos);
+        }
 #else /* !Q_WS_MAC */
 
@@ -2168,5 +1751,5 @@
          * to simulate the endless moving */
 
-#ifdef Q_WS_WIN32
+# ifdef Q_WS_WIN32
         int we = viewport()->width() - 1;
         int he = viewport()->height() - 1;
@@ -2183,12 +1766,12 @@
         if (p != aPos)
         {
-            mLastPos = viewport()->mapToGlobal (p);
-            QCursor::setPos (mLastPos);
+            m_lastMousePos = viewport()->mapToGlobal (p);
+            QCursor::setPos (m_lastMousePos);
         }
         else
         {
-            mLastPos = aGlobalPos;
-        }
-#else
+            m_lastMousePos = aGlobalPos;
+        }
+# else
         int we = QApplication::desktop()->width() - 1;
         int he = QApplication::desktop()->height() - 1;
@@ -2205,12 +1788,12 @@
         if (p != aGlobalPos)
         {
-            mLastPos =  p;
-            QCursor::setPos (mLastPos);
+            m_lastMousePos =  p;
+            QCursor::setPos (m_lastMousePos);
         }
         else
         {
-            mLastPos = aGlobalPos;
-        }
-#endif
+            m_lastMousePos = aGlobalPos;
+        }
+# endif
 #endif /* !Q_WS_MAC */
         return true; /* stop further event handling */
@@ -2218,27 +1801,26 @@
     else /* !m_bIsMouseCaptured */
     {
-        //if (machineWindowWrapper()->isTrueFullscreen()) // TODO check that!
-        {
-            if (mode != VBoxDefs::SDLMode)
-            {
-                /* try to automatically scroll the guest canvas if the
-                 * mouse is on the screen border */
-                /// @todo (r=dmik) better use a timer for autoscroll
-                QRect scrGeo = QApplication::desktop()->screenGeometry (this);
-                int dx = 0, dy = 0;
-                if (scrGeo.width() < contentsWidth())
-                {
-                    if (scrGeo.left() == aGlobalPos.x()) dx = -1;
-                    if (scrGeo.right() == aGlobalPos.x()) dx = +1;
-                }
-                if (scrGeo.height() < contentsHeight())
-                {
-                    if (scrGeo.top() == aGlobalPos.y()) dy = -1;
-                    if (scrGeo.bottom() == aGlobalPos.y()) dy = +1;
-                }
-                if (dx || dy)
-                    scrollBy (dx, dy);
-            }
-        }
+#if 0 // TODO: Move that to fullscreen event-hjadler:
+        if (mode() != VBoxDefs::SDLMode)
+        {
+            /* try to automatically scroll the guest canvas if the
+             * mouse is on the screen border */
+            /// @todo (r=dmik) better use a timer for autoscroll
+            QRect scrGeo = QApplication::desktop()->screenGeometry (this);
+            int dx = 0, dy = 0;
+            if (scrGeo.width() < contentsWidth())
+            {
+                if (scrGeo.left() == aGlobalPos.x()) dx = -1;
+                if (scrGeo.right() == aGlobalPos.x()) dx = +1;
+            }
+            if (scrGeo.height() < contentsHeight())
+            {
+                if (scrGeo.top() == aGlobalPos.y()) dy = -1;
+                if (scrGeo.bottom() == aGlobalPos.y()) dy = +1;
+            }
+            if (dx || dy)
+                scrollBy(dx, dy);
+        }
+#endif
 
         if (m_bIsMouseAbsolute && m_bIsMouseIntegrated)
@@ -2247,8 +1829,8 @@
             int vw = visibleWidth(), vh = visibleHeight();
 
-            if (mode != VBoxDefs::SDLMode)
-            {
-                /* try to automatically scroll the guest canvas if the
-                 * mouse goes outside its visible part */
+            if (mode() != VBoxDefs::SDLMode)
+            {
+                /* Try to automatically scroll the guest canvas if the
+                 * mouse goes outside its visible part: */
 
                 int dx = 0;
@@ -2270,11 +1852,9 @@
             mouse.PutMouseEventAbsolute (cpnt.x(), cpnt.y(), wheelVertical,
                                          wheelHorizontal, state);
-            return true; /* stop further event handling */
+            return true;
         }
         else
         {
-            if (hasFocus() &&
-                (aType == QEvent::MouseButtonRelease &&
-                 aButtons == Qt::NoButton))
+            if (hasFocus() && (aType == QEvent::MouseButtonRelease && aButtons == Qt::NoButton))
             {
                 if (machineWindowWrapper()->machineLogic()->isPaused())
@@ -2284,8 +1864,6 @@
                 else if (isRunning())
                 {
-                    /* temporarily disable auto capture that will take
-                     * place after this dialog is dismissed because
-                     * the capture state is to be defined by the
-                     * dialog result itself */
+                    /* Temporarily disable auto capture that will take place after this dialog is dismissed because
+                     * the capture state is to be defined by the dialog result itself: */
                     m_bIsAutoCaptureDisabled = true;
                     bool autoConfirmed = false;
@@ -2293,19 +1871,15 @@
                     if (autoConfirmed)
                         m_bIsAutoCaptureDisabled = false;
-                    /* otherwise, the disable flag will be reset in
-                     * the next console view's foucs in event (since
-                     * may happen asynchronously on some platforms,
-                     * after we return from this code) */
-
+                    /* Otherwise, the disable flag will be reset in the next console view's foucs in event (since
+                     * may happen asynchronously on some platforms, after we return from this code): */
                     if (ok)
                     {
 #ifdef Q_WS_X11
-                        /* make sure that pending FocusOut events from the
-                         * previous message box are handled, otherwise the
-                         * mouse is immediately ungrabbed again */
+                        /* Make sure that pending FocusOut events from the previous message box are handled,
+                         * otherwise the mouse is immediately ungrabbed again: */
                         qApp->processEvents();
 #endif
-                        captureKbd (true);
-                        captureMouse (true);
+                        captureKbd(true);
+                        captureMouse(true);
                     }
                 }
@@ -2317,14 +1891,15 @@
 }
 
-void UIMachineView::resizeEvent(QResizeEvent *)
+void UIMachineView::resizeEvent(QResizeEvent *pEvent)
 {
     updateSliders();
 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
-    QRect r = viewport()->geometry();
-    PostBoundsChanged(r);
+    QRect rectangle = viewport()->geometry();
+    PostBoundsChanged(rectangle);
 #endif /* Q_WS_MAC */
-}
-
-void UIMachineView::moveEvent(QMoveEvent *)
+    return QAbstractScrollArea::resizeEvent(pEvent);
+}
+
+void UIMachineView::moveEvent(QMoveEvent *pEvent)
 {
 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
@@ -2332,13 +1907,14 @@
     PostBoundsChanged (r);
 #endif /* Q_WS_MAC */
-}
-
-void UIMachineView::paintEvent(QPaintEvent *pe)
-{
-    if (mPausedShot.isNull())
-    {
-        /* delegate the paint function to the VBoxFrameBuffer interface */
-        if (mFrameBuf)
-            mFrameBuf->paintEvent(pe);
+    return QAbstractScrollArea::moveEvent(pEvent);
+}
+
+void UIMachineView::paintEvent(QPaintEvent *pPaintEvent)
+{
+    if (m_pauseShot.isNull())
+    {
+        /* Delegate the paint function to the VBoxFrameBuffer interface: */
+        if (m_pFrameBuffer)
+            m_pFrameBuffer->paintEvent(pPaintEvent);
 #ifdef Q_WS_MAC
         /* Update the dock icon if we are in the running state */
@@ -2350,7 +1926,7 @@
 
 #ifdef VBOX_GUI_USE_QUARTZ2D
-    if (mode == VBoxDefs::Quartz2DMode && mFrameBuf)
-    {
-        mFrameBuf->paintEvent(pe);
+    if (mode() == VBoxDefs::Quartz2DMode && m_pFrameBuffer)
+    {
+        m_pFrameBuffer->paintEvent(pPaintEvent);
         updateDockIcon();
     }
@@ -2359,12 +1935,10 @@
     {
         /* We have a snapshot for the paused state: */
-        QRect r = pe->rect().intersect (viewport()->rect());
+        QRect r = pPaintEvent->rect().intersect (viewport()->rect());
         /* We have to disable paint on screen if we are using the regular painter */
         bool paintOnScreen = viewport()->testAttribute(Qt::WA_PaintOnScreen);
         viewport()->setAttribute(Qt::WA_PaintOnScreen, false);
         QPainter pnt(viewport());
-        pnt.drawPixmap(r.x(), r.y(), mPausedShot,
-                       r.x() + contentsX(), r.y() + contentsY(),
-                       r.width(), r.height());
+        pnt.drawPixmap(r.x(), r.y(), m_pauseShot, r.x() + contentsX(), r.y() + contentsY(), r.width(), r.height());
         /* Restore the attribute to its previous state */
         viewport()->setAttribute(Qt::WA_PaintOnScreen, paintOnScreen);
@@ -2375,4 +1949,518 @@
 }
 
+#if defined(Q_WS_WIN32)
+
+static HHOOK gKbdHook = NULL;
+static UIMachineView *gView = 0;
+LRESULT CALLBACK UIMachineView::lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
+{
+    Assert(gView);
+    if (gView && nCode == HC_ACTION && gView->winLowKeyboardEvent(wParam, *(KBDLLHOOKSTRUCT *)lParam))
+        return 1;
+
+    return CallNextHookEx(NULL, nCode, wParam, lParam);
+}
+
+bool UIMachineView::winLowKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event)
+{
+    /* Sometimes it happens that Win inserts additional events on some key
+     * press/release. For example, it prepends ALT_GR in German layout with
+     * the VK_LCONTROL vkey with curious 0x21D scan code (seems to be necessary
+     * to specially treat ALT_GR to enter additional chars to regular apps).
+     * These events are definitely unwanted in VM, so filter them out. */
+    /* Note (michael): it also sometimes sends the VK_CAPITAL vkey with scan
+     * code 0x23a. If this is not passed through then it is impossible to
+     * cancel CapsLock on a French keyboard.  I didn't find any other examples
+     * of these strange events.  Let's hope we are not missing anything else
+     * of importance! */
+    if (hasFocus() && (event.scanCode & ~0xFF))
+    {
+        if (event.vkCode == VK_CAPITAL)
+            return false;
+        else
+            return true;
+    }
+
+    if (!m_bIsKeyboardCaptured)
+        return false;
+
+    /* it's possible that a key has been pressed while the keyboard was not
+     * captured, but is being released under the capture. Detect this situation
+     * and return false to let Windows process the message normally and update
+     * its key state table (to avoid the stuck key effect). */
+    uint8_t what_pressed = (event.flags & 0x01) && (event.vkCode != VK_RSHIFT) ? IsExtKeyPressed : IsKeyPressed;
+    if ((event.flags & 0x80) /* released */ &&
+        ((event.vkCode == m_globalSettings.hostKey() && !m_bHostkeyInCapture) ||
+         (m_pressedKeys[event.scanCode] & (IsKbdCaptured | what_pressed)) == what_pressed))
+        return false;
+
+    MSG message;
+    message.hwnd = winId();
+    message.message = msg;
+    message.wParam = event.vkCode;
+    message.lParam = 1 | (event.scanCode & 0xFF) << 16 | (event.flags & 0xFF) << 24;
+
+    /* Windows sets here the extended bit when the Right Shift key is pressed,
+     * which is totally wrong. Undo it. */
+    if (event.vkCode == VK_RSHIFT)
+        message.lParam &= ~0x1000000;
+
+    /* we suppose here that this hook is always called on the main GUI thread */
+    long dummyResult;
+    return winEvent(&message, &dummyResult);
+}
+
+bool UIMachineView::winEvent(MSG *aMsg, long* /* aResult */)
+{
+    if (!(aMsg->message == WM_KEYDOWN || aMsg->message == WM_SYSKEYDOWN ||
+          aMsg->message == WM_KEYUP || aMsg->message == WM_SYSKEYUP))
+        return false;
+
+    /* Check for the special flag possibly set at the end of this function */
+    if (aMsg->lParam & (0x1 << 25))
+    {
+        aMsg->lParam &= ~(0x1 << 25);
+        return false;
+    }
+
+    int scan = (aMsg->lParam >> 16) & 0x7F;
+    /* scancodes 0x80 and 0x00 are ignored */
+    if (!scan)
+        return true;
+
+    int vkey = aMsg->wParam;
+
+    /* When one of the SHIFT keys is held and one of the cursor movement
+     * keys is pressed, Windows duplicates SHIFT press/release messages,
+     * but with the virtual key code set to 0xFF. These virtual keys are also
+     * sent in some other situations (Pause, PrtScn, etc.). Ignore such
+     * messages. */
+    if (vkey == 0xFF)
+        return true;
+
+    int flags = 0;
+    if (aMsg->lParam & 0x1000000)
+        flags |= KeyExtended;
+    if (!(aMsg->lParam & 0x80000000))
+        flags |= KeyPressed;
+
+    switch (vkey)
+    {
+        case VK_SHIFT:
+        case VK_CONTROL:
+        case VK_MENU:
+        {
+            /* overcome stupid Win32 modifier key generalization */
+            int keyscan = scan;
+            if (flags & KeyExtended)
+                keyscan |= 0xE000;
+            switch (keyscan)
+            {
+                case 0x002A: vkey = VK_LSHIFT; break;
+                case 0x0036: vkey = VK_RSHIFT; break;
+                case 0x001D: vkey = VK_LCONTROL; break;
+                case 0xE01D: vkey = VK_RCONTROL; break;
+                case 0x0038: vkey = VK_LMENU; break;
+                case 0xE038: vkey = VK_RMENU; break;
+            }
+            break;
+        }
+        case VK_NUMLOCK:
+            /* Win32 sets the extended bit for the NumLock key. Reset it. */
+            flags &= ~KeyExtended;
+            break;
+        case VK_SNAPSHOT:
+            flags |= KeyPrint;
+            break;
+        case VK_PAUSE:
+            flags |= KeyPause;
+            break;
+    }
+
+    bool result = keyEvent(vkey, scan, flags);
+    if (!result && m_bIsKeyboardCaptured)
+    {
+        /* keyEvent() returned that it didn't process the message, but since the
+         * keyboard is captured, we don't want to pass it to Windows. We just want
+         * to let Qt process the message (to handle non-alphanumeric <HOST>+key
+         * shortcuts for example). So send it direcltly to the window with the
+         * special flag in the reserved area of lParam (to avoid recursion). */
+        ::SendMessage(aMsg->hwnd, aMsg->message,
+                      aMsg->wParam, aMsg->lParam | (0x1 << 25));
+        return true;
+    }
+
+    /* These special keys have to be handled by Windows as well to update the
+     * internal modifier state and to enable/disable the keyboard LED */
+    if (vkey == VK_NUMLOCK || vkey == VK_CAPITAL || vkey == VK_LSHIFT || vkey == VK_RSHIFT)
+        return false;
+
+    return result;
+}
+
+#elif defined(Q_WS_PM)
+
+bool UIMachineView::pmEvent(QMSG *aMsg)
+{
+    if (aMsg->msg == UM_PREACCEL_CHAR)
+    {
+        /* We are inside the input hook
+         * let the message go through the normal system pipeline. */
+        if (!m_bIsKeyboardCaptured)
+            return false;
+    }
+
+    if (aMsg->msg != WM_CHAR && aMsg->msg != UM_PREACCEL_CHAR)
+        return false;
+
+    /* check for the special flag possibly set at the end of this function */
+    if (SHORT2FROMMP(aMsg->mp2) & 0x8000)
+    {
+        aMsg->mp2 = MPFROM2SHORT(SHORT1FROMMP(aMsg->mp2), SHORT2FROMMP(aMsg->mp2) & ~0x8000);
+        return false;
+    }
+
+    USHORT ch = SHORT1FROMMP(aMsg->mp2);
+    USHORT f = SHORT1FROMMP(aMsg->mp1);
+
+    int scan = (unsigned int)CHAR4FROMMP(aMsg->mp1);
+    if (!scan || scan > 0x7F)
+        return true;
+
+    int vkey = QIHotKeyEdit::virtualKey(aMsg);
+
+    int flags = 0;
+
+    if ((ch & 0xFF) == 0xE0)
+    {
+        flags |= KeyExtended;
+        scan = ch >> 8;
+    }
+    else if (scan == 0x5C && (ch & 0xFF) == '/')
+    {
+        /* this is the '/' key on the keypad */
+        scan = 0x35;
+        flags |= KeyExtended;
+    }
+    else
+    {
+        /* For some keys, the scan code passed in QMSG is a pseudo scan
+         * code. We replace it with a real hardware scan code, according to
+         * http://www.computer-engineering.org/ps2keyboard/scancodes1.html.
+         * Also detect Pause and PrtScn and set flags. */
+        switch (vkey)
+        {
+            case VK_ENTER:     scan = 0x1C; flags |= KeyExtended; break;
+            case VK_CTRL:      scan = 0x1D; flags |= KeyExtended; break;
+            case VK_ALTGRAF:   scan = 0x38; flags |= KeyExtended; break;
+            case VK_LWIN:      scan = 0x5B; flags |= KeyExtended; break;
+            case VK_RWIN:      scan = 0x5C; flags |= KeyExtended; break;
+            case VK_WINMENU:   scan = 0x5D; flags |= KeyExtended; break;
+            case VK_FORWARD:   scan = 0x69; flags |= KeyExtended; break;
+            case VK_BACKWARD:  scan = 0x6A; flags |= KeyExtended; break;
+#if 0
+            /// @todo this would send 0xE0 0x46 0xE0 0xC6. It's not fully
+            // clear what is more correct
+            case VK_BREAK:     scan = 0x46; flags |= KeyExtended; break;
+#else
+            case VK_BREAK:     scan = 0;    flags |= KeyPause; break;
+#endif
+            case VK_PAUSE:     scan = 0;    flags |= KeyPause;    break;
+            case VK_PRINTSCRN: scan = 0;    flags |= KeyPrint;    break;
+            default:;
+        }
+    }
+
+    if (!(f & KC_KEYUP))
+        flags |= KeyPressed;
+
+    bool result = keyEvent (vkey, scan, flags);
+    if (!result && m_bIsKeyboardCaptured)
+    {
+        /* keyEvent() returned that it didn't process the message, but since the
+         * keyboard is captured, we don't want to pass it to PM. We just want
+         * to let Qt process the message (to handle non-alphanumeric <HOST>+key
+         * shortcuts for example). So send it direcltly to the window with the
+         * special flag in the reserved area of lParam (to avoid recursion). */
+        ::WinSendMsg (aMsg->hwnd, WM_CHAR, aMsg->mp1,
+                      MPFROM2SHORT (SHORT1FROMMP (aMsg->mp2), SHORT2FROMMP (aMsg->mp2) | 0x8000));
+        return true;
+    }
+    return result;
+}
+
+#elif defined(Q_WS_X11)
+
+static Bool VBoxConsoleViewCompEvent(Display *, XEvent *pEvent, XPointer pvArg)
+{
+    XEvent *pKeyEvent = (XEvent*)pvArg;
+    if ((pEvent->type == XKeyPress) && (pEvent->xkey.keycode == pKeyEvent->xkey.keycode))
+        return True;
+    else
+        return False;
+}
+
+bool UIMachineView::x11Event(XEvent *pEvent)
+{
+    switch (pEvent->type)
+    {
+        /* We have to handle XFocusOut right here as this event is not passed
+         * to UIMachineView::event(). Handling this event is important for
+         * releasing the keyboard before the screen saver gets active. */
+        case XFocusOut:
+        case XFocusIn:
+            if (isRunning())
+                focusEvent(pEvent->type == XFocusIn);
+            return false;
+        case XKeyPress:
+        case XKeyRelease:
+            break;
+        default:
+            return false; /* pass the event to Qt */
+    }
+
+    /* Translate the keycode to a PC scan code. */
+    unsigned scan = handleXKeyEvent(pEvent);
+
+    /* scancodes 0x00 (no valid translation) and 0x80 are ignored */
+    if (!scan & 0x7F)
+        return true;
+
+    /* Fix for http://www.virtualbox.org/ticket/1296:
+     * when X11 sends events for repeated keys, it always inserts an
+     * XKeyRelease before the XKeyPress. */
+    XEvent returnEvent;
+    if ((pEvent->type == XKeyRelease) && (XCheckIfEvent(pEvent->xkey.display, &returnEvent,
+        VBoxConsoleViewCompEvent, (XPointer)pEvent) == True))
+    {
+        XPutBackEvent(pEvent->xkey.display, &returnEvent);
+        /* Discard it, don't pass it to Qt. */
+        return true;
+    }
+
+    KeySym ks = ::XKeycodeToKeysym(pEvent->xkey.display, pEvent->xkey.keycode, 0);
+
+    int flags = 0;
+    if (scan >> 8)
+        flags |= KeyExtended;
+    if (pEvent->type == XKeyPress)
+        flags |= KeyPressed;
+
+    /* Remove the extended flag */
+    scan &= 0x7F;
+
+    switch (ks)
+    {
+        case XK_Print:
+            flags |= KeyPrint;
+            break;
+        case XK_Pause:
+            flags |= KeyPause;
+            break;
+    }
+
+    return keyEvent(ks, scan, flags);
+}
+
+#elif defined(Q_WS_MAC)
+
+bool UIMachineView::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)
+{
+    bool ret = false;
+    UInt32 EventKind = ::GetEventKind(inEvent);
+    if (EventKind != kEventRawKeyModifiersChanged)
+    {
+        /* convert keycode to set 1 scan code. */
+        UInt32 keyCode = ~0U;
+        ::GetEventParameter(inEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof (keyCode), NULL, &keyCode);
+        unsigned scanCode = ::DarwinKeycodeToSet1Scancode(keyCode);
+        if (scanCode)
+        {
+            /* calc flags. */
+            int flags = 0;
+            if (EventKind != kEventRawKeyUp)
+                flags |= KeyPressed;
+            if (scanCode & VBOXKEY_EXTENDED)
+                flags |= KeyExtended;
+            /** @todo KeyPause, KeyPrint. */
+            scanCode &= VBOXKEY_SCANCODE_MASK;
+
+            /* get the unicode string (if present). */
+            AssertCompileSize(wchar_t, 2);
+            AssertCompileSize(UniChar, 2);
+            ByteCount cbWritten = 0;
+            wchar_t ucs[8];
+            if (::GetEventParameter(inEvent, kEventParamKeyUnicodes, typeUnicodeText, NULL,
+                                    sizeof(ucs), &cbWritten, &ucs[0]) != 0)
+                cbWritten = 0;
+            ucs[cbWritten / sizeof(wchar_t)] = 0; /* The api doesn't terminate it. */
+
+            ret = keyEvent(keyCode, scanCode, flags, ucs[0] ? ucs : NULL);
+        }
+    }
+    else
+    {
+        /* May contain multiple modifier changes, kind of annoying. */
+        UInt32 newMask = 0;
+        ::GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL,
+                            sizeof(newMask), NULL, &newMask);
+        newMask = ::DarwinAdjustModifierMask(newMask, pvCocoaEvent);
+        UInt32 changed = newMask ^ m_darwinKeyModifiers;
+        if (changed)
+        {
+            for (UInt32 bit = 0; bit < 32; bit++)
+            {
+                if (!(changed & (1 << bit)))
+                    continue;
+                unsigned scanCode = ::DarwinModifierMaskToSet1Scancode(1 << bit);
+                if (!scanCode)
+                    continue;
+                unsigned keyCode = ::DarwinModifierMaskToDarwinKeycode(1 << bit);
+                Assert(keyCode);
+
+                if (!(scanCode & VBOXKEY_LOCK))
+                {
+                    unsigned flags = (newMask & (1 << bit)) ? KeyPressed : 0;
+                    if (scanCode & VBOXKEY_EXTENDED)
+                        flags |= KeyExtended;
+                    scanCode &= VBOXKEY_SCANCODE_MASK;
+                    ret |= keyEvent(keyCode, scanCode & 0xff, flags);
+                }
+                else
+                {
+                    unsigned flags = 0;
+                    if (scanCode & VBOXKEY_EXTENDED)
+                        flags |= KeyExtended;
+                    scanCode &= VBOXKEY_SCANCODE_MASK;
+                    keyEvent(keyCode, scanCode, flags | KeyPressed);
+                    keyEvent(keyCode, scanCode, flags);
+                }
+            }
+        }
+
+        m_darwinKeyModifiers = newMask;
+
+        /* Always return true here because we'll otherwise getting a Qt event
+           we don't want and that will only cause the Pause warning to pop up. */
+        ret = true;
+    }
+
+    return ret;
+}
+
+void UIMachineView::darwinGrabKeyboardEvents(bool fGrab)
+{
+    m_fKeyboardGrabbed = fGrab;
+    if (fGrab)
+    {
+        /* Disable mouse and keyboard event compression/delaying to make sure we *really* get all of the events. */
+        ::CGSetLocalEventsSuppressionInterval(0.0);
+        setMouseCoalescingEnabled(false);
+
+        /* Register the event callback/hook and grab the keyboard. */
+# ifdef QT_MAC_USE_COCOA
+        ::VBoxCocoaApplication_setCallback (UINT32_MAX, /** @todo fix mask */
+                                            UIMachineView::darwinEventHandlerProc, this);
+
+# else /* QT_MAC_USE_COCOA */
+        EventTypeSpec eventTypes[6];
+        eventTypes[0].eventClass = kEventClassKeyboard;
+        eventTypes[0].eventKind  = kEventRawKeyDown;
+        eventTypes[1].eventClass = kEventClassKeyboard;
+        eventTypes[1].eventKind  = kEventRawKeyUp;
+        eventTypes[2].eventClass = kEventClassKeyboard;
+        eventTypes[2].eventKind  = kEventRawKeyRepeat;
+        eventTypes[3].eventClass = kEventClassKeyboard;
+        eventTypes[3].eventKind  = kEventRawKeyModifiersChanged;
+        /* For ignorning Command-H and Command-Q which aren't affected by the
+         * global hotkey stuff (doesn't work well): */
+        eventTypes[4].eventClass = kEventClassCommand;
+        eventTypes[4].eventKind  = kEventCommandProcess;
+        eventTypes[5].eventClass = kEventClassCommand;
+        eventTypes[5].eventKind  = kEventCommandUpdateStatus;
+
+        EventHandlerUPP eventHandler = ::NewEventHandlerUPP(UIMachineView::darwinEventHandlerProc);
+
+        m_darwinEventHandlerRef = NULL;
+        ::InstallApplicationEventHandler(eventHandler, RT_ELEMENTS (eventTypes), &eventTypes[0],
+                                         this, &m_darwinEventHandlerRef);
+        ::DisposeEventHandlerUPP(eventHandler);
+# endif /* !QT_MAC_USE_COCOA */
+
+        ::DarwinGrabKeyboard (false);
+    }
+    else
+    {
+        ::DarwinReleaseKeyboard();
+# ifdef QT_MAC_USE_COCOA
+        ::VBoxCocoaApplication_unsetCallback(UINT32_MAX, /** @todo fix mask */
+                                             UIMachineView::darwinEventHandlerProc, this);
+# else /* QT_MAC_USE_COCOA */
+        if (m_darwinEventHandlerRef)
+        {
+            ::RemoveEventHandler(m_darwinEventHandlerRef);
+            m_darwinEventHandlerRef = NULL;
+        }
+# endif /* !QT_MAC_USE_COCOA */
+    }
+}
+
+# ifdef QT_MAC_USE_COCOA
+bool UIMachineView::darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
+{
+    UIMachineView *view = (UIMachineView*)pvUser;
+    EventRef inEvent = (EventRef)pvCarbonEvent;
+    UInt32 eventClass = ::GetEventClass(inEvent);
+
+    /* Check if this is an application key combo. In that case we will not pass
+     * the event to the guest, but let the host process it. */
+    if (VBoxCocoaApplication_isApplicationCommand(pvCocoaEvent))
+        return false;
+
+    /* All keyboard class events needs to be handled. */
+    if (eventClass == kEventClassKeyboard)
+    {
+        if (view->darwinKeyboardEvent (pvCocoaEvent, inEvent))
+            return true;
+    }
+    /* Pass the event along. */
+    return false;
+}
+# else /* QT_MAC_USE_COCOA */
+
+pascal OSStatus UIMachineView::darwinEventHandlerProc(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
+{
+    UIMachineView *view = static_cast<UIMachineView *> (inUserData);
+    UInt32 eventClass = ::GetEventClass (inEvent);
+
+    /* Not sure but this seems an triggered event if the spotlight searchbar is
+     * displayed. So flag that the host key isn't pressed alone. */
+    if (eventClass == 'cgs ' && view->m_bIsHostkeyPressed && ::GetEventKind (inEvent) == 0x15)
+        view->m_bIsHostkeyAlone = false;
+
+    if (eventClass == kEventClassKeyboard)
+    {
+        if (view->darwinKeyboardEvent (NULL, inEvent))
+            return 0;
+    }
+
+    /*
+     * Command-H and Command-Q aren't properly disabled yet, and it's still
+     * possible to use the left command key to invoke them when the keyboard
+     * is captured. We discard the events these if the keyboard is captured
+     * as a half measure to prevent unexpected behaviour. However, we don't
+     * get any key down/up events, so these combinations are dead to the guest...
+     */
+    else if (eventClass == kEventClassCommand)
+    {
+        if (view->m_bIsKeyboardCaptured)
+            return 0;
+    }
+    return ::CallNextEventHandler(inHandlerCallRef, inEvent);
+}
+# endif /* !QT_MAC_USE_COCOA */
+
+#endif
+
 void UIMachineView::fixModifierState(LONG *piCodes, uint *puCount)
 {
@@ -2380,5 +2468,5 @@
      * This function will add up to 6 additional keycodes to codes. */
 
-#if defined (Q_WS_X11)
+#if defined(Q_WS_X11)
 
     Window   wDummy1, wDummy2;
@@ -2403,13 +2491,13 @@
     XFreeModifiermap(map);
 
-    if (muNumLockAdaptionCnt && (mNumLock ^ !!(uMask & uKeyMaskNum)))
-    {
-        -- muNumLockAdaptionCnt;
+    if (m_uNumLockAdaptionCnt && (m_numLock ^ !!(uMask & uKeyMaskNum)))
+    {
+        -- m_uNumLockAdaptionCnt;
         piCodes[(*puCount)++] = 0x45;
         piCodes[(*puCount)++] = 0x45 | 0x80;
     }
-    if (muCapsLockAdaptionCnt && (mCapsLock ^ !!(uMask & uKeyMaskCaps)))
-    {
-        muCapsLockAdaptionCnt--;
+    if (m_uCapsLockAdaptionCnt && (m_capsLock ^ !!(uMask & uKeyMaskCaps)))
+    {
+        m_uCapsLockAdaptionCnt--;
         piCodes[(*puCount)++] = 0x3a;
         piCodes[(*puCount)++] = 0x3a | 0x80;
@@ -2417,5 +2505,5 @@
          * capslock.  For simplicity, only do this if shift is not
          * already held down. */
-        if (mCapsLock && !(mPressedKeys [0x2a] & IsKeyPressed))
+        if (m_capsLock && !(m_pressedKeys[0x2a] & IsKeyPressed))
         {
             piCodes[(*puCount)++] = 0x2a;
@@ -2424,15 +2512,15 @@
     }
 
-#elif defined (Q_WS_WIN32)
-
-    if (muNumLockAdaptionCnt && (mNumLock ^ !!(GetKeyState(VK_NUMLOCK))))
-    {
-        muNumLockAdaptionCnt--;
+#elif defined(Q_WS_WIN32)
+
+    if (m_uNumLockAdaptionCnt && (m_numLock ^ !!(GetKeyState(VK_NUMLOCK))))
+    {
+        m_uNumLockAdaptionCnt--;
         piCodes[(*puCount)++] = 0x45;
         piCodes[(*puCount)++] = 0x45 | 0x80;
     }
-    if (muCapsLockAdaptionCnt && (mCapsLock ^ !!(GetKeyState(VK_CAPITAL))))
-    {
-        muCapsLockAdaptionCnt--;
+    if (m_uCapsLockAdaptionCnt && (m_capsLock ^ !!(GetKeyState(VK_CAPITAL))))
+    {
+        m_uCapsLockAdaptionCnt--;
         piCodes[(*puCount)++] = 0x3a;
         piCodes[(*puCount)++] = 0x3a | 0x80;
@@ -2440,5 +2528,5 @@
          * capslock.  For simplicity, only do this if shift is not
          * already held down. */
-        if (mCapsLock && !(mPressedKeys [0x2a] & IsKeyPressed))
+        if (m_capsLock && !(m_pressedKeys[0x2a] & IsKeyPressed))
         {
             piCodes[(*puCount)++] = 0x2a;
@@ -2447,10 +2535,10 @@
     }
 
-#elif defined (Q_WS_MAC)
-
-    /* if (muNumLockAdaptionCnt) ... - NumLock isn't implemented by Mac OS X so ignore it. */
-    if (muCapsLockAdaptionCnt && (mCapsLock ^ !!(::GetCurrentEventKeyModifiers() & alphaLock)))
-    {
-        muCapsLockAdaptionCnt--;
+#elif defined(Q_WS_MAC)
+
+    /* if (m_uNumLockAdaptionCnt) ... - NumLock isn't implemented by Mac OS X so ignore it. */
+    if (m_uCapsLockAdaptionCnt && (m_capsLock ^ !!(::GetCurrentEventKeyModifiers() & alphaLock)))
+    {
+        m_uCapsLockAdaptionCnt--;
         piCodes[(*puCount)++] = 0x3a;
         piCodes[(*puCount)++] = 0x3a | 0x80;
@@ -2458,5 +2546,5 @@
          * capslock.  For simplicity, only do this if shift is not
          * already held down. */
-        if (mCapsLock && !(mPressedKeys [0x2a] & IsKeyPressed))
+        if (m_capsLock && !(m_pressedKeys[0x2a] & IsKeyPressed))
         {
             piCodes[(*puCount)++] = 0x2a;
@@ -2472,10 +2560,4 @@
 }
 
-void UIMachineView::scrollBy(int dx, int dy)
-{
-    horizontalScrollBar()->setValue(horizontalScrollBar()->value() + dx);
-    verticalScrollBar()->setValue(verticalScrollBar()->value() + dy);
-}
-
 QPoint UIMachineView::viewportToContents(const QPoint &vp) const
 {
@@ -2488,5 +2570,5 @@
     QSize m = maximumViewportSize();
 
-    QSize v = QSize(mFrameBuf->width(), mFrameBuf->height());
+    QSize v = QSize(m_pFrameBuffer->width(), m_pFrameBuffer->height());
     /* no scroll bars needed */
     if (m.expandedTo(v) == m)
@@ -2499,110 +2581,54 @@
 }
 
+void UIMachineView::scrollBy(int dx, int dy)
+{
+    horizontalScrollBar()->setValue(horizontalScrollBar()->value() + dx);
+    verticalScrollBar()->setValue(verticalScrollBar()->value() + dy);
+}
+
 #ifdef VBOX_WITH_VIDEOHWACCEL
-void UIMachineView::scrollContentsBy (int dx, int dy)
-{
-    if (mFrameBuf)
-    {
-        mFrameBuf->viewportScrolled(dx, dy);
-    }
-    QAbstractScrollArea::scrollContentsBy (dx, dy);
-}
-#endif
-
-void UIMachineView::onStateChange(KMachineState state)
-{
-    switch (state)
-    {
-        case KMachineState_Paused:
-        case KMachineState_TeleportingPausedVM:
-        {
-            if (    mode != VBoxDefs::TimerMode
-                &&  mFrameBuf
-                &&  (   state      != KMachineState_TeleportingPausedVM
-                     || mLastState != KMachineState_Teleporting)
-               )
-            {
-                /*
-                 *  Take a screen snapshot. Note that TakeScreenShot() always
-                 *  needs a 32bpp image
-                 */
-                QImage shot = QImage (mFrameBuf->width(), mFrameBuf->height(), QImage::Format_RGB32);
-                CDisplay dsp = m_console.GetDisplay();
-                dsp.TakeScreenShot (shot.bits(), shot.width(), shot.height());
-                /*
-                 *  TakeScreenShot() may fail if, e.g. the Paused notification
-                 *  was delivered after the machine execution was resumed. It's
-                 *  not fatal.
-                 */
-                if (dsp.isOk())
-                {
-                    dimImage (shot);
-                    mPausedShot = QPixmap::fromImage (shot);
-                    /* fully repaint to pick up mPausedShot */
-                    repaint();
-                }
-            }
-            /* fall through */
-        }
-        case KMachineState_Stuck:
-        {
-            /* reuse the focus event handler to uncapture everything */
-            if (hasFocus())
-                focusEvent (false /* aHasFocus*/, false /* aReleaseHostKey */);
-            break;
-        }
-        case KMachineState_Running:
-        {
-            if (   mLastState == KMachineState_Paused
-                || mLastState == KMachineState_TeleportingPausedVM
-               )
-            {
-                if (mode != VBoxDefs::TimerMode && mFrameBuf)
-                {
-                    /* reset the pixmap to free memory */
-                    mPausedShot = QPixmap ();
-                    /*
-                     *  ask for full guest display update (it will also update
-                     *  the viewport through IFramebuffer::NotifyUpdate)
-                     */
-                    CDisplay dsp = m_console.GetDisplay();
-                    dsp.InvalidateAndUpdate();
-                }
-            }
-            /* reuse the focus event handler to capture input */
-            if (hasFocus())
-                focusEvent (true /* aHasFocus */);
-            break;
-        }
-        default:
-            break;
-    }
-
-    mLastState = state;
-}
-
-void UIMachineView::captureKbd(bool aCapture, bool aEmitSignal /* = true */)
-{
-    //AssertMsg(m_bIsAttached, ("Console must be attached"));
-
-    if (m_bIsKeyboardCaptured == aCapture)
+void UIMachineView::scrollContentsBy(int dx, int dy)
+{
+    if (m_pFrameBuffer)
+    {
+        m_pFrameBuffer->viewportScrolled(dx, dy);
+    }
+    QAbstractScrollArea::scrollContentsBy(dx, dy);
+}
+#endif
+
+void UIMachineView::emitKeyboardStateChanged()
+{
+    emit keyboardStateChanged((m_bIsKeyboardCaptured ? UIViewStateType_KeyboardCaptured : 0) |
+                              (m_bIsHostkeyPressed ? UIViewStateType_HostKeyPressed : 0));
+}
+
+void UIMachineView::emitMouseStateChanged()
+{
+    emit mouseStateChanged((m_bIsMouseCaptured ? UIMouseStateType_MouseCaptured : 0) |
+                           (m_bIsMouseAbsolute ? UIMouseStateType_MouseAbsolute : 0) |
+                           (!m_bIsMouseIntegrated ? UIMouseStateType_MouseAbsoluteDisabled : 0));
+}
+
+void UIMachineView::captureKbd(bool fCapture, bool fEmitSignal /* = true */)
+{
+    if (m_bIsKeyboardCaptured == fCapture)
         return;
 
-    /* On Win32, keyboard grabbing is ineffective, a low-level keyboard hook is
-     * used instead. On X11, we use XGrabKey instead of XGrabKeyboard (called
-     * by QWidget::grabKeyboard()) because the latter causes problems under
-     * metacity 2.16 (in particular, due to a bug, a window cannot be moved
-     * using the mouse if it is currently grabing the keyboard). On Mac OS X,
-     * we use the Qt methods + disabling global hot keys + watching modifiers
+    /* On Win32, keyboard grabbing is ineffective, a low-level keyboard hook is used instead.
+     * On X11, we use XGrabKey instead of XGrabKeyboard (called by QWidget::grabKeyboard())
+     * because the latter causes problems under metacity 2.16 (in particular, due to a bug,
+     * a window cannot be moved using the mouse if it is currently grabing the keyboard).
+     * On Mac OS X, we use the Qt methods + disabling global hot keys + watching modifiers
      * (for right/left separation). */
-#if defined (Q_WS_WIN32)
+#if defined(Q_WS_WIN32)
     /**/
-#elif defined (Q_WS_X11)
-        if (aCapture)
+#elif defined(Q_WS_X11)
+        if (fCapture)
                 XGrabKey(QX11Info::display(), AnyKey, AnyModifier, window()->winId(), False, GrabModeAsync, GrabModeAsync);
         else
-                XUngrabKey(QX11Info::display(),  AnyKey, AnyModifier, window()->winId());
-#elif defined (Q_WS_MAC)
-    if (aCapture)
+                XUngrabKey(QX11Info::display(), AnyKey, AnyModifier, window()->winId());
+#elif defined(Q_WS_MAC)
+    if (fCapture)
     {
         ::DarwinDisableGlobalHotKeys(true);
@@ -2615,5 +2641,5 @@
     }
 #else
-    if (aCapture)
+    if (fCapture)
         grabKeyboard();
     else
@@ -2621,35 +2647,33 @@
 #endif
 
-    m_bIsKeyboardCaptured = aCapture;
-
-    if (aEmitSignal)
+    m_bIsKeyboardCaptured = fCapture;
+
+    if (fEmitSignal)
         emitKeyboardStateChanged();
 }
 
-void UIMachineView::captureMouse(bool aCapture, bool aEmitSignal /* = true */)
-{
-    //AssertMsg (m_bIsAttached, ("Console must be attached"));
-
-    if (m_bIsMouseCaptured == aCapture)
+void UIMachineView::captureMouse(bool fCapture, bool fEmitSignal /* = true */)
+{
+    if (m_bIsMouseCaptured == fCapture)
         return;
 
-    if (aCapture)
-    {
-        /* memorize the host position where the cursor was captured */
-        mCapturedPos = QCursor::pos();
+    if (fCapture)
+    {
+        /* Memorize the host position where the cursor was captured: */
+        m_capturedMousePos = QCursor::pos();
 #ifdef Q_WS_WIN32
         viewport()->setCursor (QCursor (Qt::BlankCursor));
-        /* move the mouse to the center of the visible area */
+        /* Move the mouse to the center of the visible area: */
         QCursor::setPos (mapToGlobal (visibleRegion().boundingRect().center()));
-        mLastPos = QCursor::pos();
+        m_lastMousePos = QCursor::pos();
 #elif defined (Q_WS_MAC)
-        /* move the mouse to the center of the visible area */
-        mLastPos = mapToGlobal (visibleRegion().boundingRect().center());
-        QCursor::setPos (mLastPos);
-        /* grab all mouse events. */
+        /* Move the mouse to the center of the visible area: */
+        m_lastMousePos = mapToGlobal (visibleRegion().boundingRect().center());
+        QCursor::setPos (m_lastMousePos);
+        /* Grab all mouse events: */
         viewport()->grabMouse();
 #else
         viewport()->grabMouse();
-        mLastPos = QCursor::pos();
+        m_lastMousePos = QCursor::pos();
 #endif
     }
@@ -2659,25 +2683,31 @@
         viewport()->releaseMouse();
 #endif
-        /* release mouse buttons */
+        /* Release mouse buttons: */
         CMouse mouse = m_console.GetMouse();
         mouse.PutMouseEvent (0, 0, 0, 0 /* Horizontal wheel */, 0);
     }
 
-    m_bIsMouseCaptured = aCapture;
+    m_bIsMouseCaptured = fCapture;
 
     updateMouseClipping();
 
-    if (aEmitSignal)
+    if (fEmitSignal)
         emitMouseStateChanged();
 }
 
-bool UIMachineView::processHotKey(const QKeySequence &aKey, const QList <QAction*> &aData)
-{
-    foreach (QAction *pAction, aData)
+void UIMachineView::saveKeyStates()
+{
+    ::memcpy(m_pressedKeysCopy, m_pressedKeys, sizeof(m_pressedKeys));
+}
+
+bool UIMachineView::processHotKey(const QKeySequence &key, const QList<QAction*> &actions)
+{
+    // TODO: Make it work for all modes:
+    foreach (QAction *pAction, actions)
     {
         if (QMenu *menu = pAction->menu())
         {
             /* Process recursively for each sub-menu */
-            if (processHotKey(aKey, menu->actions()))
+            if (processHotKey(key, menu->actions()))
                 return true;
         }
@@ -2687,5 +2717,5 @@
             if (pAction->isEnabled() && !hotkey.isEmpty())
             {
-                if (aKey.matches(QKeySequence (hotkey)) == QKeySequence::ExactMatch)
+                if (key.matches(QKeySequence (hotkey)) == QKeySequence::ExactMatch)
                 {
                     /* We asynchronously post a special event instead of calling
@@ -2708,18 +2738,15 @@
 void UIMachineView::releaseAllPressedKeys(bool aReleaseHostKey /* = true */)
 {
-    //AssertMsg(m_bIsAttached, ("Console must be attached"));
-
     CKeyboard keyboard = m_console.GetKeyboard();
     bool fSentRESEND = false;
 
-    /* send a dummy scan code (RESEND) to prevent the guest OS from recognizing
+    /* Send a dummy scan code (RESEND) to prevent the guest OS from recognizing
      * a single key click (for ex., Alt) and performing an unwanted action
      * (for ex., activating the menu) when we release all pressed keys below.
      * Note, that it's just a guess that sending RESEND will give the desired
      * effect :), but at least it works with NT and W2k guests. */
-
-    for (uint i = 0; i < SIZEOF_ARRAY (mPressedKeys); i++)
-    {
-        if (mPressedKeys[i] & IsKeyPressed)
+    for (uint i = 0; i < SIZEOF_ARRAY (m_pressedKeys); i++)
+    {
+        if (m_pressedKeys[i] & IsKeyPressed)
         {
             if (!fSentRESEND)
@@ -2730,5 +2757,5 @@
             keyboard.PutScancode(i | 0x80);
         }
-        else if (mPressedKeys[i] & IsExtKeyPressed)
+        else if (m_pressedKeys[i] & IsExtKeyPressed)
         {
             if (!fSentRESEND)
@@ -2742,5 +2769,5 @@
             keyboard.PutScancodes(codes);
         }
-        mPressedKeys[i] = 0;
+        m_pressedKeys[i] = 0;
     }
 
@@ -2749,6 +2776,6 @@
 
 #ifdef Q_WS_MAC
-    /* clear most of the modifiers. */
-    mDarwinKeyModifiers &=
+    /* Clear most of the modifiers: */
+    m_darwinKeyModifiers &=
         alphaLock | kEventKeyModifierNumLockMask |
         (aReleaseHostKey ? 0 : ::DarwinKeyCodeToDarwinModifierMask (m_globalSettings.hostKey()));
@@ -2758,19 +2785,12 @@
 }
 
-void UIMachineView::saveKeyStates()
-{
-    ::memcpy(mPressedKeysCopy, mPressedKeys, sizeof(mPressedKeys));
-}
-
 void UIMachineView::sendChangedKeyStates()
 {
-    //AssertMsg(m_bIsAttached, ("Console must be attached"));
-
     QVector <LONG> codes(2);
     CKeyboard keyboard = m_console.GetKeyboard();
-    for (uint i = 0; i < SIZEOF_ARRAY(mPressedKeys); ++ i)
-    {
-        uint8_t os = mPressedKeysCopy[i];
-        uint8_t ns = mPressedKeys[i];
+    for (uint i = 0; i < SIZEOF_ARRAY(m_pressedKeys); ++ i)
+    {
+        uint8_t os = m_pressedKeysCopy[i];
+        uint8_t ns = m_pressedKeys[i];
         if ((os & IsKeyPressed) != (ns & IsKeyPressed))
         {
@@ -2793,6 +2813,4 @@
 void UIMachineView::updateMouseClipping()
 {
-    //AssertMsg(m_bIsAttached, ("Console must be attached"));
-
     if (m_bIsMouseCaptured)
     {
@@ -2811,241 +2829,240 @@
 #endif
         /* return the cursor to where it was when we captured it and show it */
-        QCursor::setPos(mCapturedPos);
+        QCursor::setPos(m_capturedMousePos);
         viewport()->unsetCursor();
     }
 }
 
-#if 0
-void UIMachineView::setPointerShape(MousePointerChangeEvent *pEvent)
-{
-    if (pEvent->shapeData() != NULL)
-    {
-        bool ok = false;
-
-        const uchar *srcAndMaskPtr = pEvent->shapeData();
-        uint andMaskSize = (pEvent->width() + 7) / 8 * pEvent->height();
-        const uchar *srcShapePtr = pEvent->shapeData() + ((andMaskSize + 3) & ~3);
-        uint srcShapePtrScan = pEvent->width() * 4;
+void UIMachineView::setPointerShape(const uchar *pShapeData, bool fHasAlpha,
+                                    uint uXHot, uint uYHot, uint uWidth, uint uHeight)
+{
+    AssertMsg(pShapeData, ("Shape data must not be NULL!\n"));
+
+    bool ok = false;
+
+    const uchar *srcAndMaskPtr = pShapeData;
+    uint andMaskSize = (uWidth + 7) / 8 * uHeight;
+    const uchar *srcShapePtr = pShapeData + ((andMaskSize + 3) & ~3);
+    uint srcShapePtrScan = uWidth * 4;
 
 #if defined (Q_WS_WIN)
 
-        BITMAPV5HEADER bi;
-        HBITMAP hBitmap;
-        void *lpBits;
-
-        ::ZeroMemory(&bi, sizeof (BITMAPV5HEADER));
-        bi.bV5Size = sizeof(BITMAPV5HEADER);
-        bi.bV5Width = pEvent->width();
-        bi.bV5Height = - (LONG)pEvent->height();
-        bi.bV5Planes = 1;
-        bi.bV5BitCount = 32;
-        bi.bV5Compression = BI_BITFIELDS;
-        bi.bV5RedMask   = 0x00FF0000;
-        bi.bV5GreenMask = 0x0000FF00;
-        bi.bV5BlueMask  = 0x000000FF;
-        if (pEvent->hasAlpha())
-            bi.bV5AlphaMask = 0xFF000000;
-        else
-            bi.bV5AlphaMask = 0;
-
-        HDC hdc = GetDC(NULL);
-
-        // create the DIB section with an alpha channel
-        hBitmap = CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, (void **)&lpBits, NULL, (DWORD) 0);
-
-        ReleaseDC(NULL, hdc);
-
-        HBITMAP hMonoBitmap = NULL;
-        if (pEvent->hasAlpha())
-        {
-            // create an empty mask bitmap
-            hMonoBitmap = CreateBitmap(pEvent->width(), pEvent->height(), 1, 1, NULL);
-        }
-        else
-        {
-            /* Word aligned AND mask. Will be allocated and created if necessary. */
-            uint8_t *pu8AndMaskWordAligned = NULL;
-
-            /* Width in bytes of the original AND mask scan line. */
-            uint32_t cbAndMaskScan = (pEvent->width() + 7) / 8;
-
-            if (cbAndMaskScan & 1)
-            {
-                /* Original AND mask is not word aligned. */
-
-                /* Allocate memory for aligned AND mask. */
-                pu8AndMaskWordAligned = (uint8_t *)RTMemTmpAllocZ((cbAndMaskScan + 1) * pEvent->height());
-
-                Assert(pu8AndMaskWordAligned);
-
-                if (pu8AndMaskWordAligned)
+    BITMAPV5HEADER bi;
+    HBITMAP hBitmap;
+    void *lpBits;
+
+    ::ZeroMemory(&bi, sizeof (BITMAPV5HEADER));
+    bi.bV5Size = sizeof(BITMAPV5HEADER);
+    bi.bV5Width = uWidth;
+    bi.bV5Height = - (LONG)uHeight;
+    bi.bV5Planes = 1;
+    bi.bV5BitCount = 32;
+    bi.bV5Compression = BI_BITFIELDS;
+    bi.bV5RedMask   = 0x00FF0000;
+    bi.bV5GreenMask = 0x0000FF00;
+    bi.bV5BlueMask  = 0x000000FF;
+    if (fHasAlpha)
+        bi.bV5AlphaMask = 0xFF000000;
+    else
+        bi.bV5AlphaMask = 0;
+
+    HDC hdc = GetDC(NULL);
+
+    /* Create the DIB section with an alpha channel: */
+    hBitmap = CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, (void **)&lpBits, NULL, (DWORD) 0);
+
+    ReleaseDC(NULL, hdc);
+
+    HBITMAP hMonoBitmap = NULL;
+    if (fHasAlpha)
+    {
+        /* Create an empty mask bitmap: */
+        hMonoBitmap = CreateBitmap(uWidth, uHeight, 1, 1, NULL);
+    }
+    else
+    {
+        /* Word aligned AND mask. Will be allocated and created if necessary. */
+        uint8_t *pu8AndMaskWordAligned = NULL;
+
+        /* Width in bytes of the original AND mask scan line. */
+        uint32_t cbAndMaskScan = (uWidth + 7) / 8;
+
+        if (cbAndMaskScan & 1)
+        {
+            /* Original AND mask is not word aligned. */
+
+            /* Allocate memory for aligned AND mask. */
+            pu8AndMaskWordAligned = (uint8_t *)RTMemTmpAllocZ((cbAndMaskScan + 1) * uHeight);
+
+            Assert(pu8AndMaskWordAligned);
+
+            if (pu8AndMaskWordAligned)
+            {
+                /* According to MSDN the padding bits must be 0.
+                 * Compute the bit mask to set padding bits to 0 in the last byte of original AND mask. */
+                uint32_t u32PaddingBits = cbAndMaskScan * 8  - uWidth;
+                Assert(u32PaddingBits < 8);
+                uint8_t u8LastBytesPaddingMask = (uint8_t)(0xFF << u32PaddingBits);
+
+                Log(("u8LastBytesPaddingMask = %02X, aligned w = %d, width = %d, cbAndMaskScan = %d\n",
+                      u8LastBytesPaddingMask, (cbAndMaskScan + 1) * 8, uWidth, cbAndMaskScan));
+
+                uint8_t *src = (uint8_t *)srcAndMaskPtr;
+                uint8_t *dst = pu8AndMaskWordAligned;
+
+                unsigned i;
+                for (i = 0; i < uHeight; i++)
                 {
-                    /* According to MSDN the padding bits must be 0.
-                     * Compute the bit mask to set padding bits to 0 in the last byte of original AND mask. */
-                    uint32_t u32PaddingBits = cbAndMaskScan * 8  - pEvent->width();
-                    Assert(u32PaddingBits < 8);
-                    uint8_t u8LastBytesPaddingMask = (uint8_t)(0xFF << u32PaddingBits);
-
-                    Log(("u8LastBytesPaddingMask = %02X, aligned w = %d, width = %d, cbAndMaskScan = %d\n",
-                          u8LastBytesPaddingMask, (cbAndMaskScan + 1) * 8, pEvent->width(), cbAndMaskScan));
-
-                    uint8_t *src = (uint8_t *)srcAndMaskPtr;
-                    uint8_t *dst = pu8AndMaskWordAligned;
-
-                    unsigned i;
-                    for (i = 0; i < pEvent->height(); i++)
+                    memcpy(dst, src, cbAndMaskScan);
+
+                    dst[cbAndMaskScan - 1] &= u8LastBytesPaddingMask;
+
+                    src += cbAndMaskScan;
+                    dst += cbAndMaskScan + 1;
+                }
+            }
+        }
+
+        /* Create the AND mask bitmap: */
+        hMonoBitmap = ::CreateBitmap(uWidth, uHeight, 1, 1,
+                                     pu8AndMaskWordAligned? pu8AndMaskWordAligned: srcAndMaskPtr);
+
+        if (pu8AndMaskWordAligned)
+        {
+            RTMemTmpFree(pu8AndMaskWordAligned);
+        }
+    }
+
+    Assert(hBitmap);
+    Assert(hMonoBitmap);
+    if (hBitmap && hMonoBitmap)
+    {
+        DWORD *dstShapePtr = (DWORD *) lpBits;
+
+        for (uint y = 0; y < uHeight; y ++)
+        {
+            memcpy(dstShapePtr, srcShapePtr, srcShapePtrScan);
+            srcShapePtr += srcShapePtrScan;
+            dstShapePtr += uWidth;
+        }
+
+        ICONINFO ii;
+        ii.fIcon = FALSE;
+        ii.xHotspot = uXHot;
+        ii.yHotspot = uYHot;
+        ii.hbmMask = hMonoBitmap;
+        ii.hbmColor = hBitmap;
+
+        HCURSOR hAlphaCursor = CreateIconIndirect(&ii);
+        Assert(hAlphaCursor);
+        if (hAlphaCursor)
+        {
+            viewport()->setCursor(QCursor(hAlphaCursor));
+            ok = true;
+            if (m_alphaCursor)
+                DestroyIcon(m_alphaCursor);
+            m_alphaCursor = hAlphaCursor;
+        }
+    }
+
+    if (hMonoBitmap)
+        DeleteObject(hMonoBitmap);
+    if (hBitmap)
+        DeleteObject(hBitmap);
+
+#elif defined (Q_WS_X11) && !defined (VBOX_WITHOUT_XCURSOR)
+
+    XcursorImage *img = XcursorImageCreate(uWidth, uHeight);
+    Assert(img);
+    if (img)
+    {
+        img->xhot = uXHot;
+        img->yhot = uYHot;
+
+        XcursorPixel *dstShapePtr = img->pixels;
+
+        for (uint y = 0; y < uHeight; y ++)
+        {
+            memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
+
+            if (!fHasAlpha)
+            {
+                /* Convert AND mask to the alpha channel: */
+                uchar byte = 0;
+                for (uint x = 0; x < uWidth; x ++)
+                {
+                    if (!(x % 8))
+                        byte = *(srcAndMaskPtr ++);
+                    else
+                        byte <<= 1;
+
+                    if (byte & 0x80)
                     {
-                        memcpy(dst, src, cbAndMaskScan);
-
-                        dst[cbAndMaskScan - 1] &= u8LastBytesPaddingMask;
-
-                        src += cbAndMaskScan;
-                        dst += cbAndMaskScan + 1;
+                        /* Linux doesn't support inverted pixels (XOR ops,
+                         * to be exact) in cursor shapes, so we detect such
+                         * pixels and always replace them with black ones to
+                         * make them visible at least over light colors */
+                        if (dstShapePtr [x] & 0x00FFFFFF)
+                            dstShapePtr [x] = 0xFF000000;
+                        else
+                            dstShapePtr [x] = 0x00000000;
                     }
+                    else
+                        dstShapePtr [x] |= 0xFF000000;
                 }
             }
 
-            /* create the AND mask bitmap */
-            hMonoBitmap = ::CreateBitmap(pEvent->width(), pEvent->height(), 1, 1,
-                                         pu8AndMaskWordAligned? pu8AndMaskWordAligned: srcAndMaskPtr);
-
-            if (pu8AndMaskWordAligned)
-            {
-                RTMemTmpFree(pu8AndMaskWordAligned);
-            }
-        }
-
-        Assert(hBitmap);
-        Assert(hMonoBitmap);
-        if (hBitmap && hMonoBitmap)
-        {
-            DWORD *dstShapePtr = (DWORD *) lpBits;
-
-            for (uint y = 0; y < pEvent->height(); y ++)
-            {
-                memcpy(dstShapePtr, srcShapePtr, srcShapePtrScan);
-                srcShapePtr += srcShapePtrScan;
-                dstShapePtr += pEvent->width();
-            }
-
-            ICONINFO ii;
-            ii.fIcon = FALSE;
-            ii.xHotspot = pEvent->xHot();
-            ii.yHotspot = pEvent->yHot();
-            ii.hbmMask = hMonoBitmap;
-            ii.hbmColor = hBitmap;
-
-            HCURSOR hAlphaCursor = CreateIconIndirect(&ii);
-            Assert(hAlphaCursor);
-            if (hAlphaCursor)
-            {
-                viewport()->setCursor(QCursor(hAlphaCursor));
-                ok = true;
-                if (mAlphaCursor)
-                    DestroyIcon(mAlphaCursor);
-                mAlphaCursor = hAlphaCursor;
-            }
-        }
-
-        if (hMonoBitmap)
-            DeleteObject(hMonoBitmap);
-        if (hBitmap)
-            DeleteObject(hBitmap);
-
-#elif defined (Q_WS_X11) && !defined (VBOX_WITHOUT_XCURSOR)
-
-        XcursorImage *img = XcursorImageCreate (pEvent->width(), pEvent->height());
-        Assert (img);
-        if (img)
-        {
-            img->xhot = pEvent->xHot();
-            img->yhot = pEvent->yHot();
-
-            XcursorPixel *dstShapePtr = img->pixels;
-
-            for (uint y = 0; y < pEvent->height(); y ++)
-            {
-                memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
-
-                if (!pEvent->hasAlpha())
-                {
-                    /* convert AND mask to the alpha channel */
-                    uchar byte = 0;
-                    for (uint x = 0; x < pEvent->width(); x ++)
-                    {
-                        if (!(x % 8))
-                            byte = *(srcAndMaskPtr ++);
-                        else
-                            byte <<= 1;
-
-                        if (byte & 0x80)
-                        {
-                            /* Linux doesn't support inverted pixels (XOR ops,
-                             * to be exact) in cursor shapes, so we detect such
-                             * pixels and always replace them with black ones to
-                             * make them visible at least over light colors */
-                            if (dstShapePtr [x] & 0x00FFFFFF)
-                                dstShapePtr [x] = 0xFF000000;
-                            else
-                                dstShapePtr [x] = 0x00000000;
-                        }
-                        else
-                            dstShapePtr [x] |= 0xFF000000;
-                    }
-                }
-
-                srcShapePtr += srcShapePtrScan;
-                dstShapePtr += pEvent->width();
-            }
-
-            Cursor cur = XcursorImageLoadCursor (QX11Info::display(), img);
-            Assert (cur);
-            if (cur)
-            {
-                viewport()->setCursor (QCursor (cur));
-                ok = true;
-            }
-
-            XcursorImageDestroy (img);
-        }
+            srcShapePtr += srcShapePtrScan;
+            dstShapePtr += uWidth;
+        }
+
+        Cursor cur = XcursorImageLoadCursor(QX11Info::display(), img);
+        Assert (cur);
+        if (cur)
+        {
+            viewport()->setCursor(QCursor(cur));
+            ok = true;
+        }
+
+        XcursorImageDestroy(img);
+    }
 
 #elif defined(Q_WS_MAC)
 
-        /* Create a ARGB image out of the shape data. */
-        QImage image  (pEvent->width(), pEvent->height(), QImage::Format_ARGB32);
-        const uint8_t* pbSrcMask = static_cast<const uint8_t*> (srcAndMaskPtr);
-        unsigned cbSrcMaskLine = RT_ALIGN (pEvent->width(), 8) / 8;
-        for (unsigned int y = 0; y < pEvent->height(); ++y)
-        {
-            for (unsigned int x = 0; x < pEvent->width(); ++x)
-            {
-               unsigned int color = ((unsigned int*)srcShapePtr)[y*pEvent->width()+x];
-               /* If the alpha channel isn't in the shape data, we have to
-                * create them from the and-mask. This is a bit field where 1
-                * represent transparency & 0 opaque respectively. */
-               if (!pEvent->hasAlpha())
+    /* Create a ARGB image out of the shape data. */
+    QImage image  (uWidth, uHeight, QImage::Format_ARGB32);
+    const uint8_t* pbSrcMask = static_cast<const uint8_t*> (srcAndMaskPtr);
+    unsigned cbSrcMaskLine = RT_ALIGN (uWidth, 8) / 8;
+    for (unsigned int y = 0; y < uHeight; ++y)
+    {
+        for (unsigned int x = 0; x < uWidth; ++x)
+        {
+           unsigned int color = ((unsigned int*)srcShapePtr)[y*uWidth+x];
+           /* If the alpha channel isn't in the shape data, we have to
+            * create them from the and-mask. This is a bit field where 1
+            * represent transparency & 0 opaque respectively. */
+           if (!fHasAlpha)
+           {
+               if (!(pbSrcMask[x / 8] & (1 << (7 - (x % 8)))))
+                   color  |= 0xff000000;
+               else
                {
-                   if (!(pbSrcMask[x / 8] & (1 << (7 - (x % 8)))))
-                       color  |= 0xff000000;
+                   /* This isn't quite right, but it's the best we can do I think... */
+                   if (color & 0x00ffffff)
+                       color = 0xff000000;
                    else
-                   {
-                       /* This isn't quite right, but it's the best we can do I
-                        * think... */
-                       if (color & 0x00ffffff)
-                           color = 0xff000000;
-                       else
-                           color = 0x00000000;
-                   }
+                       color = 0x00000000;
                }
-               image.setPixel (x, y, color);
-            }
-            /* Move one scanline forward. */
-            pbSrcMask += cbSrcMaskLine;
-        }
-        /* Set the new cursor */
-        QCursor cursor (QPixmap::fromImage (image), pEvent->xHot(), pEvent->yHot());
-        viewport()->setCursor (cursor);
-        ok = true;
-        NOREF (srcShapePtrScan);
+           }
+           image.setPixel (x, y, color);
+        }
+        /* Move one scanline forward. */
+        pbSrcMask += cbSrcMaskLine;
+    }
+    /* Set the new cursor: */
+    QCursor cursor(QPixmap::fromImage(image), uXHot, uYHot);
+    viewport()->setCursor(cursor);
+    ok = true;
+    NOREF(srcShapePtrScan);
 
 #else
@@ -3055,36 +3072,8 @@
 #endif
 
-        if (ok)
-            mLastCursor = viewport()->cursor();
-        else
-            viewport()->unsetCursor();
-    }
+    if (ok)
+        m_lastCursor = viewport()->cursor();
     else
-    {
-        if (pEvent->isVisible())
-        {
-            viewport()->setCursor(mLastCursor);
-        }
-        else
-        {
-            viewport()->setCursor(Qt::BlankCursor);
-        }
-    }
-    mHideHostPointer = !pEvent->isVisible();
-}
-#endif
-
-inline QRgb qRgbIntensity(QRgb rgb, int mul, int div)
-{
-    int r = qRed(rgb);
-    int g = qGreen(rgb);
-    int b = qBlue(rgb);
-    return qRgb(mul * r / div, mul * g / div, mul * b / div);
-}
-
-void UIMachineView::storeConsoleSize(int aWidth, int aHeight)
-{
-    LogFlowThisFunc(("aWidth=%d, aHeight=%d\n", aWidth, aHeight));
-    mStoredConsoleSize = QRect(0, 0, aWidth, aHeight);
+        viewport()->unsetCursor();
 }
 
@@ -3093,38 +3082,4 @@
     machineWindowWrapper()->machineLogic()->actionsPool()->action(UIActionIndex_Toggle_MouseIntegration)->setChecked(false);
     machineWindowWrapper()->machineLogic()->actionsPool()->action(UIActionIndex_Toggle_MouseIntegration)->setEnabled(bDisabled);
-}
-
-void UIMachineView::setDesktopGeometry(DesktopGeo aGeo, int aWidth, int aHeight)
-{
-    switch (aGeo)
-    {
-        case DesktopGeo_Fixed:
-            mDesktopGeo = DesktopGeo_Fixed;
-            if (aWidth != 0 && aHeight != 0)
-                mDesktopGeometry = QRect(0, 0, aWidth, aHeight);
-            else
-                mDesktopGeometry = QRect(0, 0, 0, 0);
-            storeConsoleSize(0, 0);
-            break;
-        case DesktopGeo_Automatic:
-            mDesktopGeo = DesktopGeo_Automatic;
-            mDesktopGeometry = QRect(0, 0, 0, 0);
-            storeConsoleSize(0, 0);
-            break;
-        case DesktopGeo_Any:
-            mDesktopGeo = DesktopGeo_Any;
-            mDesktopGeometry = QRect(0, 0, 0, 0);
-            break;
-        default:
-            AssertMsgFailed(("Invalid desktop geometry type %d\n", aGeo));
-            mDesktopGeo = DesktopGeo_Invalid;
-    }
-}
-
-QRect UIMachineView::availableGeometry()
-{
-    return machineWindowWrapper()->machineWindow()->isFullScreen() ?
-           QApplication::desktop()->screenGeometry(this) :
-           QApplication::desktop()->availableGeometry(this);
 }
 
@@ -3167,7 +3122,7 @@
     if (mDockIconEnabled)
     {
-        if (!mPausedShot.isNull())
-        {
-            CGImageRef pauseImg = ::darwinToCGImageRef (&mPausedShot);
+        if (!m_pauseShot.isNull())
+        {
+            CGImageRef pauseImg = ::darwinToCGImageRef (&m_pauseShot);
             /* Use the pause image as background */
             mDockIconPreview->updateDockPreview (pauseImg);
@@ -3178,10 +3133,10 @@
 # if defined (VBOX_GUI_USE_QUARTZ2D)
                 // TODO_NEW_CORE
-//            if (mode == VBoxDefs::Quartz2DMode)
+//            if (mode() == VBoxDefs::Quartz2DMode)
 //            {
                 /* If the render mode is Quartz2D we could use the CGImageRef
                  * of the framebuffer for the dock icon creation. This saves
                  * some conversion time. */
-//                mDockIconPreview->updateDockPreview (static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef());
+//                mDockIconPreview->updateDockPreview (static_cast <VBoxQuartz2DFrameBuffer *> (m_pFrameBuffer)->imageRef());
 //            }
 //            else
@@ -3190,5 +3145,5 @@
                  * framebuffer */
                 // TODO_NEW_CORE
-//                mDockIconPreview->updateDockPreview (mFrameBuf);
+//                mDockIconPreview->updateDockPreview (m_pFrameBuffer);
         }
     }
@@ -3201,12 +3156,12 @@
      * the overlay stuff only. */
     if (mDockIconEnabled &&
-        (mLastState == KMachineState_Running ||
-         mLastState == KMachineState_Paused ||
-         mLastState == KMachineState_Teleporting ||
-         mLastState == KMachineState_LiveSnapshotting ||
-         mLastState == KMachineState_Restoring ||
-         mLastState == KMachineState_TeleportingPausedVM ||
-         mLastState == KMachineState_TeleportingIn ||
-         mLastState == KMachineState_Saving))
+        (m_machineState == KMachineState_Running ||
+         m_machineState == KMachineState_Paused ||
+         m_machineState == KMachineState_Teleporting ||
+         m_machineState == KMachineState_LiveSnapshotting ||
+         m_machineState == KMachineState_Restoring ||
+         m_machineState == KMachineState_TeleportingPausedVM ||
+         m_machineState == KMachineState_TeleportingIn ||
+         m_machineState == KMachineState_Saving))
         updateDockIcon();
     else
@@ -3223,5 +3178,5 @@
        the keyboard/mouse is grabbed (this is when we have a valid
        event handler). */
-    if (aOn || mKeyboardGrabbed)
+    if (aOn || m_fKeyboardGrabbed)
         ::darwinSetMouseCoalescingEnabled (aOn);
 }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h	(revision 26753)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h	(revision 26754)
@@ -40,8 +40,10 @@
 #endif /* Q_WS_MAC */
 
-/* Local forward declarations */
+/* Local forwards */
+#ifdef Q_WS_MAC
 class VBoxChangeDockIconUpdateEvent;
 class VBoxChangePresentationModeEvent;
 class VBoxDockIconPreview;
+#endif /* Q_WS_MAC */
 
 class UIMachineView : public QAbstractScrollArea
@@ -59,8 +61,10 @@
                                  , UIVisualStateType visualStateType);
 
+    /* Public virtual members: */
+    virtual void normalizeGeometry(bool bAdjustPosition = false) = 0;
+
     /* Public setters: */
     void setIgnoreGuestResize(bool bIgnore) { m_bIsGuestResizeIgnored = bIgnore; }
     void setMouseIntegrationEnabled(bool bEnabled);
-    virtual void normalizeGeometry(bool bAdjustPosition = false) = 0;
     //void setMachineViewFinalized(bool fTrue = true) { m_bIsMachineWindowResizeIgnored = !fTrue; }
 
@@ -70,11 +74,9 @@
     void setMouseCoalescingEnabled(bool aOn);
     void setDockIconEnabled(bool aOn) { mDockIconEnabled = aOn; };
-
-    const QPixmap& pauseShot() const { return mPausedShot; }
 #endif
 
 signals:
 
-    /* Machine view signals: */
+    /* Mouse/Keyboard state-change signals: */
     void keyboardStateChanged(int iState);
     void mouseStateChanged(int iState);
@@ -97,4 +99,7 @@
     );
     virtual ~UIMachineView();
+
+    /* Desktop geometry types: */
+    enum DesktopGeo { DesktopGeo_Invalid = 0, DesktopGeo_Fixed, DesktopGeo_Automatic, DesktopGeo_Any };
 
     /* Protected getters: */
@@ -102,5 +107,6 @@
     CConsole &console() { return m_console; }
 
-    /* Protected members: */
+    /* Protected getters: */
+    VBoxDefs::RenderMode mode() const { return m_mode; }
     QSize sizeHint() const;
     int contentsX() const;
@@ -110,25 +116,39 @@
     int visibleWidth() const;
     int visibleHeight() const;
+    QRect desktopGeometry() const;
+    bool isGuestSupportsGraphics() const { return m_bIsGuestSupportsGraphics; }
+    const QPixmap& pauseShot() const { return m_pauseShot; }
+    //bool isMouseAbsolute() const { return m_bIsMouseAbsolute; }
+
+    /* Protected members: */
     void calculateDesktopGeometry();
-    QRect desktopGeometry() const;
-    //bool isMouseAbsolute() const { return m_bIsMouseAbsolute; }
+    void setDesktopGeometry(DesktopGeo geometry, int iWidth, int iHeight);
+    void storeConsoleSize(int iWidth, int iHeight);
+    QRect availableGeometry();
+    virtual void maybeRestrictMinimumSize() = 0;
 
     /* Prepare routines: */
-    void prepareFrameBuffer();
-    void prepareCommon();
-    void prepareFilters();
-    void loadMachineViewSettings();
+    virtual void prepareFrameBuffer();
+    virtual void prepareCommon();
+    virtual void prepareFilters();
+    virtual void prepareConsoleConnections();
+    virtual void loadMachineViewSettings();
 
     /* Cleanup routines: */
-    //void saveMachineViewSettings();
-    //void cleanupFilters();
-    void cleanupCommon();
-    void cleanupFrameBuffer();
-
-    /* Protected variables: */
-    VBoxDefs::RenderMode mode;
-    bool m_bIsGuestSupportsGraphics : 1;
+    //virtual void saveMachineViewSettings();
+    //virtual void cleanupConsoleConnections();
+    //virtual void cleanupFilters();
+    virtual void cleanupCommon();
+    virtual void cleanupFrameBuffer();
 
 private slots:
+
+    void sltMousePointerShapeChange(bool fIsVisible, bool fHasAlpha,
+                                    uint uXHot, uint uYHot, uint uWidth, uint uHeight,
+                                    const uchar *pShapeData);
+    void sltMouseCapabilityChange(bool bIsSupportsAbsolute, bool bNeedsHostCursor);
+    void sltKeyboardLedsChange(bool bNumLock, bool bCapsLock, bool bScrollLock);
+    void sltStateChange(KMachineState state);
+    void sltAdditionsStateChange();
 
 #ifdef Q_WS_MAC
@@ -143,8 +163,19 @@
 private:
 
-    /* Event processors: */
+    /* Cross-platforms event processors: */
     bool event(QEvent *pEvent);
     bool eventFilter(QObject *pWatched, QEvent *pEvent);
+    void focusEvent(bool aHasFocus, bool aReleaseHostKey = true);
+    bool keyEvent(int aKey, uint8_t aScan, int aFlags, wchar_t *aUniKey = NULL);
+    bool mouseEvent(int aType, const QPoint &aPos, const QPoint &aGlobalPos,
+                    Qt::MouseButtons aButtons, Qt::KeyboardModifiers aModifiers,
+                    int aWheelDelta, Qt::Orientation aWheelDir);
+    void resizeEvent(QResizeEvent *pEvent);
+    void moveEvent(QMoveEvent *pEvent);
+    void paintEvent(QPaintEvent *pEvent);
+
+    /* Platform specific event processors: */
 #if defined(Q_WS_WIN32)
+    static LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
     bool winLowKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event);
     bool winEvent(MSG *aMsg, long *aResult);
@@ -156,8 +187,4 @@
     bool darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent);
     void darwinGrabKeyboardEvents(bool fGrab);
-#endif
-#if defined (Q_WS_WIN32)
-    static LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
-#elif defined (Q_WS_MAC)
 # ifdef QT_MAC_USE_COCOA
     static bool darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
@@ -167,53 +194,28 @@
 #endif
 
-    /* Flags for keyEvent() */
-    enum { KeyExtended = 0x01, KeyPressed = 0x02, KeyPause = 0x04, KeyPrint = 0x08 };
-    void emitKeyboardStateChanged()
-    {
-        emit keyboardStateChanged((m_bIsKeyboardCaptured ? UIViewStateType_KeyboardCaptured : 0) |
-                                  (m_bIsHostkeyPressed ? UIViewStateType_HostKeyPressed : 0));
-    }
-    void emitMouseStateChanged()
-    {
-        emit mouseStateChanged((m_bIsMouseCaptured ? UIMouseStateType_MouseCaptured : 0) |
-                               (m_bIsMouseAbsolute ? UIMouseStateType_MouseAbsolute : 0) |
-                               (!m_bIsMouseIntegrated ? UIMouseStateType_MouseAbsoluteDisabled : 0));
-    }
-
-    void focusEvent(bool aHasFocus, bool aReleaseHostKey = true);
-    bool keyEvent(int aKey, uint8_t aScan, int aFlags, wchar_t *aUniKey = NULL);
-    bool mouseEvent(int aType, const QPoint &aPos, const QPoint &aGlobalPos,
-                    Qt::MouseButtons aButtons, Qt::KeyboardModifiers aModifiers,
-                    int aWheelDelta, Qt::Orientation aWheelDir);
-    void resizeEvent(QResizeEvent *pEvent);
-    void moveEvent(QMoveEvent *pEvent);
-    void paintEvent(QPaintEvent *pEvent);
-
-    /* Private members: */
-    bool shouldHideHostPointer() const { return m_bIsMouseCaptured || (m_bIsMouseAbsolute && mHideHostPointer); }
-    bool isRunning() { return mLastState == KMachineState_Running || mLastState == KMachineState_Teleporting || mLastState == KMachineState_LiveSnapshotting; }
+    /* Private helpers: */
     void fixModifierState(LONG *piCodes, uint *puCount);
-    void scrollBy(int dx, int dy);
     QPoint viewportToContents(const QPoint &vp) const;
     void updateSliders();
+    void scrollBy(int dx, int dy);
 #ifdef VBOX_WITH_VIDEOHWACCEL
     void scrollContentsBy(int dx, int dy);
 #endif
-    void onStateChange(KMachineState state);
-    void captureKbd(bool aCapture, bool aEmitSignal = true);
-    void captureMouse(bool aCapture, bool aEmitSignal = true);
+    void emitKeyboardStateChanged();
+    void emitMouseStateChanged();
+    void captureKbd(bool fCapture, bool fEmitSignal = true);
+    void captureMouse(bool fCapture, bool fEmitSignal = true);
+    void saveKeyStates();
     bool processHotKey(const QKeySequence &key, const QList<QAction*> &data);
     void releaseAllPressedKeys(bool aReleaseHostKey = true);
-    void saveKeyStates();
     void sendChangedKeyStates();
     void updateMouseClipping();
-    //void setPointerShape(MousePointerChangeEvent *pEvent);
-
-    enum DesktopGeo { DesktopGeo_Invalid = 0, DesktopGeo_Fixed, DesktopGeo_Automatic, DesktopGeo_Any };
-    void storeConsoleSize(int aWidth, int aHeight);
-    void setMouseIntegrationLocked(bool bDisabled);
-    void setDesktopGeometry(DesktopGeo aGeo, int aWidth, int aHeight);
-    virtual void maybeRestrictMinimumSize() = 0;
-    QRect availableGeometry();
+    void setPointerShape(const uchar *pShapeData, bool fHasAlpha,
+                         uint uXHot, uint uYHot, uint uWidth, uint uHeight);
+    void setMouseIntegrationLocked(bool fDisabled);
+
+    /* Private getters: */
+    bool isRunning() { return m_machineState == KMachineState_Running || m_machineState == KMachineState_Teleporting || m_machineState == KMachineState_LiveSnapshotting; }
+    bool shouldHideHostPointer() const { return m_bIsMouseCaptured || (m_bIsMouseAbsolute && m_fHideHostPointer); }
 
     static void dimImage(QImage &img);
@@ -222,17 +224,22 @@
     UIMachineWindow *m_pMachineWindow;
     CConsole m_console;
+    VBoxDefs::RenderMode m_mode;
     const VBoxGlobalSettings &m_globalSettings;
-    KMachineState mLastState;
-
-    QPoint mLastPos;
-    QPoint mCapturedPos;
+    KMachineState m_machineState;
+    UIFrameBuffer *m_pFrameBuffer;
+
+    QCursor m_lastCursor;
+#if defined(Q_WS_WIN)
+    HCURSOR m_alphaCursor;
+#endif
+    QPoint m_lastMousePos;
+    QPoint m_capturedMousePos;
     int m_iLastMouseWheelDelta;
 
-    enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 };
-    uint8_t mPressedKeys[128];
-    uint8_t mPressedKeysCopy[128];
-
-    long muNumLockAdaptionCnt;
-    long muCapsLockAdaptionCnt;
+    uint8_t m_pressedKeys[128];
+    uint8_t m_pressedKeysCopy[128];
+
+    long m_uNumLockAdaptionCnt;
+    long m_uCapsLockAdaptionCnt;
 
     bool m_bIsAutoCaptureDisabled : 1;
@@ -243,19 +250,19 @@
     bool m_bIsHostkeyPressed : 1;
     bool m_bIsHostkeyAlone : 1;
-    bool hostkey_in_capture : 1;
+    bool m_bHostkeyInCapture : 1;
+    bool m_bIsGuestSupportsGraphics : 1;
     bool m_bIsMachineWindowResizeIgnored : 1;
     bool m_bIsFrameBufferResizeIgnored : 1;
     bool m_bIsGuestResizeIgnored : 1;
+    bool m_numLock : 1;
+    bool m_scrollLock : 1;
+    bool m_capsLock : 1;
+    bool m_fPassCAD;
+    bool m_fHideHostPointer;
+#ifdef VBOX_WITH_VIDEOHWACCEL
+    bool m_fAccelerate2DVideo;
+#endif
+#if 0 // TODO: Do we need this flag?
     bool mDoResize : 1;
-    bool mNumLock : 1;
-    bool mScrollLock : 1;
-    bool mCapsLock : 1;
-
-#ifdef VBOX_WITH_VIDEOHWACCEL
-    bool mAccelerate2DVideo;
-#endif
-
-#if defined(Q_WS_WIN)
-    HCURSOR mAlphaCursor;
 #endif
 
@@ -263,15 +270,13 @@
 # ifndef QT_MAC_USE_COCOA
     /** Event handler reference. NULL if the handler isn't installed. */
-    EventHandlerRef mDarwinEventHandlerRef;
+    EventHandlerRef m_darwinEventHandlerRef;
 # endif /* !QT_MAC_USE_COCOA */
     /** The current modifier key mask. Used to figure out which modifier
      *  key was pressed when we get a kEventRawKeyModifiersChanged event. */
-    UInt32 mDarwinKeyModifiers;
-    bool mKeyboardGrabbed;
-#endif
-
-    UIFrameBuffer *mFrameBuf;
-
-    QPixmap mPausedShot;
+    UInt32 m_darwinKeyModifiers;
+    bool m_fKeyboardGrabbed;
+#endif
+
+    QPixmap m_pauseShot;
 #if defined(Q_WS_MAC)
 # if !defined (QT_MAC_USE_COCOA)
@@ -281,14 +286,12 @@
     bool mDockIconEnabled;
 #endif
-    DesktopGeo mDesktopGeo;
-    QRect mDesktopGeometry;
-    QRect mStoredConsoleSize;
-    bool mPassCAD;
-    bool mHideHostPointer;
-    QCursor mLastCursor;
+    DesktopGeo m_desktopGeometryType;
+    QRect m_desktopGeometry;
+    QRect m_storedConsoleSize;
 
     /* Friend classes: */
     friend class UIFrameBuffer;
     friend class UIFrameBufferQImage;
+    friend class UIFrameBufferQuartz2D;
 };
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 26753)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 26754)
@@ -537,17 +537,4 @@
         case UIConsoleEventType_MousePointerShapeChange:
         {
-#if 0 // TODO: Move to machine view!
-            MousePointerChangeEvent *me = (MousePointerChangeEvent*)pEvent;
-            /* Change cursor shape only when mouse integration is
-             * supported (change mouse shape type event may arrive after
-             * mouse capability change that disables integration. */
-            if (m_bIsMouseAbsolute)
-                setPointerShape (me);
-            else
-                /* Note: actually we should still remember the requested
-                 * cursor shape.  If we can't do that, at least remember
-                 * the requested visiblilty. */
-                mHideHostPointer = !me->isVisible();
-#endif
             UIMousePointerShapeChangeEvent *pConsoleEvent = static_cast<UIMousePointerShapeChangeEvent*>(pEvent);
             emit sigMousePointerShapeChange(pConsoleEvent->isVisible(), pConsoleEvent->hasAlpha(),
@@ -560,30 +547,4 @@
         case UIConsoleEventType_MouseCapabilityChange:
         {
-#if 0 // TODO: Move to machine view!
-            MouseCapabilityEvent *me = (MouseCapabilityEvent*)pEvent;
-            if (m_bIsMouseAbsolute != me->supportsAbsolute())
-            {
-                m_bIsMouseAbsolute = me->supportsAbsolute();
-                /* correct the mouse capture state and reset the cursor
-                 * to the default shape if necessary */
-                if (m_bIsMouseAbsolute)
-                {
-                    CMouse mouse = m_console.GetMouse();
-                    mouse.PutMouseEventAbsolute (-1, -1, 0,
-                                                 0 /* Horizontal wheel */,
-                                                 0);
-                    captureMouse (false, false);
-                }
-                else
-                    viewport()->unsetCursor();
-                emitMouseStateChanged();
-                vboxProblem().remindAboutMouseIntegration (m_bIsMouseAbsolute);
-            }
-            if (me->needsHostCursor())
-                setMouseIntegrationLocked (false);
-            else
-                setMouseIntegrationLocked (true);
-            return true;
-#endif
             UIMouseCapabilityChangeEvent *pConsoleEvent = static_cast<UIMouseCapabilityChangeEvent*>(pEvent);
             emit sigMouseCapabilityChange(pConsoleEvent->supportsAbsolute(), pConsoleEvent->needsHostCursor());
@@ -593,14 +554,4 @@
         case UIConsoleEventType_KeyboardLedsChange:
         {
-#if 0 // TODO: Move to machine view!
-            ModifierKeyChangeEvent *me = (ModifierKeyChangeEvent* )pEvent;
-            if (me->numLock() != mNumLock)
-                muNumLockAdaptionCnt = 2;
-            if (me->capsLock() != mCapsLock)
-                muCapsLockAdaptionCnt = 2;
-            mNumLock    = me->numLock();
-            mCapsLock   = me->capsLock();
-            mScrollLock = me->scrollLock();
-#endif
             UIKeyboardLedsChangeEvent *pConsoleEvent = static_cast<UIKeyboardLedsChangeEvent*>(pEvent);
             emit sigKeyboardLedsChange(pConsoleEvent->numLock(), pConsoleEvent->capsLock(), pConsoleEvent->scrollLock());
@@ -610,11 +561,4 @@
         case UIConsoleEventType_StateChange:
         {
-#if 0 // TODO: Move to machine view!
-            MachineUIStateChangeEvent *me = (MachineUIStateChangeEvent *) pEvent;
-            LogFlowFunc (("MachineUIStateChangeEventType: state=%d\n",
-                           me->machineState()));
-            onStateChange (me->machineState());
-            emit machineStateChanged (me->machineState());
-#endif
             UIStateChangeEvent *pConsoleEvent = static_cast<UIStateChangeEvent*>(pEvent);
             emit sigStateChange(pConsoleEvent->machineState());
@@ -624,30 +568,4 @@
         case UIConsoleEventType_AdditionsStateChange:
         {
-#if 0 // TODO: Move to machine view!
-            GuestAdditionsChangeEvent *ge = (GuestAdditionsChangeEvent *) pEvent;
-            LogFlowFunc (("UIAdditionsStateChangeEventType\n"));
-            /* Always send a size hint if we are in fullscreen or seamless
-             * when the graphics capability is enabled, in case the host
-             * resolution has changed since the VM was last run. */
-#if 0
-            if (!mDoResize && !m_bIsGuestSupportsGraphics &&
-                ge->supportsGraphics() &&
-                (machineWindowWrapper()->isTrueSeamless() || machineWindowWrapper()->isTrueFullscreen()))
-                mDoResize = true;
-#endif
-            m_bIsGuestSupportsGraphics = ge->supportsGraphics();
-
-            maybeRestrictMinimumSize();
-
-#if 0
-            /* This will only be acted upon if mDoResize is true. */
-            doResizeHint();
-#endif
-
-            emit additionsStateChanged (ge->additionVersion(),
-                                        ge->additionActive(),
-                                        ge->supportsSeamless(),
-                                        ge->supportsGraphics());
-#endif
             emit sigAdditionsStateChange();
             return true;
@@ -656,9 +574,4 @@
         case UIConsoleEventType_NetworkAdapterChange:
         {
-#if 0 // TODO: Move to machine view!
-            /* no specific adapter information stored in this
-             * event is currently used */
-            emit networkStateChange();
-#endif
             UINetworkAdapterChangeEvent *pConsoleEvent = static_cast<UINetworkAdapterChangeEvent*>(pEvent);
             emit sigNetworkAdapterChange(pConsoleEvent->networkAdapter());
@@ -688,10 +601,4 @@
         case UIConsoleEventType_MediumChange:
         {
-#if 0 // TODO: Move to machine view!
-            MediaDriveChangeEvent *mce = (MediaDriveChangeEvent *) pEvent;
-            LogFlowFunc (("MediaChangeEvent\n"));
-
-            emit mediaDriveChanged (mce->type());
-#endif
             UIMediumChangeEvent *pConsoleEvent = static_cast<UIMediumChangeEvent*>(pEvent);
             emit sigMediumChange(pConsoleEvent->mediumAttahment());
@@ -726,23 +633,4 @@
         case UIConsoleEventType_USBDeviceStateChange:
         {
-#if 0 // TODO: Move to machine view!
-            UIUSBDeviceUIStateChangeEvent *ue = (UIUSBDeviceUIStateChangeEvent *)pEvent;
-
-            bool success = ue->error().isNull();
-
-            if (!success)
-            {
-                if (ue->attached())
-                    vboxProblem().cannotAttachUSBDevice (
-                        m_console,
-                        vboxGlobal().details (ue->device()), ue->error());
-                else
-                    vboxProblem().cannotDetachUSBDevice (
-                        m_console,
-                        vboxGlobal().details (ue->device()), ue->error());
-            }
-
-            emit usbStateChange();
-#endif
             UIUSBDeviceUIStateChangeEvent *pConsoleEvent = static_cast<UIUSBDeviceUIStateChangeEvent*>(pEvent);
             emit sigUSBDeviceStateChange(pConsoleEvent->device(), pConsoleEvent->attached(), pConsoleEvent->error());
@@ -758,8 +646,4 @@
         case UIConsoleEventType_RuntimeError:
         {
-#if 0 // TODO: Move to machine view!
-            UIRuntimeErrorEvent *pConsoleEvent = (UIRuntimeErrorEvent *) pEvent;
-            vboxProblem().showRuntimeError(m_console, ee->fatal(), ee->errorID(), ee->message());
-#endif
             UIRuntimeErrorEvent *pConsoleEvent = static_cast<UIRuntimeErrorEvent*>(pEvent);
             emit sigRuntimeError(pConsoleEvent->fatal(), pConsoleEvent->errorID(), pConsoleEvent->message());
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 26753)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 26754)
@@ -75,5 +75,5 @@
 
     /* Console signals: */
-    void sigMousePointerShapeChange(bool bIsVisible, bool bHasAlpha, bool uXHot, bool uYHot, bool uWidth, bool uHeight, const uchar *pShapeData);
+    void sigMousePointerShapeChange(bool bIsVisible, bool bHasAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight, const uchar *pShapeData);
     void sigMouseCapabilityChange(bool bIsSupportsAbsolute, bool bNeedsHostCursor);
     void sigKeyboardLedsChange(bool bNumLock, bool bCapsLock, bool bScrollLock);
@@ -91,5 +91,5 @@
     void sigUSBDeviceStateChange(const CUSBDevice &device, bool bIsAttached, const CVirtualBoxErrorInfo &error);
     void sigSharedFolderChange();
-    void sigRuntimeError(bool bIsFatal, QString strErrorId, QString strMessage);
+    void sigRuntimeError(bool bIsFatal, const QString &strErrorId, const QString &strMessage);
 
 private:
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp	(revision 26753)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp	(revision 26754)
@@ -25,4 +25,6 @@
 #include <QApplication>
 #include <QDesktopWidget>
+#include <QMainWindow>
+#include <QMenuBar>
 
 /* Local includes */
@@ -54,4 +56,7 @@
     /* Prepare event-filters: */
     prepareFilters();
+
+    /* Prepare console connections: */
+    prepareConsoleConnections();
 
     /* Load machine view settings: */
@@ -104,5 +109,5 @@
             ar = dwt->availableGeometry(pTopLevelWidget->pos());
 
-        fr = VBoxGlobal::normalizeGeometry(fr, ar, mode != VBoxDefs::SDLMode /* canResize */);
+        fr = VBoxGlobal::normalizeGeometry(fr, ar, mode() != VBoxDefs::SDLMode /* canResize */);
     }
 
@@ -122,7 +127,7 @@
      * We need to do that because we cannot correctly draw in a scrolled window in SDL mode.
      * In all other modes, or when auto-resize is in force, this function does nothing. */
-    if (mode == VBoxDefs::SDLMode)
-    {
-        if (!m_bIsGuestSupportsGraphics || !m_bIsGuestAutoresizeEnabled)
+    if (mode() == VBoxDefs::SDLMode)
+    {
+        if (!isGuestSupportsGraphics() || !m_bIsGuestAutoresizeEnabled)
             setMinimumSize(sizeHint());
         else
@@ -134,5 +139,5 @@
 {
 #if 0 // TODO: fix that logic!
-    if (m_bIsGuestSupportsGraphics && m_bIsGuestAutoresizeEnabled)
+    if (isGuestSupportsGraphics() && m_bIsGuestAutoresizeEnabled)
     {
         /* If this slot is invoked directly then use the passed size
@@ -180,5 +185,5 @@
         maybeRestrictMinimumSize();
 
-        if (m_bIsGuestSupportsGraphics && m_bIsGuestAutoresizeEnabled)
+        if (isGuestSupportsGraphics() && m_bIsGuestAutoresizeEnabled)
             doResizeHint();
     }
@@ -192,2 +197,11 @@
 }
 
+void UIMachineViewNormal::prepareFilters()
+{
+    /* Parent class filters: */
+    UIMachineView::prepareFilters();
+
+    /* Normal window filters: */
+    qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->menuBar()->installEventFilter(this);
+}
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.h	(revision 26753)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.h	(revision 26754)
@@ -57,4 +57,7 @@
 private:
 
+    /* Prepare routines: */
+    void prepareFilters();
+
     bool m_bIsGuestAutoresizeEnabled : 1;
 
