VirtualBox

Changeset 7871 in vbox for trunk


Ignore:
Timestamp:
Apr 10, 2008 2:59:03 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
29493
Message:

FE/Qt4-OSX: Some minor fixes, updates & naming changes.

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h

    r7867 r7871  
    198198# include <Carbon/Carbon.h>
    199199
     200/* Asserts if a != noErr and prints the error code */
    200201#define AssertCarbonOSStatus(a) AssertMsg ((a) == noErr, ("Carbon OSStatus: %d\n", static_cast<int> (a)))
    201202
     
    203204class QPixmap;
    204205class VBoxFrameBuffer;
    205 CGImageRef DarwinQImageToCGImage (const QImage *aImage);
    206 CGImageRef DarwinQImageFromMimeSourceToCGImage (const char *aSource);
    207 CGImageRef DarwinQPixmapToCGImage (const QPixmap *aPixmap);
    208 CGImageRef DarwinQPixmapFromMimeSourceToCGImage (const char *aSource);
    209 CGImageRef DarwinCreateDockBadge (const char *aSource);
    210 void DarwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
    211 void DarwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
    212 OSStatus DarwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
    213 
    214 inline HIViewRef mapToHIViewRef (QWidget *aWidget)
     206
     207/* Converting stuff */
     208CGImageRef darwinToCGImageRef (const QImage *aImage);
     209CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
     210CGImageRef darwinToCGImageRef (const char *aSource);
     211
     212/**
     213 * Returns a reference to the HIView of the QWidget.
     214 *
     215 * @returns HIViewRef of the QWidget.
     216 * @param   aWidget   Pointer to the QWidget
     217 */
     218inline HIViewRef darwinToHIViewRef (QWidget *aWidget)
    215219{
    216220    return HIViewRef(aWidget->winId());
    217221}
    218222
    219 inline WindowRef mapToWindowRef (HIViewRef aViewRef)
     223/**
     224 * Returns a reference to the Window of the HIView.
     225 *
     226 * @returns WindowRef of the HIView.
     227 * @param   aViewRef  Reference to the HIView
     228 */
     229inline WindowRef darwinToWindowRef (HIViewRef aViewRef)
    220230{
    221231    return reinterpret_cast<WindowRef> (HIViewGetWindow(aViewRef));
    222232}
    223233
    224 inline WindowRef mapToWindowRef (QWidget *aWidget)
    225 {
    226     return mapToWindowRef (mapToHIViewRef (aWidget));
    227 }
    228 
    229 inline CGContextRef mapToCGContextRef (QWidget *aWidget)
     234/**
     235 * Returns a reference to the Window of the QWidget.
     236 *
     237 * @returns WindowRef of the QWidget.
     238 * @param   aWidget   Pointer to the QWidget
     239 */
     240inline WindowRef darwinToWindowRef (QWidget *aWidget)
     241{
     242    return ::darwinToWindowRef (::darwinToHIViewRef (aWidget));
     243}
     244
     245/**
     246 * Returns a reference to the CGContext of the QWidget.
     247 *
     248 * @returns CGContextRef of the QWidget.
     249 * @param   aWidget      Pointer to the QWidget
     250 */
     251inline CGContextRef darwinToCGContextRef (QWidget *aWidget)
    230252{
    231253    return static_cast<CGContext *> (aWidget->macCGHandle());
    232254}
    233255
    234 inline HIRect mapToHIRect (const QRect &aRect)
     256/**
     257 * Converts a QRect to a HIRect.
     258 *
     259 * @returns HIRect for the converted QRect.
     260 * @param   aRect  the QRect to convert
     261 */
     262inline HIRect darwinToHIRect (const QRect &aRect)
    235263{
    236264    return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height());
    237265}
    238266
     267/* Special routines for the dock handling */
     268CGImageRef darwinCreateDockBadge (const char *aSource);
     269void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
     270void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
     271
     272/* Experimental region handler for the seamless mode */
     273OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
     274
    239275#endif /* Q_WS_MAC */
    240276
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp

    r7867 r7871  
    639639#ifdef Q_WS_MAC
    640640    /* Overlay logo for the dock icon */
    641     mVirtualBoxLogo = ::DarwinQPixmapFromMimeSourceToCGImage ("VirtualBox_48px.png");
     641    mVirtualBoxLogo = ::darwinToCGImageRef ("VirtualBox_48px.png");
    642642#endif
    643643
     
    14441444                 */
    14451445                topLevelWidget()->show();
    1446                 topLevelWidget()->setActiveWindow();
     1446                topLevelWidget()->activateWindow();
    14471447                return true;
    14481448            }
     
    25212521        if (aUniKey && aUniKey [0] && !aUniKey [1])
    25222522            processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL +
    2523                                                      QChar (aUniKey [0]).upper().unicode()),
     2523                                                     QChar (aUniKey [0]).toUpper().unicode()),
    25242524                                       mMainWnd->menuBar()->actions());
    25252525
     
    26322632         * (Note, synergy and other remote clients might not like this cursor warping.)
    26332633         */
    2634         QRect rect = viewport()->visibleRect();
     2634        QRect rect = viewport()->visibleRegion().boundingRect();
    26352635        QPoint pw = viewport()->mapToGlobal (viewport()->pos());
    2636         rect.moveBy (pw.x(), pw.y());
     2636        rect.translate (pw.x(), pw.y());
    26372637
    26382638        QRect dpRect = QApplication::desktop()->screenGeometry (viewport());
     
    29182918                CGImageRef ir =
    29192919                    static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef();
    2920                 ::DarwinUpdateDockPreview (ir, mVirtualBoxLogo);
     2920                ::darwinUpdateDockPreview (ir, mVirtualBoxLogo);
    29212921            }
    29222922            else
    29232923# endif
    2924                 ::DarwinUpdateDockPreview (mFrameBuf, mVirtualBoxLogo);
     2924                ::darwinUpdateDockPreview (mFrameBuf, mVirtualBoxLogo);
    29252925        }
    29262926#endif
     
    29412941
    29422942#ifdef Q_WS_MAC
    2943     ::DarwinUpdateDockPreview (DarwinQPixmapToCGImage (&mPausedShot),
     2943    ::darwinUpdateDockPreview (::darwinToCGImageRef (&mPausedShot),
    29442944                               mVirtualBoxLogo,
    29452945                               mMainWnd->dockImageState());
     
    30273027#elif defined (Q_WS_MAC)
    30283028        /* move the mouse to the center of the visible area */
    3029         mLastPos = mapToGlobal (visibleRect().center());
     3029        mLastPos = mapToGlobal (visibleRegion().boundingRect().center());
    30303030        QCursor::setPos (mLastPos);
    30313031        /* grab all mouse events. */
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp

    r7868 r7871  
    5353#include "VBoxUtils.h"
    5454#include "VBoxIChatTheaterWrapper.h"
     55/* Qt includes */
     56#include <QPainter>
    5557#endif
    5658
     
    589591# endif
    590592    /* prepare the dock images */
    591     dockImgStatePaused    = ::DarwinCreateDockBadge (":/state_paused_16px.png");
    592     dockImgStateSaving    = ::DarwinCreateDockBadge (":/state_saving_16px.png");
    593     dockImgStateRestoring = ::DarwinCreateDockBadge (":/state_restoring_16px.png");
    594     dockImgBack100x75     = ::DarwinCreateDockBadge (":/dock_1.png");
     593    dockImgStatePaused    = ::darwinCreateDockBadge (":/state_paused_16px.png");
     594    dockImgStateSaving    = ::darwinCreateDockBadge (":/state_saving_16px.png");
     595    dockImgStateRestoring = ::darwinCreateDockBadge (":/state_restoring_16px.png");
     596    dockImgBack100x75     = ::darwinCreateDockBadge (":/dock_1.png");
    595597    SetApplicationDockTileImage (dockImgOS);
    596598#endif
     
    809811#ifdef Q_WS_MAC
    810812    QString osTypeId = cmachine.GetOSTypeId();
    811     QImage osImg100x75 = vboxGlobal().vmGuestOSTypeIcon (osTypeId).convertToImage().smoothScale (100, 75);
     813    QImage osImg100x75 = vboxGlobal().vmGuestOSTypeIcon (osTypeId).toImage().scaled (100, 75, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    812814    QImage osImg = QImage (":/dock_1.png");
    813 #warning port me
    814 //    bitBlt (&osImg, 14, 22,
    815 //            &osImg100x75, 0, 0,
    816 //            100, 75, /* conversion_flags */ 0);
    817 //    QImage VBoxOverlay = QImage (":/VirtualBox_48px.png");
    818 //    bitBlt (&osImg, osImg.width() - VBoxOverlay.width(), osImg.height() - VBoxOverlay.height(),
    819 //            &VBoxOverlay, 0, 0,
    820 //            VBoxOverlay.width(), VBoxOverlay.height(), /* conversion_flags */ 0);
    821 //    if (dockImgOS)
    822 //        CGImageRelease (dockImgOS);
    823     dockImgOS = ::DarwinQImageToCGImage (&osImg);
     815    QImage VBoxOverlay = QImage (":/VirtualBox_48px.png");
     816    QPainter painter (&osImg);
     817    painter.drawImage (QPoint (14, 22), osImg100x75);
     818    painter.drawImage (QPoint (osImg.width() - VBoxOverlay.width(), osImg.height() - VBoxOverlay.height()), VBoxOverlay);
     819    painter.end();
     820    if (dockImgOS)
     821        CGImageRelease (dockImgOS);
     822    dockImgOS = ::darwinToCGImageRef (&osImg);
    824823    SetApplicationDockTileImage (dockImgOS);
    825824#endif
     
    11671166                /* Clear the background */
    11681167                HIRect viewRect;
    1169                 HIViewGetBounds (mapToHIViewRef (this), &viewRect);
    1170                 CGContextClearRect (mapToCGContextRef (this), viewRect);
     1168                HIViewGetBounds (::darwinToHIViewRef (this), &viewRect);
     1169                CGContextClearRect (::darwinToCGContextRef (this), viewRect);
    11711170            }
    11721171            break;
     
    21362135        {
    21372136            OSStatus status;
    2138             HIViewRef viewRef = mapToHIViewRef (console->viewport());
     2137            HIViewRef viewRef = ::darwinToHIViewRef (console->viewport());
    21392138            Assert (VALID_PTR (viewRef));
    2140             WindowRef windowRef = mapToWindowRef (viewRef);
     2139            WindowRef windowRef = ::darwinToWindowRef (viewRef);
    21412140            Assert (VALID_PTR (windowRef));
    21422141            /* @todo=poetzsch: Currently this isn't necessary. I should
     
    22042203            /* Undo all mac specific installations */
    22052204            OSStatus status;
    2206             WindowRef windowRef = mapToWindowRef (this);
     2205            WindowRef windowRef = ::darwinToWindowRef (this);
    22072206            Assert (VALID_PTR (windowRef));
    22082207            /* See above.
     
    27352734         * an repaint only. All the magic clipping stuff is done
    27362735         * in the paint engine. */
    2737         HIViewReshapeStructure (mapToHIViewRef (console->viewport()));
     2736        HIViewReshapeStructure (::darwinToHIViewRef (console->viewport()));
    27382737//        ReshapeCustomWindow (mapToWindowRef (this));
    27392738    }
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxFBQuartz2D.cpp

    r7867 r7871  
    158158    Assert (VALID_PTR (viewport));
    159159
    160     HIViewRef viewRef = mapToHIViewRef (viewport);
     160    HIViewRef viewRef = ::darwinToHIViewRef (viewport);
    161161    Assert (VALID_PTR (viewRef));
    162162    /* Get the dimensions of this HIView */
     
    164164    HIViewGetBounds (viewRef, &viewRect);
    165165    /* Get the context of this window from qt */
    166     CGContextRef ctx = mapToCGContextRef (viewport);
     166    CGContextRef ctx = ::darwinToCGContextRef (viewport);
    167167    Assert (VALID_PTR (ctx));
    168168    /* We handle the seamless mode as a special case. */
     
    217217        QRect ir = aEvent->rect();
    218218        QRect is = QRect (ir.x() + mView->contentsX(), ir.y() + mView->contentsY(), ir.width(), ir.height());
    219         CGImageRef subImage = CGImageCreateWithImageInRect (mImage, mapToHIRect (is));
     219        CGImageRef subImage = CGImageCreateWithImageInRect (mImage, ::darwinToHIRect (is));
    220220        Assert (VALID_PTR (subImage));
    221221        /* Ok, for more performance we set a clipping path of the
     
    227227            /* Add all region rects to the current context as path components */
    228228            for (int i = 0; i < a.size(); ++i)
    229                 CGContextAddRect (ctx, mapToHIRect (a[i]));
     229                CGContextAddRect (ctx, ::darwinToHIRect (a[i]));
    230230            /* Now convert the path to a clipping path. */
    231231            CGContextClip (ctx);
     
    235235        CGContextClipToRect (ctx, viewRect);
    236236        /* At this point draw the real vm image */
    237         HIRect destRect = mapToHIRect (ir);
     237        HIRect destRect = ::darwinToHIRect (ir);
    238238        HIViewDrawCGImage (ctx, &destRect, subImage);
    239239    }
  • trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp

    r7867 r7871  
    2727#include <QImage>
    2828#include <QPixmap>
     29#include <QPainter>
    2930
    3031/**
     
    4647 * @param   aPixmap     Pointer to the QPixmap instance to convert.
    4748 */
    48 CGImageRef DarwinQImageToCGImage (const QImage *aImage)
     49CGImageRef darwinToCGImageRef (const QImage *aImage)
    4950{
    5051    QImage *imageCopy = new QImage (*aImage);
    5152    /** @todo this code assumes 32-bit image input, the lazy bird convert image to 32-bit method is anything but optimal... */
    52     if (imageCopy->depth() != 32)
    53         *imageCopy = imageCopy->convertDepth (32);
     53    if (imageCopy->format() != QImage::Format_ARGB32)
     54        *imageCopy = imageCopy->convertToFormat (QImage::Format_ARGB32);
    5455    Assert (!imageCopy->isNull());
    5556
     
    5758    CGDataProviderRef dp = CGDataProviderCreateWithData (imageCopy, aImage->bits(), aImage->numBytes(), darwinDataProviderReleaseQImage);
    5859
    59     CGBitmapInfo bmpInfo = imageCopy->hasAlphaBuffer() ? kCGImageAlphaFirst : kCGImageAlphaNoneSkipFirst;
    60     bmpInfo |= kCGBitmapByteOrder32Host;
     60    CGBitmapInfo bmpInfo = kCGImageAlphaFirst | kCGBitmapByteOrder32Host;
    6161    CGImageRef ir = CGImageCreate (imageCopy->width(), imageCopy->height(), 8, 32, imageCopy->bytesPerLine(), cs,
    6262                                   bmpInfo, dp, 0 /*decode */, 0 /* shouldInterpolate */,
     
    7070
    7171/**
     72 * Converts a QPixmap to a CGImage.
     73 *
     74 * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
     75 * @param   aPixmap     Pointer to the QPixmap instance to convert.
     76 */
     77CGImageRef darwinToCGImageRef (const QPixmap *aPixmap)
     78{
     79    return aPixmap->toMacCGImageRef();
     80}
     81
     82/**
    7283 * Loads an image using Qt and converts it to a CGImage.
    7384 *
     
    7586 * @param   aSource     The source name.
    7687 */
    77 CGImageRef DarwinQImageFromMimeSourceToCGImage (const char *aSource)
    78 {
    79     QImage qim (QString(":/") + aSource);
    80     Assert (!qim.isNull());
    81     return DarwinQImageToCGImage (&qim);
    82 }
    83 
    84 /**
    85  * Converts a QPixmap to a CGImage.
    86  *
    87  * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
    88  * @param   aPixmap     Pointer to the QPixmap instance to convert.
    89  */
    90 CGImageRef DarwinQPixmapToCGImage (const QPixmap *aPixmap)
    91 {
    92     QImage qimg = aPixmap->convertToImage();
    93     Assert (!qimg.isNull());
    94     return DarwinQImageToCGImage (&qimg);
    95 }
    96 
    97 /**
    98  * Loads an image using Qt and converts it to a CGImage.
    99  *
    100  * @returns CGImageRef for the new image. (Remember to release it when finished with it.)
    101  * @param   aSource     The source name.
    102  */
    103 CGImageRef DarwinQPixmapFromMimeSourceToCGImage (const char *aSource)
     88CGImageRef darwinToCGImageRef (const char *aSource)
    10489{
    10590    QPixmap qpm (QString(":/") + aSource);
    10691    Assert (!qpm.isNull());
    107     return DarwinQPixmapToCGImage (&qpm);
     92    return ::darwinToCGImageRef (&qpm);
    10893}
    10994
     
    117102 * @param   aSource     The source name.
    118103 */
    119 CGImageRef DarwinCreateDockBadge (const char *aSource)
    120 {
    121     /* Create a transparent image in size 128x128.
    122      * This is unnecessary complicated in qt3. */
    123     QImage transImage (128, 128, 32);
     104CGImageRef darwinCreateDockBadge (const char *aSource)
     105{
     106    /* Create a transparent image in size 128x128. */
     107    QImage transImage (128, 128, QImage::Format_ARGB32);
    124108    transImage.fill (qRgba (0, 0, 0, 0));
    125     transImage.setAlphaBuffer (true);
    126     QPixmap back (transImage);
    127 
    128109    /* load the badge */
    129     QPixmap badge (aSource);
     110    QImage badge (aSource);
    130111    Assert (!badge.isNull());
    131 
    132112    /* resize it and copy it onto the background. */
    133113    if (badge.width() < 32)
    134         badge = badge.convertToImage().smoothScale (32, 32);
    135     copyBlt (&back, (back.width() - badge.width()) / 2.0, (back.height() - badge.height()) / 2.0,
    136              &badge, 0, 0,
    137              badge.width(), badge.height());
    138 
     114        badge = badge.scaled (32, 32, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     115    QPainter painter (&transImage);
     116    painter.drawImage (QPoint ((transImage.width() - badge.width()) / 2.0,
     117                               (transImage.height() - badge.height()) / 2.0),
     118                       badge);
     119    painter.end();
    139120    /* Convert it to a CGImage. */
    140     return ::DarwinQPixmapToCGImage (&back);
     121    return ::darwinToCGImageRef (&transImage);
    141122}
    142123
     
    150131 * @param   aStateImage   an optional state overlay image to add at the center of the icon
    151132 */
    152 void DarwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/)
     133void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/)
    153134{
    154135    Assert (aVMImage);
     
    233214 * @param   aOverlayImage   an optional icon overlay image to add at the bottom right of the icon
    234215 */
    235 void DarwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage)
     216void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage)
    236217{
    237218    CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
     
    244225                                   kCGRenderingIntentDefault);
    245226    /* Update the dock preview icon */
    246     ::DarwinUpdateDockPreview (ir, aOverlayImage);
     227    ::darwinUpdateDockPreview (ir, aOverlayImage);
    247228    /* Release the temp data and image */
    248229    CGDataProviderRelease (dp);
     
    252233
    253234/* Currently not used! */
    254 OSStatus DarwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData)
     235OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData)
    255236{
    256237    NOREF (aInHandlerCallRef);
     
    282263                GetEventParameter (aInEvent, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof (rgn), NULL, &rgn);
    283264                QRegion *pRegion = static_cast <QRegion*> (aInUserData);
    284                 if (!pRegion->isNull() && pRegion)
     265                if (!pRegion->isEmpty() && pRegion)
    285266                {
    286267                    CopyRgn (pRegion->handle(), rgn);
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