1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00
transmission/macosx/FileBrowserCell.m

104 lines
4.6 KiB
Mathematica
Raw Normal View History

2007-04-03 02:15:24 +00:00
/******************************************************************************
* $Id$
*
* Copyright (c) 2007 Transmission authors and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
2007-01-18 01:19:14 +00:00
#import "FileBrowserCell.h"
2007-01-18 22:53:27 +00:00
#import "StringAdditions.h"
2007-01-18 01:19:14 +00:00
#define SPACE 2.0
@implementation FileBrowserCell
- (void) awakeFromNib
{
[self setLeaf: YES];
}
2007-01-18 01:19:14 +00:00
- (void) setImage: (NSImage *) image
{
[image setFlipped: YES];
[image setScalesWhenResized: YES];
2007-01-18 01:19:14 +00:00
[super setImage: image];
}
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
{
NSMutableDictionary * item;
if (!(item = [self objectValue]))
return;
2007-01-18 01:19:14 +00:00
//image
float imageHeight = cellFrame.size.height - 2.0;
2007-01-18 01:19:14 +00:00
NSImage * image = [self image];
[image setSize: NSMakeSize(imageHeight, imageHeight)];
NSRect imageRect = NSMakeRect(cellFrame.origin.x + 2.0 * SPACE,
cellFrame.origin.y + (cellFrame.size.height - imageHeight) / 2.0,
imageHeight, imageHeight);
[image drawInRect: imageRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
2007-01-18 01:19:14 +00:00
//text
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
BOOL highlighted = [self isHighlighted] && [[self highlightColorWithFrame: cellFrame inView: controlView]
isEqual: [NSColor alternateSelectedControlColor]];
NSDictionary * nameAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
highlighted ? [NSColor whiteColor] : [NSColor controlTextColor], NSForegroundColorAttributeName,
[NSFont messageFontOfSize: 12.0], NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil];
NSString * nameString = [item objectForKey: @"Name"];
NSRect nameTextRect = NSMakeRect(NSMaxX(imageRect) + SPACE, cellFrame.origin.y + 1.0,
NSMaxX(cellFrame) - NSMaxX(imageRect) - 2.0 * SPACE, [nameString sizeWithAttributes: nameAttributes].height);
[nameString drawInRect: nameTextRect withAttributes: nameAttributes];
[nameAttributes release];
2007-01-18 01:19:14 +00:00
//status text
2007-01-18 22:53:27 +00:00
if (![[item objectForKey: @"IsFolder"] boolValue])
2007-01-18 01:19:14 +00:00
{
NSDictionary * statusAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
highlighted ? [NSColor whiteColor] : [NSColor darkGrayColor], NSForegroundColorAttributeName,
[NSFont messageFontOfSize: 9.0], NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil];
2007-01-18 01:19:14 +00:00
2007-02-23 15:56:52 +00:00
NSString * statusString = [NSString stringWithFormat: NSLocalizedString(@"%.2f%% of %@",
"Inspector -> Files tab -> file status string"),
100.0 * [[item objectForKey: @"Progress"] floatValue],
[NSString stringForFileSize: [[item objectForKey: @"Size"] unsignedLongLongValue]]];
NSRect statusTextRect = nameTextRect;
statusTextRect.size.height = [statusString sizeWithAttributes: statusAttributes].height;
statusTextRect.origin.y += (cellFrame.size.height + nameTextRect.size.height - statusTextRect.size.height) * 0.5 - 1.0;
2007-01-18 01:19:14 +00:00
[statusString drawInRect: statusTextRect withAttributes: statusAttributes];
[statusAttributes release];
}
[paragraphStyle release];
2007-01-18 01:19:14 +00:00
}
@end