From 4bf2a1687a25c410e3c3b13b39d9c6d73c1199c0 Mon Sep 17 00:00:00 2001 From: Christopher Lloyd Date: Tue, 29 Apr 2008 03:43:42 +0000 Subject: [PATCH] - Issue 90, Dan Knapp's NSColor fix for new system colors present in an archive --- AppKit/NSColor.subproj/NSColor.m | 23 +++++++++++++++++++---- AppKit/Win32.subproj/Win32Display.m | 6 ++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/AppKit/NSColor.subproj/NSColor.m b/AppKit/NSColor.subproj/NSColor.m index 88924919..ff9accab 100755 --- a/AppKit/NSColor.subproj/NSColor.m +++ b/AppKit/NSColor.subproj/NSColor.m @@ -21,6 +21,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #import #import +#import + @implementation NSColor -(void)encodeWithCoder:(NSCoder *)coder { @@ -117,10 +119,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI case 6:{ NSString *catalogName=[keyed decodeObjectForKey:@"NSCatalogName"]; NSString *colorName=[keyed decodeObjectForKey:@"NSColorName"]; - NSColor *color=[keyed decodeObjectForKey:@"NSColor"]; // backup ? + NSColor *color=[keyed decodeObjectForKey:@"NSColor"]; - if((result=[NSColor colorWithCatalogName:catalogName colorName:colorName])==nil) - result=color; + if([catalogName isEqualToString: @"System"]) { + NSDisplay *display = [NSDisplay currentDisplay]; + result = [display colorWithName: colorName]; + if(!result) { + result = color; + [display _addSystemColor: result forName: colorName]; + } + } else { + result = [NSColor colorWithCatalogName: catalogName colorName: colorName]; + if(!result) { + result=color; + } + } } break; @@ -129,9 +142,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI result=[NSColor blackColor]; break; } - + return [result retain]; } + + else { [NSException raise:NSInvalidArgumentException format:@"%@ can not initWithCoder:%@",isa,[coder class]]; return nil; diff --git a/AppKit/Win32.subproj/Win32Display.m b/AppKit/Win32.subproj/Win32Display.m index 9c15d8f4..18c25f91 100755 --- a/AppKit/Win32.subproj/Win32Display.m +++ b/AppKit/Win32.subproj/Win32Display.m @@ -250,6 +250,12 @@ BOOL CALLBACK monitorEnumerator(HMONITOR hMonitor,HDC hdcMonitor,LPRECT rect,LPA return [_nameToColor objectForKey:colorName]; } +-(void) _addSystemColor: (NSColor *) color forName: (NSString *) name { + if([_nameToColor count]==0) + [self buildSystemColors]; + [_nameToColor setObject: color forKey: name]; +} + -(NSString *)menuFontNameAndSize:(float *)pointSize { #if 1 *pointSize=10;