- Timestamp:
- Apr 10, 2008 2:59:03 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 29493
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h
r7867 r7871 198 198 # include <Carbon/Carbon.h> 199 199 200 /* Asserts if a != noErr and prints the error code */ 200 201 #define AssertCarbonOSStatus(a) AssertMsg ((a) == noErr, ("Carbon OSStatus: %d\n", static_cast<int> (a))) 201 202 … … 203 204 class QPixmap; 204 205 class 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 */ 208 CGImageRef darwinToCGImageRef (const QImage *aImage); 209 CGImageRef darwinToCGImageRef (const QPixmap *aPixmap); 210 CGImageRef 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 */ 218 inline HIViewRef darwinToHIViewRef (QWidget *aWidget) 215 219 { 216 220 return HIViewRef(aWidget->winId()); 217 221 } 218 222 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 */ 229 inline WindowRef darwinToWindowRef (HIViewRef aViewRef) 220 230 { 221 231 return reinterpret_cast<WindowRef> (HIViewGetWindow(aViewRef)); 222 232 } 223 233 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 */ 240 inline 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 */ 251 inline CGContextRef darwinToCGContextRef (QWidget *aWidget) 230 252 { 231 253 return static_cast<CGContext *> (aWidget->macCGHandle()); 232 254 } 233 255 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 */ 262 inline HIRect darwinToHIRect (const QRect &aRect) 235 263 { 236 264 return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height()); 237 265 } 238 266 267 /* Special routines for the dock handling */ 268 CGImageRef darwinCreateDockBadge (const char *aSource); 269 void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL); 270 void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage); 271 272 /* Experimental region handler for the seamless mode */ 273 OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData); 274 239 275 #endif /* Q_WS_MAC */ 240 276 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp
r7867 r7871 639 639 #ifdef Q_WS_MAC 640 640 /* Overlay logo for the dock icon */ 641 mVirtualBoxLogo = :: DarwinQPixmapFromMimeSourceToCGImage("VirtualBox_48px.png");641 mVirtualBoxLogo = ::darwinToCGImageRef ("VirtualBox_48px.png"); 642 642 #endif 643 643 … … 1444 1444 */ 1445 1445 topLevelWidget()->show(); 1446 topLevelWidget()-> setActiveWindow();1446 topLevelWidget()->activateWindow(); 1447 1447 return true; 1448 1448 } … … 2521 2521 if (aUniKey && aUniKey [0] && !aUniKey [1]) 2522 2522 processed = processHotKey (QKeySequence (Qt::UNICODE_ACCEL + 2523 QChar (aUniKey [0]). upper().unicode()),2523 QChar (aUniKey [0]).toUpper().unicode()), 2524 2524 mMainWnd->menuBar()->actions()); 2525 2525 … … 2632 2632 * (Note, synergy and other remote clients might not like this cursor warping.) 2633 2633 */ 2634 QRect rect = viewport()->visibleRe ct();2634 QRect rect = viewport()->visibleRegion().boundingRect(); 2635 2635 QPoint pw = viewport()->mapToGlobal (viewport()->pos()); 2636 rect. moveBy(pw.x(), pw.y());2636 rect.translate (pw.x(), pw.y()); 2637 2637 2638 2638 QRect dpRect = QApplication::desktop()->screenGeometry (viewport()); … … 2918 2918 CGImageRef ir = 2919 2919 static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef(); 2920 :: DarwinUpdateDockPreview (ir, mVirtualBoxLogo);2920 ::darwinUpdateDockPreview (ir, mVirtualBoxLogo); 2921 2921 } 2922 2922 else 2923 2923 # endif 2924 :: DarwinUpdateDockPreview (mFrameBuf, mVirtualBoxLogo);2924 ::darwinUpdateDockPreview (mFrameBuf, mVirtualBoxLogo); 2925 2925 } 2926 2926 #endif … … 2941 2941 2942 2942 #ifdef Q_WS_MAC 2943 :: DarwinUpdateDockPreview (DarwinQPixmapToCGImage(&mPausedShot),2943 ::darwinUpdateDockPreview (::darwinToCGImageRef (&mPausedShot), 2944 2944 mVirtualBoxLogo, 2945 2945 mMainWnd->dockImageState()); … … 3027 3027 #elif defined (Q_WS_MAC) 3028 3028 /* move the mouse to the center of the visible area */ 3029 mLastPos = mapToGlobal (visibleRe ct().center());3029 mLastPos = mapToGlobal (visibleRegion().boundingRect().center()); 3030 3030 QCursor::setPos (mLastPos); 3031 3031 /* grab all mouse events. */ -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp
r7868 r7871 53 53 #include "VBoxUtils.h" 54 54 #include "VBoxIChatTheaterWrapper.h" 55 /* Qt includes */ 56 #include <QPainter> 55 57 #endif 56 58 … … 589 591 # endif 590 592 /* 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"); 595 597 SetApplicationDockTileImage (dockImgOS); 596 598 #endif … … 809 811 #ifdef Q_WS_MAC 810 812 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); 812 814 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); 824 823 SetApplicationDockTileImage (dockImgOS); 825 824 #endif … … 1167 1166 /* Clear the background */ 1168 1167 HIRect viewRect; 1169 HIViewGetBounds ( mapToHIViewRef (this), &viewRect);1170 CGContextClearRect ( mapToCGContextRef (this), viewRect);1168 HIViewGetBounds (::darwinToHIViewRef (this), &viewRect); 1169 CGContextClearRect (::darwinToCGContextRef (this), viewRect); 1171 1170 } 1172 1171 break; … … 2136 2135 { 2137 2136 OSStatus status; 2138 HIViewRef viewRef = mapToHIViewRef (console->viewport());2137 HIViewRef viewRef = ::darwinToHIViewRef (console->viewport()); 2139 2138 Assert (VALID_PTR (viewRef)); 2140 WindowRef windowRef = mapToWindowRef (viewRef);2139 WindowRef windowRef = ::darwinToWindowRef (viewRef); 2141 2140 Assert (VALID_PTR (windowRef)); 2142 2141 /* @todo=poetzsch: Currently this isn't necessary. I should … … 2204 2203 /* Undo all mac specific installations */ 2205 2204 OSStatus status; 2206 WindowRef windowRef = mapToWindowRef (this);2205 WindowRef windowRef = ::darwinToWindowRef (this); 2207 2206 Assert (VALID_PTR (windowRef)); 2208 2207 /* See above. … … 2735 2734 * an repaint only. All the magic clipping stuff is done 2736 2735 * in the paint engine. */ 2737 HIViewReshapeStructure ( mapToHIViewRef (console->viewport()));2736 HIViewReshapeStructure (::darwinToHIViewRef (console->viewport())); 2738 2737 // ReshapeCustomWindow (mapToWindowRef (this)); 2739 2738 } -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxFBQuartz2D.cpp
r7867 r7871 158 158 Assert (VALID_PTR (viewport)); 159 159 160 HIViewRef viewRef = mapToHIViewRef (viewport);160 HIViewRef viewRef = ::darwinToHIViewRef (viewport); 161 161 Assert (VALID_PTR (viewRef)); 162 162 /* Get the dimensions of this HIView */ … … 164 164 HIViewGetBounds (viewRef, &viewRect); 165 165 /* Get the context of this window from qt */ 166 CGContextRef ctx = mapToCGContextRef (viewport);166 CGContextRef ctx = ::darwinToCGContextRef (viewport); 167 167 Assert (VALID_PTR (ctx)); 168 168 /* We handle the seamless mode as a special case. */ … … 217 217 QRect ir = aEvent->rect(); 218 218 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)); 220 220 Assert (VALID_PTR (subImage)); 221 221 /* Ok, for more performance we set a clipping path of the … … 227 227 /* Add all region rects to the current context as path components */ 228 228 for (int i = 0; i < a.size(); ++i) 229 CGContextAddRect (ctx, mapToHIRect (a[i]));229 CGContextAddRect (ctx, ::darwinToHIRect (a[i])); 230 230 /* Now convert the path to a clipping path. */ 231 231 CGContextClip (ctx); … … 235 235 CGContextClipToRect (ctx, viewRect); 236 236 /* At this point draw the real vm image */ 237 HIRect destRect = mapToHIRect (ir);237 HIRect destRect = ::darwinToHIRect (ir); 238 238 HIViewDrawCGImage (ctx, &destRect, subImage); 239 239 } -
trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp
r7867 r7871 27 27 #include <QImage> 28 28 #include <QPixmap> 29 #include <QPainter> 29 30 30 31 /** … … 46 47 * @param aPixmap Pointer to the QPixmap instance to convert. 47 48 */ 48 CGImageRef DarwinQImageToCGImage(const QImage *aImage)49 CGImageRef darwinToCGImageRef (const QImage *aImage) 49 50 { 50 51 QImage *imageCopy = new QImage (*aImage); 51 52 /** @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->convert Depth (32);53 if (imageCopy->format() != QImage::Format_ARGB32) 54 *imageCopy = imageCopy->convertToFormat (QImage::Format_ARGB32); 54 55 Assert (!imageCopy->isNull()); 55 56 … … 57 58 CGDataProviderRef dp = CGDataProviderCreateWithData (imageCopy, aImage->bits(), aImage->numBytes(), darwinDataProviderReleaseQImage); 58 59 59 CGBitmapInfo bmpInfo = imageCopy->hasAlphaBuffer() ? kCGImageAlphaFirst : kCGImageAlphaNoneSkipFirst; 60 bmpInfo |= kCGBitmapByteOrder32Host; 60 CGBitmapInfo bmpInfo = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; 61 61 CGImageRef ir = CGImageCreate (imageCopy->width(), imageCopy->height(), 8, 32, imageCopy->bytesPerLine(), cs, 62 62 bmpInfo, dp, 0 /*decode */, 0 /* shouldInterpolate */, … … 70 70 71 71 /** 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 */ 77 CGImageRef darwinToCGImageRef (const QPixmap *aPixmap) 78 { 79 return aPixmap->toMacCGImageRef(); 80 } 81 82 /** 72 83 * Loads an image using Qt and converts it to a CGImage. 73 84 * … … 75 86 * @param aSource The source name. 76 87 */ 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) 88 CGImageRef darwinToCGImageRef (const char *aSource) 104 89 { 105 90 QPixmap qpm (QString(":/") + aSource); 106 91 Assert (!qpm.isNull()); 107 return DarwinQPixmapToCGImage(&qpm);92 return ::darwinToCGImageRef (&qpm); 108 93 } 109 94 … … 117 102 * @param aSource The source name. 118 103 */ 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); 104 CGImageRef darwinCreateDockBadge (const char *aSource) 105 { 106 /* Create a transparent image in size 128x128. */ 107 QImage transImage (128, 128, QImage::Format_ARGB32); 124 108 transImage.fill (qRgba (0, 0, 0, 0)); 125 transImage.setAlphaBuffer (true);126 QPixmap back (transImage);127 128 109 /* load the badge */ 129 Q Pixmapbadge (aSource);110 QImage badge (aSource); 130 111 Assert (!badge.isNull()); 131 132 112 /* resize it and copy it onto the background. */ 133 113 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(); 139 120 /* Convert it to a CGImage. */ 140 return :: DarwinQPixmapToCGImage (&back);121 return ::darwinToCGImageRef (&transImage); 141 122 } 142 123 … … 150 131 * @param aStateImage an optional state overlay image to add at the center of the icon 151 132 */ 152 void DarwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/)133 void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/) 153 134 { 154 135 Assert (aVMImage); … … 233 214 * @param aOverlayImage an optional icon overlay image to add at the bottom right of the icon 234 215 */ 235 void DarwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage)216 void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage) 236 217 { 237 218 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); … … 244 225 kCGRenderingIntentDefault); 245 226 /* Update the dock preview icon */ 246 :: DarwinUpdateDockPreview (ir, aOverlayImage);227 ::darwinUpdateDockPreview (ir, aOverlayImage); 247 228 /* Release the temp data and image */ 248 229 CGDataProviderRelease (dp); … … 252 233 253 234 /* Currently not used! */ 254 OSStatus DarwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData)235 OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData) 255 236 { 256 237 NOREF (aInHandlerCallRef); … … 282 263 GetEventParameter (aInEvent, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof (rgn), NULL, &rgn); 283 264 QRegion *pRegion = static_cast <QRegion*> (aInUserData); 284 if (!pRegion->is Null() && pRegion)265 if (!pRegion->isEmpty() && pRegion) 285 266 { 286 267 CopyRgn (pRegion->handle(), rgn);
Note:
See TracChangeset
for help on using the changeset viewer.