Index: trunk/src/VBox/Frontends/VirtualBox/src/darwin/UICocoaDockIconPreview.mm
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/darwin/UICocoaDockIconPreview.mm	(revision 30142)
+++ trunk/src/VBox/Frontends/VirtualBox/src/darwin/UICocoaDockIconPreview.mm	(revision 30151)
@@ -152,5 +152,5 @@
         /* The state view */
         mMonitorGlossy = [[NSImageView alloc] initWithFrame:NSRectFromCGRect(p->flipRect(p->m_monitorRect))];
-        [mMonitorGlossy setImage: darwinCGImageToNSImage (p->m_dockMonitorGlossy)];
+        [mMonitorGlossy setImage: ::darwinToNSImageRef(p->m_dockMonitorGlossy)];
         [self addSubview: mMonitorGlossy];
     }
@@ -161,5 +161,5 @@
 - (void)drawRect:(NSRect)aRect;
 {
-    NSImage *dockMonitor = darwinCGImageToNSImage(p->m_dockMonitor);
+    NSImage *dockMonitor = ::darwinToNSImageRef(p->m_dockMonitor);
     [dockMonitor drawInRect:NSRectFromCGRect(p->flipRect(p->m_monitorRect)) fromRect:aRect operation:NSCompositeSourceOver fraction:1.0];
     [dockMonitor release];
@@ -315,5 +315,5 @@
 {
     [self restoreMonitor];
-    NSImage *nsimage = darwinCGImageToNSImage (image);
+    NSImage *nsimage = ::darwinToNSImageRef(image);
     [[mMonitor screenContent] setImage: nsimage];
     [nsimage release];
Index: trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaHelper.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaHelper.h	(revision 30142)
+++ trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaHelper.h	(revision 30151)
@@ -55,15 +55,4 @@
 }
 
-inline NSImage *darwinCGImageToNSImage (const CGImageRef aImage)
-{
-    /* Create a bitmap rep from the image. */
-    NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:aImage];
-    /* Create an NSImage and add the bitmap rep to it */
-    NSImage *image = [[NSImage alloc] init];
-    [image addRepresentation:bitmapRep];
-    [bitmapRep release];
-    return image;
-}
-
 #endif /* __OBJC__ */
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin-cocoa.mm
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin-cocoa.mm	(revision 30142)
+++ trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin-cocoa.mm	(revision 30151)
@@ -34,38 +34,72 @@
 #include "DarwinKeyboard.h"
 
