Index: trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h	(revision 7870)
+++ trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h	(revision 7871)
@@ -198,4 +198,5 @@
 # include <Carbon/Carbon.h>
 
+/* Asserts if a != noErr and prints the error code */
 #define AssertCarbonOSStatus(a) AssertMsg ((a) == noErr, ("Carbon OSStatus: %d\n", static_cast<int> (a)))
 
@@ -203,38 +204,73 @@
 class QPixmap;
 class VBoxFrameBuffer;
-CGImageRef DarwinQImageToCGImage (const QImage *aImage);
-CGImageRef DarwinQImageFromMimeSourceToCGImage (const char *aSource);
-CGImageRef DarwinQPixmapToCGImage (const QPixmap *aPixmap);
-CGImageRef DarwinQPixmapFromMimeSourceToCGImage (const char *aSource);
-CGImageRef DarwinCreateDockBadge (const char *aSource);
-void DarwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
-void DarwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
-OSStatus DarwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
-
-inline HIViewRef mapToHIViewRef (QWidget *aWidget)
+
+/* Converting stuff */
+CGImageRef darwinToCGImageRef (const QImage *aImage);
+CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
+CGImageRef darwinToCGImageRef (const char *aSource);
+
+/**
+ * Returns a reference to the HIView of the QWidget.
+ *
+ * @returns HIViewRef of the QWidget.
+ * @param   aWidget   Pointer to the QWidget
+ */
+inline HIViewRef darwinToHIViewRef (QWidget *aWidget)
 {
     return HIViewRef(aWidget->winId());
 }
 
-inline WindowRef mapToWindowRef (HIViewRef aViewRef)
+/**
+ * Returns a reference to the Window of the HIView.
+ *
+ * @returns WindowRef of the HIView.
+ * @param   aViewRef  Reference to the HIView
+ */
+inline WindowRef darwinToWindowRef (HIViewRef aViewRef)
 {
     return reinterpret_cast<WindowRef> (HIViewGetWindow(aViewRef)); 
 }
 
-inline WindowRef mapToWindowRef (QWidget *aWidget)
-{
-    return mapToWindowRef (mapToHIViewRef (aWidget));
-}
-
-inline CGContextRef mapToCGContextRef (QWidget *aWidget)
+/**
+ * Returns a reference to the Window of the QWidget.
+ *
+ * @returns WindowRef of the QWidget.
+ * @param   aWidget   Pointer to the QWidget
+ */
+inline WindowRef darwinToWindowRef (QWidget *aWidget)
+{
+    return ::darwinToWindowRef (::darwinToHIViewRef (aWidget));
+}
+
+/**
+ * Returns a reference to the CGContext of the QWidget.
+ *
+ * @returns CGContextRef of the QWidget.
+ * @param   aWidget      Pointer to the QWidget
+ */
+inline CGContextRef darwinToCGContextRef (QWidget *aWidget)
 {
     return static_cast<CGContext *> (aWidget->macCGHandle());
 }
 
-inline HIRect mapToHIRect (const QRect &aRect)
+/**
+ * Converts a QRect to a HIRect.
+ *
+ * @returns HIRect for the converted QRect.
+ * @param   aRect  the QRect to convert
+ */
+inline HIRect darwinToHIRect (const QRect &aRect)
 {
     return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height());
 }
 
+/* Special routines for the dock handling */
+CGImageRef darwinCreateDockBadge (const char *aSource);
+void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
+void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
+
+/* Experimental region handler for the seamless mode */
+OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
+
 #endif /* Q_WS_MAC */
 
Index: trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp	(revision 7870)
+++ trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp	(revision 7871)
@@ -639,5 +639,5 @@
 #ifdef Q_WS_MAC
     /* Overlay logo for the dock icon */
-    mVirtualBoxLogo = ::DarwinQPixmapFromMimeSourceToCGImage ("VirtualBox_48px.png");
+    mVirtualBoxLogo = ::darwinToCGImageRef ("VirtualBox_48px.png");
 #endif
 
