-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathZXOvalTextFieldCell.m
More file actions
147 lines (137 loc) · 4.32 KB
/
ZXOvalTextFieldCell.m
File metadata and controls
147 lines (137 loc) · 4.32 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Name: ZXOvalTextFieldCell.m
* Project: Strongbox
* Created on: 2009-05-22
*
* Copyright (C) 2009 Pierre-Hans Corcoran
*
* --------------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (version 2) as published
* by the Free Software Foundation. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have
* received a copy of the GNU General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* --------------------------------------------------------------------------
*/
/*
* Original File WYOvalTextFieldCell.m by Whitney Young
* Copyright (C) 2004 Whitney Young
*/
#import "ZXOvalTextFieldCell.h"
@implementation NSActionCell(OvalCellAdditions)
- (BOOL)isOvalCell {
return NO;
}
@end
@implementation ZXOvalTextFieldCell
@synthesize shouldDrawOval, shouldDrawBorder, shouldDrawRightOval, shouldDrawLeftOval;
@synthesize ovalColor, borderColor;
- (BOOL)isOvalCell {
return YES;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSRect inner = cellFrame;
BOOL oval = [shouldDrawOval boolValue];
BOOL border = [shouldDrawBorder boolValue];
BOOL rightOval = [shouldDrawRightOval boolValue];
BOOL leftOval = [shouldDrawLeftOval boolValue];
inner.size.width += 3;
inner.origin.x -= 1;
//inner.origin.y -= 1;
//inner.size.height += 1;
if(([[ovalColor colorSpaceName] isEqual:@"NSCalibratedWhiteColorSpace"] &&
[ovalColor isEqual:[NSColor whiteColor]]) ||
(([[ovalColor colorSpaceName] isEqual:@"NSDeviceRGBColorSpace"] ||
[[ovalColor colorSpaceName] isEqual:@"NSCalibratedRGBColorSpace"]) &&
[ovalColor redComponent] > 0.9 &&
[ovalColor greenComponent] > 0.9 &&
[ovalColor blueComponent] > 0.9)) {
NSRange r = [(NSTableView *)controlView rowsInRect:cellFrame];
id colors = [NSColor controlAlternatingRowBackgroundColors];
ovalColor = [colors objectAtIndex:r.location % 2];
}
// draw the left
if(leftOval)
{
NSRect left;
NSDivideRect(inner, &left, &inner, inner.size.height, NSMinXEdge);
if (border && borderColor) {
if (![self isHighlighted] && oval) {
[borderColor set];
[[NSBezierPath bezierPathWithOvalInRect:left] fill];
}
double w = 1.0;
left.size.width -= (w * 2);
left.size.height -= (w * 2);
left.origin.x += w;
left.origin.y += w;
}
if (![self isHighlighted] && oval) {
[ovalColor set];
[[NSBezierPath bezierPathWithOvalInRect:left] fill];
}
inner = NSMakeRect(inner.origin.x - (inner.size.height / 2),
inner.origin.y,
inner.size.width + (inner.size.height / 2),
inner.size.height);
}
// draw the right
if (rightOval)
{
NSRect right;
NSDivideRect(inner, &right, &inner, inner.size.height, NSMaxXEdge);
if (border && borderColor) {
if (![self isHighlighted] && oval) {
[borderColor set];
[[NSBezierPath bezierPathWithOvalInRect:right] fill];
}
double w = 1.0;
right.size.width -= (w * 2);
right.size.height -= (w * 2);
right.origin.x += w;
right.origin.y += w;
}
if (![self isHighlighted] && oval) {
[ovalColor set];
[[NSBezierPath bezierPathWithOvalInRect:right] fill];
}
inner = NSMakeRect(inner.origin.x,
inner.origin.y,
inner.size.width + (inner.size.height / 2),
inner.size.height);
}
// draw interior
if (border && borderColor) {
if (![self isHighlighted] && oval) {
[borderColor set];
[NSBezierPath fillRect:inner];
}
double w = 1.0;
inner.size.height -= (w * 2);
inner.size.width += (w * 2);
inner.origin.x -= w;
inner.origin.y += w;
}
if (![self isHighlighted] && oval) {
[ovalColor set];
[NSBezierPath fillRect:inner];
}
[super drawWithFrame:inner inView:controlView];
}
- (void)dealloc
{
[shouldDrawOval release];
[shouldDrawBorder release];
[shouldDrawRightOval release];
[shouldDrawLeftOval release];
[ovalColor release];
// This caused some crashes.
//[borderColor release];
[super dealloc];
}
@end