-NativeWindowRef darwinToNativeWindowImpl(NativeViewRef aView)
-{
-    NativeWindowRef window = NULL;
-    if (aView)
-        window = [aView window];
+NativeNSWindowRef darwinToNativeWindowImpl(NativeNSViewRef pView)
+{
+    NativeNSWindowRef window = NULL;
+    if (pView)
+        window = [pView window];
 
     return window;
 }
 
-NativeViewRef darwinToNativeViewImpl(NativeWindowRef aWindow)
-{
-    NativeViewRef view = NULL;
-    if (aWindow)
-        view = [aWindow contentView];
+NativeNSViewRef darwinToNativeViewImpl(NativeNSWindowRef pWindow)
+{
+    NativeNSViewRef view = NULL;
+    if (pWindow)
+        view = [pWindow contentView];
 
     return view;
 }
 
-void darwinSetShowsToolbarButtonImpl(NativeWindowRef aWindow, bool aEnabled)
-{
-    [aWindow setShowsToolbarButton:aEnabled];
-}
-
-void darwinSetShowsResizeIndicatorImpl(NativeWindowRef aWindow, bool aEnabled)
-{
-    [aWindow setShowsResizeIndicator:aEnabled];
-}
-
-void darwinSetHidesAllTitleButtonsImpl(NativeWindowRef aWindow)
+NativeNSImageRef darwinToNSImageRef(const CGImageRef pImage)
+{
+    /* Create a bitmap rep from the image. */
+    NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:pImage];
+    /* Create an NSImage and add the bitmap rep to it */
+    NSImage *image = [[[NSImage alloc] init] autorelease];
+    [image addRepresentation:bitmapRep];
+    return image;
+}
+
+NativeNSImageRef darwinToNSImageRef(const QImage *pImage)
+{
+   CGImageRef pCGImage = ::darwinToCGImageRef(pImage);
+   NativeNSImageRef pNSImage = ::darwinToNSImageRef(pCGImage);
+   CGImageRelease(pCGImage);
+   return pNSImage;
+}
+
+NativeNSImageRef darwinToNSImageRef(const QPixmap *pPixmap)
+{
+   CGImageRef pCGImage = ::darwinToCGImageRef(pPixmap);
+   NativeNSImageRef pNSImage = ::darwinToNSImageRef(pCGImage);
+   CGImageRelease(pCGImage);
+   return pNSImage;
+}
+
+NativeNSImageRef darwinToNSImageRef(const char *pczSource)
+{
+   CGImageRef pCGImage = ::darwinToCGImageRef(pczSource);
+   NativeNSImageRef pNSImage = ::darwinToNSImageRef(pCGImage);
+   CGImageRelease(pCGImage);
+   return pNSImage;
+}
+
+void darwinSetShowsToolbarButtonImpl(NativeNSWindowRef pWindow, bool fEnabled)
+{
+    [pWindow setShowsToolbarButton:fEnabled];
+}
+
+void darwinSetShowsResizeIndicatorImpl(NativeNSWindowRef pWindow, bool fEnabled)
+{
+    [pWindow setShowsResizeIndicator:fEnabled];
+}
+
+void darwinSetHidesAllTitleButtonsImpl(NativeNSWindowRef pWindow)
 {
     /* Remove all title buttons by changing the style mask. This method is
        available from 10.6 on only. */
-    if ([aWindow respondsToSelector: @selector(setStyleMask:)])
-        [aWindow performSelector: @selector(setStyleMask:) withObject: (id)NSTitledWindowMask];
+    if ([pWindow respondsToSelector: @selector(setStyleMask:)])
+        [pWindow performSelector: @selector(setStyleMask:) withObject: (id)NSTitledWindowMask];
     else
     {
@@ -73,32 +107,32 @@
            setHidden cause this remove the buttons, but didn't release the
            place used for the buttons. */
-        NSButton *pButton = [aWindow standardWindowButton:NSWindowCloseButton];
-        if (pButton != Nil)
-            [pButton setEnabled: NO];
-        pButton = [aWindow standardWindowButton:NSWindowMiniaturizeButton];
-        if (pButton != Nil)
-            [pButton setEnabled: NO];
-        pButton = [aWindow standardWindowButton:NSWindowZoomButton];
-        if (pButton != Nil)
-            [pButton setEnabled: NO];
-        pButton = [aWindow standardWindowButton:NSWindowDocumentIconButton];
-        if (pButton != Nil)
-            [pButton setEnabled: NO];
-    }
-}
-
-void darwinSetShowsWindowTransparentImpl(NativeWindowRef aWindow, bool aEnabled)
-{
-    if (aEnabled)
-    {
-        [aWindow setOpaque:NO];
-        [aWindow setBackgroundColor:[NSColor clearColor]];
-        [aWindow setHasShadow:NO];
+        NSButton *pButton = [pWindow standardWindowButton:NSWindowCloseButton];
+        if (pButton != Nil)
+            [pButton setEnabled: NO];
+        pButton = [pWindow standardWindowButton:NSWindowMiniaturizeButton];
+        if (pButton != Nil)
+            [pButton setEnabled: NO];
+        pButton = [pWindow standardWindowButton:NSWindowZoomButton];
+        if (pButton != Nil)
+            [pButton setEnabled: NO];
+        pButton = [pWindow standardWindowButton:NSWindowDocumentIconButton];
+        if (pButton != Nil)
+            [pButton setEnabled: NO];
+    }
+}
+
+void darwinSetShowsWindowTransparentImpl(NativeNSWindowRef pWindow, bool fEnabled)
+{
+    if (fEnabled)
+    {
+        [pWindow setOpaque:NO];
+        [pWindow setBackgroundColor:[NSColor clearColor]];
+        [pWindow setHasShadow:NO];
     }
     else
     {
-        [aWindow setOpaque:YES];
-        [aWindow setBackgroundColor:[NSColor windowBackgroundColor]];
-        [aWindow setHasShadow:YES];
+        [pWindow setOpaque:YES];
+        [pWindow setBackgroundColor:[NSColor windowBackgroundColor]];
+        [pWindow setHasShadow:YES];
     }
 }
@@ -115,19 +149,19 @@
  * @param   fEnabled    Whether to enable or disable coalescing.
  */
-void darwinSetMouseCoalescingEnabled(bool aEnabled)
-{
-    [NSEvent setMouseCoalescingEnabled:aEnabled];
-}
-
-void darwinWindowAnimateResizeImpl(NativeWindowRef aWindow, int x, int y, int width, int height)
+void darwinSetMouseCoalescingEnabled(bool fEnabled)
+{
+    [NSEvent setMouseCoalescingEnabled:fEnabled];
+}
+
+void darwinWindowAnimateResizeImpl(NativeNSWindowRef pWindow, int x, int y, int width, int height)
 {
     /* It seems that Qt doesn't return the height of the window with the
      * toolbar height included. So add this size manually. Could easily be that
      * the Trolls fix this in the final release. */
-    NSToolbar *toolbar = [aWindow toolbar];
-    NSRect windowFrame = [aWindow frame];
+    NSToolbar *toolbar = [pWindow toolbar];
+    NSRect windowFrame = [pWindow frame];
     int toolbarHeight = 0;
     if(toolbar && [toolbar isVisible])
-        toolbarHeight = NSHeight(windowFrame) - NSHeight([[aWindow contentView] frame]);
+        toolbarHeight = NSHeight(windowFrame) - NSHeight([[pWindow contentView] frame]);
     int h = height + toolbarHeight;
     int h1 = h - NSHeight(windowFrame);
@@ -135,27 +169,27 @@
     windowFrame.origin.y -= h1;
 
-    [aWindow setFrame:windowFrame display:YES animate:YES];
-}
-
-void darwinWindowInvalidateShadowImpl(NativeWindowRef aWindow)
-{
-    [aWindow invalidateShadow];
-}
-
-int darwinWindowToolBarHeight(NativeWindowRef aWindow)
-{
-    NSToolbar *toolbar = [aWindow toolbar];
-    NSRect windowFrame = [aWindow frame];
+    [pWindow setFrame:windowFrame display:YES animate:YES];
+}
+
+void darwinWindowInvalidateShadowImpl(NativeNSWindowRef pWindow)
+{
+    [pWindow invalidateShadow];
+}
+
+int darwinWindowToolBarHeight(NativeNSWindowRef pWindow)
+{
+    NSToolbar *toolbar = [pWindow toolbar];
+    NSRect windowFrame = [pWindow frame];
     int toolbarHeight = 0;
-    int theight = (NSHeight([NSWindow contentRectForFrameRect:[aWindow frame] styleMask:[aWindow styleMask]]) - NSHeight([[aWindow contentView] frame]));
+    int theight = (NSHeight([NSWindow contentRectForFrameRect:[pWindow frame] styleMask:[pWindow styleMask]]) - NSHeight([[pWindow contentView] frame]));
     /* toolbar height: */
     if(toolbar && [toolbar isVisible])
         /* title bar height: */
-        toolbarHeight = NSHeight(windowFrame) - NSHeight([[aWindow contentView] frame]) - theight;
+        toolbarHeight = NSHeight(windowFrame) - NSHeight([[pWindow contentView] frame]) - theight;
 
     return toolbarHeight;
 }
 
-bool darwinIsToolbarVisible(NativeWindowRef pWindow)
+bool darwinIsToolbarVisible(NativeNSWindowRef pWindow)
 {
     NSToolbar *pToolbar = [pWindow toolbar];
@@ -164,7 +198,7 @@
 }
 
-bool darwinIsWindowMaximized(NativeWindowRef aWindow)
-{
-    bool fResult = [aWindow isZoomed];
+bool darwinIsWindowMaximized(NativeNSWindowRef pWindow)
+{
+    bool fResult = [pWindow isZoomed];
 
     return fResult;
@@ -205,97 +239,4 @@
     }
     return false;
-}
-
-/**
- * Calls the -(NSUInteger)modifierFlags method on a NSEvent object.
- *
- * @return  The Cocoa event modifier mask.
- * @param   pEvent          The Cocoa event.
- */
-unsigned long darwinEventModifierFlags(ConstNativeNSEventRef pEvent)
-{
-    return [pEvent modifierFlags];
-}
-
-/**
- * Calls the -(NSUInteger)modifierFlags method on a NSEvent object and
- * converts the flags to carbon style.
- *
- * @return  The Carbon modifier mask.
- * @param   pEvent          The Cocoa event.
- */
-uint32_t darwinEventModifierFlagsXlated(ConstNativeNSEventRef pEvent)
-{
-    NSUInteger  fCocoa  = [pEvent modifierFlags];
-    uint32_t    fCarbon = 0;
-    if (fCocoa)
-    {
-        if (fCocoa & NSAlphaShiftKeyMask)
-            fCarbon |= alphaLock;
-        if (fCocoa & (NSShiftKeyMask | NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK))
-        {
-            if (fCocoa & (NX_DEVICERSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK))
-            {
-                if (fCocoa & NX_DEVICERSHIFTKEYMASK)
-                    fCarbon |= rightShiftKey;
-                if (fCocoa & NX_DEVICELSHIFTKEYMASK)
-                    fCarbon |= shiftKey;
-            }
-            else
-                fCarbon |= shiftKey;
-        }
-
-        if (fCocoa & (NSControlKeyMask | NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK))
-        {
-            if (fCocoa & (NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK))
-            {
-                if (fCocoa & NX_DEVICERCTLKEYMASK)
-                    fCarbon |= rightControlKey;
-                if (fCocoa & NX_DEVICELCTLKEYMASK)
-                    fCarbon |= controlKey;
-            }
-            else
-                fCarbon |= controlKey;
-        }
-
-        if (fCocoa & (NSAlternateKeyMask | NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK))
-        {
-            if (fCocoa & (NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK))
-            {
-                if (fCocoa & NX_DEVICERALTKEYMASK)
-                    fCarbon |= rightOptionKey;
-                if (fCocoa & NX_DEVICELALTKEYMASK)
-                    fCarbon |= optionKey;
-            }
-            else
-                fCarbon |= optionKey;
-        }
-
-        if (fCocoa & (NSCommandKeyMask | NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK))
-        {
-            if (fCocoa & (NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK))
-            {
-                if (fCocoa & NX_DEVICERCMDKEYMASK)
-                    fCarbon |= kEventKeyModifierRightCmdKeyMask;
-                if (fCocoa & NX_DEVICELCMDKEYMASK)
-                    fCarbon |= cmdKey;
-            }
-            else
-                fCarbon |= cmdKey;
-        }
-
-        /*
-        if (fCocoa & NSNumericPadKeyMask)
-            fCarbon |= ???;
-
-        if (fCocoa & NSHelpKeyMask)
-            fCarbon |= ???;
-
-        if (fCocoa & NSFunctionKeyMask)
-            fCarbon |= ???;
-        */
-    }
-
-    return fCarbon;
 }
 
@@ -339,178 +280,2 @@
 }
 
