Added missing keyed encoding for NSColor.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@21121 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2005-04-17 19:40:57 +00:00
parent 819869d5e3
commit afe71bc4c7
2 changed files with 94 additions and 11 deletions

View file

@ -1,3 +1,7 @@
2005-04-17 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSColor.m: Implemented the missing keyed encoding methods.
2005-04-11 10:24 Gregory John Casamento <greg_casamento@yahoo.com> 2005-04-11 10:24 Gregory John Casamento <greg_casamento@yahoo.com>
* Source/GSNibTemplates.m: Correction for minor leak in * Source/GSNibTemplates.m: Correction for minor leak in

View file

@ -1075,7 +1075,8 @@ systemColorWithName(NSString *name)
int colorSpace = [aDecoder decodeIntForKey: @"NSColorSpace"]; int colorSpace = [aDecoder decodeIntForKey: @"NSColorSpace"];
DESTROY(self); DESTROY(self);
if (colorSpace == 1)
if ((colorSpace == 1) || (colorSpace == 2))
{ {
unsigned length; unsigned length;
const uint8_t *data; const uint8_t *data;
@ -1099,12 +1100,22 @@ systemColorWithName(NSString *name)
RELEASE(str); RELEASE(str);
} }
self = [NSColor colorWithCalibratedRed: red if (colorSpace == 1)
green: green {
blue: blue self = [NSColor colorWithCalibratedRed: red
alpha: alpha]; green: green
blue: blue
alpha: alpha];
}
else
{
self = [NSColor colorWithDeviceRed: red
green: green
blue: blue
alpha: alpha];
}
} }
else if (colorSpace == 3) else if ((colorSpace == 3) || (colorSpace == 4))
{ {
unsigned length; unsigned length;
const uint8_t *data; const uint8_t *data;
@ -1124,7 +1135,47 @@ systemColorWithName(NSString *name)
RELEASE(str); RELEASE(str);
} }
self = [NSColor colorWithDeviceWhite: white if (colorSpace == 3)
{
self = [NSColor colorWithCalibratedWhite: white
alpha: alpha];
}
else
{
self = [NSColor colorWithDeviceWhite: white
alpha: alpha];
}
}
else if (colorSpace == 5)
{
unsigned length;
const uint8_t *data;
float cyan = 0.0;
float yellow = 0.0;
float magenta = 0.0;
float black = 0.0;
float alpha = 1.0;
NSString *str;
NSScanner *scanner;
if ([aDecoder containsValueForKey: @"NSCYMK"])
{
data = [aDecoder decodeBytesForKey: @"NSCYMK"
returnedLength: &length];
str = [[NSString alloc] initWithCString: data length: length];
scanner = [[NSScanner alloc] initWithString: str];
[scanner scanFloat: &cyan];
[scanner scanFloat: &yellow];
[scanner scanFloat: &magenta];
[scanner scanFloat: &black];
RELEASE(scanner);
RELEASE(str);
}
self = [NSColor colorWithDeviceCyan: cyan
magenta: magenta
yellow: yellow
black: black
alpha: alpha]; alpha: alpha];
} }
else if (colorSpace == 6) else if (colorSpace == 6)
@ -1136,6 +1187,12 @@ systemColorWithName(NSString *name)
self = [NSColor colorWithCatalogName: catalog self = [NSColor colorWithCatalogName: catalog
colorName: name]; colorName: name];
} }
else if (colorSpace == 10)
{
NSImage *image = [aDecoder decodeObjectForKey: @"NSImage"];
self = [NSColor colorWithPatternImage: image];
}
return self; return self;
} }
@ -1761,9 +1818,16 @@ systemColorWithName(NSString *name)
{ {
NSString *str; NSString *str;
if ([[self colorSpaceName] isEqualToString: NSCalibratedWhiteColorSpace])
{
[aCoder encodeInt: 3 forKey: @"NSColorSpace"];
}
else
{
[aCoder encodeInt: 4 forKey: @"NSColorSpace"];
}
// FIXME: Missing handling of alpha value // FIXME: Missing handling of alpha value
str = [[NSString alloc] initWithFormat: @"%f", _white_component]; str = [[NSString alloc] initWithFormat: @"%f", _white_component];
[aCoder encodeInt: 3 forKey: @"NSColorSpace"];
[aCoder encodeBytes: [str cString] length: [str cStringLength] forKey: @"NSWhite"]; [aCoder encodeBytes: [str cString] length: [str cStringLength] forKey: @"NSWhite"];
RELEASE(str); RELEASE(str);
} }
@ -2056,7 +2120,14 @@ systemColorWithName(NSString *name)
{ {
if ([aCoder allowsKeyedCoding]) if ([aCoder allowsKeyedCoding])
{ {
// FIXME NSString *str;
// FIXME: Missing handling of alpha value
[aCoder encodeInt: 5 forKey: @"NSColorSpace"];
str = [[NSString alloc] initWithFormat: @"%f %f %f %f", _cyan_component,
_magenta_component, _yellow_component, _black_component];
[aCoder encodeBytes: [str cString] length: [str cStringLength] forKey: @"NSCYMK"];
RELEASE(str);
} }
else else
{ {
@ -2302,10 +2373,17 @@ systemColorWithName(NSString *name)
{ {
NSString *str; NSString *str;
if ([[self colorSpaceName] isEqualToString: NSCalibratedRGBColorSpace])
{
[aCoder encodeInt: 1 forKey: @"NSColorSpace"];
}
else
{
[aCoder encodeInt: 2 forKey: @"NSColorSpace"];
}
// FIXME: Missing handling of alpha value // FIXME: Missing handling of alpha value
str = [[NSString alloc] initWithFormat: @"%f %f %f", _red_component, str = [[NSString alloc] initWithFormat: @"%f %f %f", _red_component,
_green_component, _blue_component]; _green_component, _blue_component];
[aCoder encodeInt: 1 forKey: @"NSColorSpace"];
[aCoder encodeBytes: [str cString] length: [str cStringLength] forKey: @"NSRGB"]; [aCoder encodeBytes: [str cString] length: [str cStringLength] forKey: @"NSRGB"];
RELEASE(str); RELEASE(str);
} }
@ -2674,7 +2752,8 @@ systemColorWithName(NSString *name)
{ {
if ([aCoder allowsKeyedCoding]) if ([aCoder allowsKeyedCoding])
{ {
// FIXME [aCoder encodeInt: 10 forKey: @"NSColorSpace"];
[aCoder encodeObject: _pattern forKey: @"NSImage"];
} }
else else
{ {