Ignore:
Timestamp:
10/12/07 21:53:46 (17 years ago)
Author:
rchin
Message:

Leopard compatibility changes:

  • Removed some icon caching code that was causing crashes (not sure we really needed those optimizations anyway -- doesn't appear to affect performance)
  • Added code to automatically try to add certificate to keychain, for new code signing behavior (replaces previous procmod nonesense).
  • Note that the enclosed public certificate is mine, and so it will need to be signed by me. In the case that someone else wants to distribute this binary, please replace Certficiate.cer with your own public certificate, and then make sure o code sign the binary after it is built.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/F-Script Anywhere/Source/NJRLabeledImageCell.m

    r19 r342  
    3838- (void)dealloc {
    3939    [image release];
    40     [imageCacheSource release];
    4140    image = nil;
    4241    [super dealloc];
     
    5857- (NSImage *)image {
    5958    return image;
    60 }
    61 
    62 - (void)setImageCacheSource:(id)aSource {
    63     if (aSource != imageCacheSource) {
    64         [imageCacheSource release];
    65         imageCacheSource = [aSource retain];
    66     }
    6759}
    6860
     
    10294        imageSize = NSMakeSize(cellFrame.size.height - 1, cellFrame.size.height - 1);
    10395
    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
    160146       
    161147        NSDivideRect(cellFrame, &imageFrame, &cellFrame,
     
    176162            fromRect: NSOffsetRect(imageFrame, -imageFrame.origin.x, -imageFrame.origin.y)
    177163            operation: NSCompositeSourceOver fraction: 1.0];
    178         [imageCacheSource setCachedImage: image];
    179164    }
    180165    [self setAttributedStringValue:
    181166        [[self stringValue] asAttributedStringTruncatedToWidth: cellFrame.size.width - 4]];
    182     [self setImageCacheSource: nil]; // without this, we crash (multiple cells get created!)
    183167    [super drawWithFrame: cellFrame inView: controlView];
    184168}
Note: See TracChangeset for help on using the changeset viewer.