-/**
- * Get the name for a Cocoa event type.
- *
- * @returns Read-only name string.
- * @param   eEvtType        The Cocoa event type.
- */
-const char *darwinEventTypeName(unsigned long eEvtType)
-{
-    switch (eEvtType)
-    {
-#define EVT_CASE(nm) case nm: return #nm
-        EVT_CASE(NSLeftMouseDown);
-        EVT_CASE(NSLeftMouseUp);
-        EVT_CASE(NSRightMouseDown);
-        EVT_CASE(NSRightMouseUp);
-        EVT_CASE(NSMouseMoved);
-        EVT_CASE(NSLeftMouseDragged);
-        EVT_CASE(NSRightMouseDragged);
-        EVT_CASE(NSMouseEntered);
-        EVT_CASE(NSMouseExited);
-        EVT_CASE(NSKeyDown);
-        EVT_CASE(NSKeyUp);
-        EVT_CASE(NSFlagsChanged);
-        EVT_CASE(NSAppKitDefined);
-        EVT_CASE(NSSystemDefined);
-        EVT_CASE(NSApplicationDefined);
-        EVT_CASE(NSPeriodic);
-        EVT_CASE(NSCursorUpdate);
-        EVT_CASE(NSScrollWheel);
-        EVT_CASE(NSTabletPoint);
-        EVT_CASE(NSTabletProximity);
-        EVT_CASE(NSOtherMouseDown);
-        EVT_CASE(NSOtherMouseUp);
-        EVT_CASE(NSOtherMouseDragged);
-#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
-        EVT_CASE(NSEventTypeGesture);
-        EVT_CASE(NSEventTypeMagnify);
-        EVT_CASE(NSEventTypeSwipe);
-        EVT_CASE(NSEventTypeRotate);
-        EVT_CASE(NSEventTypeBeginGesture);
-        EVT_CASE(NSEventTypeEndGesture);
-#endif
-#undef EVT_CASE
-        default:
-            return "Unknown!";
-    }
-}
-
-/**
- * Debug helper function for dumping a Cocoa event to stdout.
- *
- * @param   pszPrefix       Message prefix.
- * @param   pEvent          The Cocoa event.
- */
-void darwinPrintEvent(const char *pszPrefix, ConstNativeNSEventRef pEvent)
-{
-    NSEventType         eEvtType = [pEvent type];
-    NSUInteger          fEvtMask = [pEvent modifierFlags];
-    NSWindow           *pEvtWindow = [pEvent window];
-    NSInteger           iEvtWindow = [pEvent windowNumber];
-    NSGraphicsContext  *pEvtGraphCtx = [pEvent context];
-
-    printf("%s%p: Type=%lu Modifiers=%08lx pWindow=%p #Wnd=%ld pGraphCtx=%p %s\n",
-           pszPrefix, (void*)pEvent, (unsigned long)eEvtType, (unsigned long)fEvtMask, (void*)pEvtWindow,
-           (long)iEvtWindow, (void*)pEvtGraphCtx, darwinEventTypeName(eEvtType));
-
-    /* dump type specific into. */
-    switch (eEvtType)
-    {
-        case NSLeftMouseDown:
-        case NSLeftMouseUp:
-        case NSRightMouseDown:
-        case NSRightMouseUp:
-        case NSMouseMoved:
-
-        case NSLeftMouseDragged:
-        case NSRightMouseDragged:
-        case NSMouseEntered:
-        case NSMouseExited:
-            break;
-
-        case NSKeyDown:
-        case NSKeyUp:
-        {
-            NSUInteger i;
-            NSUInteger cch;
-            NSString *pChars = [pEvent characters];
-            NSString *pCharsIgnMod = [pEvent charactersIgnoringModifiers];
-            BOOL fIsARepeat = [pEvent isARepeat];
-            unsigned short KeyCode = [pEvent keyCode];
-
-            printf("    KeyCode=%04x isARepeat=%d", KeyCode, fIsARepeat);
-            if (pChars)
-            {
-                cch = [pChars length];
-                printf(" characters={");
-                for (i = 0; i < cch; i++)
-                    printf(i == 0 ? "%02x" : ",%02x", [pChars characterAtIndex: i]);
-                printf("}");
-            }
-
-            if (pCharsIgnMod)
-            {
-                cch = [pCharsIgnMod length];
-                printf(" charactersIgnoringModifiers={");
-                for (i = 0; i < cch; i++)
-                    printf(i == 0 ? "%02x" : ",%02x", [pCharsIgnMod characterAtIndex: i]);
-                printf("}");
-            }
-            printf("\n");
-            break;
-        }
-
-        case NSFlagsChanged:
-        {
-            NSUInteger fOddBits = NSAlphaShiftKeyMask | NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask
-                                | NSCommandKeyMask | NSNumericPadKeyMask | NSHelpKeyMask | NSFunctionKeyMask
-                                | NX_DEVICELCTLKEYMASK | NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK
-                                | NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK | NX_DEVICELALTKEYMASK
-                                | NX_DEVICERALTKEYMASK | NX_DEVICERCTLKEYMASK;
-
-            printf("    KeyCode=%04x", (int)[pEvent keyCode]);
-#define PRINT_MOD(cnst, nm) do { if (fEvtMask & (cnst)) printf(" %s", #nm); } while (0)
-            /* device-independent: */
-            PRINT_MOD(NSAlphaShiftKeyMask, "AlphaShift");
-            PRINT_MOD(NSShiftKeyMask, "Shift");
-            PRINT_MOD(NSControlKeyMask, "Ctrl");
-            PRINT_MOD(NSAlternateKeyMask, "Alt");
-            PRINT_MOD(NSCommandKeyMask, "Cmd");
-            PRINT_MOD(NSNumericPadKeyMask, "NumLock");
-            PRINT_MOD(NSHelpKeyMask, "Help");
-            PRINT_MOD(NSFunctionKeyMask, "Fn");
-            /* device-dependent (sort of): */
-            PRINT_MOD(NX_DEVICELCTLKEYMASK,   "$L-Ctrl");
-            PRINT_MOD(NX_DEVICELSHIFTKEYMASK, "$L-Shift");
-            PRINT_MOD(NX_DEVICERSHIFTKEYMASK, "$R-Shift");
-            PRINT_MOD(NX_DEVICELCMDKEYMASK,   "$L-Cmd");
-            PRINT_MOD(NX_DEVICERCMDKEYMASK,   "$R-Cmd");
-            PRINT_MOD(NX_DEVICELALTKEYMASK,   "$L-Alt");
-            PRINT_MOD(NX_DEVICERALTKEYMASK,   "$R-Alt");
-            PRINT_MOD(NX_DEVICERCTLKEYMASK,   "$R-Ctrl");
-#undef  PRINT_MOD
-
-            fOddBits = fEvtMask & ~fOddBits;
-            if (fOddBits)
-                printf(" fOddBits=%#08lx", (unsigned long)fOddBits);
-#undef  KNOWN_BITS
-            printf("\n");
-            break;
-        }
-
-        case NSAppKitDefined:
-        case NSSystemDefined:
-        case NSApplicationDefined:
-        case NSPeriodic:
-        case NSCursorUpdate:
-        case NSScrollWheel:
-        case NSTabletPoint:
-        case NSTabletProximity:
-        case NSOtherMouseDown:
-        case NSOtherMouseUp:
-        case NSOtherMouseDragged:
-#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
-        case NSEventTypeGesture:
-        case NSEventTypeMagnify:
-        case NSEventTypeSwipe:
-        case NSEventTypeRotate:
-        case NSEventTypeBeginGesture:
-        case NSEventTypeEndGesture:
-#endif
-        default:
-            printf(" Unknown!\n");
-            break;
-    }
-}
-
Index: trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp	(revision 30142)
+++ trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp	(revision 30151)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2009 Oracle Corporation
+ * Copyright (C) 2006-2010 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -17,4 +17,5 @@
 
 #include "VBoxUtils-darwin.h"
