GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of Caged/gitnub
Description: A Gitk-like application written in RubyCocoa that looks like it belongs on a Mac. See the wiki for downloads and screenshots.
Homepage: http://alternateidea.com
Clone URL: git://github.com/auser/gitnub.git
gitnub / CommitSummaryCell.m
100644 114 lines (91 sloc) 3.438 kb
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// CommitSummaryCell.m
// GitNub
//
// Created by local22 on 3/12/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
 
#import "CommitSummaryCell.h"
 
#define PADDING (2.0)
#define GRAVATAR_WIDTH (36.0)
 
@implementation CommitSummaryCell
- (void)dealloc {
    [titleCell release];
    [subtitleCell release];
    [gravatarCell release];
    
    [super dealloc];
}
 
- (id)init {
    self = [super init];
    if(self) {
        titleCell = [[NSTextFieldCell alloc] init];
        [titleCell setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
        [titleCell setLineBreakMode:NSLineBreakByTruncatingTail];
        
        subtitleCell = [[NSTextFieldCell alloc] init];
        [subtitleCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
        [subtitleCell setLineBreakMode:NSLineBreakByTruncatingTail];
        
        gravatarCell = [[NSImageCell alloc] init];
    }
    return self;
}
 
- (id)copyWithZone:(NSZone *)zone {
    CommitSummaryCell *copy = [super copyWithZone:zone];
    if(copy) {
        copy->titleCell = [titleCell copyWithZone:zone];
        copy->subtitleCell = [subtitleCell copyWithZone:zone];
        copy->gravatarCell = [gravatarCell copyWithZone:zone];
    }
    return copy;
}
 
- (void)setGravatarImage:(NSImage *)image {
    [gravatarCell setImage:image];
}
 
- (void)setSubtitle:(NSString *)string {
    [subtitleCell setStringValue:string];
}
 
- (void)setObjectValue:(id)object {
    [titleCell setObjectValue:object];
}
 
- (void)setBackgroundStyle:(NSBackgroundStyle)style {
    [super setBackgroundStyle:style];
    
    [titleCell setBackgroundStyle:style];
    
    [subtitleCell setBackgroundStyle:style];
    [subtitleCell setTextColor:(style == NSBackgroundStyleLight) ? [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
}
 
- (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView *)view {
    NSSize fullSize = [[titleCell attributedStringValue] size];
    fullSize.width += PADDING + GRAVATAR_WIDTH;
    
    if(fullSize.width > NSWidth(cellFrame)) {
        cellFrame.size.width = fullSize.width;
    } else {
        cellFrame = NSZeroRect;
    }
    
    return cellFrame;
}
 
- (NSRect)titleRectForBounds:(NSRect)theRect {
    NSRect imageRect, titleRect;
    theRect = NSInsetRect(theRect, PADDING, PADDING);
    NSDivideRect(theRect, &imageRect, &titleRect, GRAVATAR_WIDTH + 4, NSMinXEdge);
    NSSize stringSize = [[titleCell attributedStringValue] size];
    //titleRect.origin.y += (NSHeight(titleRect) - stringSize.height)/2.0;
    titleRect.origin.x += PADDING;
    titleRect.size.height = stringSize.height;
    
    return titleRect;
}
 
- (NSRect)subtitleRectForBounds:(NSRect)theRect {
    theRect = [self titleRectForBounds:theRect];
    theRect.origin.y += NSHeight(theRect) + PADDING;
    return theRect;
}
 
- (NSRect)gravatarRectForBounds:(NSRect)theRect {
    NSRect imageRect, titleRect;
    theRect = NSInsetRect(theRect, PADDING, PADDING);
    NSDivideRect(theRect, &imageRect, &titleRect, GRAVATAR_WIDTH + 4, NSMinXEdge);
    return imageRect;
}
 
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)view {
    [titleCell drawInteriorWithFrame:[self titleRectForBounds:cellFrame] inView:view];
    [subtitleCell drawInteriorWithFrame:[self subtitleRectForBounds:cellFrame] inView:view];
    [gravatarCell drawInteriorWithFrame:[self gravatarRectForBounds:cellFrame] inView:view];
}
@end