Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 59355)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 59356)
@@ -100,4 +100,5 @@
     /* Prepare keyboard-handler: */
     UIKeyboardHandler *pKeyboardHandler = 0;
+
     /* Depending on visual-state type: */
     switch (visualStateType)
@@ -118,9 +119,11 @@
             break;
     }
+
 #ifdef Q_WS_WIN
-    /* Its required to have static pointer to created handler
+    /* It is necessary to have static pointer to created handler
      * because windows keyboard-hook works only with static members: */
     m_spKeyboardHandler = pKeyboardHandler;
 #endif /* Q_WS_WIN */
+
     /* Return prepared keyboard-handler: */
     return pKeyboardHandler;
@@ -130,8 +133,11 @@
 void UIKeyboardHandler::destroy(UIKeyboardHandler *pKeyboardHandler)
 {
-    /* Delete keyboard-handler: */
 #ifdef Q_WS_WIN
+    /* It was necessary to have static pointer to created handler
+     * because windows keyboard-hook works only with static members: */
     m_spKeyboardHandler = 0;
 #endif /* Q_WS_WIN */
+
+    /* Delete keyboard-handler: */
     delete pKeyboardHandler;
 }
@@ -232,7 +238,16 @@
         m_iKeyboardCaptureViewIndex = uScreenId;
 
-#if defined(Q_WS_WIN)
+#if defined(Q_WS_MAC)
+
+        /* On Mac, we use the Qt methods + disabling global hot keys + watching modifiers (for right/left separation). */
+        ::DarwinDisableGlobalHotKeys(true);
+        m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard();
+
+#elif defined(Q_WS_WIN)
+
         /* On Win, keyboard grabbing is ineffective, a low-level keyboard hook is used instead. */
+
 #elif defined(Q_WS_X11)
+
         /* On X11, we are using passive XGrabKey for normal (windowed) mode
          * instead of XGrabKeyboard (called by QWidget::grabKeyboard())
@@ -282,11 +297,10 @@
                 break;
         }
-#elif defined(Q_WS_MAC)
-        /* On Mac, we use the Qt methods + disabling global hot keys + watching modifiers (for right/left separation). */
-        ::DarwinDisableGlobalHotKeys(true);
-        m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard();
+
 #else
+
         /* On other platforms we are just praying Qt method will work. */
         m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard();
+
 #endif
 
@@ -308,7 +322,15 @@
         m_fIsKeyboardCaptured = false;
 
-#if defined(Q_WS_WIN)
+#if defined(Q_WS_MAC)
+
+        ::DarwinDisableGlobalHotKeys(false);
+        m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard();
+
+#elif defined(Q_WS_WIN)
+
         /* On Win, keyboard grabbing is ineffective, a low-level keyboard hook is used instead. */
+
 #elif defined(Q_WS_X11)
+
         /* On X11, we are using passive XGrabKey for normal (windowed) mode
          * instead of XGrabKeyboard (called by QWidget::grabKeyboard())
@@ -344,9 +366,9 @@
                 break;
         }
-#elif defined(Q_WS_MAC)
-        ::DarwinDisableGlobalHotKeys(false);
+
+#else
+
         m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard();
-#else
-        m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard();
+
 #endif
 
@@ -409,5 +431,5 @@
         alphaLock | kEventKeyModifierNumLockMask |
         (aReleaseHostKey ? 0 : hostComboModifierMask);
-#endif
+#endif /* Q_WS_MAC */
 
     /* Notify all the listeners: */
@@ -852,5 +874,5 @@
                     if (!isAutoCaptureDisabled() && autoCaptureSetGlobally() &&
                         GetAncestor((HWND)m_views[theListOfViewIds[i]]->winId(), GA_ROOT) == GetForegroundWindow())
-#else /* Q_WS_WIN */
+#else /* !Q_WS_WIN */
                     if (!isAutoCaptureDisabled() && autoCaptureSetGlobally())
 #endif /* !Q_WS_WIN */
@@ -939,5 +961,5 @@
     /* Initialize the X keyboard subsystem: */
     initMappedX11Keyboard(QX11Info::display(), vboxGlobal().settings().publicProperty("GUI/RemapScancodes"));
-#endif
+#endif /* Q_WS_X11 */
 
     /* Extra data settings: */
