Chameleon Applications

Chameleon Applications Commit Details

Date:2011-12-01 02:43:04 (8 years 10 months ago)
Author:Rekursor
Commit:372
Parents: 371
Message:greatly simplified nscenteredtext
Changes:
M/trunk/ChameleonPrefPane/Sources/CenterTextFieldCell.mm

File differences

trunk/ChameleonPrefPane/Sources/CenterTextFieldCell.mm
1212
1313
1414
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
15
16
17
18
19
4420
4521
4622
//--------------------------------------------------------------------------
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSSize contentSize = [self cellSize];
cellFrame.origin.y += (cellFrame.size.height - contentSize.height) / 2.0;
cellFrame.size.height = contentSize.height;
NSAttributedString *drawString = [self attributedStringValue];
NSRange range;
NSDictionary *attributes = [drawString attributesAtIndex:0 effectiveRange:&range];
float maxWidth = cellFrame.size.width;
float stringWidth = [drawString size].width;
if (maxWidth < stringWidth)
{
int i;
for (i = 0;i <= [drawString length];i++)
{
if ([[drawString attributedSubstringFromRange:NSMakeRange(0,i)]size].width >= maxWidth)
{
drawString = [[NSMutableAttributedString alloc] initWithString:
[[[drawString attributedSubstringFromRange:NSMakeRange(0,i-3)]string] stringByAppendingString:@"..."]attributes:attributes];
[drawString autorelease];
}
}
}
[drawString drawInRect:cellFrame];
NSSize contentSize = [self cellSize];
cellFrame.origin.y += (cellFrame.size.height - contentSize.height) / 2.0;
cellFrame.size.height = contentSize.height;
[super drawInteriorWithFrame:cellFrame inView:controlView];
}
@end

Archive Download the corresponding diff file

Revision: 372