VirtualBox

Changeset 17340 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 4, 2009 12:11:33 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43720
Message:

FE/Qt4-OSX: Make the dock icon preview work in Cocoa.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r17201 r17340  
    406406 VirtualBox_SOURCES.darwin += \
    407407        src/darwin/VBoxCocoaApplication.m \
    408         src/darwin/VBoxUtils-darwin-cocoa.m
     408        src/darwin/VBoxUtils-darwin-cocoa.m \
     409        src/darwin/VBoxDockIconPreview-cocoa.m
    409410else
    410411 VirtualBox_SOURCES.darwin += \
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxDockIconPreview.h

    r17175 r17340  
    2424#define ___VBoxDockIconPreview_h___
    2525
    26 #include <QObject> /* drag in QT_MAC_USE_COCOA */
     26#include "VBoxUtils-darwin.h"
    2727
    28 #ifdef QT_MAC_USE_COCOA
    29 # include <ApplicationServices/ApplicationServices.h>
    30 /** @todo include chocolatey headers... */
    31 #else
    32 # include <Carbon/Carbon.h>
    33 #endif
     28__BEGIN_DECLS
     29void darwinCreateVBoxDockIconTileView (void);
     30void darwinDestroyVBoxDockIconTileView (void);
    3431
     32CGContextRef darwinBeginCGContextForApplicationDockTile (void);
     33void darwinEndCGContextForApplicationDockTile (CGContextRef aContext);
     34
     35void darwinOverlayApplicationDockTileImage (CGImageRef pImage);
     36void darwinRestoreApplicationDockTileImage (void);
     37__END_DECLS
     38
     39#ifndef __OBJC__
    3540class VBoxConsoleWnd;
    3641class VBoxFrameBuffer;
     
    4550
    4651    void updateDockOverlay();
    47 //#ifndef QT_MAC_USE_COCOA
    4852    void updateDockPreview (CGImageRef aVMImage);
    49 //#endif
    5053    void updateDockPreview (VBoxFrameBuffer *aFrameBuffer);
    5154
    5255private:
    53 //#ifdef QT_MAC_USE_COCOA
    54     /** @todo Carbon -> Cocoa */
    55 //#else
    5656    inline void initPreviewImages();
    5757    inline void initOverlayData (int aBitmapByteCount);
     
    6060
    6161    /* Flipping is necessary cause the drawing context in Carbon is flipped by 180 degree */
    62     inline CGRect flipRect (CGRect aRect) const { aRect.origin.y = mDockIconRect.size.height - aRect.origin.y - aRect.size.height; return aRect; }
    63     inline CGRect centerRect (CGRect aRect) const { return centerRectTo (aRect, mDockIconRect); }
    64     inline CGRect centerRectTo (CGRect aRect, const CGRect& aToRect) const
    65     {
    66         aRect.origin.x = aToRect.origin.x + (aToRect.size.width  - aRect.size.width)  / 2.0;
    67         aRect.origin.y = aToRect.origin.y + (aToRect.size.height - aRect.size.height) / 2.0;
    68         return aRect;
    69     }
    70 //#endif /* !QT_MAC_USE_COCOA */
     62    inline CGRect flipRect (CGRect aRect) const { return ::darwinFlipCGRect (aRect, mDockIconRect); }
     63    inline CGRect centerRect (CGRect aRect) const { return ::darwinCenterRectTo (aRect, mDockIconRect); }
     64    inline CGRect centerRectTo (CGRect aRect, const CGRect& aToRect) const { return ::darwinCenterRectTo (aRect, aToRect); }
     65
     66    void updateDockPreviewImpl (CGContextRef aContext, CGImageRef aVMImage);
    7167
    7268    /* Private member vars */
    7369    VBoxConsoleWnd *mMainWnd;
    74 //#ifdef QT_MAC_USE_COCOA
    75     /** @todo Carbon -> Cocoa */
    76 //#else
    7770    const CGRect mDockIconRect;
    7871
     
    8982    CGRect mUpdateRect;
    9083    CGRect mMonitorRect;
    91 //#endif
    9284};
     85#endif /* !__OBJC__ */
    9386
    9487#endif /* !___VBoxDockIconPreview_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxUtils-darwin.h

    r17201 r17340  
    4040#else
    4141# include <iprt/cdefs.h> /* for __BEGIN_DECLS/__END_DECLS & stuff */
     42
    4243# include <qglobal.h> /* for QT_MAC_USE_COCOA */
     44# include <QRect>
    4345
    4446# include <ApplicationServices/ApplicationServices.h>
     47
    4548class QWidget;
    4649class QToolBar;
    4750class QPixmap;
    48 class QRect;
     51class QImage;
    4952
    5053# ifdef QT_MAC_USE_COCOA
     
    8992void darwinWindowInvalidateShadowImpl (NativeWindowRef aWindow);
    9093
    91 
    9294__END_DECLS
    9395
     
    157159
    158160
    159 
    160 /********************************************************************************
    161  *
    162  * Old carbon stuff. Have to be converted soon!
    163  *
    164  ********************************************************************************/
    165 
    166 #include <QWidget>
    167 class QImage;
    168 
    169 /* Converting stuff */
     161/********************************************************************************
     162 *
     163 * Graphics stuff (Qt Wrapper)
     164 *
     165 ********************************************************************************/
     166/**
     167 * Returns a reference to the CGContext of the QWidget.
     168 *
     169 * @returns CGContextRef of the QWidget.
     170 * @param   aWidget      Pointer to the QWidget
     171 */
     172CGContextRef darwinToCGContextRef (QWidget *aWidget);
     173
    170174CGImageRef darwinToCGImageRef (const QImage *aImage);
    171175CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
    172176CGImageRef darwinToCGImageRef (const char *aSource);
    173177
    174 /**
    175  * Returns a reference to the CGContext of the QWidget.
    176  *
    177  * @returns CGContextRef of the QWidget.
    178  * @param   aWidget      Pointer to the QWidget
    179  */
    180 DECLINLINE(CGContextRef) darwinToCGContextRef (QWidget *aWidget)
    181 {
    182     return static_cast<CGContext *> (aWidget->macCGHandle());
    183 }
    184 
    185178DECLINLINE(CGRect) darwinToCGRect (const QRect& aRect) { return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height()); }
    186179DECLINLINE(CGRect) darwinFlipCGRect (CGRect aRect, int aTargetHeight) { aRect.origin.y = aTargetHeight - aRect.origin.y - aRect.size.height; return aRect; }
     180DECLINLINE(CGRect) darwinFlipCGRect (CGRect aRect, const CGRect &aTarget) { return darwinFlipCGRect (aRect, aTarget.size.height); }
     181DECLINLINE(CGRect) darwinCenterRectTo (CGRect aRect, const CGRect& aToRect)
     182{
     183    aRect.origin.x = aToRect.origin.x + (aToRect.size.width  - aRect.size.width)  / 2.0;
     184    aRect.origin.y = aToRect.origin.y + (aToRect.size.height - aRect.size.height) / 2.0;
     185    return aRect;
     186}
     187
     188
     189
     190
     191
     192/********************************************************************************
     193 *
     194 * Old carbon stuff. Have to be converted soon!
     195 *
     196 ********************************************************************************/
     197
     198#include <QWidget>
    187199
    188200# ifndef QT_MAC_USE_COCOA
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r17301 r17340  
    40374037        if (!mPausedShot.isNull())
    40384038        {
    4039 # ifdef QT_MAC_USE_COCOA
    4040             /** @todo Carbon -> Cocoa */
    4041 # else
    40424039            CGImageRef pauseImg = ::darwinToCGImageRef (&mPausedShot);
    40434040            /* Use the pause image as background */
    40444041            mDockIconPreview->updateDockPreview (pauseImg);
    40454042            CGImageRelease (pauseImg);
    4046 # endif
    40474043        }
    40484044        else
     
    40724068    if (mDockIconEnabled &&
    40734069        (mLastState == KMachineState_Running ||
     4070         mLastState == KMachineState_Paused ||
    40744071         mLastState == KMachineState_Restoring ||
    40754072         mLastState == KMachineState_Saving))
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxDockIconPreview.cpp

    r17176 r17340  
    2828
    2929#include <QPixmap>
    30 #ifndef Q_WS_MAC
    31 # error "Q_WS_MAC isn't defined"
    32 #endif
    3330
    3431#ifndef QT_MAC_USE_COCOA
     
    4542VBoxDockIconPreview::VBoxDockIconPreview (VBoxConsoleWnd *aMainWnd, const QPixmap& aOverlayImage)
    4643    :  mMainWnd (aMainWnd)
    47 //#ifdef QT_MAC_USE_COCOA
    48 //#else
    4944     , mDockIconRect (CGRectMake (0, 0, 128, 128))
    5045     , mDockMonitor (NULL)
     
    5348     , mUpdateRect (CGRectMake (0, 0, 0, 0))
    5449     , mMonitorRect (CGRectMake (0, 0, 0, 0))
    55 //#endif
    56 {
    57 #ifdef QT_MAC_USE_COCOA
    58 #else  /* !QT_MAC_USE_COCOA */
     50{
    5951    mOverlayImage   = ::darwinToCGImageRef (&aOverlayImage);
    6052    Assert (mOverlayImage);
     
    6658    mStateRestoring = ::darwinToCGImageRef ("state_restoring_16px.png");
    6759    Assert (mStateRestoring);
    68 #endif /* !QT_MAC_USE_COCOA */
     60
     61#ifdef QT_MAC_USE_COCOA
     62    ::darwinCreateVBoxDockIconTileView();
     63#endif /* QT_MAC_USE_COCOA */
    6964}
    7065
     
    7267{
    7368#ifdef QT_MAC_USE_COCOA
    74 #else  /* !QT_MAC_USE_COCOA */
     69    ::darwinDestroyVBoxDockIconTileView();
     70#endif /* QT_MAC_USE_COCOA */
     71
    7572    CGImageRelease (mOverlayImage);
    7673    if (mDockMonitor)
     
    8582    CGImageRelease (mStateSaving);
    8683    CGImageRelease (mStateRestoring);
    87 #endif /* !QT_MAC_USE_COCOA */
    88 }
    89 
    90 //#ifndef QT_MAC_USE_COCOA
     84}
    9185
    9286void VBoxDockIconPreview::initPreviewImages()
     
    158152}
    159153
    160 //#endif /* !QT_MAC_USE_COCOA */
    161 
    162154void VBoxDockIconPreview::updateDockOverlay()
    163155{
    164 #ifdef QT_MAC_USE_COCOA
    165 #else  /* !QT_MAC_USE_COCOA */
    166 
    167156    /* Remove all previously set tile images */
    168     RestoreApplicationDockTileImage();
     157#ifdef QT_MAC_USE_COCOA
     158    ::darwinRestoreApplicationDockTileImage();
     159#else /* QT_MAC_USE_COCOA */
     160    ::RestoreApplicationDockTileImage();
     161#endif /* QT_MAC_USE_COCOA */
    169162
    170163    CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
     
    200193
    201194    /* Update the dock overlay icon */
    202     OverlayApplicationDockTileImage (overlayImage);
     195#ifdef QT_MAC_USE_COCOA
     196    ::darwinOverlayApplicationDockTileImage (overlayImage);
     197#else /* QT_MAC_USE_COCOA */
     198    ::OverlayApplicationDockTileImage (overlayImage);
     199#endif /* QT_MAC_USE_COCOA */
    203200
    204201    /* Release the temp image */
    205202    CGImageRelease (overlayImage);
    206203    CGColorSpaceRelease (cs);
    207 #endif /* !QT_MAC_USE_COCOA */
    208204}
    209205
    210206void VBoxDockIconPreview::updateDockPreview (CGImageRef aVMImage)
    211207{
    212 #ifndef QT_MAC_USE_COCOA
    213208    Assert (aVMImage);
     209
     210#ifdef QT_MAC_USE_COCOA
     211    /* Create the context to draw on */
     212    CGContextRef context = ::darwinBeginCGContextForApplicationDockTile();
     213    updateDockPreviewImpl (context, aVMImage);
     214    /* This flush updates the dock icon */
     215    CGContextFlush (context);
     216    ::darwinEndCGContextForApplicationDockTile (context);
     217#else /* QT_MAC_USE_COCOA */
     218    /* Create the context to draw on */
     219    CGContextRef context = BeginCGContextForApplicationDockTile ();
     220    updateDockPreviewImpl (context, aVMImage);
     221    /* This flush updates the dock icon */
     222    CGContextFlush (context);
     223    EndCGContextForApplicationDockTile (context);
     224#endif /* QT_MAC_USE_COCOA */
     225}
     226
     227void VBoxDockIconPreview::updateDockPreviewImpl (CGContextRef aContext, CGImageRef aVMImage)
     228{
     229    Assert (aContext);
    214230
    215231    /* Init all dependend images in the case it wasn't done already */
     
    219235    Assert (cs);
    220236
    221     /* Create the context to draw on */
    222     CGContextRef context = BeginCGContextForApplicationDockTile();
    223     Assert (context);
    224 
    225237    /* Clear the background to be transparent */
    226     CGContextSetBlendMode (context, kCGBlendModeNormal);
    227     CGContextClearRect (context, flipRect (mDockIconRect));
     238    CGContextSetBlendMode (aContext, kCGBlendModeNormal);
     239    CGContextClearRect (aContext, flipRect (mDockIconRect));
    228240
    229241    /* Draw the monitor as the background */
    230     CGContextDrawImage (context, flipRect (mMonitorRect), mDockMonitor);
     242    CGContextDrawImage (aContext, flipRect (mMonitorRect), mDockMonitor);
    231243
    232244    /* Calc the size of the dock icon image and fit it into 128x128 */
     
    249261                                    mUpdateRect);
    250262    /* Draw the VM content */
    251     CGContextDrawImage (context, flipRect (iconRect), aVMImage);
    252 
     263    CGContextDrawImage (aContext, flipRect (iconRect), aVMImage);
     264
     265#ifndef QT_MAC_USE_COCOA
    253266    /* Process the content of any external OpenGL window. */
    254267    WindowRef w = darwinToNativeWindow (mMainWnd);
     
    258271    float a1 = iconRect.size.width / static_cast <float> (CGImageGetWidth (aVMImage));
    259272    float a2 = iconRect.size.height / static_cast <float> (CGImageGetHeight (aVMImage));
    260     HIViewRef mainView = HIViewGetRoot (w);
    261273    Rect tmpR;
    262274    GetWindowBounds (w, kWindowContentRgn, &tmpR);
     
    289301                 * around with gPixelRead or something like that. */
    290302                CGSWindowID wid = GetNativeWindowFromWindowRef (wc);
    291                 CGContextCopyWindowCaptureContentsToRect(context, flipRect (rect), CGSMainConnectionID(), wid, 0);
     303                CGContextCopyWindowCaptureContentsToRect(aContext, flipRect (rect), CGSMainConnectionID(), wid, 0);
    292304            }
    293305        }
    294306    }
     307#endif /* QT_MAC_USE_COCOA */
    295308
    296309    /* Draw the glossy overlay */
    297     CGContextDrawImage (context, flipRect (mMonitorRect), mDockMonitorGlossy);
     310    CGContextDrawImage (aContext, flipRect (mMonitorRect), mDockMonitorGlossy);
    298311
    299312    /* Draw the state image & the overlay image */
    300     drawOverlayIcons (context);
    301 
    302     /* This flush updates the dock icon */
    303     CGContextFlush (context);
    304     EndCGContextForApplicationDockTile (context);
     313    drawOverlayIcons (aContext);
    305314
    306315    CGColorSpaceRelease (cs);
    307 #endif /* QT_MAC_USE_COCOA */
    308 }
    309 //#endif /* !QT_MAC_USE_COCOA */
     316}
    310317
    311318void VBoxDockIconPreview::updateDockPreview (VBoxFrameBuffer *aFrameBuffer)
    312319{
    313 //#ifdef QT_MAC_USE_COCOA
    314 //#else  /* !QT_MAC_USE_COCOA */
    315320    CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
    316321    Assert (cs);
     
    330335    CGDataProviderRelease (dp);
    331336    CGColorSpaceRelease (cs);
    332 //#endif /* !QT_MAC_USE_COCOA */
    333 }
    334 
     337}
     338
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin-cocoa.m

    r17201 r17340  
    2424#include "VBoxUtils-darwin.h"
    2525
     26#include <iprt/assert.h>
     27
    2628#import <AppKit/NSWindow.h>
    2729#import <AppKit/NSView.h>
     
    2931#import <AppKit/NSToolbar.h>
    3032#import <AppKit/NSColor.h>
     33#import <AppKit/NSGraphicsContext.h>
     34#import <AppKit/NSApplication.h>
     35#import <AppKit/NSImageView.h>
    3136
    3237NativeWindowRef darwinToNativeWindowImpl (NativeViewRef aView)
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxUtils-darwin.cpp

    r17201 r17340  
    140140}
    141141
     142CGContextRef darwinToCGContextRef (QWidget *aWidget)
     143{
     144    return static_cast<CGContext *> (aWidget->macCGHandle());
     145}
    142146
    143147/* Proxy icon creation */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette