- Timestamp:
- 10/12/07 21:53:46 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/F-Script Anywhere/Source/NJRLabeledImageCell.m
r19 r342 38 38 - (void)dealloc { 39 39 [image release]; 40 [imageCacheSource release];41 40 image = nil; 42 41 [super dealloc]; … … 58 57 - (NSImage *)image { 59 58 return image; 60 }61 62 - (void)setImageCacheSource:(id)aSource {63 if (aSource != imageCacheSource) {64 [imageCacheSource release];65 imageCacheSource = [aSource retain];66 }67 59 } 68 60 … … 102 94 imageSize = NSMakeSize(cellFrame.size.height - 1, cellFrame.size.height - 1); 103 95 104 preferredRep = [[[imageCacheSource cachedImage] representations] objectAtIndex: 0]; 105 if (preferredRep != nil && abs([preferredRep size].width - imageSize.width) < 1 && abs([preferredRep size].height != imageSize.height) < 1) { 106 [self setImage: [imageCacheSource cachedImage]]; 107 // FSALog(@"%@ accepting cached image: %@", [self stringValue], preferredRep); 108 } else { 109 NSArray *imageReps = [image representations]; 110 int i, repCount = [imageReps count]; 111 NSSize repSize; 112 113 preferredRep = [imageReps objectAtIndex: 0]; 114 // FSALog(@"%@ rejecting cached image: %@", [self stringValue], preferredRep); 115 for (i = 1 ; i < repCount ; i++) { 116 rep = [imageReps objectAtIndex: i]; 117 repSize = [rep size]; 118 if (repSize.width == imageSize.width && repSize.height == imageSize.height) { 119 preferredRep = rep; 120 break; 121 } 122 if (repSize.width >= imageSize.width || repSize.height >= imageSize.height) { 123 // pick the smallest of the larger representations 124 if (repSize.width <= [preferredRep size].width || 125 repSize.height <= [preferredRep size].height) preferredRep = rep; 126 } else { 127 // or the largest of the smaller representations 128 if (repSize.width >= [preferredRep size].width || 129 repSize.height >= [preferredRep size].height) preferredRep = rep; 130 } 131 } 132 /* // Working code as of OS X 10.0.4; this breaks in 10.1 133 for (i = repCount - 1 ; i >= 0 ; i--) { 134 rep = [imageReps objectAtIndex: i]; 135 if (rep != preferredRep) { 136 [image removeRepresentation: rep]; 137 } 138 } 139 // End working code 140 */ 141 // Begin workaround code for bug in OS X 10.1 (removeRepresentation: has no effect) 142 if ([preferredRep size].width > imageSize.width || [preferredRep size].height > imageSize.height) { 143 NSImage *scaledImage = [[NSImage alloc] initWithSize: imageSize]; 144 NSRect rect = { NSZeroPoint, imageSize }; 145 FSALog(@"rescaling %@", [self stringValue]); 146 [scaledImage setFlipped: [controlView isFlipped]]; // XXX this works, but is correct? 147 [scaledImage lockFocus]; 148 [preferredRep drawInRect: rect]; 149 [scaledImage unlockFocus]; 150 [image release]; 151 image = scaledImage; 152 } else if (repCount > 1) { 153 NSImage *sizedImage = [[NSImage alloc] initWithSize: [preferredRep size]]; 154 [sizedImage addRepresentation: preferredRep]; 155 [image release]; 156 image = sizedImage; 157 } 158 // End workaround code 159 } 96 NSArray *imageReps = [image representations]; 97 int i, repCount = [imageReps count]; 98 NSSize repSize; 99 100 preferredRep = [imageReps objectAtIndex: 0]; 101 // FSALog(@"%@ rejecting cached image: %@", [self stringValue], preferredRep); 102 for (i = 1 ; i < repCount ; i++) { 103 rep = [imageReps objectAtIndex: i]; 104 repSize = [rep size]; 105 if (repSize.width == imageSize.width && repSize.height == imageSize.height) { 106 preferredRep = rep; 107 break; 108 } 109 if (repSize.width >= imageSize.width || repSize.height >= imageSize.height) { 110 // pick the smallest of the larger representations 111 if (repSize.width <= [preferredRep size].width || 112 repSize.height <= [preferredRep size].height) preferredRep = rep; 113 } else { 114 // or the largest of the smaller representations 115 if (repSize.width >= [preferredRep size].width || 116 repSize.height >= [preferredRep size].height) preferredRep = rep; 117 } 118 } 119 /* // Working code as of OS X 10.0.4; this breaks in 10.1 120 for (i = repCount - 1 ; i >= 0 ; i--) { 121 rep = [imageReps objectAtIndex: i]; 122 if (rep != preferredRep) { 123 [image removeRepresentation: rep]; 124 } 125 } 126 // End working code 127 */ 128 // Begin workaround code for bug in OS X 10.1 (removeRepresentation: has no effect) 129 if ([preferredRep size].width > imageSize.width || [preferredRep size].height > imageSize.height) { 130 NSImage *scaledImage = [[NSImage alloc] initWithSize: imageSize]; 131 NSRect rect = { NSZeroPoint, imageSize }; 132 FSALog(@"rescaling %@", [self stringValue]); 133 [scaledImage setFlipped: [controlView isFlipped]]; // XXX this works, but is correct? 134 [scaledImage lockFocus]; 135 [preferredRep drawInRect: rect]; 136 [scaledImage unlockFocus]; 137 [image release]; 138 image = scaledImage; 139 } else if (repCount > 1) { 140 NSImage *sizedImage = [[NSImage alloc] initWithSize: [preferredRep size]]; 141 [sizedImage addRepresentation: preferredRep]; 142 [image release]; 143 image = sizedImage; 144 } 145 // End workaround code 160 146 161 147 NSDivideRect(cellFrame, &imageFrame, &cellFrame, … … 176 162 fromRect: NSOffsetRect(imageFrame, -imageFrame.origin.x, -imageFrame.origin.y) 177 163 operation: NSCompositeSourceOver fraction: 1.0]; 178 [imageCacheSource setCachedImage: image];179 164 } 180 165 [self setAttributedStringValue: 181 166 [[self stringValue] asAttributedStringTruncatedToWidth: cellFrame.size.width - 4]]; 182 [self setImageCacheSource: nil]; // without this, we crash (multiple cells get created!)183 167 [super drawWithFrame: cellFrame inView: controlView]; 184 168 }
Note:
See TracChangeset
for help on using the changeset viewer.