@@ -950,21 +972,25 @@
 void UIKeyboardHandler::cleanupCommon()
 {
-#if defined(Q_WS_WIN)
-    /* Cleanup AltGR monitor: */
-    delete m_pAltGrMonitor;
-    m_pAltGrMonitor = 0;
-
-    /* Cleaning keyboard-hook: */
-    if (m_keyboardHook)
-    {
-        UnhookWindowsHookEx(m_keyboardHook);
-        m_keyboardHook = NULL;
-    }
-#elif defined(Q_WS_MAC)
+#if defined(Q_WS_MAC)
+
     /* We have to make sure the callback for the keyboard events
      * is released when closing this view. */
     if (m_iKeyboardHookViewIndex != -1)
         darwinGrabKeyboardEvents(false);
-#endif /* Q_WS_MAC */
+
+#elif defined(Q_WS_WIN)
+
+    /* Cleanup AltGR monitor: */
+    delete m_pAltGrMonitor;
+    m_pAltGrMonitor = 0;
+
+    /* Cleaning keyboard-hook: */
+    if (m_keyboardHook)
+    {
+        UnhookWindowsHookEx(m_keyboardHook);
+        m_keyboardHook = NULL;
+    }
+
+#endif /* Q_WS_WIN */
 }
 
@@ -1004,5 +1030,5 @@
         switch (pEvent->type())
         {
-#if defined(Q_WS_WIN)
+#ifdef Q_WS_WIN
             /* Install/uninstall low-level keyboard-hook on every activation/deactivation to:
              * a) avoid excess hook calls when we're not active and;
@@ -1042,5 +1068,5 @@
                 break;
             }
-#endif
+#endif /* Q_WS_WIN */
             default:
                 break;
@@ -1083,5 +1109,5 @@
                     if (!isAutoCaptureDisabled() && autoCaptureSetGlobally() &&
                         GetAncestor((HWND)pWatchedView->winId(), GA_ROOT) == GetForegroundWindow())
-#else /* Q_WS_WIN */
+#else /* !Q_WS_WIN */
                     if (!isAutoCaptureDisabled() && autoCaptureSetGlobally())
 #endif /* !Q_WS_WIN */
@@ -1707,5 +1733,12 @@
     bool fWasProcessed = false;
 
-#ifdef Q_WS_WIN
+#if defined(Q_WS_MAC)
+
+    Q_UNUSED(iHotKey);
+    if (pHotKey && pHotKey[0] && !pHotKey[1])
+        fWasProcessed = actionPool()->processHotKey(QKeySequence(Qt::UNICODE_ACCEL + QChar(pHotKey[0]).toUpper().unicode()));
+
+#elif defined(Q_WS_WIN)
+
     Q_UNUSED(pHotKey);
     int iKeyboardLayout = GetKeyboardLayoutList(0, NULL);
@@ -1723,7 +1756,7 @@
     }
     delete[] pList;
-#endif /* Q_WS_WIN */
-
-#ifdef Q_WS_X11
+
+#elif defined(Q_WS_X11)
+
     Q_UNUSED(pHotKey);
     Display *pDisplay = QX11Info::display();
@@ -1741,11 +1774,10 @@
         }
     }
-#endif /* Q_WS_X11 */
-
-#ifdef Q_WS_MAC
-    Q_UNUSED(iHotKey);
-    if (pHotKey && pHotKey[0] && !pHotKey[1])
-        fWasProcessed = actionPool()->processHotKey(QKeySequence(Qt::UNICODE_ACCEL + QChar(pHotKey[0]).toUpper().unicode()));
-#endif /* Q_WS_MAC */
+
+#else
+
+# warning "port me!"
+
+#endif
 
     /* Grab the key from the Qt if it was processed, or pass it to the Qt otherwise
@@ -1758,28 +1790,9 @@
     /* Synchronize the views of the host and the guest to the modifier keys.
      * This function will add up to 6 additional keycodes to codes. */
