-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSFObjectCell.m
79 lines (57 loc) · 2.8 KB
/
SFObjectCell.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// SFObjectCell.m
// SilverFlow
//
// Created by Julius Eckert on 26.01.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "SFObjectCell.h"
@implementation SFObjectCell
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
QSObject *drawObject = [self representedObject];
[self buildStylesForFrame:cellFrame inView:controlView];
if ([drawObject isKindOfClass:[QSNullObject class]]) return;
if (!drawObject) {
return;
}
[self drawIconForObject:drawObject withFrame:(NSRect) cellFrame inView:(NSView *)controlView];
[self drawTextForObject:drawObject withFrame:(NSRect) cellFrame inView:(NSView *)controlView];
}
- (void)buildStylesForFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSMutableParagraphStyle *style = [[[NSMutableParagraphStyle alloc] init] autorelease];
[style setLineBreakMode:NSLineBreakByTruncatingTail];
[style setFirstLineHeadIndent:1.0];
[style setHeadIndent:1.0];
[style setAlignment:[self alignment]];
NSColor *mainColor = [NSColor whiteColor];
NSColor *fadedColor = [mainColor colorWithAlphaComponent:0.80];
[nameAttributes release];
nameAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSFont fontWithName:[[self font] fontName] size:MIN([[self font] pointSize] , NSHeight(cellFrame) *1.125*2/3) -1] , NSFontAttributeName,
mainColor, NSForegroundColorAttributeName,
style, NSParagraphStyleAttributeName,
nil];
[detailsAttributes release];
detailsAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSFont fontWithName:[[self font] fontName] size:[[self font] pointSize] *5/6] , NSFontAttributeName,
fadedColor, NSForegroundColorAttributeName,
style, NSParagraphStyleAttributeName,
nil];
}
- (void)drawTextForObject:(QSObject *)drawObject withFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSString *nameString = nil;
if (!nameString) nameString = [drawObject label];
if (!nameString) nameString = [drawObject name];
if (!nameString) nameString = @"<Unknown>";
NSSize nameSize = [nameString sizeWithAttributes:nameAttributes];
NSRect textDrawRect = [self titleRectForBounds:cellFrame];
NSMutableAttributedString *titleString = [[[NSMutableAttributedString alloc] initWithString:nameString?nameString:@"???"] autorelease];
[titleString setAttributes:nameAttributes range:NSMakeRange(0, [titleString length])];
[titleString addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithFloat:-1.0] range:NSMakeRange(0, [titleString length])];
[[NSColor whiteColor] set];
NSRect centerRect = rectFromSize([titleString size]);
centerRect.size.width = NSWidth(textDrawRect);
centerRect.size.height = MIN(NSHeight(textDrawRect), centerRect.size.height);
[titleString drawInRect:centerRectInRect(centerRect, textDrawRect)];
}
@end