+#include "VBoxCocoaHelper.h"
 #include "UICocoaApplication.h"
 
@@ -35,100 +36,100 @@
 #endif /* QT_VERSION < 0x040400 */
 
-NativeViewRef darwinToNativeView (QWidget *aWidget)
-{
-    return reinterpret_cast<NativeViewRef>(aWidget->winId());
-}
-
-NativeWindowRef darwinToNativeWindow (QWidget *aWidget)
-{
-    return ::darwinToNativeWindowImpl (::darwinToNativeView (aWidget));
-}
-
-NativeWindowRef darwinToNativeWindow (NativeViewRef aView)
-{
-    return ::darwinToNativeWindowImpl (aView);
-}
-
-NativeViewRef darwinToNativeView (NativeWindowRef aWindow)
-{
-    return ::darwinToNativeViewImpl (aWindow);
-}
-
-void darwinSetShowsToolbarButton (QToolBar *aToolBar, bool aEnabled)
+NativeNSViewRef darwinToNativeView(QWidget *pWidget)
+{
+    return reinterpret_cast<NativeNSViewRef>(pWidget->winId());
+}
+
+NativeNSWindowRef darwinToNativeWindow(QWidget *pWidget)
+{
+    return ::darwinToNativeWindowImpl(::darwinToNativeView(pWidget));
+}
+
+NativeNSWindowRef darwinToNativeWindow(NativeNSViewRef aView)
+{
+    return ::darwinToNativeWindowImpl(aView);
+}
+
+NativeNSViewRef darwinToNativeView(NativeNSWindowRef aWindow)
+{
+    return ::darwinToNativeViewImpl(aWindow);
+}
+
+void darwinSetShowsToolbarButton(QToolBar *aToolBar, bool fEnabled)
 {
     QWidget *parent = aToolBar->parentWidget();
     if (parent)
-        ::darwinSetShowsToolbarButtonImpl (::darwinToNativeWindow (parent), aEnabled);
-}
-
-void darwinSetHidesAllTitleButtons (QWidget *aWidget)
+        ::darwinSetShowsToolbarButtonImpl(::darwinToNativeWindow(parent), fEnabled);
+}
+
+void darwinSetHidesAllTitleButtons(QWidget *pWidget)
 {
 #ifdef QT_MAC_USE_COCOA
     /* Currently only necessary in the Cocoa version */
-    ::darwinSetHidesAllTitleButtonsImpl (::darwinToNativeWindow (aWidget));
+    ::darwinSetHidesAllTitleButtonsImpl(::darwinToNativeWindow(pWidget));
 #else /* QT_MAC_USE_COCOA */
-    NOREF (aWidget);
+    NOREF(pWidget);
 #endif /* !QT_MAC_USE_COCOA */
 }
 
-void darwinSetShowsWindowTransparent (QWidget *aWidget, bool aEnabled)
-{
-    ::darwinSetShowsWindowTransparentImpl (::darwinToNativeWindow (aWidget), aEnabled);
-}
-
-void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget)
-{
-    ::darwinWindowAnimateResizeImpl (::darwinToNativeWindow (aWidget), aTarget.x(), aTarget.y(), aTarget.width(), aTarget.height());
-}
-
-void darwinWindowInvalidateShape (QWidget *aWidget)
+void darwinSetShowsWindowTransparent(QWidget *pWidget, bool fEnabled)
+{
+    ::darwinSetShowsWindowTransparentImpl(::darwinToNativeWindow(pWidget), fEnabled);
+}
+
+void darwinWindowAnimateResize(QWidget *pWidget, const QRect &aTarget)
+{
+    ::darwinWindowAnimateResizeImpl(::darwinToNativeWindow(pWidget), aTarget.x(), aTarget.y(), aTarget.width(), aTarget.height());
+}
+
+void darwinWindowInvalidateShape(QWidget *pWidget)
 {
 #ifdef QT_MAC_USE_COCOA
     /* Here a simple update is enough! */
-    aWidget->update();
+    pWidget->update();
 #else /* QT_MAC_USE_COCOA */
-    ::darwinWindowInvalidateShapeImpl (::darwinToNativeWindow (aWidget));
+    ::darwinWindowInvalidateShapeImpl(::darwinToNativeWindow(pWidget));
 #endif /* QT_MAC_USE_COCOA */
 }
 ;
-void darwinWindowInvalidateShadow (QWidget *aWidget)
+void darwinWindowInvalidateShadow(QWidget *pWidget)
 {
 #ifdef QT_MAC_USE_COCOA
-    ::darwinWindowInvalidateShadowImpl (::darwinToNativeWindow (aWidget));
+    ::darwinWindowInvalidateShadowImpl(::darwinToNativeWindow(pWidget));
 #else /* QT_MAC_USE_COCOA */
-    NOREF (aWidget);
+    NOREF(pWidget);
 #endif /* QT_MAC_USE_COCOA */
 }
 
