Chameleon Applications

Chameleon Applications Svn Source Tree

Root/trunk/ChameleonPrefPane/Sources/CenterTextFieldCell.mm

  • Property svn:executable set to *
1//
2// CenterTextField.mm
3// ChameleonPrefPane
4//
5// Created by Rekursor on 11/10/11.
6//
7
8#import "CenterTextFieldCell.h"
9
10//--------------------------------------------------------------------------
11@implementation CenteredTextFieldCell
12//--------------------------------------------------------------------------
13- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
14{
15 NSSize contentSize = [self cellSize];
16 cellFrame.origin.y += (cellFrame.size.height - contentSize.height) / 2.0;
17 cellFrame.size.height = contentSize.height;
18
19NSAttributedString *drawString = [self attributedStringValue];
20
21NSRange range;
22NSDictionary *attributes = [drawString attributesAtIndex:0 effectiveRange:&range];
23
24float maxWidth = cellFrame.size.width;
25float stringWidth = [drawString size].width;
26
27if (maxWidth < stringWidth)
28{
29int i;
30
31for (i = 0;i <= [drawString length];i++)
32{
33if ([[drawString attributedSubstringFromRange:NSMakeRange(0,i)]size].width >= maxWidth)
34{
35drawString = [[NSMutableAttributedString alloc] initWithString:
36 [[[drawString attributedSubstringFromRange:NSMakeRange(0,i-3)]string] stringByAppendingString:@"..."]attributes:attributes];
37[drawString autorelease];
38}
39}
40}
41
42[drawString drawInRect:cellFrame];
43
44}
45
46@end
47
48
49

Archive Download this file

Revision: 341