source: trunk/ICeCoffEE/ICeCoffEE/ICeCoffEELabeledIconCell.m@ 424

Last change on this file since 424 was 422, checked in by Nicholas Riley, 16 years ago

ICeCoffEELabeledIconCell.[hm]: highlighting now, for better keyboard control; remove obsolete commented-out code

File size: 3.5 KB
Line 
1//
2// ICeCoffEELabeledIconCell.m
3// ICeCoffEE
4//
5// Created by Nicholas Riley on 6/8/07.
6// Copyright 2007 Nicholas Riley. All rights reserved.
7//
8
9#import "ICeCoffEELabeledIconCell.h"
10
11
12@implementation ICeCoffEELabeledIconCell
13
14const static float LEFT_PADDING = 3;
15const static float PADDING = 5;
16const static NSSize ICON_SIZE = {16, 16};
17
18- (ICeCoffEELabeledIconCell *)justCopySuper;
19{
20 return [super copy];
21}
22
23+ (ICeCoffEELabeledIconCell *)copyFromTextFieldCell:(NSTextFieldCell *)cell;
24{
25 ((struct objc_object *)cell)->isa = self;
26 ICeCoffEELabeledIconCell *copy = [(ICeCoffEELabeledIconCell *)cell justCopySuper];
27 copy->iconRef = NULL;
28 ((struct objc_object *)cell)->isa = [NSTextFieldCell class];
29 return [copy autorelease];
30}
31
32- (void)dealloc;
33{
34 if (iconRef != NULL) {
35 ReleaseIconRef(iconRef);
36 iconRef = NULL;
37 }
38 [super dealloc];
39}
40
41- (id)copyWithZone:(NSZone *)zone;
42{
43 ICeCoffEELabeledIconCell *cell = [super copyWithZone: zone];
44 cell->iconRef = iconRef;
45 if (iconRef != NULL)
46 AcquireIconRef(iconRef);
47 return cell;
48}
49
50- (void)setIconRef:(IconRef)anIconRef;
51{
52 if (anIconRef == iconRef)
53 return;
54 if (iconRef != NULL)
55 ReleaseIconRef(iconRef);
56 if (anIconRef != NULL)
57 AcquireIconRef(anIconRef);
58 iconRef = anIconRef;
59}
60
61- (IconRef)iconRef;
62{
63 return iconRef;
64}
65
66- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent;
67{
68 NSRect textFrame, imageFrame;
69 NSDivideRect(aRect, &imageFrame, &textFrame,
70 PADDING + ICON_SIZE.width, NSMinXEdge);
71 [super editWithFrame: textFrame inView: controlView
72 editor: textObj delegate: anObject event: theEvent];
73}
74
75- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(int)selStart length:(int)selLength;
76{
77 NSRect textFrame, imageFrame;
78 NSDivideRect(aRect, &imageFrame, &textFrame, PADDING + ICON_SIZE.width,
79 NSMinXEdge);
80 [super selectWithFrame: textFrame inView: controlView editor:textObj delegate: anObject start: selStart length: selLength];
81}
82
83- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
84{
85 if (iconRef != NULL) {
86 NSRect imageFrame;
87 BOOL flipped = [controlView isFlipped];
88
89 NSDivideRect(cellFrame, &imageFrame, &cellFrame, PADDING + ICON_SIZE.width, NSMinXEdge);
90 if ([self drawsBackground]) {
91 [[self backgroundColor] set];
92 NSRectFill(imageFrame);
93 }
94 imageFrame.origin.x += LEFT_PADDING;
95 imageFrame.size = ICON_SIZE;
96
97 imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height + 2) / 2);
98
99 NSRect imageRect = NSOffsetRect(imageFrame, -imageFrame.origin.x, -imageFrame.origin.y);
100 CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
101 CGContextTranslateCTM(context, imageFrame.origin.x, imageFrame.origin.y);
102 if (flipped)
103 CGContextScaleCTM(context, 1, -1);
104 PlotIconRefInContext(context, (CGRect *)&imageRect, kAlignNone, kTransformNone,
105 NULL /*inLabelColor*/, kPlotIconRefNormalFlags, iconRef);
106 if (flipped)
107 CGContextScaleCTM(context, 1, -1);
108 CGContextTranslateCTM(context, -imageFrame.origin.x, -imageFrame.origin.y);
109 }
110 [super drawWithFrame: cellFrame inView: controlView];
111}
112
113- (NSSize)cellSize;
114{
115 NSSize cellSize = [super cellSize];
116 cellSize.width += (iconRef != NULL ? (ICON_SIZE.width + PADDING): 0);
117 return cellSize;
118}
119
120@end
Note: See TracBrowser for help on using the repository browser.