Changeset 587 for trunk/Cocoa
- Timestamp:
- 09/20/09 21:08:13 (15 years ago)
- Location:
- trunk/Cocoa/Pester/Source
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/NJRFSObjectSelector.m
r558 r587 111 111 } 112 112 113 - (void)revealInFinder:( id<NSMenuItem>)sender;113 - (void)revealInFinder:(NSMenuItem *)sender; 114 114 { 115 115 NSString *path = [sender representedObject]; -
trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m
r576 r587 568 568 while ( (type = [e nextObject]) != nil) { 569 569 if ([type hasPrefix: @"CorePasteboardFlavorType 0x"]) { 570 const char *osTypeHex = [[type substringFromIndex: [type rangeOfString: @"0x" options: NSBackwardsSearch].location] lossyCString];570 const char *osTypeHex = [[type substringFromIndex: [type rangeOfString: @"0x" options: NSBackwardsSearch].location] UTF8String]; 571 571 OSType osType; 572 572 sscanf(osTypeHex, "%lx", &osType); -
trunk/Cocoa/Pester/Source/NSImage-OAExtensions.h
r102 r587 14 14 @interface NSImage (OAExtensions) 15 15 16 + (NSImage *)imageNamed:(NSString *)imageName inBundleForClass:(Class)aClass;17 16 + (NSImage *)imageNamed:(NSString *)imageName inBundle:(NSBundle *)aBundle; 18 + (NSImage *)imageForFileType:(NSString *)fileType;19 // Caching wrapper for -[NSWorkspace iconForFileType:]. This method is not thread-safe at the moment.20 + (NSImage *)draggingIconWithTitle:(NSString *)title andImage:(NSImage *)image;21 22 - (void)drawFlippedInRect:(NSRect)rect operation:(NSCompositingOperation)op fraction:(float)delta;23 - (void)drawFlippedInRect:(NSRect)rect operation:(NSCompositingOperation)op;24 25 // Puts the image on the pasteboard as TIFF, and also supplies data from any PDF, EPS, or PICT representations available. Returns the number of types added to the pasteboard and adds their names to notThese. This routine uses -addTypes:owner:, so the pasteboard must have previously been set up using -declareTypes:owner.26 - (int)addDataToPasteboard:(NSPasteboard *)aPasteboard exceptTypes:(NSMutableSet *)notThese;27 17 28 18 @end -
trunk/Cocoa/Pester/Source/NSImage-OAExtensions.m
r555 r587 13 13 14 14 @implementation NSImage (OAExtensions) 15 16 + (NSImage *)imageNamed:(NSString *)imageName inBundleForClass:(Class)aClass;17 {18 return [self imageNamed:imageName inBundle:[NSBundle bundleForClass:aClass]];19 }20 15 21 16 + (NSImage *)imageNamed:(NSString *)imageName inBundle:(NSBundle *)aBundle; … … 38 33 } 39 34 40 + (NSImage *)imageForFileType:(NSString *)fileType;41 // It turns out that -[NSWorkspace iconForFileType:] doesn't cache previously returned values, so we cache them here.42 {43 static NSMutableDictionary *imageDictionary = nil;44 id image;45 46 // ASSERT_IN_MAIN_THREAD(@"+imageForFileType: is not thread-safe; must be called from the main thread");47 // We could fix this by adding locks around imageDictionary48 49 if (!fileType)50 return nil;51 52 if (imageDictionary == nil)53 imageDictionary = [[NSMutableDictionary alloc] init];54 55 image = [imageDictionary objectForKey:fileType];56 if (image == nil) {57 #ifdef DEBUG58 // Make sure that our caching doesn't go insane (and that we don't ask it to cache insane stuff)59 NSLog(@"Caching workspace image for file type '%@'", fileType);60 #endif61 image = [[NSWorkspace sharedWorkspace] iconForFileType:fileType];62 if (image == nil)63 image = [NSNull null];64 [imageDictionary setObject:image forKey:fileType];65 }66 return image != [NSNull null] ? image : nil;67 }68 69 #define X_SPACE_BETWEEN_ICON_AND_TEXT_BOX 270 #define X_TEXT_BOX_BORDER 271 #define Y_TEXT_BOX_BORDER 272 static NSDictionary *titleFontAttributes;73 74 + (NSImage *)draggingIconWithTitle:(NSString *)title andImage:(NSImage *)image;75 {76 NSImage *drawImage;77 NSSize imageSize, totalSize;78 NSSize titleSize, titleBoxSize;79 NSRect titleBox;80 NSPoint textPoint;81 82 NSParameterAssert(image != nil);83 imageSize = [image size];84 85 if (!titleFontAttributes)86 titleFontAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:[NSFont systemFontOfSize:12.0], NSFontAttributeName, [NSColor textColor], NSForegroundColorAttributeName, nil];87 88 if (!title || [title length] == 0)89 return image;90 91 titleSize = [title sizeWithAttributes:titleFontAttributes];92 titleBoxSize = NSMakeSize(titleSize.width + 2.0 * X_TEXT_BOX_BORDER, titleSize.height + Y_TEXT_BOX_BORDER);93 94 totalSize = NSMakeSize(imageSize.width + X_SPACE_BETWEEN_ICON_AND_TEXT_BOX + titleBoxSize.width, MAX(imageSize.height, titleBoxSize.height));95 96 drawImage = [[NSImage alloc] initWithSize:totalSize];97 [drawImage setFlipped:YES];98 99 [drawImage lockFocus];100 101 // Draw transparent background102 [[NSColor colorWithDeviceWhite:1.0 alpha:0.0] set];103 NSRectFill(NSMakeRect(0, 0, totalSize.width, totalSize.height));104 105 // Draw icon106 [image compositeToPoint:NSMakePoint(0.0, rint(totalSize.height / 2.0 + imageSize.height / 2.0)) operation:NSCompositeSourceOver];107 108 // Draw box around title109 titleBox = NSMakeRect(imageSize.width + X_SPACE_BETWEEN_ICON_AND_TEXT_BOX, floor((totalSize.height - titleBoxSize.height)/2.0), titleBoxSize.width, titleBoxSize.height);110 [[[NSColor selectedTextBackgroundColor] colorWithAlphaComponent:0.5] set];111 NSRectFill(titleBox);112 113 // Draw title114 textPoint = NSMakePoint(imageSize.width + X_SPACE_BETWEEN_ICON_AND_TEXT_BOX + X_TEXT_BOX_BORDER, Y_TEXT_BOX_BORDER - 1);115 116 [title drawAtPoint:textPoint withAttributes:titleFontAttributes];117 118 [drawImage unlockFocus];119 120 return [drawImage autorelease];121 }122 123 //124 125 - (void)drawFlippedInRect:(NSRect)rect operation:(NSCompositingOperation)op fraction:(float)delta;126 {127 CGContextRef context;128 129 context = [[NSGraphicsContext currentContext] graphicsPort];130 CGContextSaveGState(context); {131 CGContextTranslateCTM(context, 0, NSMaxY(rect));132 CGContextScaleCTM(context, 1, -1);133 134 rect.origin.y = 0; // We've translated ourselves so it's zero135 [self drawInRect:rect fromRect:NSZeroRect operation:op fraction:delta];136 } CGContextRestoreGState(context);137 138 /*139 NSAffineTransform *flipTransform;140 NSPoint transformedPoint;141 NSSize transformedSize;142 NSRect transformedRect;143 144 flipTransform = [[NSAffineTransform alloc] init];145 [flipTransform scaleXBy:1.0 yBy:-1.0];146 147 transformedPoint = [flipTransform transformPoint:rect.origin];148 transformedSize = [flipTransform transformSize:rect.size];149 [flipTransform concat];150 transformedRect = NSMakeRect(transformedPoint.x, transformedPoint.y + transformedSize.height, transformedSize.width, -transformedSize.height);151 [anImage drawInRect:transformedRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];152 [flipTransform concat];153 [flipTransform release];154 */155 }156 157 - (void)drawFlippedInRect:(NSRect)rect operation:(NSCompositingOperation)op;158 {159 [self drawFlippedInRect:rect operation:op fraction:1.0];160 }161 162 - (int)addDataToPasteboard:(NSPasteboard *)aPasteboard exceptTypes:(NSMutableSet *)notThese163 {164 NSArray *myRepresentations;165 int repIndex, repCount;166 int count = 0;167 168 if (!notThese)169 notThese = [NSMutableSet set];170 171 #define IF_ADD(typename, dataOwner) if( ![notThese containsObject:(typename)] && [aPasteboard addTypes:[NSArray arrayWithObject:(typename)] owner:(dataOwner)] > 0 )172 173 #define ADD_CHEAP_DATA(typename, expr) IF_ADD(typename, nil) { [aPasteboard setData:(expr) forType:(typename)]; [notThese addObject:(typename)]; count ++; }174 175 /* If we have image representations lying around that already have data in some concrete format, add that data to the pasteboard. */176 myRepresentations = [self representations];177 repCount = [myRepresentations count];178 for(repIndex = 0; repIndex < repCount; repIndex ++) {179 NSImageRep *aRep = [myRepresentations objectAtIndex:repIndex];180 181 if ([aRep respondsToSelector:@selector(PDFRepresentation)]) {182 ADD_CHEAP_DATA(NSPDFPboardType, [(NSPDFImageRep *)aRep PDFRepresentation]);183 }184 185 if ([aRep respondsToSelector:@selector(PICTRepresentation)]) {186 ADD_CHEAP_DATA(NSPICTPboardType, [(NSPICTImageRep *)aRep PICTRepresentation]);187 }188 189 if ([aRep respondsToSelector:@selector(EPSRepresentation)]) {190 ADD_CHEAP_DATA(NSPostScriptPboardType, [(NSEPSImageRep *)aRep EPSRepresentation]);191 }192 }193 194 /* Always offer to convert to TIFF. Do this lazily, though, since we probably have to extract it from a bitmap image rep. */195 IF_ADD(NSTIFFPboardType, self) {196 count ++;197 }198 199 return count;200 }201 202 - (void)pasteboard:(NSPasteboard *)aPasteboard provideDataForType:(NSString *)wanted203 {204 if ([wanted isEqual:NSTIFFPboardType]) {205 [aPasteboard setData:[self TIFFRepresentation] forType:NSTIFFPboardType];206 }207 }208 209 210 211 35 @end -
trunk/Cocoa/Pester/Source/PSAlarm.m
r551 r587 116 116 if ([string isEqualToString: @"PSAlarmSnooze"]) return PSAlarmSnooze; 117 117 if ([string isEqualToString: @"PSAlarmExpired"]) return PSAlarmExpired; 118 NSLog(@"unknown alarm type string: %@", string); 119 return nil; 118 return PSAlarmInvalid; 120 119 } 121 120 -
trunk/Cocoa/Pester/Source/PSAlarmSetController.m
r579 r587 23 23 #import "NSAttributedString-NJRExtensions.h" 24 24 #import "NSCalendarDate-NJRExtensions.h" 25 #import <Carbon/Carbon.h>26 25 27 26 #import "PSAlerts.h" -
trunk/Cocoa/Pester/Source/PSApplication.m
r522 r587 19 19 #import "NJRHotKey.h" 20 20 #import "NSWindowCollectionBehavior.h" 21 22 #import <Carbon/Carbon.h>23 21 24 22 @implementation PSApplication -
trunk/Cocoa/Pester/Source/PSTimer.m
r364 r587 231 231 // NSLog(@"going to sleep, setting timer %@", PSTimerOnWake); 232 232 @try { 233 // XXX replaced by dateByAddingTimeInterval: in 10.5 and later 233 234 [PSPowerManager setWakeTime: [[PSTimerOnWake fireDate] addTimeInterval: -15]]; 234 235 } @catch (NSException *exception) {
Note:
See TracChangeset
for help on using the changeset viewer.