@@ -1444,5 +1444,5 @@
                  */
                 topLevelWidget()->show();
-                topLevelWidget()->setActiveWindow();
+                topLevelWidget()->activateWindow();
                 return true;
             }
@@ -2521,5 +2521,5 @@
         if (aUniKey && aUniKey [0] && !aUniKey [1])
             processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL +
-                                                     QChar (aUniKey [0]).upper().unicode()),
+                                                     QChar (aUniKey [0]).toUpper().unicode()),
                                        mMainWnd->menuBar()->actions());
 
@@ -2632,7 +2632,7 @@
          * (Note, synergy and other remote clients might not like this cursor warping.)
          */
-        QRect rect = viewport()->visibleRect();
+        QRect rect = viewport()->visibleRegion().boundingRect();
         QPoint pw = viewport()->mapToGlobal (viewport()->pos());
-        rect.moveBy (pw.x(), pw.y());
+        rect.translate (pw.x(), pw.y());
 
         QRect dpRect = QApplication::desktop()->screenGeometry (viewport());
@@ -2918,9 +2918,9 @@
                 CGImageRef ir =
                     static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef();
-                ::DarwinUpdateDockPreview (ir, mVirtualBoxLogo);
+                ::darwinUpdateDockPreview (ir, mVirtualBoxLogo);
             }
             else
 # endif
-                ::DarwinUpdateDockPreview (mFrameBuf, mVirtualBoxLogo);
+                ::darwinUpdateDockPreview (mFrameBuf, mVirtualBoxLogo);
         }
 #endif
@@ -2941,5 +2941,5 @@
 
 #ifdef Q_WS_MAC