-#if defined(Q_WS_X11)
-    Window   wDummy1, wDummy2;
-    int      iDummy3, iDummy4, iDummy5, iDummy6;
-    unsigned uMask;
-    unsigned uKeyMaskNum = 0, uKeyMaskCaps = 0;
-
-    uKeyMaskCaps          = LockMask;
-    XModifierKeymap* map  = XGetModifierMapping(QX11Info::display());
-    KeyCode keyCodeNum    = XKeysymToKeycode(QX11Info::display(), XK_Num_Lock);
-
-    for (int i = 0; i < 8; ++ i)
-        if (keyCodeNum != NoSymbol && map->modifiermap[map->max_keypermod * i] == keyCodeNum)
-            uKeyMaskNum = 1 << i;
-    XQueryPointer(QX11Info::display(), DefaultRootWindow(QX11Info::display()), &wDummy1, &wDummy2,
-                  &iDummy3, &iDummy4, &iDummy5, &iDummy6, &uMask);
-    XFreeModifiermap(map);
-
-    if (uisession()->numLockAdaptionCnt() && (uisession()->isNumLock() ^ !!(uMask & uKeyMaskNum)))
-    {
-        uisession()->setNumLockAdaptionCnt(uisession()->numLockAdaptionCnt() - 1);
-        piCodes[(*puCount)++] = 0x45;
-        piCodes[(*puCount)++] = 0x45 | 0x80;
-    }
-    if (uisession()->capsLockAdaptionCnt() && (uisession()->isCapsLock() ^ !!(uMask & uKeyMaskCaps)))
+
+#if defined(Q_WS_MAC)
+
+    /* if (uisession()->numLockAdaptionCnt()) ... - NumLock isn't implemented by Mac OS X so ignore it. */
+    if (uisession()->capsLockAdaptionCnt() && (uisession()->isCapsLock() ^ !!(::GetCurrentEventKeyModifiers() & alphaLock)))
     {
         uisession()->setCapsLockAdaptionCnt(uisession()->capsLockAdaptionCnt() - 1);
@@ -1795,5 +1808,7 @@
         }
     }
+
 #elif defined(Q_WS_WIN)
+
     if (uisession()->numLockAdaptionCnt() && (uisession()->isNumLock() ^ !!(GetKeyState(VK_NUMLOCK))))
     {
@@ -1816,7 +1831,30 @@
         }
     }
-#elif defined(Q_WS_MAC)
-    /* if (uisession()->numLockAdaptionCnt()) ... - NumLock isn't implemented by Mac OS X so ignore it. */
-    if (uisession()->capsLockAdaptionCnt() && (uisession()->isCapsLock() ^ !!(::GetCurrentEventKeyModifiers() & alphaLock)))
+
+#elif defined(Q_WS_X11)
+
+    Window   wDummy1, wDummy2;
+    int      iDummy3, iDummy4, iDummy5, iDummy6;
+    unsigned uMask;
+    unsigned uKeyMaskNum = 0, uKeyMaskCaps = 0;
+
+    uKeyMaskCaps          = LockMask;
+    XModifierKeymap* map  = XGetModifierMapping(QX11Info::display());
+    KeyCode keyCodeNum    = XKeysymToKeycode(QX11Info::display(), XK_Num_Lock);
+
+    for (int i = 0; i < 8; ++ i)
+        if (keyCodeNum != NoSymbol && map->modifiermap[map->max_keypermod * i] == keyCodeNum)
+            uKeyMaskNum = 1 << i;
+    XQueryPointer(QX11Info::display(), DefaultRootWindow(QX11Info::display()), &wDummy1, &wDummy2,
+                  &iDummy3, &iDummy4, &iDummy5, &iDummy6, &uMask);
+    XFreeModifiermap(map);
+
+    if (uisession()->numLockAdaptionCnt() && (uisession()->isNumLock() ^ !!(uMask & uKeyMaskNum)))
+    {
+        uisession()->setNumLockAdaptionCnt(uisession()->numLockAdaptionCnt() - 1);
+        piCodes[(*puCount)++] = 0x45;
+        piCodes[(*puCount)++] = 0x45 | 0x80;
+    }
+    if (uisession()->capsLockAdaptionCnt() && (uisession()->isCapsLock() ^ !!(uMask & uKeyMaskCaps)))
     {
         uisession()->setCapsLockAdaptionCnt(uisession()->capsLockAdaptionCnt() - 1);
@@ -1832,6 +1870,9 @@
         }
     }
+
 #else
-//#warning Adapt UIKeyboardHandler::fixModifierState
+
+# warning "port me!"
+
 #endif
 }
