3
* VBox frontends: Qt GUI ("VirtualBox"):
4
* Cocoa helper for the dock icon preview
8
* Copyright (C) 2009 Sun Microsystems, Inc.
10
* This file is part of VirtualBox Open Source Edition (OSE), as
11
* available from http://www.virtualbox.org. This file is free software;
12
* you can redistribute it and/or modify it under the terms of the GNU
13
* General Public License (GPL) as published by the Free Software
14
* Foundation, in version 2 as it comes in the "COPYING" file of the
15
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19
* Clara, CA 95054 USA or visit http://www.sun.com if you need
20
* additional information or have any questions.
23
#import "VBoxDockIconPreview.h"
25
#import <AppKit/NSView.h>
26
#import <AppKit/NSDockTile.h>
27
#import <AppKit/NSApplication.h>
28
#import <AppKit/NSGraphicsContext.h>
29
#import <AppKit/NSImage.h>
31
static NSImage *gDockIconImage = NULL;
33
/********************************************************************************
35
* C-Helper: This is the external interface to the Cocoa dock tile handling.
37
********************************************************************************/
39
void darwinCreateVBoxDockIconTileView (void)
41
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
43
if (gDockIconImage == NULL)
44
gDockIconImage = [[NSImage imageNamed:@"NSApplicationIcon"] copy];
49
void darwinDestroyVBoxDockIconTileView (void)
51
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
53
if (gDockIconImage != NULL)
55
[gDockIconImage release];
56
gDockIconImage = NULL;
62
CGContextRef darwinBeginCGContextForApplicationDockTile (void)
64
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
66
[gDockIconImage lockFocus];
68
NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
69
CGContextRef pCGContext = (CGContextRef)[nsContext graphicsPort];
75
void darwinEndCGContextForApplicationDockTile (CGContextRef aContext)
77
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
79
[gDockIconImage unlockFocus];
81
[NSApp setApplicationIconImage:gDockIconImage];
86
void darwinOverlayApplicationDockTileImage (CGImageRef pImage)
88
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
90
/* Convert the CGImage to an NSImage */
91
NSBitmapImageRep *bitmapImageRep = [[NSBitmapImageRep alloc] initWithCGImage:pImage];
94
NSImage *badgeImage = [[NSImage alloc] initWithSize:[bitmapImageRep size]];
95
[badgeImage addRepresentation:bitmapImageRep];
96
[bitmapImageRep release];
97
/* Make subsequent drawing operations on the icon */
98
[gDockIconImage lockFocus];
99
/* Draw the overlay bottom left */
100
[badgeImage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
101
[gDockIconImage unlockFocus];
102
[badgeImage release];
104
/* Set the new application icon */
105
[NSApp setApplicationIconImage:gDockIconImage];
110
void darwinRestoreApplicationDockTileImage (void)
112
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
115
darwinDestroyVBoxDockIconTileView();
116
darwinCreateVBoxDockIconTileView();