-    ::DarwinUpdateDockPreview (DarwinQPixmapToCGImage (&mPausedShot),
+    ::darwinUpdateDockPreview (::darwinToCGImageRef (&mPausedShot),
                                mVirtualBoxLogo,
                                mMainWnd->dockImageState());
@@ -3027,5 +3027,5 @@
 #elif defined (Q_WS_MAC)
         /* move the mouse to the center of the visible area */
-        mLastPos = mapToGlobal (visibleRect().center());
+        mLastPos = mapToGlobal (visibleRegion().boundingRect().center());
         QCursor::setPos (mLastPos);
         /* grab all mouse events. */
Index: trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp	(revision 7870)
+++ trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp	(revision 7871)
@@ -53,4 +53,6 @@
 #include "VBoxUtils.h"
 #include "VBoxIChatTheaterWrapper.h"
+/* Qt includes */
+#include <QPainter>
 #endif
 
@@ -589,8 +591,8 @@
 # endif
     /* prepare the dock images */
-    dockImgStatePaused    = ::DarwinCreateDockBadge (":/state_paused_16px.png");
-    dockImgStateSaving    = ::DarwinCreateDockBadge (":/state_saving_16px.png");
-    dockImgStateRestoring = ::DarwinCreateDockBadge (":/state_restoring_16px.png");
-    dockImgBack100x75     = ::DarwinCreateDockBadge (":/dock_1.png");
+    dockImgStatePaused    = ::darwinCreateDockBadge (":/state_paused_16px.png");
+    dockImgStateSaving    = ::darwinCreateDockBadge (":/state_saving_16px.png");
+    dockImgStateRestoring = ::darwinCreateDockBadge (":/state_restoring_16px.png");
+    dockImgBack100x75     = ::darwinCreateDockBadge (":/dock_1.png");
     SetApplicationDockTileImage (dockImgOS);
 #endif
@@ -809,17 +811,14 @@
 #ifdef Q_WS_MAC
     QString osTypeId = cmachine.GetOSTypeId();
-    QImage osImg100x75 = vboxGlobal().vmGuestOSTypeIcon (osTypeId).convertToImage().smoothScale (100, 75);
+    QImage osImg100x75 = vboxGlobal().vmGuestOSTypeIcon (osTypeId).toImage().scaled (100, 75, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     QImage osImg = QImage (":/dock_1.png");
-#warning port me
-//    bitBlt (&osImg, 14, 22,
-//            &osImg100x75, 0, 0,
-//            100, 75, /* conversion_flags */ 0);
-//    QImage VBoxOverlay = QImage (":/VirtualBox_48px.png");
-//    bitBlt (&osImg, osImg.width() - VBoxOverlay.width(), osImg.height() - VBoxOverlay.height(),
-//            &VBoxOverlay, 0, 0,
-//            VBoxOverlay.width(), VBoxOverlay.height(), /* conversion_flags */ 0);
-//    if (dockImgOS)
-//        CGImageRelease (dockImgOS);
-    dockImgOS = ::DarwinQImageToCGImage (&osImg);
+    QImage VBoxOverlay = QImage (":/VirtualBox_48px.png");
+    QPainter painter (&osImg);
+    painter.drawImage (QPoint (14, 22), osImg100x75);
+    painter.drawImage (QPoint (osImg.width() - VBoxOverlay.width(), osImg.height() - VBoxOverlay.height()), VBoxOverlay);
+    painter.end();
+    if (dockImgOS)
+        CGImageRelease (dockImgOS);
+    dockImgOS = ::darwinToCGImageRef (&osImg);
     SetApplicationDockTileImage (dockImgOS);
 #endif
@@ -1167,6 +1166,6 @@
                 /* Clear the background */
                 HIRect viewRect;
-                HIViewGetBounds (mapToHIViewRef (this), &viewRect);
-                CGContextClearRect (mapToCGContextRef (this), viewRect);
+                HIViewGetBounds (::darwinToHIViewRef (this), &viewRect);
+                CGContextClearRect (::darwinToCGContextRef (this), viewRect);
             }
             break;
@@ -2136,7 +2135,7 @@
         {
             OSStatus status;
-            HIViewRef viewRef = mapToHIViewRef (console->viewport());
+            HIViewRef viewRef = ::darwinToHIViewRef (console->viewport());
             Assert (VALID_PTR (viewRef));
-            WindowRef windowRef = mapToWindowRef (viewRef);
+            WindowRef windowRef = ::darwinToWindowRef (viewRef);
             Assert (VALID_PTR (windowRef));
             /* @todo=poetzsch: Currently this isn't necessary. I should
@@ -2204,5 +2203,5 @@
             /* Undo all mac specific installations */
             OSStatus status;
-            WindowRef windowRef = mapToWindowRef (this);
+            WindowRef windowRef = ::darwinToWindowRef (this);
             Assert (VALID_PTR (windowRef));
             /* See above. 
@@ -2735,5 +2734,5 @@
          * an repaint only. All the magic clipping stuff is done
          * in the paint engine. */
-        HIViewReshapeStructure (mapToHIViewRef (console->viewport()));
+        HIViewReshapeStructure (::darwinToHIViewRef (console->viewport()));
 //        ReshapeCustomWindow (mapToWindowRef (this));
     }
Index: trunk/src/VBox/Frontends/VirtualBox4/src/VBoxFBQuartz2D.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/src/VBoxFBQuartz2D.cpp	(revision 7870)
+++ trunk/src/VBox/Frontends/VirtualBox4/src/VBoxFBQuartz2D.cpp	(revision 7871)
@@ -158,5 +158,5 @@
     Assert (VALID_PTR (viewport));
 
-    HIViewRef viewRef = mapToHIViewRef (viewport);
+    HIViewRef viewRef = ::darwinToHIViewRef (viewport);
     Assert (VALID_PTR (viewRef));
     /* Get the dimensions of this HIView */
@@ -164,5 +164,5 @@
     HIViewGetBounds (viewRef, &viewRect);
     /* Get the context of this window from qt */
-    CGContextRef ctx = mapToCGContextRef (viewport);
+    CGContextRef ctx = ::darwinToCGContextRef (viewport);
     Assert (VALID_PTR (ctx));
     /* We handle the seamless mode as a special case. */
@@ -217,5 +217,5 @@
         QRect ir = aEvent->rect();
         QRect is = QRect (ir.x() + mView->contentsX(), ir.y() + mView->contentsY(), ir.width(), ir.height());
-        CGImageRef subImage = CGImageCreateWithImageInRect (mImage, mapToHIRect (is));
+        CGImageRef subImage = CGImageCreateWithImageInRect (mImage, ::darwinToHIRect (is));
         Assert (VALID_PTR (subImage));
         /* Ok, for more performance we set a clipping path of the
@@ -227,5 +227,5 @@
             /* Add all region rects to the current context as path components */
             for (int i = 0; i < a.size(); ++i)
-                CGContextAddRect (ctx, mapToHIRect (a[i]));
+                CGContextAddRect (ctx, ::darwinToHIRect (a[i]));
             /* Now convert the path to a clipping path. */
             CGContextClip (ctx);
@@ -235,5 +235,5 @@
         CGContextClipToRect (ctx, viewRect);
         /* At this point draw the real vm image */
-        HIRect destRect = mapToHIRect (ir);
+        HIRect destRect = ::darwinToHIRect (ir);
         HIViewDrawCGImage (ctx, &destRect, subImage);
     }
