Index: /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaApplication.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaApplication.h	(revision 71660)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaApplication.h	(revision 71661)
@@ -1,9 +1,9 @@
 /* $Id$ */
 /** @file
- * VBox Qt GUI - UICocoaApplication - C++ interface to NSApplication for handling -sendEvent.
+ * VBox Qt GUI - UICocoaApplication class declaration.
  */
 
 /*
- * Copyright (C) 2009-2017 Oracle Corporation
+ * Copyright (C) 2009-2018 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -16,6 +16,6 @@
  */
 
-#ifndef ___darwin_VBoxCocoaApplication_h
-#define ___darwin_VBoxCocoaApplication_h
+#ifndef ___VBoxCocoaApplication_h___
+#define ___VBoxCocoaApplication_h___
 
 /* Qt includes: */
@@ -26,4 +26,9 @@
 #include "VBoxUtils-darwin.h"
 
+/* Forward declarations: */
+class QObject;
+class QWidget;
+
+/* Cocoa declarations: */
 ADD_COCOA_NATIVE_REF(UICocoaApplicationPrivate);
 ADD_COCOA_NATIVE_REF(NSAutoreleasePool);
@@ -32,14 +37,6 @@
 ADD_COCOA_NATIVE_REF(NSButton);
 
-/* Forward declarations: */
-class QObject;
-class QWidget;
 
-/** Event handler callback.
- * @returns true if handled, false if not.
- * @param   pvCocoaEvent    The Cocoa event.
- * @param   pvCarbonEvent   The Carbon event.
- * @param   pvUser          The user argument.
- */
+/** Event handler callback. */
 typedef bool (*PFNVBOXCACALLBACK)(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
 
@@ -51,14 +48,15 @@
 typedef void (*PfnStandardWindowButtonCallbackForQWidget)(StandardWindowButtonType emnButtonType, bool fWithOptionKey, QWidget *pWidget);
 
-/* C++ singleton for our private NSApplication object. */
+
+/** Singleton prototype for our private NSApplication object. */
 class UICocoaApplication
 {
 public:
 
-    /** Returns singleton access instance. */
-    static UICocoaApplication* instance();
+    /** Returns singleton instance. */
+    static UICocoaApplication *instance();
 
-    /** Destructor. */
-    ~UICocoaApplication();
+    /** Destructs cocoa application. */
+    virtual ~UICocoaApplication();
 
     /** Returns whether application is currently active. */
@@ -97,24 +95,24 @@
 private:
 
-    /** Constructor. */
+    /** Constructs cocoa application. */
     UICocoaApplication();
 
     /** Holds the singleton access instance. */
-    static UICocoaApplication *m_pInstance;
+    static UICocoaApplication *s_pInstance;
 
     /** Holds the private NSApplication instance. */
-    NativeUICocoaApplicationPrivateRef m_pNative;
+    NativeUICocoaApplicationPrivateRef  m_pNative;
     /** Holds the private NSAutoreleasePool instance. */
-    NativeNSAutoreleasePoolRef m_pPool;
+    NativeNSAutoreleasePoolRef          m_pPool;
 
     /** Map of notification callbacks registered for corresponding QObject(s). */
-    QMap<QObject*, QMap<QString, PfnNativeNotificationCallbackForQObject> > m_objectCallbacks;
+    QMap<QObject*, QMap<QString, PfnNativeNotificationCallbackForQObject> >  m_objectCallbacks;
     /** Map of notification callbacks registered for corresponding QWidget(s). */
-    QMap<QWidget*, QMap<QString, PfnNativeNotificationCallbackForQWidget> > m_widgetCallbacks;
+    QMap<QWidget*, QMap<QString, PfnNativeNotificationCallbackForQWidget> >  m_widgetCallbacks;
 
     /** Map of callbacks registered for standard window button(s) of corresponding QWidget(s). */
-    QMap<QWidget*, QMap<StandardWindowButtonType, PfnStandardWindowButtonCallbackForQWidget> > m_stdWindowButtonCallbacks;
+    QMap<QWidget*, QMap<StandardWindowButtonType, PfnStandardWindowButtonCallbackForQWidget> >  m_stdWindowButtonCallbacks;
 };
 
-#endif /* ___darwin_VBoxCocoaApplication_h */
+#endif /* !___VBoxCocoaApplication_h___ */
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaApplication.mm
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaApplication.mm	(revision 71660)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/platform/darwin/UICocoaApplication.mm	(revision 71661)
@@ -1,9 +1,9 @@
 /* $Id$ */
 /** @file
- * VBox Qt GUI - UICocoaApplication - C++ interface to NSApplication for handling -sendEvent.
+ * VBox Qt GUI - UICocoaApplication class implementation.
  */
 
 /*
- * Copyright (C) 2009-2017 Oracle Corporation
+ * Copyright (C) 2009-2018 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -19,29 +19,32 @@
 #include "UICocoaApplication.h"
 
-/* Global includes */
+/* Other VBox includes: */
+#include <iprt/assert.h>
+
+/* External includes: */
+#import <AppKit/NSApplication.h>
+#import <AppKit/NSButton.h>
 #import <AppKit/NSEvent.h>
-#import <AppKit/NSApplication.h>
+#import <AppKit/NSWindow.h>
 #import <Foundation/NSArray.h>
-#import <AppKit/NSWindow.h>
-#import <AppKit/NSButton.h>
-
-#include <iprt/assert.h>
+
 
 /** Class for tracking a callback. */
-@interface CallbackData: NSObject
+@interface CallbackData : NSObject
 {
 @public
-    /** Mask of events to send to this callback. */
-    uint32_t            fMask;
-    /** The callback. */
-    PFNVBOXCACALLBACK   pfnCallback;
-    /** The user argument. */
-    void               *pvUser;
-}
-- (id) initWithMask:(uint32)mask callback:(PFNVBOXCACALLBACK)callback user:(void*)user;
+    /** Holds the mask of events to send to this callback. */
+    uint32_t           fMask;
+    /** Holds the callback. */
+    PFNVBOXCACALLBACK  pfnCallback;
+    /** Holds the user argument. */
+    void              *pvUser;
+}
+- (id)initWithMask :(uint32)mask callback :(PFNVBOXCACALLBACK)callback user :(void *)user;
 @end /* @interface CallbackData  */
 
 @implementation CallbackData
