Changeset 15804 in vbox for trunk/src/VBox
- Timestamp:
- Jan 5, 2009 2:55:35 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 4 added
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/Makefile.kmk
r15513 r15804 382 382 src/darwin/DarwinKeyboard.cpp \ 383 383 src/darwin/VBoxUtils-darwin.cpp \ 384 src/darwin/VBoxDockIconPreview.cpp \ 384 385 src/VBoxFBQuartz2D.cpp 385 # src/darwin/VBoxAquaStyle.cpp386 386 387 387 ifdef VBOX_WITH_ICHAT_THEATER -
trunk/src/VBox/Frontends/VirtualBox4/VirtualBox.qrc
r15501 r15804 301 301 <file alias="meditation_32px.png">images/meditation_32px.png</file> 302 302 <file alias="welcome.png">images/welcome.png</file> 303 <file alias="dock_1.png">images/dock_1.png</file> 303 <file alias="monitor.png">images/monitor.png</file> 304 <file alias="monitor_glossy.png">images/monitor_glossy.png</file> 304 305 </qresource> 305 306 </RCC> -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleView.h
r15652 r15804 45 45 class MousePointerChangeEvent; 46 46 class VBoxFrameBuffer; 47 class VBoxDockIconPreview; 47 48 48 49 class QPainter; … … 128 129 #if defined(Q_WS_MAC) 129 130 void updateDockIcon(); 131 void updateDockOverlay(); 130 132 void setDockIconEnabled (bool aOn) { mDockIconEnabled = aOn; }; 131 133 void setMouseCoalescingEnabled (bool aOn); … … 323 325 QPixmap mPausedShot; 324 326 #if defined(Q_WS_MAC) 325 CGImageRef mVirtualBoxLogo;327 VBoxDockIconPreview *mDockIconPreview; 326 328 bool mDockIconEnabled; 327 329 #endif -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxConsoleWnd.h
r15469 r15804 111 111 void clearMask(); 112 112 113 #if defined (Q_WS_MAC) 114 CGImageRef dockImageState () const; 115 #endif 113 KMachineState machineState() const { return machine_state; } 116 114 117 115 public slots: … … 372 370 QRect mNormalGeometry; 373 371 Qt::WindowFlags mSavedFlags; 374 /* Dock images */375 CGImageRef dockImgStatePaused;376 CGImageRef dockImgStateSaving;377 CGImageRef dockImgStateRestoring;378 CGImageRef dockImgBack100x75;379 CGImageRef dockImgOS;380 372 /* For the fade effect if the the window goes fullscreen */ 381 373 CGDisplayFadeReservationToken mFadeToken; -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h
r15642 r15804 209 209 QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText); 210 210 211 /* Special routines for the dock handling */212 CGImageRef darwinCreateDockBadge (const char *aSource);213 void darwinUpdateDockPreview (QWidget *aMainWindow, CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);214 void darwinUpdateDockPreview (QWidget *aMainWindow, VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);215 216 211 /* Icons in the menu of an mac application are unusual. */ 217 212 void darwinDisableIconsInMenus(); -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleView.cpp
r15652 r15804 80 80 81 81 #if defined (Q_WS_MAC) 82 # include "VBoxDockIconPreview.h" 82 83 # include "DarwinKeyboard.h" 83 84 # ifdef VBOX_WITH_HACKED_QT … … 670 671 , mDarwinKeyModifiers (0) 671 672 , mKeyboardGrabbed (false) 672 , mVirtualBoxLogo (NULL)673 673 , mDockIconEnabled (true) 674 674 #endif … … 683 683 #ifdef Q_WS_MAC 684 684 /* Overlay logo for the dock icon */ 685 mVirtualBoxLogo = ::darwinToCGImageRef ("VirtualBox_cube_42px.png"); 685 //mVirtualBoxLogo = ::darwinToCGImageRef ("VirtualBox_cube_42px.png"); 686 QString osTypeId = mConsole.GetGuest().GetOSTypeId(); 687 mDockIconPreview = new VBoxDockIconPreview (mMainWnd, vboxGlobal().vmGuestOSTypeIcon (osTypeId)); 686 688 687 689 /* Install the event handler which will proceed external window handling */ … … 885 887 mDarwinWindowOverlayHandlerRef = NULL; 886 888 } 887 CGImageRelease (mVirtualBoxLogo);889 delete mDockIconPreview; 888 890 #endif 889 891 } … … 3903 3905 { 3904 3906 if (!mPausedShot.isNull()) 3907 { 3908 CGImageRef pauseImg = ::darwinToCGImageRef (&mPausedShot); 3905 3909 /* Use the pause image as background */ 3906 ::darwinUpdateDockPreview (mMainWnd, ::darwinToCGImageRef (&mPausedShot), mVirtualBoxLogo, mMainWnd->dockImageState()); 3910 mDockIconPreview->updateDockPreview (pauseImg); 3911 CGImageRelease (pauseImg); 3912 } 3907 3913 else 3908 3914 { … … 3913 3919 * of the framebuffer for the dock icon creation. This saves 3914 3920 * some conversion time. */ 3915 ::darwinUpdateDockPreview (mMainWnd, static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef(), mVirtualBoxLogo, mMainWnd->dockImageState());3921 mDockIconPreview->updateDockPreview (static_cast <VBoxQuartz2DFrameBuffer *> (mFrameBuf)->imageRef()); 3916 3922 } 3917 3923 else … … 3919 3925 /* In image mode we have to create the image ref out of the 3920 3926 * framebuffer */ 3921 ::darwinUpdateDockPreview (mMainWnd, mFrameBuf, mVirtualBoxLogo, mMainWnd->dockImageState()); 3922 } 3923 } 3927 mDockIconPreview->updateDockPreview (mFrameBuf); 3928 } 3929 } 3930 } 3931 3932 void VBoxConsoleView::updateDockOverlay() 3933 { 3934 if (mDockIconEnabled) 3935 updateDockIcon(); 3936 else 3937 mDockIconPreview->updateDockOverlay (); 3924 3938 } 3925 3939 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxConsoleWnd.cpp
r15642 r15804 238 238 , mDbgGui (NULL) 239 239 , mDbgGuiVT (NULL) 240 #endif241 #ifdef Q_WS_MAC242 , dockImgStatePaused (NULL)243 , dockImgStateSaving (NULL)244 , dockImgStateRestoring (NULL)245 , dockImgBack100x75 (NULL)246 , dockImgOS (NULL)247 240 #endif 248 241 { … … 694 687 initSharedAVManager(); 695 688 # endif 696 /* prepare the dock images */697 dockImgStatePaused = ::darwinCreateDockBadge (":/state_paused_16px.png");698 dockImgStateSaving = ::darwinCreateDockBadge (":/state_saving_16px.png");699 dockImgStateRestoring = ::darwinCreateDockBadge (":/state_restoring_16px.png");700 dockImgBack100x75 = ::darwinCreateDockBadge (":/dock_1.png");701 SetApplicationDockTileImage (dockImgOS);702 689 #endif 703 690 mMaskShift.scale (0, 0, Qt::IgnoreAspectRatio); … … 707 694 { 708 695 closeView(); 709 710 #ifdef Q_WS_MAC711 /* release the dock images */712 if (dockImgStatePaused)713 CGImageRelease (dockImgStatePaused);714 if (dockImgStateSaving)715 CGImageRelease (dockImgStateSaving);716 if (dockImgStateRestoring)717 CGImageRelease (dockImgStateRestoring);718 if (dockImgBack100x75)719 CGImageRelease (dockImgBack100x75);720 if (dockImgOS)721 CGImageRelease (dockImgOS);722 #endif723 696 724 697 #ifdef VBOX_WITH_DEBUGGER_GUI … … 951 924 bool f = (testStr.isEmpty() || testStr == "true"); 952 925 console->setDockIconEnabled (f); 953 if (f) 954 { 955 QString osTypeId = cmachine.GetOSTypeId(); 956 QImage osImg100x75 = vboxGlobal().vmGuestOSTypeIcon (osTypeId).toImage().scaled (100, 75, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); 957 QImage osImg = QImage (":/dock_1.png"); 958 QImage VBoxOverlay = QImage (":/VirtualBox_cube_42px.png"); 959 QPainter painter (&osImg); 960 painter.drawImage (QPoint (14, 22), osImg100x75); 961 painter.drawImage (QPoint (osImg.width() - VBoxOverlay.width(), osImg.height() - VBoxOverlay.height()), VBoxOverlay); 962 painter.end(); 963 if (dockImgOS) 964 CGImageRelease (dockImgOS); 965 dockImgOS = ::darwinToCGImageRef (&osImg); 966 SetApplicationDockTileImage (dockImgOS); 967 } 926 console->updateDockOverlay(); 968 927 #endif 969 928 … … 2449 2408 } 2450 2409 2451 #ifdef Q_WS_MAC2452 CGImageRef VBoxConsoleWnd::dockImageState() const2453 {2454 CGImageRef img;2455 if (machine_state == KMachineState_Paused)2456 img = dockImgStatePaused;2457 else if (machine_state == KMachineState_Restoring)2458 img = dockImgStateRestoring;2459 else if (machine_state == KMachineState_Saving)2460 img = dockImgStateSaving;2461 else2462 img = NULL;2463 return img;2464 }2465 #endif2466 2467 2410 void VBoxConsoleWnd::changeDockIconUpdate (const VBoxChangeDockIconUpdateEvent &e) 2468 2411 { … … 2471 2414 { 2472 2415 console->setDockIconEnabled (e.mChanged); 2473 if (e.mChanged) 2474 console->updateDockIcon(); 2475 else 2476 { 2477 RestoreApplicationDockTileImage(); 2478 CGImageRef img = dockImageState(); 2479 if (img) 2480 OverlayApplicationDockTileImage (img); 2481 } 2416 console->updateDockOverlay(); 2482 2417 } 2483 2418 #else … … 3487 3422 3488 3423 #ifdef Q_WS_MAC 3489 CGImageRef img = dockImageState(); 3490 if (img) 3491 OverlayApplicationDockTileImage (img); 3492 else 3493 RestoreApplicationDockTileImage(); 3424 if (console) 3425 console->updateDockOverlay(); 3494 3426 #endif 3495 3427 } -
trunk/src/VBox/Frontends/VirtualBox4/src/darwin/VBoxUtils-darwin.cpp
r15642 r15804 140 140 painter.end(); 141 141 return dragPixmap; 142 }143 144 /**145 * Creates a dock badge image.146 *147 * The badge will be placed on the right hand size and vertically centered148 * after having been scaled up to 32x32.149 *150 * @returns CGImageRef for the new image. (Remember to release it when finished with it.)151 * @param aSource The source name.152 */153 CGImageRef darwinCreateDockBadge (const char *aSource)154 {155 /* Create a transparent image in size 128x128. */156 QImage transImage (128, 128, QImage::Format_ARGB32);157 transImage.fill (qRgba (0, 0, 0, 0));158 /* load the badge */159 QImage badge (aSource);160 Assert (!badge.isNull());161 /* resize it and copy it onto the background. */162 if (badge.width() < 32)163 badge = badge.scaled (32, 32, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);164 QPainter painter (&transImage);165 painter.drawImage (QPoint ((transImage.width() - badge.width()) / 2.0,166 (transImage.height() - badge.height()) / 2.0),167 badge);168 painter.end();169 /* Convert it to a CGImage. */170 return ::darwinToCGImageRef (&transImage);171 }172 173 /* Import private function to capture the window content of any given window. */174 CG_EXTERN_C_BEGIN175 typedef int CGSWindowID;176 typedef void *CGSConnectionID;177 CG_EXTERN CGSWindowID GetNativeWindowFromWindowRef(WindowRef ref);178 CG_EXTERN CGSConnectionID CGSMainConnectionID(void);179 CG_EXTERN void CGContextCopyWindowCaptureContentsToRect(CGContextRef c, CGRect dstRect, CGSConnectionID connection, CGSWindowID window, int zero);180 CG_EXTERN_C_END181 182 /**183 * Updates the dock preview image.184 *185 * This method is a callback that updates the 128x128 preview image of the VM window in the dock.186 *187 * @param aVMImage the vm screen as a CGImageRef188 * @param aOverlayImage an optional icon overlay image to add at the bottom right of the icon189 * @param aStateImage an optional state overlay image to add at the center of the icon190 */191 void darwinUpdateDockPreview (QWidget *aMainWindow, CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/)192 {193 Assert (aVMImage);194 195 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();196 Assert (cs);197 198 /* Calc the size of the dock icon image and fit it into 128x128 */199 int targetWidth = 128;200 int targetHeight = 128;201 int scaledWidth;202 int scaledHeight;203 float aspect = static_cast <float> (CGImageGetWidth (aVMImage)) / CGImageGetHeight (aVMImage);204 if (aspect > 1.0)205 {206 scaledWidth = targetWidth;207 scaledHeight = targetHeight / aspect;208 }209 else210 {211 scaledWidth = targetWidth * aspect;212 scaledHeight = targetHeight;213 }214 CGRect iconRect = CGRectMake ((targetWidth - scaledWidth) / 2.0,215 (targetHeight - scaledHeight) / 2.0,216 scaledWidth, scaledHeight);217 /* Create the context to draw on */218 CGContextRef context = BeginCGContextForApplicationDockTile();219 Assert (context);220 /* Clear the background */221 CGContextSetBlendMode (context, kCGBlendModeNormal);222 CGContextClearRect (context, CGRectMake (0, 0, 128, 128));223 /* rounded corners */224 // CGContextSetLineJoin (context, kCGLineJoinRound);225 // CGContextSetShadow (context, CGSizeMake (10, 5), 1);226 // CGContextSetAllowsAntialiasing (context, true);227 /* some little boarder */228 iconRect = CGRectInset (iconRect, 1, 1);229 /* gray stroke */230 CGContextSetRGBStrokeColor (context, 225.0/255.0, 218.0/255.0, 211.0/255.0, 1);231 iconRect = CGRectInset (iconRect, 6, 6);232 CGContextStrokeRectWithWidth (context, iconRect, 12);233 iconRect = CGRectInset (iconRect, 5, 5);234 /* black stroke */235 CGContextSetRGBStrokeColor (context, 0.0, 0.0, 0.0, 1.0);236 CGContextStrokeRectWithWidth (context, iconRect, 2);237 /* vm content */238 iconRect = CGRectInset (iconRect, 1, 1);239 CGContextDrawImage (context, iconRect, aVMImage);240 /* Process the content of any external OpenGL windows. */241 WindowRef w = darwinToWindowRef (aMainWindow);242 WindowGroupRef g = GetWindowGroup (w);243 WindowGroupContentOptions wgco = kWindowGroupContentsReturnWindows | kWindowGroupContentsRecurse | kWindowGroupContentsVisible;244 ItemCount c = CountWindowGroupContents (g, wgco);245 float a1 = iconRect.size.width / static_cast <float> (CGImageGetWidth (aVMImage));246 float a2 = iconRect.size.height / static_cast <float> (CGImageGetHeight (aVMImage));247 HIViewRef mainView = HIViewGetRoot (w);248 Rect tmpR;249 GetWindowBounds (w, kWindowContentRgn, &tmpR);250 HIRect mainRect = CGRectMake (tmpR.left, tmpR.top, tmpR.right-tmpR.left, tmpR.bottom-tmpR.top);251 for (ItemCount i = 0; i <= c; ++i)252 {253 WindowRef wc;254 OSStatus status = GetIndexedWindow (g, i, wgco, &wc);255 if (status == noErr &&256 wc != w)257 {258 WindowClass winClass;259 status = GetWindowClass (wc, &winClass);260 if (status == noErr &&261 winClass == kOverlayWindowClass)262 {263 Rect tmpR1;264 GetWindowBounds (wc, kWindowContentRgn, &tmpR1);265 HIRect rect;266 rect.size.width = (tmpR1.right-tmpR1.left) * a1;267 rect.size.height = (tmpR1.bottom-tmpR1.top) * a2;268 rect.origin.x = iconRect.origin.x + (tmpR1.left - mainRect.origin.x) * a1;269 rect.origin.y = targetHeight - (iconRect.origin.y + (tmpR1.top - mainRect.origin.y) * a2) - rect.size.height;270 /* This is a big, bad hack. The following functions aren't271 * documented nor official supported by apple. But its the only way272 * to capture the OpenGL content of a window without fiddling273 * around with gPixelRead or something like that. */274 CGSWindowID wid = GetNativeWindowFromWindowRef(wc);275 CGContextCopyWindowCaptureContentsToRect(context, rect, CGSMainConnectionID(), wid, 0);276 }277 }278 }279 280 /* the state image at center */281 if (aStateImage)282 {283 CGRect stateRect = CGRectMake ((targetWidth - CGImageGetWidth (aStateImage)) / 2.0,284 (targetHeight - CGImageGetHeight (aStateImage)) / 2.0,285 CGImageGetWidth (aStateImage),286 CGImageGetHeight (aStateImage));287 CGContextDrawImage (context, stateRect, aStateImage);288 }289 /* the overlay image at bottom/right */290 if (aOverlayImage)291 {292 293 CGRect overlayRect = CGRectMake (targetWidth - CGImageGetWidth (aOverlayImage),294 0,295 CGImageGetWidth (aOverlayImage),296 CGImageGetHeight (aOverlayImage));297 CGContextDrawImage (context, overlayRect, aOverlayImage);298 }299 /* This flush updates the dock icon */300 CGContextFlush (context);301 EndCGContextForApplicationDockTile (context);302 303 CGColorSpaceRelease (cs);304 }305 306 /**307 * Updates the dock preview image.308 *309 * This method is a callback that updates the 128x128 preview image of the VM window in the dock.310 *311 * @param aFrameBuffer The guest frame buffer.312 * @param aOverlayImage an optional icon overlay image to add at the bottom right of the icon313 */314 void darwinUpdateDockPreview (QWidget *aMainWindow, VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage, CGImageRef aStateImage /*= NULL*/)315 {316 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();317 Assert (cs);318 /* Create the image copy of the framebuffer */319 CGDataProviderRef dp = CGDataProviderCreateWithData (aFrameBuffer, aFrameBuffer->address(), aFrameBuffer->bitsPerPixel() / 8 * aFrameBuffer->width() * aFrameBuffer->height(), NULL);320 Assert (dp);321 CGImageRef ir = CGImageCreate (aFrameBuffer->width(), aFrameBuffer->height(), 8, 32, aFrameBuffer->bytesPerLine(), cs,322 kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host, dp, 0, false,323 kCGRenderingIntentDefault);324 /* Update the dock preview icon */325 ::darwinUpdateDockPreview (aMainWindow, ir, aOverlayImage, aStateImage);326 /* Release the temp data and image */327 CGDataProviderRelease (dp);328 CGImageRelease (ir);329 CGColorSpaceRelease (cs);330 142 } 331 143
Note:
See TracChangeset
for help on using the changeset viewer.