- Issue 90, Dan Knapp's NSColor fix for new system colors present in an archive

This commit is contained in:
Christopher Lloyd 2008-04-29 03:43:42 +00:00
parent aa7eae87c1
commit 4bf2a1687a
2 changed files with 25 additions and 4 deletions

View File

@ -21,6 +21,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSPasteboard.h>
#import <AppKit/NSNibKeyedUnarchiver.h>
#import <AppKit/NSDisplay.h>
@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;

View File

@ -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;