forked from AlessandroSangiuliano/rik.theme
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NSCell+Rik.m
67 lines (56 loc) · 1.73 KB
/
NSCell+Rik.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
/**
* Copyright (C) 2014 Alessandro Sangiuliano
* Author: Alessandro Sangiuliano <[email protected]>
* Date: 29 September 2014
*/
#import "Rik.h"
@implementation NSCell(RikTheme)
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
NSRect drawingRect = [self drawingRectForBounds: cellFrame];
//FIXME: Check if this is also neccessary for images,
// Add spacing between border and inside
if (_cell.is_bordered || _cell.is_bezeled)
{
drawingRect.origin.x += 3;
drawingRect.size.width -= 6;
drawingRect.origin.y -= 2;
drawingRect.size.height += 3;
}
switch (_cell.type)
{
case NSTextCellType:
if (_cell.in_editing)
{
cellFrame.origin.y -= 2;
cellFrame.size.height += 4; //it works well, but not perfect
[self _drawEditorWithFrame: cellFrame inView: controlView];
}
else
[self _drawAttributedText: [self _drawAttributedString]
inFrame: drawingRect];
break;
case NSImageCellType:
if (_cell_image)
{
NSSize size;
NSPoint position;
size = [_cell_image size];
position.x = MAX(NSMidX(drawingRect) - (size.width/2.),0.);
position.y = MAX(NSMidY(drawingRect) - (size.height/2.),0.);
[_cell_image drawInRect: NSMakeRect(position.x, position.y, size.width, size.height)
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0
respectFlipped: YES
hints: nil];
}
break;
case NSNullCellType:
break;
}
// NB: We don't do any highlighting to make it easier for subclasses
// to reuse this code while doing their own custom highlighting and
// prettyfying
}
@end