1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-09 21:54:09 +00:00

clean up icon memory management for the window drag overlay - pointed out by Stick Men on the forum

This commit is contained in:
Mitchell Livingston 2007-12-04 06:03:38 +00:00
parent fa7a76bbf6
commit 06743cb430
3 changed files with 10 additions and 30 deletions

View file

@ -26,7 +26,7 @@
@interface DragOverlayView : NSView
{
NSImage * fBadge, * fBackBadge, * fAppIcon;
NSImage * fBadge, * fBackBadge;
NSDictionary * fMainLineAttributes, * fSubLineAttributes;
}

View file

@ -26,6 +26,7 @@
#import "NSBezierPathAdditions.h"
#define PADDING 10.0
#define ICON_WIDTH 64.0
@implementation DragOverlayView
@ -76,9 +77,7 @@
- (void) dealloc
{
[fBackBadge release];
[fBadge release];
[fAppIcon release];
[fMainLineAttributes release];
[fSubLineAttributes release];
@ -92,39 +91,19 @@
fBadge = [fBackBadge copy];
NSSize badgeSize = [fBadge size];
//get icon
NSSize iconSize = NSMakeSize(64.0, 64.0);
if (!icon)
{
if (!fAppIcon)
{
fAppIcon = [[NSImage imageNamed: @"TransmissionDocument.icns"] copy];
[fAppIcon setScalesWhenResized: YES];
[fAppIcon setSize: iconSize];
}
icon = [fAppIcon retain];
}
else
{
icon = [icon copy];
[icon setScalesWhenResized: YES];
[icon setSize: iconSize];
}
[fBadge lockFocus];
//place icon
[icon compositeToPoint: NSMakePoint(PADDING, (badgeSize.height - iconSize.height) * 0.5)
operation: NSCompositeSourceOver];
[icon release];
[fBadge lockFocus];
const float WIDTH = 64.0;
[icon drawInRect: NSMakeRect(PADDING, (badgeSize.height - ICON_WIDTH) * 0.5, ICON_WIDTH, ICON_WIDTH) fromRect: NSZeroRect
operation: NSCompositeSourceOver fraction: 1.0];
//place main text
NSSize mainLineSize = [mainLine sizeWithAttributes: fMainLineAttributes];
NSSize subLineSize = [subLine sizeWithAttributes: fSubLineAttributes];
NSRect lineRect = NSMakeRect(PADDING + iconSize.width + 5.0,
NSRect lineRect = NSMakeRect(PADDING + ICON_WIDTH + 5.0,
(badgeSize.height + (subLineSize.height + 2.0 - mainLineSize.height)) * 0.5,
badgeSize.width - (PADDING + iconSize.width + 2.0) - PADDING, mainLineSize.height);
badgeSize.width - (PADDING + ICON_WIDTH + 2.0) - PADDING, mainLineSize.height);
[mainLine drawInRect: lineRect withAttributes: fMainLineAttributes];
//place sub text

View file

@ -106,7 +106,6 @@
return;
//set strings and icon
NSImage * icon = nil;
NSString * secondString = [NSString stringForFileSize: size];
if (count > 1 || folder)
{
@ -118,12 +117,14 @@
secondString = [fileString stringByAppendingString: secondString];
}
NSImage * icon;
if (count == 1)
icon = [[NSWorkspace sharedWorkspace] iconForFileType: folder ? NSFileTypeForHFSTypeCode('fldr') : [name pathExtension]];
else
{
name = [NSString stringWithFormat: NSLocalizedString(@"%d Torrent Files", "Drag overlay -> torrents"), count];
secondString = [secondString stringByAppendingString: @" Total"];
icon = [NSImage imageNamed: @"TransmissionDocument.icns"];
}
[[self contentView] setOverlay: icon mainLine: name subLine: secondString];