-void darwinSetShowsResizeIndicator (QWidget *aWidget, bool aEnabled)
-{
-    ::darwinSetShowsResizeIndicatorImpl (::darwinToNativeWindow (aWidget), aEnabled);
-}
-
-bool darwinIsWindowMaximized(QWidget *aWidget)
+void darwinSetShowsResizeIndicator(QWidget *pWidget, bool fEnabled)
+{
+    ::darwinSetShowsResizeIndicatorImpl(::darwinToNativeWindow(pWidget), fEnabled);
+}
+
+bool darwinIsWindowMaximized(QWidget *pWidget)
 {
 #ifdef QT_MAC_USE_COCOA
     /* Currently only necessary in the Cocoa version */
-    return ::darwinIsWindowMaximized(::darwinToNativeWindow(aWidget));
+    return ::darwinIsWindowMaximized(::darwinToNativeWindow(pWidget));
 #else /* QT_MAC_USE_COCOA */
-    NOREF (aWidget);
+    NOREF(pWidget);
     return false;
 #endif /* !QT_MAC_USE_COCOA */
 }
 
-QString darwinSystemLanguage (void)
+QString darwinSystemLanguage(void)
 {
     /* Get the locales supported by our bundle */
-    CFArrayRef supportedLocales = ::CFBundleCopyBundleLocalizations (::CFBundleGetMainBundle());
+    CFArrayRef supportedLocales = ::CFBundleCopyBundleLocalizations(::CFBundleGetMainBundle());
     /* Check them against the languages currently selected by the user */
-    CFArrayRef preferredLocales = ::CFBundleCopyPreferredLocalizationsFromArray (supportedLocales);
+    CFArrayRef preferredLocales = ::CFBundleCopyPreferredLocalizationsFromArray(supportedLocales);
     /* Get the one which is on top */
-    CFStringRef localeId = (CFStringRef)::CFArrayGetValueAtIndex (preferredLocales, 0);
+    CFStringRef localeId = (CFStringRef)::CFArrayGetValueAtIndex(preferredLocales, 0);
     /* Convert them to a C-string */
     char localeName[20];
-    ::CFStringGetCString (localeId, localeName, sizeof (localeName), kCFStringEncodingUTF8);
+    ::CFStringGetCString(localeId, localeName, sizeof(localeName), kCFStringEncodingUTF8);
     /* Some cleanup */
-    ::CFRelease (supportedLocales);
-    ::CFRelease (preferredLocales);
+    ::CFRelease(supportedLocales);
+    ::CFRelease(preferredLocales);
     QString id(localeName);
     /* Check for some misbehavior */
@@ -139,21 +140,21 @@
 }
 
-void darwinDisableIconsInMenus (void)
+void darwinDisableIconsInMenus(void)
 {
     /* No icons in the menu of a mac application. */
 #if QT_VERSION < 0x040400
-    qt_mac_set_menubar_icons (false);
+    qt_mac_set_menubar_icons(false);
 #else /* QT_VERSION < 0x040400 */
     /* Available since Qt 4.4 only */
-    QApplication::instance()->setAttribute (Qt::AA_DontShowIconsInMenus, true);
+    QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, true);
 #endif /* QT_VERSION >= 0x040400 */
 }
 
-int darwinWindowToolBarHeight (QWidget *aWidget)
+int darwinWindowToolBarHeight(QWidget *pWidget)
 {
 #ifndef QT_MAC_USE_COCOA
-    return ::darwinWindowToolBarHeight (::darwinToNativeWindow (aWidget));
+    return ::darwinWindowToolBarHeight(::darwinToNativeWindow(pWidget));
 #else /* QT_MAC_USE_COCOA */
-    NOREF (aWidget);
+    NOREF(pWidget);
     return 0;
 #endif /* QT_MAC_USE_COCOA */
@@ -185,24 +186,24 @@
 }
 
