Index: /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UIWindowMenuManager.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UIWindowMenuManager.cpp	(revision 57890)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UIWindowMenuManager.cpp	(revision 57891)
@@ -20,16 +20,19 @@
 #else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
 
-/* GUI includes: */
-# include "UIWindowMenuManager.h"
-
 /* Qt includes: */
 # include <QApplication>
 # include <QMenu>
 
+/* GUI includes: */
+# include "UIWindowMenuManager.h"
+
+/* Other VBox includes: */
+#include <iprt/assert.h>
+
 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
 
 /** QObject extension
   * used as Mac OS X 'Window' menu helper. */
-class UIMenuHelper: public QObject
+class UIMenuHelper : public QObject
 {
     Q_OBJECT;
@@ -37,19 +40,22 @@
 public:
 
-    /** Constructs menu-helper on the basis of passed @a winList. */
-    UIMenuHelper(const QList<QWidget*> &winList)
-    {
-        m_pWindowMenu = new QMenu(0);
+    /** Constructs menu-helper on the basis of passed @a windows. */
+    UIMenuHelper(const QList<QWidget*> &windows)
+    {
+        /* Prepare 'Window' menu: */
+        m_pWindowMenu = new QMenu;
+        /* Prepare action group: */
         m_pGroup = new QActionGroup(this);
         m_pGroup->setExclusive(true);
+        /* Prepare 'Minimize' action: */
         m_pMinimizeAction = new QAction(this);
         m_pWindowMenu->addAction(m_pMinimizeAction);
         connect(m_pMinimizeAction, SIGNAL(triggered(bool)),
-                this, SLOT(minimizeActive(bool)));
-        /* Make sure all already available windows are properly registered on
-         * this menu. */
-        for (int i=0; i < winList.size(); ++i)
-            addWindow(winList.at(i));
-
+                this, SLOT(sltMinimizeActiveWindow()));
+        /* Make sure all already available windows are
+         * properly registered within this menu: */
+        for (int i = 0; i < windows.size(); ++i)
+            addWindow(windows.at(i));
+        /* Translate finally: */
         retranslateUi();
     }
@@ -58,45 +64,48 @@
     ~UIMenuHelper()
     {
+        /* Cleanup 'Window' menu: */
         delete m_pWindowMenu;
-        qDeleteAll(m_regWindows);
+        /* Cleanup actions: */
+        qDeleteAll(m_windows);
     }
 
     /** Returns 'Window' menu. */
-    QMenu *menu() const { return m_pWindowMenu; }
-
-    /** Adds window into 'Window' menu. */
+    QMenu* menu() const { return m_pWindowMenu; }
+
+    /** Adds @a pWindow into 'Window' menu. */
     QAction* addWindow(QWidget *pWindow)
     {
         QAction *pAction = 0;
-        if (    pWindow
-            && !m_regWindows.contains(pWindow->windowTitle()))
-        {
-            if (m_regWindows.size() < 2)
+        if (   pWindow
+            && !m_windows.contains(pWindow->windowTitle()))
+        {
+            if (m_windows.size() < 2)
                 m_pWindowMenu->addSeparator();
-            /* The main window always first */
+            /* The main window always first: */
             pAction = new QAction(this);
             pAction->setText(pWindow->windowTitle());
             pAction->setMenuRole(QAction::NoRole);
-            pAction->setData(qVariantFromValue(pWindow));
+            pAction->setData(QVariant::fromValue(pWindow));
             pAction->setCheckable(true);
-            /* The first registered one is always considered as the main window */
-            if (m_regWindows.size() == 0)
+            /* The first registered one is always
+             * considered as the main window: */
+            if (m_windows.size() == 0)
                 pAction->setShortcut(QKeySequence("Ctrl+0"));
             m_pGroup->addAction(pAction);
             connect(pAction, SIGNAL(triggered(bool)),
-                    this, SLOT(raiseSender(bool)));
+                    this, SLOT(sltRaiseSender()));
             m_pWindowMenu->addAction(pAction);
-            m_regWindows[pWindow->windowTitle()] = pAction;
+            m_windows[pWindow->windowTitle()] = pAction;
         }
         return pAction;
     }
 
-    /** Removes window from 'Window' menu. */
+    /** Removes @a pWindow from 'Window' menu. */
     void removeWindow(QWidget *pWindow)
     {
-        if (m_regWindows.contains(pWindow->windowTitle()))
-        {
-            delete m_regWindows[pWindow->windowTitle()];
-            m_regWindows.remove(pWindow->windowTitle());
+        if (m_windows.contains(pWindow->windowTitle()))
+        {
+            delete m_windows.value(pWindow->windowTitle());
+            m_windows.remove(pWindow->windowTitle());
         }
     }
@@ -105,24 +114,31 @@
     void retranslateUi()
     {
+        /* Translate menu: */
         m_pWindowMenu->setTitle(tr("&Window"));
+
+        /* Translate menu 'Minimize' action: */
         m_pMinimizeAction->setText(tr("Minimize"));
         m_pMinimizeAction->setShortcut(QKeySequence("Ctrl+M"));
     }
 
-    /** Updates toggle action states according to passed @a pActive. */
-    void updateStatus(QWidget *pActive)
-    {
-        m_pMinimizeAction->setEnabled(pActive != 0);
-        if (pActive)
-        {
-            if (m_regWindows.contains(pActive->windowTitle()))
-                m_regWindows[pActive->windowTitle()]->setChecked(true);
-        }
+    /** Updates toggle action states according to passed @a pActiveWindow. */
+    void updateStatus(QWidget *pActiveWindow)
+    {
+        /* 'Minimize' action is enabled if there is active-window: */
+        m_pMinimizeAction->setEnabled(pActiveWindow != 0);
+        /* If there is active-window: */
+        if (pActiveWindow)
+        {
+            /* Toggle corresponding action on: */
+            if (m_windows.contains(pActiveWindow->windowTitle()))
+                m_windows.value(pActiveWindow->windowTitle())->setChecked(true);
+        }
+        /* If there is no active-window: */
         else
         {
+            /* Make sure corresponding action toggled off: */
             if (QAction *pChecked = m_pGroup->checkedAction())
                 pChecked->setChecked(false);
         }
-
     }
 
@@ -130,16 +146,17 @@
 
     /** Handles request to minimize active-window. */
-    void minimizeActive(bool /* fToggle */)
-    {
-        if (QWidget *pActive = qApp->activeWindow())
-            pActive->showMinimized();
+    void sltMinimizeActiveWindow()
+    {
+        if (QWidget *pActiveWindow = qApp->activeWindow())
+            pActiveWindow->showMinimized();
     }
 
     /** Handles request to raise sender window. */
-    void raiseSender(bool /* fToggle */)
-    {
-        if (QAction *pAction= qobject_cast<QAction*>(sender()))
-        {
-            if (QWidget *pWidget = qVariantValue<QWidget*>(pAction->data()))
+    void sltRaiseSender()
+    {
+        AssertReturnVoid(sender());
+        if (QAction *pAction = qobject_cast<QAction*>(sender()))
+        {
+            if (QWidget *pWidget = pAction->data().value<QWidget*>())
             {
                 pWidget->show();
@@ -159,17 +176,23 @@
     QAction *m_pMinimizeAction;
     /** Holds the hash of the registered menu-helper instances. */
-    QHash<QString, QAction*> m_regWindows;
+    QHash<QString, QAction*> m_windows;
 };
 
+/*********************************************************************************************************************************
+*   Class UIWindowMenuManager implementation.                                                                                    *
+*********************************************************************************************************************************/
+
 /* static */
-UIWindowMenuManager *UIWindowMenuManager::m_pInstance = 0;
+UIWindowMenuManager* UIWindowMenuManager::m_spInstance = 0;
 
 /* static */
-UIWindowMenuManager *UIWindowMenuManager::instance(QWidget *pParent /* = 0 */)
-{
-    if (!m_pInstance)
-        m_pInstance = new UIWindowMenuManager(pParent);
-
-    return m_pInstance;
+UIWindowMenuManager* UIWindowMenuManager::instance()
+{
+    /* Make sure 'Window' menu Manager is created: */
+    if (!m_spInstance)
+        m_spInstance = new UIWindowMenuManager;
+
+    /* Return 'Window' menu Manager: */
+    return m_spInstance;
 }
 
@@ -177,17 +200,19 @@
 void UIWindowMenuManager::destroy()
 {
-    if (!m_pInstance)
-    {
-        delete m_pInstance;
-        m_pInstance = 0;
-    }
+    /* Make sure 'Window' menu Manager is created: */
+    AssertPtrReturnVoid(m_spInstance);
+
+    /* Delete 'Window' menu Manager: */
+    delete m_spInstance;
 }
 
 QMenu *UIWindowMenuManager::createMenu(QWidget *pWindow)
 {
-    UIMenuHelper *pHelper = new UIMenuHelper(m_regWindows);
-
+    /* Create helper: */
+    UIMenuHelper *pHelper = new UIMenuHelper(m_windows);
+    /* Register it: */
     m_helpers[pWindow] = pHelper;
 
+    /* Return menu of created helper: */
     return pHelper->menu();
 }
@@ -195,7 +220,10 @@
 void UIWindowMenuManager::destroyMenu(QWidget *pWindow)
 {
+    /* If window is registered: */
     if (m_helpers.contains(pWindow))
     {
-        delete m_helpers[pWindow];
+        /* Delete helper: */
+        delete m_helpers.value(pWindow);
+        /* Unregister it: */
         m_helpers.remove(pWindow);
     }
@@ -204,5 +232,7 @@
 void UIWindowMenuManager::addWindow(QWidget *pWindow)
 {
-    m_regWindows.append(pWindow);
+    /* Register window: */
+    m_windows.append(pWindow);
+    /* Add window to all menus we have: */
     QHash<QWidget*, UIMenuHelper*>::const_iterator i = m_helpers.constBegin();
     while (i != m_helpers.constEnd())
@@ -215,4 +245,5 @@
 void UIWindowMenuManager::removeWindow(QWidget *pWindow)
 {
+    /* Remove window from all menus we have: */
     QHash<QWidget*, UIMenuHelper*>::const_iterator i = m_helpers.constBegin();
     while (i != m_helpers.constEnd())
@@ -221,9 +252,11 @@
         ++i;
     }
-    m_regWindows.removeAll(pWindow);
+    /* Unregister window: */
+    m_windows.removeAll(pWindow);
 }
 
 void UIWindowMenuManager::retranslateUi()
 {
+    /* Translate all the helpers: */
     QHash<QWidget*, UIMenuHelper*>::const_iterator i = m_helpers.constBegin();
     while (i != m_helpers.constEnd())
@@ -234,7 +267,9 @@
 }
 
-bool UIWindowMenuManager::eventFilter(QObject *pObj, QEvent *pEvent)
-{
-    QEvent::Type type = pEvent->type();
+bool UIWindowMenuManager::eventFilter(QObject *pObject, QEvent *pEvent)
+{
+    /* Acquire event type: */
+    const QEvent::Type type = pEvent->type();
+
 #if defined(VBOX_OSE) || (QT_VERSION < 0x040700)
     /* Stupid Qt: Qt doesn't check if a window is minimized when a command is
@@ -243,8 +278,9 @@
      * window before we let execute the command.
      * Note: fixed in our local Qt build since 4.7.0. */
-    if (type == QEvent::Show)
-    {
-        QWidget *pWidget = (QWidget*)pObj;
-        if (   pWidget->parentWidget()
+    if (pObject && type == QEvent::Show)
+    {
+        QWidget *pWidget = qobject_cast<QWidget*>(pObject);
+        if (   pWidget
+            && pWidget->parentWidget()
             && pWidget->parentWidget()->isMinimized())
         {
@@ -254,5 +290,6 @@
         }
     }
-#endif /* defined(VBOX_OSE) || (QT_VERSION < 0x040700) */
+#endif /* VBOX_OSE || QT_VERSION < 0x040700 */
+
     /* We need to track several events which leads to different window
      * activation and change the menu items in that case. */
@@ -265,24 +302,23 @@
         || type == QEvent::Hide)
     {
-        QWidget *pActive = qApp->activeWindow();
+        QWidget *pActiveWindow = qApp->activeWindow();
         QHash<QWidget*, UIMenuHelper*>::const_iterator i = m_helpers.constBegin();
         while (i != m_helpers.constEnd())
         {
-            i.value()->updateStatus(pActive);
+            i.value()->updateStatus(pActiveWindow);
             ++i;
         }
     }
-    /* Change the strings in all registers window menus */
-    if (   type == QEvent::LanguageChange
-        && pObj == m_pParent)
-        retranslateUi();
-
-    return false;
-}
-
-UIWindowMenuManager::UIWindowMenuManager(QWidget *pParent /* = 0 */)
-  : QObject(pParent)
-  , m_pParent(pParent)
-{
+
+    /* Call to base-class: */
+    return QIWithRetranslateUI3<QObject>::eventFilter(pObject, pEvent);
+}
+
+UIWindowMenuManager::UIWindowMenuManager()
+{
+    /* Assign instance: */
+    m_spInstance = this;
+
+    /* Install global event-filter: */
     qApp->installEventFilter(this);
 }
@@ -290,5 +326,9 @@
 UIWindowMenuManager::~UIWindowMenuManager()
 {
+    /* Cleanup all helpers: */
     qDeleteAll(m_helpers);
+
+    /* Unassign instance: */
+    m_spInstance = 0;
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UIWindowMenuManager.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UIWindowMenuManager.h	(revision 57890)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UIWindowMenuManager.h	(revision 57891)
@@ -23,4 +23,7 @@
 #include <QHash>
 
+/* GUI includes: */
+#include "QIWithRetranslateUI.h"
+
 /* Forward declarations: */
 class UIMenuHelper;
@@ -29,5 +32,5 @@
 /** Singleton QObject extension
   * used as Mac OS X 'Window' menu Manager. */
-class UIWindowMenuManager: public QObject
+class UIWindowMenuManager : public QIWithRetranslateUI3<QObject>
 {
     Q_OBJECT;
@@ -36,10 +39,10 @@
 
     /** Static constructor and instance provider. */
-    static UIWindowMenuManager *instance(QWidget *pParent = 0);
+    static UIWindowMenuManager *instance();
     /** Static destructor. */
     static void destroy();
 
     /** Creates 'Window' menu for passed @a pWindow. */
-    QMenu *createMenu(QWidget *pWindow);
+    QMenu* createMenu(QWidget *pWindow);
     /** Destroys 'Window' menu for passed @a pWindow. */
     void destroyMenu(QWidget *pWindow);
@@ -51,26 +54,23 @@
 
     /** Handles translation event. */
-    void retranslateUi();
+    virtual void retranslateUi();
 
 protected:
 
     /** Preprocesses any Qt @a pEvent for passed @a pObject. */
-    bool eventFilter(QObject *pObj, QEvent *pEvent);
+    bool eventFilter(QObject *pObject, QEvent *pEvent);
 
 private:
 
     /** Constructs 'Window' menu Manager. */
-    UIWindowMenuManager(QWidget *pParent = 0);
+    UIWindowMenuManager();
     /** Destructs 'Window' menu Manager. */
     ~UIWindowMenuManager();
 
     /** Holds the static instance. */
-    static UIWindowMenuManager *m_pInstance;
-
-    /** Holds the passed parent reference. */
-    QWidget *m_pParent;
+    static UIWindowMenuManager *m_spInstance;
 
     /** Holds the list of the registered window references. */
-    QList<QWidget*> m_regWindows;
+    QList<QWidget*> m_windows;
 
     /** Holds the hash of the registered menu-helper instances. */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp	(revision 57890)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp	(revision 57891)
@@ -1212,5 +1212,5 @@
 
 #ifdef Q_WS_MAC
-    menuBar()->addMenu(UIWindowMenuManager::instance(this)->createMenu(this));
+    menuBar()->addMenu(UIWindowMenuManager::instance()->createMenu(this));
 #endif /* Q_WS_MAC */
 
