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

Last change on this file since 387 was 319, checked in by Nicholas Riley, 17 years ago

VERSION: Starting with 1.5d1.

ICeCoffEEKeyEquivalents.m: Support "collision font" for displaying key
equivalent conflicts.

ICeCoffEE.m: Increase debug ICCF_MAX_URL_LEN to 120 for testing. Set
icons in ICCF_ConsolidateServicesMenu (needs better caching).

ICeCoffEEServicePrefController.m: Display icons, proper key
equivalents (instead of #, what was I thinking?!) and conflicts. Fix
a dumb bug in ICCF_PropagateServiceStateChange. Ellipsize long menu
items rather than chopping them off. Fix key equivalent column
getting moved when expanding disclosure triangles.

ICeCoffEELabeledIconCell.[hm]: An IconRef-displaying text cell.

Info-APE Module.plist: Update version to 1.5d1.

ICeCoffEE.xcodeproj: Added files, no significant changes.

English.lproj/InfoPlist.strings: Update version to 1.5d1.

English.lproj/APEInfo.rtfd/TXT.rtf: Some overdue documentation
updates.

ICeCoffEEShared.[hm]: Enable debugging; we're now using
kICServiceShortcut (though not yet for customizable shortcuts) so
define its data type.

ICeCoffEETerminal.m: Remove some useless code to "extend to beginning
of string" which seems to have been stolen from the NSTextView
implementation and not well understood. Handle common uses of
parentheses in URLs; still need to do this for NSTextView.

ICeCoffEESetServicesMenu.[hm]: Needs renaming; now with icon
extraction functionality and semi-working code to create a service
info dictionary.

Info-APEManagerPrefPane.plist: Update version to 1.5d1.

File size: 3.6 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 // XXX fix this
111 // [self setAttributedStringValue:
112 // [[self stringValue] asAttributedStringTruncatedToWidth: cellFrame.size.width - 4]];
113 [super drawWithFrame: cellFrame inView: controlView];
114}
115
116- (NSSize)cellSize;
117{
118 NSSize cellSize = [super cellSize];
119 cellSize.width += (iconRef != NULL ? (ICON_SIZE.width + PADDING): 0);
120 return cellSize;
121}
122
123@end
Note: See TracBrowser for help on using the repository browser.