-CGContextRef darwinToCGContextRef (QWidget *aWidget)
-{
-    return static_cast<CGContext *> (aWidget->macCGHandle());
+CGContextRef darwinToCGContextRef(QWidget *pWidget)
+{
+    return static_cast<CGContext *>(pWidget->macCGHandle());
 }
 
 /* Proxy icon creation */
-QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText)
-{
-    QFontMetrics fm (qApp->font());
-    QRect tbRect = fm.boundingRect (aText);
-    const int h = qMax (aPixmap.height(), fm.ascent() + 1);
+QPixmap darwinCreateDragPixmap(const QPixmap& aPixmap, const QString &aText)
+{
+    QFontMetrics fm(qApp->font());
+    QRect tbRect = fm.boundingRect(aText);
+    const int h = qMax(aPixmap.height(), fm.ascent() + 1);
     const int m = 2;
-    QPixmap dragPixmap (aPixmap.width() + tbRect.width() + m, h);
-    dragPixmap.fill (Qt::transparent);
-    QPainter painter (&dragPixmap);
-    painter.drawPixmap (0, qAbs (h - aPixmap.height()) / 2.0, aPixmap);
-    painter.setPen (Qt::white);
-    painter.drawText (QRect (aPixmap.width() + m, 1, tbRect.width(), h - 1), Qt::AlignLeft | Qt::AlignVCenter, aText);
-    painter.setPen (Qt::black);
-    painter.drawText (QRect (aPixmap.width() + m, 0, tbRect.width(), h - 1), Qt::AlignLeft | Qt::AlignVCenter, aText);
+    QPixmap dragPixmap(aPixmap.width() + tbRect.width() + m, h);
+    dragPixmap.fill(Qt::transparent);
+    QPainter painter(&dragPixmap);
+    painter.drawPixmap(0, qAbs(h - aPixmap.height()) / 2.0, aPixmap);
+    painter.setPen(Qt::white);
+    painter.drawText(QRect(aPixmap.width() + m, 1, tbRect.width(), h - 1), Qt::AlignLeft | Qt::AlignVCenter, aText);
+    painter.setPen(Qt::black);
+    painter.drawText(QRect(aPixmap.width() + m, 0, tbRect.width(), h - 1), Qt::AlignLeft | Qt::AlignVCenter, aText);
     painter.end();
     return dragPixmap;
@@ -215,5 +216,5 @@
  * @param   info        Pointer to the QImage.
  */
-static void darwinDataProviderReleaseQImage (void *info, const void *, size_t)
+static void darwinDataProviderReleaseQImage(void *info, const void *, size_t)
 {
     QImage *qimg = (QImage *)info;
@@ -227,23 +228,23 @@
  * @param   aPixmap     Pointer to the QPixmap instance to convert.
  */
-CGImageRef darwinToCGImageRef (const QImage *aImage)
-{
-    QImage *imageCopy = new QImage (*aImage);
+CGImageRef darwinToCGImageRef(const QImage *pImage)
+{
+    QImage *imageCopy = new QImage(*pImage);
     /** @todo this code assumes 32-bit image input, the lazy bird convert image to 32-bit method is anything but optimal... */
     if (imageCopy->format() != QImage::Format_ARGB32)
-        *imageCopy = imageCopy->convertToFormat (QImage::Format_ARGB32);
-    Assert (!imageCopy->isNull());
+        *imageCopy = imageCopy->convertToFormat(QImage::Format_ARGB32);
+    Assert(!imageCopy->isNull());
 
     CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
-    CGDataProviderRef dp = CGDataProviderCreateWithData (imageCopy, aImage->bits(), aImage->numBytes(), darwinDataProviderReleaseQImage);
+    CGDataProviderRef dp = CGDataProviderCreateWithData(imageCopy, pImage->bits(), pImage->numBytes(), darwinDataProviderReleaseQImage);
 
     CGBitmapInfo bmpInfo = kCGImageAlphaFirst | kCGBitmapByteOrder32Host;
-    CGImageRef ir = CGImageCreate (imageCopy->width(), imageCopy->height(), 8, 32, imageCopy->bytesPerLine(), cs,
+    CGImageRef ir = CGImageCreate(imageCopy->width(), imageCopy->height(), 8, 32, imageCopy->bytesPerLine(), cs,
                                    bmpInfo, dp, 0 /*decode */, 0 /* shouldInterpolate */,
                                    kCGRenderingIntentDefault);
-    CGColorSpaceRelease (cs);
-    CGDataProviderRelease (dp);
-
-    Assert (ir);
+    CGColorSpaceRelease(cs);
+    CGDataProviderRelease(dp);
+
+    Assert(ir);
     return ir;
 }
@@ -255,19 +256,19 @@
  * @param   aPixmap     Pointer to the QPixmap instance to convert.
  */
-CGImageRef darwinToCGImageRef (const QPixmap *aPixmap)
+CGImageRef darwinToCGImageRef(const QPixmap *pPixmap)
 {
     /* It seems Qt releases the memory to an returned CGImageRef when the
      * associated QPixmap is destroyed. This shouldn't happen as long a
      * CGImageRef has a retrain count. As a workaround we make a real copy. */
-    int bitmapBytesPerRow = aPixmap->width() * 4;
-    int bitmapByteCount = (bitmapBytesPerRow * aPixmap->height());
+    int bitmapBytesPerRow = pPixmap->width() * 4;
+    int bitmapByteCount = (bitmapBytesPerRow * pPixmap->height());
     /* Create a memory block for the temporary image. It is initialized by zero
      * which means black & zero alpha. */
-    void *pBitmapData = RTMemAllocZ (bitmapByteCount);
+    void *pBitmapData = RTMemAllocZ(bitmapByteCount);
     CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
     /* Create a context to paint on */
-    CGContextRef ctx = CGBitmapContextCreate (pBitmapData,
-                                              aPixmap->width(),
-                                              aPixmap->height(),
+    CGContextRef ctx = CGBitmapContextCreate(pBitmapData,
+                                              pPixmap->width(),
+                                              pPixmap->height(),
                                               8,
                                               bitmapBytesPerRow,
@@ -275,13 +276,13 @@
                                               kCGImageAlphaPremultipliedFirst);
     /* Get the CGImageRef from Qt */
-    CGImageRef qtPixmap = aPixmap->toMacCGImageRef();
+    CGImageRef qtPixmap = pPixmap->toMacCGImageRef();
     /* Draw the image from Qt & convert the context back to a new CGImageRef. */
-    CGContextDrawImage (ctx, CGRectMake (0, 0, aPixmap->width(), aPixmap->height()), qtPixmap);
-    CGImageRef newImage = CGBitmapContextCreateImage (ctx);
+    CGContextDrawImage(ctx, CGRectMake(0, 0, pPixmap->width(), pPixmap->height()), qtPixmap);
+    CGImageRef newImage = CGBitmapContextCreateImage(ctx);
     /* Now release all used resources */
-    CGImageRelease (qtPixmap);
-    CGContextRelease (ctx);
-    CGColorSpaceRelease (cs);
-    RTMemFree (pBitmapData);
+    CGImageRelease(qtPixmap);
+    CGContextRelease(ctx);
+    CGColorSpaceRelease(cs);
+    RTMemFree(pBitmapData);
 
     /* Return the new CGImageRef */
@@ -295,9 +296,9 @@
  * @param   aSource     The source name.
  */
-CGImageRef darwinToCGImageRef (const char *aSource)
-{
-    QPixmap qpm (QString(":/") + aSource);
-    Assert (!qpm.isNull());
-    return ::darwinToCGImageRef (&qpm);
+CGImageRef darwinToCGImageRef(const char *pczSource)
+{
+    QPixmap qpm(QString(":/") + pczSource);
+    Assert(!qpm.isNull());
+    return ::darwinToCGImageRef(&qpm);
 }
 
@@ -330,5 +331,5 @@
 
 # define MY_CASE(a) case a: return #a
-const char * DarwinDebugEventName (UInt32 ekind)
+const char * DarwinDebugEventName(UInt32 ekind)
 {
     switch (ekind)
@@ -432,5 +433,5 @@
  * 'Developer/Headers/CFMCarbon/CarbonEvents.h' to
  * identify the event. */
-const char * darwinDebugClassName (UInt32 eclass)
+const char * darwinDebugClassName(UInt32 eclass)
 {
     char *pclass = (char*)&eclass;
@@ -443,9 +444,9 @@
 }
 
-void darwinDebugPrintEvent (const char *psz, EventRef evtRef)
+void darwinDebugPrintEvent(const char *psz, EventRef evtRef)
 {
   if (!evtRef)
       return;
-  UInt32 ekind = GetEventKind (evtRef), eclass = GetEventClass (evtRef);
+  UInt32 ekind = GetEventKind(evtRef), eclass = GetEventClass(evtRef);
   if (eclass == kEventClassWindow)
   {
@@ -463,5 +464,5 @@
               GetEventParameter(evtRef, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &wid);
               QWidget *widget = QWidget::find((WId)wid);
-              printf("%d %s: (%s) %#x win=%p wid=%p (%s)\n", (int)time(NULL), psz, darwinDebugClassName (eclass), (uint)ekind, wid, widget, DarwinDebugEventName (ekind));
+              printf("%d %s: (%s) %#x win=%p wid=%p (%s)\n", (int)time(NULL), psz, darwinDebugClassName(eclass), (uint)ekind, wid, widget, DarwinDebugEventName(ekind));
               break;
           }
@@ -483,18 +484,18 @@
               break;
       }
-      printf("%d %s: (%s) %#x win=%p wid=%p (%s)\n", (int)time(NULL), psz, darwinDebugClassName (eclass), (uint)ekind, wid, widget, name);
+      printf("%d %s: (%s) %#x win=%p wid=%p (%s)\n", (int)time(NULL), psz, darwinDebugClassName(eclass), (uint)ekind, wid, widget, name);
   }
   else if (eclass == kEventClassKeyboard)
   {
-      printf("%d %s: %#x(%s) %#x (kEventClassKeyboard)", (int)time(NULL), psz, (uint)eclass, darwinDebugClassName (eclass), (uint)ekind);
+      printf("%d %s: %#x(%s) %#x (kEventClassKeyboard)", (int)time(NULL), psz, (uint)eclass, darwinDebugClassName(eclass), (uint)ekind);
 
       UInt32 keyCode = 0;
-      ::GetEventParameter (evtRef, kEventParamKeyCode, typeUInt32, NULL,
-                           sizeof (keyCode), NULL, &keyCode);
+      ::GetEventParameter(evtRef, kEventParamKeyCode, typeUInt32, NULL,
+                           sizeof(keyCode), NULL, &keyCode);
       printf(" keyCode=%d (%#x) ", (int)keyCode, (unsigned)keyCode);
 
       char macCharCodes[8] = {0,0,0,0, 0,0,0,0};
-      ::GetEventParameter (evtRef, kEventParamKeyCode, typeChar, NULL,
-                           sizeof (macCharCodes), NULL, &macCharCodes[0]);
+      ::GetEventParameter(evtRef, kEventParamKeyCode, typeChar, NULL,
+                           sizeof(macCharCodes), NULL, &macCharCodes[0]);
       printf(" macCharCodes={");
       for (unsigned i =0; i < 8 && macCharCodes[i]; i++)
@@ -503,11 +504,11 @@
 
       UInt32 modifierMask = 0;
-      ::GetEventParameter (evtRef, kEventParamKeyModifiers, typeUInt32, NULL,
-                           sizeof (modifierMask), NULL, &modifierMask);
+      ::GetEventParameter(evtRef, kEventParamKeyModifiers, typeUInt32, NULL,
+                           sizeof(modifierMask), NULL, &modifierMask);
       printf(" modifierMask=%08x", (unsigned)modifierMask);
 
       UniChar keyUnicodes[8] = {0,0,0,0, 0,0,0,0};
-      ::GetEventParameter (evtRef, kEventParamKeyUnicodes, typeUnicodeText, NULL,
-                           sizeof (keyUnicodes), NULL, &keyUnicodes[0]);
+      ::GetEventParameter(evtRef, kEventParamKeyUnicodes, typeUnicodeText, NULL,
+                           sizeof(keyUnicodes), NULL, &keyUnicodes[0]);
       printf(" keyUnicodes={");
       for (unsigned i =0; i < 8 && keyUnicodes[i]; i++)
@@ -516,16 +517,16 @@
 
       UInt32 keyboardType = 0;
-      ::GetEventParameter (evtRef, kEventParamKeyboardType, typeUInt32, NULL,
-                           sizeof (keyboardType), NULL, &keyboardType);
+      ::GetEventParameter(evtRef, kEventParamKeyboardType, typeUInt32, NULL,
+                           sizeof(keyboardType), NULL, &keyboardType);
       printf(" keyboardType=%08x", (unsigned)keyboardType);
 
       EventHotKeyID evtHotKeyId = {0,0};
-      ::GetEventParameter (evtRef, typeEventHotKeyID, typeEventHotKeyID, NULL,
-                           sizeof (evtHotKeyId), NULL, &evtHotKeyId);
+      ::GetEventParameter(evtRef, typeEventHotKeyID, typeEventHotKeyID, NULL,
+                           sizeof(evtHotKeyId), NULL, &evtHotKeyId);
       printf(" evtHotKeyId={signature=%08x, .id=%08x}", (unsigned)evtHotKeyId.signature, (unsigned)evtHotKeyId.id);
       printf("\n");
   }
   else
-      printf("%d %s: %#x(%s) %#x\n", (int)time(NULL), psz, (uint)eclass, darwinDebugClassName (eclass), (uint)ekind);
+      printf("%d %s: %#x(%s) %#x\n", (int)time(NULL), psz, (uint)eclass, darwinDebugClassName(eclass), (uint)ekind);
 }
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.h	(revision 30142)
+++ trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.h	(revision 30151)
@@ -21,42 +21,21 @@
 #define ___VBoxUtils_darwin_h
 
-/*
- * Here is some really magic in. The "OS System native" methods are implemented
- * in the current OS specific way. This means either Carbon
- * (VBoxUtils-darwin-carbon.cpp) or Cocoa (VBoxUtils-darwin-cocoa.m). The Qt
- * wrapper methods handle the conversion from Q* data types to the native one
- * (VBoxUtils-darwin.cpp).
- */
-
-#ifdef __OBJC__
-#import <AppKit/NSWindow.h>
-
-typedef NSWindow *NativeWindowRef;
-typedef NSView *NativeViewRef;
-#else
-
-# include <qglobal.h> /* for QT_MAC_USE_COCOA */
-# include <ApplicationServices/ApplicationServices.h>
-
-class QMainWindow;
-class QToolBar;
-class QPixmap;
-class QImage;
-class QMenu;
-
-# ifdef QT_MAC_USE_COCOA
-/* Cast this to void, cause Cocoa classes aren't usable in the C++ context. */
-typedef void *NativeWindowRef;
-typedef void *NativeViewRef;
-# endif /* QT_MAC_USE_COCOA */
-#endif /* __OBJC__ */
-
 #include <VBox/VBoxCocoa.h>
 #include <iprt/cdefs.h> /* for RT_C_DECLS_BEGIN/RT_C_DECLS_END & stuff */
+
+#include <ApplicationServices/ApplicationServices.h>
 #include <QRect>
 
+ADD_COCOA_NATIVE_REF(NSEvent);
+ADD_COCOA_NATIVE_REF(NSImage);
+ADD_COCOA_NATIVE_REF(NSView);
+ADD_COCOA_NATIVE_REF(NSWindow);
+
+class QImage;
+class QMainWindow;
+class QMenu;
+class QPixmap;
+class QToolBar;
 class QWidget;
-
-ADD_COCOA_NATIVE_REF(NSEvent);
 
 RT_C_DECLS_BEGIN
@@ -67,6 +46,6 @@
  *
  ********************************************************************************/
-NativeWindowRef darwinToNativeWindowImpl(NativeViewRef aView);
-NativeViewRef darwinToNativeViewImpl(NativeWindowRef aWindow);
+NativeNSWindowRef darwinToNativeWindowImpl(NativeNSViewRef pView);
+NativeNSViewRef darwinToNativeViewImpl(NativeNSWindowRef pWindow);
 
 /********************************************************************************
@@ -75,9 +54,9 @@
  *
  ********************************************************************************/
-void darwinSetShowsToolbarButtonImpl(NativeWindowRef aWindow, bool aEnabled);
-void darwinSetShowsResizeIndicatorImpl(NativeWindowRef aWindow, bool aEnabled);
-void darwinSetHidesAllTitleButtonsImpl(NativeWindowRef aWindow);
-void darwinSetShowsWindowTransparentImpl(NativeWindowRef aWindow, bool aEnabled);
-void darwinSetMouseCoalescingEnabled(bool aEnabled);
+void darwinSetShowsToolbarButtonImpl(NativeNSWindowRef pWindow, bool fEnabled);
+void darwinSetShowsResizeIndicatorImpl(NativeNSWindowRef pWindow, bool fEnabled);
+void darwinSetHidesAllTitleButtonsImpl(NativeNSWindowRef pWindow);
+void darwinSetShowsWindowTransparentImpl(NativeNSWindowRef pWindow, bool fEnabled);
+void darwinSetMouseCoalescingEnabled(bool fEnabled);
 
 /********************************************************************************
@@ -86,10 +65,10 @@
  *
  ********************************************************************************/
-void darwinWindowAnimateResizeImpl(NativeWindowRef aWindow, int x, int y, int width, int height);
-void darwinWindowInvalidateShapeImpl(NativeWindowRef aWindow);
-void darwinWindowInvalidateShadowImpl(NativeWindowRef aWindow);
-int  darwinWindowToolBarHeight(NativeWindowRef aWindow);
-bool darwinIsToolbarVisible(NativeWindowRef pWindow);
-bool darwinIsWindowMaximized(NativeWindowRef aWindow);
+void darwinWindowAnimateResizeImpl(NativeNSWindowRef pWindow, int x, int y, int width, int height);
+void darwinWindowInvalidateShapeImpl(NativeNSWindowRef pWindow);
+void darwinWindowInvalidateShadowImpl(NativeNSWindowRef pWindow);
+int  darwinWindowToolBarHeight(NativeNSWindowRef pWindow);
+bool darwinIsToolbarVisible(NativeNSWindowRef pWindow);
+bool darwinIsWindowMaximized(NativeNSWindowRef pWindow);
 
 float darwinSmallFontSize();
@@ -114,5 +93,4 @@
 }
 
-
 /********************************************************************************
  *
@@ -125,7 +103,7 @@
  *
  * @returns either HIViewRef or NSView* of the QWidget.
- * @param   aWidget   Pointer to the QWidget
+ * @param   pWidget   Pointer to the QWidget
  */
-NativeViewRef darwinToNativeView(QWidget *aWidget);
+NativeNSViewRef darwinToNativeView(QWidget *pWidget);
 
 /**
@@ -133,7 +111,7 @@
  *
  * @returns either WindowRef or NSWindow* of the QWidget.
- * @param   aWidget   Pointer to the QWidget
+ * @param   pWidget   Pointer to the QWidget
  */
-NativeWindowRef darwinToNativeWindow(QWidget *aWidget);
+NativeNSWindowRef darwinToNativeWindow(QWidget *pWidget);
 
 /* This is necessary because of the C calling convention. Its a simple wrapper
@@ -144,7 +122,7 @@
  *
  * @returns either WindowRef or NSWindow* of the View.
- * @param   aWidget   Pointer to the native View
+ * @param   pWidget   Pointer to the native View
  */
-NativeWindowRef darwinToNativeWindow(NativeViewRef aView);
+NativeNSWindowRef darwinToNativeWindow(NativeNSViewRef pView);
 
 /**
@@ -152,37 +130,7 @@
  *
  * @returns either HIViewRef or NSView* of the Window.
- * @param   aWidget   Pointer to the native Window
+ * @param   pWidget   Pointer to the native Window
  */
-NativeViewRef darwinToNativeView(NativeWindowRef aWindow);
-
-#ifndef __OBJC__
-/********************************************************************************
- *
- * Simple setter methods (Qt Wrapper)
- *
- ********************************************************************************/
-void darwinSetShowsToolbarButton(QToolBar *aToolBar, bool aEnabled);
-void darwinSetShowsResizeIndicator(QWidget *aWidget, bool aEnabled);
-void darwinSetHidesAllTitleButtons(QWidget *aWidget);
-void darwinSetShowsWindowTransparent(QWidget *aWidget, bool aEnabled);
-void darwinSetDockIconMenu(QMenu *pMenu);
-void darwinDisableIconsInMenus(void);
-
-/********************************************************************************
- *
- * Simple helper methods (Qt Wrapper)
- *
- ********************************************************************************/
-void darwinWindowAnimateResize(QWidget *aWidget, const QRect &aTarget);
-void darwinWindowInvalidateShape(QWidget *aWidget);
-void darwinWindowInvalidateShadow(QWidget *aWidget);
-int  darwinWindowToolBarHeight(QWidget *aWidget);
-bool darwinIsToolbarVisible(QToolBar *pToolBar);
-bool darwinIsWindowMaximized(QWidget *aWidget);
-QString darwinSystemLanguage(void);
-QPixmap darwinCreateDragPixmap(const QPixmap& aPixmap, const QString &aText);
-
-void darwinRegisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
-void darwinUnregisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
+NativeNSViewRef darwinToNativeView(NativeNSWindowRef pWindow);
 
 /********************************************************************************
@@ -195,12 +143,45 @@
  *
  * @returns CGContextRef of the QWidget.
- * @param   aWidget      Pointer to the QWidget
+ * @param   pWidget      Pointer to the QWidget
  */
-CGContextRef darwinToCGContextRef(QWidget *aWidget);
+CGContextRef darwinToCGContextRef(QWidget *pWidget);
+CGImageRef darwinToCGImageRef(const QImage *pImage);
+CGImageRef darwinToCGImageRef(const QPixmap *pPixmap);
+CGImageRef darwinToCGImageRef(const char *pczSource);
 
-CGImageRef darwinToCGImageRef(const QImage *aImage);
-CGImageRef darwinToCGImageRef(const QPixmap *aPixmap);
-CGImageRef darwinToCGImageRef(const char *aSource);
+NativeNSImageRef darwinToNSImageRef(const CGImageRef pImage);
+NativeNSImageRef darwinToNSImageRef(const QImage *pImage);
+NativeNSImageRef darwinToNSImageRef(const QPixmap *pPixmap);
+NativeNSImageRef darwinToNSImageRef(const char *pczSource);
 
+#ifndef __OBJC__
+/********************************************************************************
+ *
+ * Simple setter methods (Qt Wrapper)
+ *
+ ********************************************************************************/
+void darwinSetShowsToolbarButton(QToolBar *aToolBar, bool fEnabled);
+void darwinSetShowsResizeIndicator(QWidget *pWidget, bool fEnabled);
+void darwinSetHidesAllTitleButtons(QWidget *pWidget);
+void darwinSetShowsWindowTransparent(QWidget *pWidget, bool fEnabled);
+void darwinSetDockIconMenu(QMenu *pMenu);
+void darwinDisableIconsInMenus(void);
+
+/********************************************************************************
+ *
+ * Simple helper methods (Qt Wrapper)
+ *
+ ********************************************************************************/
+void darwinWindowAnimateResize(QWidget *pWidget, const QRect &aTarget);
+void darwinWindowInvalidateShape(QWidget *pWidget);
+void darwinWindowInvalidateShadow(QWidget *pWidget);
+int  darwinWindowToolBarHeight(QWidget *pWidget);
+bool darwinIsToolbarVisible(QToolBar *pToolBar);
+bool darwinIsWindowMaximized(QWidget *pWidget);
+QString darwinSystemLanguage(void);
+QPixmap darwinCreateDragPixmap(const QPixmap& aPixmap, const QString &aText);
+
+void darwinRegisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
+void darwinUnregisterForUnifiedToolbarContextMenuEvents(QMainWindow *pWindow);
 #endif /* !__OBJC__ */
 