Index: trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp	(revision 7870)
+++ trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp	(revision 7871)
@@ -27,4 +27,5 @@
 #include <QImage>
 #include <QPixmap>
+#include <QPainter>
 
 /**
@@ -46,10 +47,10 @@
  * @param   aPixmap     Pointer to the QPixmap instance to convert.
  */
-CGImageRef DarwinQImageToCGImage (const QImage *aImage)
+CGImageRef darwinToCGImageRef (const QImage *aImage)
 {
     QImage *imageCopy = new QImage (*aImage);
     /** @todo this code assumes 32-bit image input, the lazy bird convert image to 32-bit method is anything but optimal... */
-    if (imageCopy->depth() != 32)
-        *imageCopy = imageCopy->convertDepth (32);
+    if (imageCopy->format() != QImage::Format_ARGB32)
+        *imageCopy = imageCopy->convertToFormat (QImage::Format_ARGB32);
     Assert (!imageCopy->isNull());
 
@@ -57,6 +58,5 @@
     CGDataProviderRef dp = CGDataProviderCreateWithData (imageCopy, aImage->bits(), aImage->numBytes(), darwinDataProviderReleaseQImage);
 
-    CGBitmapInfo bmpInfo = imageCopy->hasAlphaBuffer() ? kCGImageAlphaFirst : kCGImageAlphaNoneSkipFirst;
-    bmpInfo |= kCGBitmapByteOrder32Host;
+    CGBitmapInfo bmpInfo = kCGImageAlphaFirst | kCGBitmapByteOrder32Host;
     CGImageRef ir = CGImageCreate (imageCopy->width(), imageCopy->height(), 8, 32, imageCopy->bytesPerLine(), cs,
                                    bmpInfo, dp, 0 /*decode */, 0 /* shouldInterpolate */,
@@ -70,4 +70,15 @@
 
 /**
+ * Converts a QPixmap to a CGImage.
+ *
+ * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
+ * @param   aPixmap     Pointer to the QPixmap instance to convert.
+ */
+CGImageRef darwinToCGImageRef (const QPixmap *aPixmap)
+{
+    return aPixmap->toMacCGImageRef();
+}
+
+/**
  * Loads an image using Qt and converts it to a CGImage.
  *
@@ -75,35 +86,9 @@
  * @param   aSource     The source name.
  */
-CGImageRef DarwinQImageFromMimeSourceToCGImage (const char *aSource)
-{
-    QImage qim (QString(":/") + aSource);
-    Assert (!qim.isNull());
-    return DarwinQImageToCGImage (&qim);
-}
-
-/**
- * Converts a QPixmap to a CGImage.
- *
- * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
- * @param   aPixmap     Pointer to the QPixmap instance to convert.
- */
-CGImageRef DarwinQPixmapToCGImage (const QPixmap *aPixmap)
-{
-    QImage qimg = aPixmap->convertToImage();
-    Assert (!qimg.isNull());
-    return DarwinQImageToCGImage (&qimg);
-}
-
-/**
- * Loads an image using Qt and converts it to a CGImage.
- *
- * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
- * @param   aSource     The source name.
- */
-CGImageRef DarwinQPixmapFromMimeSourceToCGImage (const char *aSource)
+CGImageRef darwinToCGImageRef (const char *aSource)
 {
     QPixmap qpm (QString(":/") + aSource);
     Assert (!qpm.isNull());
-    return DarwinQPixmapToCGImage (&qpm);
+    return ::darwinToCGImageRef (&qpm);
 }
 
@@ -117,26 +102,22 @@
  * @param   aSource     The source name.
  */
-CGImageRef DarwinCreateDockBadge (const char *aSource)
-{
-    /* Create a transparent image in size 128x128.
-     * This is unnecessary complicated in qt3. */
-    QImage transImage (128, 128, 32);
+CGImageRef darwinCreateDockBadge (const char *aSource)
+{
+    /* Create a transparent image in size 128x128. */
+    QImage transImage (128, 128, QImage::Format_ARGB32);
     transImage.fill (qRgba (0, 0, 0, 0));
-    transImage.setAlphaBuffer (true);
-    QPixmap back (transImage);
-
     /* load the badge */
-    QPixmap badge (aSource);
+    QImage badge (aSource);
     Assert (!badge.isNull());
-
     /* resize it and copy it onto the background. */
     if (badge.width() < 32)
-        badge = badge.convertToImage().smoothScale (32, 32);
-    copyBlt (&back, (back.width() - badge.width()) / 2.0, (back.height() - badge.height()) / 2.0,
-             &badge, 0, 0,
-             badge.width(), badge.height());
-
+        badge = badge.scaled (32, 32, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+    QPainter painter (&transImage);
+    painter.drawImage (QPoint ((transImage.width() - badge.width()) / 2.0, 
+                               (transImage.height() - badge.height()) / 2.0),
+                       badge);
+    painter.end();
     /* Convert it to a CGImage. */
-    return ::DarwinQPixmapToCGImage (&back);
+    return ::darwinToCGImageRef (&transImage);
 }
 
@@ -150,5 +131,5 @@
  * @param   aStateImage   an optional state overlay image to add at the center of the icon
  */
-void DarwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/)
+void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/)
 {
     Assert (aVMImage);
@@ -233,5 +214,5 @@
  * @param   aOverlayImage   an optional icon overlay image to add at the bottom right of the icon
  */
-void DarwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage)
+void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage)
 {
     CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
@@ -244,5 +225,5 @@
                                    kCGRenderingIntentDefault);
     /* Update the dock preview icon */
-    ::DarwinUpdateDockPreview (ir, aOverlayImage);
+    ::darwinUpdateDockPreview (ir, aOverlayImage);
     /* Release the temp data and image */
     CGDataProviderRelease (dp);
@@ -252,5 +233,5 @@
 
 /* Currently not used! */
-OSStatus DarwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData)
+OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData)
 {
     NOREF (aInHandlerCallRef);
@@ -282,5 +263,5 @@
                 GetEventParameter (aInEvent, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof (rgn), NULL, &rgn);
                 QRegion *pRegion = static_cast <QRegion*> (aInUserData);
-                if (!pRegion->isNull() && pRegion)
+                if (!pRegion->isEmpty() && pRegion)
                 {
                     CopyRgn (pRegion->handle(), rgn);