-- (id) initWithMask:(uint32)mask callback:(PFNVBOXCACALLBACK)callback user:(void*)user
+/** Performs initialization. */
+- (id)initWithMask :(uint32)mask callback :(PFNVBOXCACALLBACK)callback user :(void *)user
 {
     self = [super init];
@@ -50,5 +53,5 @@
         fMask = mask;
         pfnCallback = callback;
-        pvUser =  user;
+        pvUser = user;
     }
     return self;
@@ -56,6 +59,7 @@
 @end /* @implementation CallbackData  */
 
-/** Class for event handling */
-@interface UICocoaApplicationPrivate: NSApplication
+
+/** Class for event handling. */
+@interface UICocoaApplicationPrivate : NSApplication
 {
     /** The event mask for which there currently are callbacks. */
@@ -65,23 +69,24 @@
 }
 - (id)init;
-- (void)sendEvent:(NSEvent *)theEvent;
-- (void)setCallback:(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser;
-- (void)unsetCallback:(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser;
-
-- (void)registerToNotificationOfWorkspace :(NSString*)pstrNotificationName;
-- (void)unregisterFromNotificationOfWorkspace :(NSString*)pstrNotificationName;
-
-- (void)registerToNotificationOfWindow :(NSString*)pstrNotificationName :(NSWindow*)pWindow;
-- (void)unregisterFromNotificationOfWindow :(NSString*)pstrNotificationName :(NSWindow*)pWindow;
-
-- (void)notificationCallbackOfObject :(NSNotification*)notification;
-- (void)notificationCallbackOfWindow :(NSNotification*)notification;
-
-- (void)registerSelectorForStandardWindowButton :(NSWindow*)pWindow :(StandardWindowButtonType)enmButtonType;
-- (void)selectorForStandardWindowButton :(NSButton*)pButton;
+- (void)sendEvent :(NSEvent *)theEvent;
+- (void)setCallback :(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser;
+- (void)unsetCallback :(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser;
+
+- (void)registerToNotificationOfWorkspace :(NSString *)pstrNotificationName;
+- (void)unregisterFromNotificationOfWorkspace :(NSString *)pstrNotificationName;
+
+- (void)registerToNotificationOfWindow :(NSString *)pstrNotificationName :(NSWindow *)pWindow;
+- (void)unregisterFromNotificationOfWindow :(NSString *)pstrNotificationName :(NSWindow *)pWindow;
+
+- (void)notificationCallbackOfObject :(NSNotification *)notification;
+- (void)notificationCallbackOfWindow :(NSNotification *)notification;
+
+- (void)registerSelectorForStandardWindowButton :(NSWindow *)pWindow :(StandardWindowButtonType)enmButtonType;
+- (void)selectorForStandardWindowButton :(NSButton *)pButton;
 @end /* @interface UICocoaApplicationPrivate */
 
 @implementation UICocoaApplicationPrivate
--(id) init
+/** Performs initialization. */
+- (id) init
 {
     self = [super init];
@@ -89,6 +94,7 @@
         m_pCallbacks = [[NSMutableArray alloc] init];
 
-    /* Gently disable El Capitan tries to break everything with the Enter Full Screen action.
-     * S.a. https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/ for reference. */
+    // WORKAROUND:
+    // Gently disable El Capitan tries to break everything with the Enter Full Screen action.
+    // S.a. https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/ for reference.
     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSFullScreenMenuItemEverywhere"];
 
@@ -96,9 +102,9 @@
 }
 
--(void) sendEvent:(NSEvent *)pEvent
-{
-    /*
-     * Check if the type matches any of the registered callbacks.
-     */
+/** Sends an event.
+  * @param  pEvent  Brings the event to be sent. */
+- (void) sendEvent :(NSEvent *)pEvent
+{
+    /* Check if the type matches any of the registered callbacks. */
     uint32_t const fMask = m_fMask;
 #if 0 /* for debugging */
@@ -111,7 +117,5 @@
         if (fMask & fEvtMask)
         {
-            /*
-             * Do the callouts in LIFO order.
-             */
+            /* Do the callouts in LIFO order. */
             for (CallbackData *pData in [m_pCallbacks reverseObjectEnumerator])
             {
@@ -126,39 +130,29 @@
     }
 
-    /*
-     * Get on with it.
-     */
+    /* Get on with it. */
     [super sendEvent:pEvent];
 }
 
-/**
- * Register an event callback.
- *
- * @param   fMask           The event mask for which the callback is to be invoked.
- * @param   pfnCallback     The callback function.
- * @param   pvUser          The user argument.
- */
--(void) setCallback: (uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser
-{
-    /* Add the callback data to the array */
-    CallbackData *pData = [[[CallbackData alloc] initWithMask: fMask callback: pfnCallback user: pvUser] autorelease];
-    [m_pCallbacks addObject: pData];
-
-    /* Update the global mask */
+/** Registers an event callback.
+  * @param  fMask        Brings the event mask for which the callback is to be invoked.
+  * @param  pfnCallback  Brings the callback function.
+  * @param  pvUser       Brings the user argument. */
+- (void) setCallback :(uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser
+{
+    /* Add the callback data to the array: */
+    CallbackData *pData = [[[CallbackData alloc] initWithMask:fMask callback:pfnCallback user:pvUser] autorelease];
+    [m_pCallbacks addObject:pData];
+
+    /* Update the global mask: */
     m_fMask |= fMask;
 }
 
-/**
- * Deregister an event callback.
- *
- * @param   fMask           Same as setCallback.
- * @param   pfnCallback     Same as setCallback.
- * @param   pvUser          Same as setCallback.
- */
--(void) unsetCallback: (uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser
-{
-    /*
-     * Loop the event array LIFO fashion searching for a matching callback.
-     */
+/** Deregisters an event callback.
+  * @param  fMask        Brings the event mask for which the callback is to be invoked.
+  * @param  pfnCallback  Brings the callback function.
+  * @param  pvUser       Brings the user argument. */
+- (void) unsetCallback: (uint32_t)fMask :(PFNVBOXCACALLBACK)pfnCallback :(void *)pvUser
+{
+    /* Loop the event array LIFO fashion searching for a matching callback. */
     for (CallbackData *pData in [m_pCallbacks reverseObjectEnumerator])
     {
@@ -167,5 +161,5 @@
             && pData->fMask       == fMask)
         {
-            [m_pCallbacks removeObject: pData];
+            [m_pCallbacks removeObject:pData];
             break;
         }
@@ -177,6 +171,6 @@
 }
 
-/** Register to cocoa notification @a pstrNotificationName. */
-- (void) registerToNotificationOfWorkspace :(NSString*)pstrNotificationName
+/** Registers to cocoa notification @a pstrNotificationName. */
+- (void) registerToNotificationOfWorkspace :(NSString *)pstrNotificationName
 {
     /* Register notification observer: */
@@ -189,5 +183,5 @@
 
 /** Unregister @a pWindow from cocoa notification @a pstrNotificationName. */
-- (void) unregisterFromNotificationOfWorkspace :(NSString*)pstrNotificationName
+- (void) unregisterFromNotificationOfWorkspace :(NSString *)pstrNotificationName
 {
     /* Uninstall notification observer: */
@@ -199,5 +193,5 @@
 
 /** Register @a pWindow to cocoa notification @a pstrNotificationName. */
-- (void) registerToNotificationOfWindow :(NSString*)pstrNotificationName :(NSWindow*)pWindow
+- (void) registerToNotificationOfWindow :(NSString *)pstrNotificationName :(NSWindow *)pWindow
 {
     /* Register notification observer: */
@@ -209,5 +203,5 @@
 
 /** Unregister @a pWindow from cocoa notification @a pstrNotificationName. */
-- (void) unregisterFromNotificationOfWindow :(NSString*)pstrNotificationName :(NSWindow*)pWindow
+- (void) unregisterFromNotificationOfWindow :(NSString *)pstrNotificationName :(NSWindow *)pWindow
 {
     /* Uninstall notification observer: */
@@ -218,5 +212,5 @@
 
 /** Redirects cocoa @a notification to UICocoaApplication instance. */
-- (void) notificationCallbackOfObject :(NSNotification*)notification
+- (void) notificationCallbackOfObject :(NSNotification *)notification
 {
     /* Get current notification name: */
@@ -241,5 +235,5 @@
 
 /** Redirects cocoa @a notification to UICocoaApplication instance. */
-- (void) notificationCallbackOfWindow :(NSNotification*)notification
+- (void) notificationCallbackOfWindow :(NSNotification *)notification
 {
     /* Get current notification name: */
@@ -251,5 +245,5 @@
 
 /** Registers selector for standard window @a enmButtonType of the passed @a pWindow. */
-- (void)registerSelectorForStandardWindowButton :(NSWindow*)pWindow :(StandardWindowButtonType)enmButtonType
+- (void)registerSelectorForStandardWindowButton :(NSWindow *)pWindow :(StandardWindowButtonType)enmButtonType
 {
     /* Retrieve corresponding button: */
@@ -269,11 +263,11 @@
     if (pButton != Nil)
     {
-        [pButton setTarget :self];
-        [pButton setAction :@selector(selectorForStandardWindowButton:)];
+        [pButton setTarget:self];
+        [pButton setAction:@selector(selectorForStandardWindowButton:)];
     }
 }
 
 /** Redirects selector of the standard window @a pButton to UICocoaApplication instance callback. */
-- (void)selectorForStandardWindowButton :(NSButton*)pButton
+- (void)selectorForStandardWindowButton :(NSButton *)pButton
 {
     /* Check if Option key is currently held: */
@@ -285,24 +279,30 @@
 @end /* @implementation UICocoaApplicationPrivate */
 
-/* C++ singleton for our private NSApplication object */
-UICocoaApplication* UICocoaApplication::m_pInstance = 0;
+
+/*********************************************************************************************************************************
+*   Class UICocoaApplication implementation.                                                                                     *
+*********************************************************************************************************************************/
+
+/* static */
+UICocoaApplication* UICocoaApplication::s_pInstance = 0;
 
 /* static */
 UICocoaApplication* UICocoaApplication::instance()
 {
-    if (!m_pInstance)
-        m_pInstance = new UICocoaApplication();
-
-    return m_pInstance;
+    if (!s_pInstance)
+        s_pInstance = new UICocoaApplication;
+
+    return s_pInstance;
 }
 
 UICocoaApplication::UICocoaApplication()
 {
-    /* Make sure our private NSApplication object is created */
+    /* Make sure our private NSApplication object is created: */
     m_pNative = (UICocoaApplicationPrivate*)[UICocoaApplicationPrivate sharedApplication];
-    /* Create one auto release pool which is in place for all the
-       initialization and deinitialization stuff. That is when the
-       NSApplication is not running the run loop (there is a separate auto
-       release pool defined). */
+    // WORKAROUND":
+    // Create one auto release pool which is in place for all the
+    // initialization and deinitialization stuff. That is when the
+    // NSApplication is not running the run loop (there is a separate
+    // auto release pool defined).
     m_pPool = [[NSAutoreleasePool alloc] init];
 }
@@ -394,5 +394,7 @@
 }
 
-void UICocoaApplication::nativeNotificationProxyForObject(NativeNSStringRef pstrNotificationName, const QMap<QString, QString> &userInfo)
+void UICocoaApplication::nativeNotificationProxyForObject(NativeNSStringRef pstrNotificationName,
+                                                          const QMap<QString,
+                                                          QString> &userInfo)
 {
     /* Get notification name: */
@@ -429,5 +431,6 @@
 {
     /* Make sure it is not registered yet: */
-    AssertReturnVoid(!m_stdWindowButtonCallbacks.contains(pWidget) || !m_stdWindowButtonCallbacks.value(pWidget).contains(enmButtonType));
+    AssertReturnVoid(   !m_stdWindowButtonCallbacks.contains(pWidget)
+                     || !m_stdWindowButtonCallbacks.value(pWidget).contains(enmButtonType));
 
     /* Remember callback: */
@@ -442,5 +445,6 @@
 {
     /* Make sure it is registered yet: */
-    AssertReturnVoid(m_stdWindowButtonCallbacks.contains(pWidget) && m_stdWindowButtonCallbacks.value(pWidget).contains(enmButtonType));
+    AssertReturnVoid(   m_stdWindowButtonCallbacks.contains(pWidget)
+                     && m_stdWindowButtonCallbacks.value(pWidget).contains(enmButtonType));
 
     /* Forget callback: */
@@ -452,4 +456,5 @@
 void UICocoaApplication::nativeCallbackProxyForStandardWindowButton(NativeNSButtonRef pButton, bool fWithOptionKey)
 {
+    // WORKAROUND:
     // Why not using nested foreach, will you ask?
     // It's because Qt 4.x has shadowing issue in Q_FOREACH macro.
@@ -461,5 +466,6 @@
     {
         QWidget *pWidget = widgets.at(iWidgetIndex);
-        const QMap<StandardWindowButtonType, PfnStandardWindowButtonCallbackForQWidget> callbacks = m_stdWindowButtonCallbacks.value(pWidget);
+        const QMap<StandardWindowButtonType, PfnStandardWindowButtonCallbackForQWidget> callbacks
+            = m_stdWindowButtonCallbacks.value(pWidget);
         const QList<StandardWindowButtonType> buttonTypes = callbacks.keys();
         for (int iButtonTypeIndex = 0; iButtonTypeIndex < buttonTypes.size(); ++iButtonTypeIndex)
