mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 22:40:48 +00:00
Coding/decoding fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9469 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bb24a06942
commit
96b026ab00
2 changed files with 273 additions and 194 deletions
|
@ -1,3 +1,10 @@
|
|||
2001-03-21 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSColor.m: Change archiving/unarchiving of colors to avoid
|
||||
storing private subclasses in archive. Fixed bug in unarchiving that
|
||||
caused crashes when retrieving old archives. Tidied source a little to
|
||||
ret rid of some contraventions of coding standards (long lines etc).
|
||||
|
||||
2001-03-21 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/gnustep/gui/NSColor.h
|
||||
|
|
188
Source/NSColor.m
188
Source/NSColor.m
|
@ -43,6 +43,8 @@
|
|||
#include <AppKit/NSGraphics.h>
|
||||
#include <AppKit/PSOperators.h>
|
||||
|
||||
static Class NSColorClass;
|
||||
|
||||
@interface GSNamedColor : NSColor
|
||||
{
|
||||
NSString *_catalog_name;
|
||||
|
@ -224,8 +226,8 @@ void initSystemColors()
|
|||
* in all the places where this colours are used, we better return
|
||||
* the real colours here.
|
||||
*/
|
||||
static
|
||||
NSColor* systemColorWithName(NSString *name)
|
||||
static NSColor*
|
||||
systemColorWithName(NSString *name)
|
||||
{
|
||||
NSString *rep;
|
||||
NSColor *color = (*cwkImp)(systemColors, cwkSel, name);
|
||||
|
@ -240,7 +242,14 @@ NSColor* systemColorWithName(NSString *name)
|
|||
return nil;
|
||||
}
|
||||
|
||||
if (NSColorClass == 0)
|
||||
{
|
||||
color = [NSColor colorFromString: rep];
|
||||
}
|
||||
else
|
||||
{
|
||||
color = [NSColorClass colorFromString: rep];
|
||||
}
|
||||
if (color == nil)
|
||||
{
|
||||
NSLog(@"System color '%@' has bad string rep - '%@'\n", name, rep);
|
||||
|
@ -260,8 +269,10 @@ NSColor* systemColorWithName(NSString *name)
|
|||
{
|
||||
if (self == [NSColor class])
|
||||
{
|
||||
NSColorClass = self;
|
||||
|
||||
// Set the version number
|
||||
[self setVersion: 2];
|
||||
[self setVersion: 3];
|
||||
|
||||
// ignore alpha by default
|
||||
gnustep_gui_ignores_alpha = YES;
|
||||
|
@ -287,10 +298,10 @@ NSColor* systemColorWithName(NSString *name)
|
|||
brightness: (float)brightness
|
||||
alpha: (float)alpha
|
||||
{
|
||||
NSColor *c;
|
||||
id c;
|
||||
|
||||
c = [[GSCalibratedRGBColor allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCalibratedHue: hue
|
||||
c = [GSCalibratedRGBColor allocWithZone: NSDefaultMallocZone()];
|
||||
c = [c initWithCalibratedHue: hue
|
||||
saturation: saturation
|
||||
brightness: brightness
|
||||
alpha: alpha];
|
||||
|
@ -303,10 +314,10 @@ NSColor* systemColorWithName(NSString *name)
|
|||
blue: (float)blue
|
||||
alpha: (float)alpha
|
||||
{
|
||||
NSColor *c;
|
||||
id c;
|
||||
|
||||
c = [[GSCalibratedRGBColor allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCalibratedRed: red
|
||||
c = [GSCalibratedRGBColor allocWithZone: NSDefaultMallocZone()];
|
||||
c = [c initWithCalibratedRed: red
|
||||
green: green
|
||||
blue: blue
|
||||
alpha: alpha];
|
||||
|
@ -316,10 +327,10 @@ NSColor* systemColorWithName(NSString *name)
|
|||
+ (NSColor*) colorWithCalibratedWhite: (float)white
|
||||
alpha: (float)alpha
|
||||
{
|
||||
NSColor *c;
|
||||
id c;
|
||||
|
||||
c = [[GSCalibratedWhiteColor allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCalibratedWhite: white
|
||||
c = [GSCalibratedWhiteColor allocWithZone: NSDefaultMallocZone()] ;
|
||||
c = [c initWithCalibratedWhite: white
|
||||
alpha: alpha];
|
||||
|
||||
return AUTORELEASE(c);
|
||||
|
@ -328,10 +339,10 @@ NSColor* systemColorWithName(NSString *name)
|
|||
+ (NSColor*) colorWithCatalogName: (NSString *)listName
|
||||
colorName: (NSString *)colorName
|
||||
{
|
||||
NSColor *c;
|
||||
id c;
|
||||
|
||||
c = [[GSNamedColor allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCatalogName: listName
|
||||
c = [GSNamedColor allocWithZone: NSDefaultMallocZone()] ;
|
||||
c = [c initWithCatalogName: listName
|
||||
colorName: colorName];
|
||||
|
||||
return AUTORELEASE(c);
|
||||
|
@ -343,10 +354,10 @@ NSColor* systemColorWithName(NSString *name)
|
|||
black: (float)black
|
||||
alpha: (float)alpha
|
||||
{
|
||||
NSColor *c;
|
||||
id c;
|
||||
|
||||
c = [[GSDeviceCMYKColor allocWithZone: NSDefaultMallocZone()]
|
||||
initWithDeviceCyan: cyan
|
||||
c = [GSDeviceCMYKColor allocWithZone: NSDefaultMallocZone()];
|
||||
c = [c initWithDeviceCyan: cyan
|
||||
magenta: magenta
|
||||
yellow: yellow
|
||||
black: black
|
||||
|
@ -360,10 +371,10 @@ NSColor* systemColorWithName(NSString *name)
|
|||
brightness: (float)brightness
|
||||
alpha: (float)alpha
|
||||
{
|
||||
NSColor *c;
|
||||
id c;
|
||||
|
||||
c = [[GSDeviceRGBColor allocWithZone: NSDefaultMallocZone()]
|
||||
initWithDeviceHue: hue
|
||||
c = [GSDeviceRGBColor allocWithZone: NSDefaultMallocZone()];
|
||||
c = [c initWithDeviceHue: hue
|
||||
saturation: saturation
|
||||
brightness: brightness
|
||||
alpha: alpha];
|
||||
|
@ -376,10 +387,10 @@ NSColor* systemColorWithName(NSString *name)
|
|||
blue: (float)blue
|
||||
alpha: (float)alpha
|
||||
{
|
||||
NSColor *c;
|
||||
id c;
|
||||
|
||||
c = [[GSDeviceRGBColor allocWithZone: NSDefaultMallocZone()]
|
||||
initWithDeviceRed: red
|
||||
c = [GSDeviceRGBColor allocWithZone: NSDefaultMallocZone()];
|
||||
c = [c initWithDeviceRed: red
|
||||
green: green
|
||||
blue: blue
|
||||
alpha: alpha];
|
||||
|
@ -390,27 +401,27 @@ NSColor* systemColorWithName(NSString *name)
|
|||
+ (NSColor*) colorWithDeviceWhite: (float)white
|
||||
alpha: (float)alpha
|
||||
{
|
||||
NSColor *c;
|
||||
id c;
|
||||
|
||||
c = [[GSDeviceWhiteColor allocWithZone: NSDefaultMallocZone()]
|
||||
initWithDeviceWhite: white
|
||||
c = [GSDeviceWhiteColor allocWithZone: NSDefaultMallocZone()];
|
||||
c = [c initWithDeviceWhite: white
|
||||
alpha: alpha];
|
||||
|
||||
return AUTORELEASE(c);
|
||||
}
|
||||
|
||||
+ (NSColor *)colorForControlTint:(NSControlTint)controlTint
|
||||
+ (NSColor*) colorForControlTint: (NSControlTint)controlTint
|
||||
{
|
||||
// TODO
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSColor*) colorWithPatternImage:(NSImage*)image
|
||||
+ (NSColor*) colorWithPatternImage: (NSImage*)image
|
||||
{
|
||||
NSColor *c;
|
||||
id c;
|
||||
|
||||
c = [[GSPatternColor allocWithZone: NSDefaultMallocZone()]
|
||||
initWithPatternImage: image];
|
||||
c = [GSPatternColor allocWithZone: NSDefaultMallocZone()];
|
||||
c = [c initWithPatternImage: image];
|
||||
|
||||
return AUTORELEASE(c);
|
||||
}
|
||||
|
@ -541,7 +552,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
NSData *d = [pasteBoard dataForType: NSColorPboardType];
|
||||
|
||||
// FIXME: This should better use the description format
|
||||
if (d)
|
||||
if (d != nil)
|
||||
return [NSUnarchiver unarchiveObjectWithData: d];
|
||||
return nil;
|
||||
}
|
||||
|
@ -754,7 +765,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
{
|
||||
if (other == self)
|
||||
return YES;
|
||||
if ([other isKindOfClass: [NSColor class]] == NO)
|
||||
if ([other isKindOfClass: NSColorClass] == NO)
|
||||
return NO;
|
||||
else
|
||||
{
|
||||
|
@ -944,7 +955,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
red = fraction * mr + (1 - fraction) * or;
|
||||
green = fraction * mg + (1 - fraction) * og;
|
||||
blue = fraction * mb + (1 - fraction) * ob;
|
||||
return [NSColor colorWithCalibratedRed: red
|
||||
return [NSColorClass colorWithCalibratedRed: red
|
||||
green: green
|
||||
blue: blue
|
||||
alpha: 1.0];
|
||||
|
@ -958,13 +969,13 @@ NSColor* systemColorWithName(NSString *name)
|
|||
- (NSColor*) highlightWithLevel: (float)level
|
||||
{
|
||||
return [self blendedColorWithFraction: level
|
||||
ofColor: [NSColor highlightColor]];
|
||||
ofColor: [NSColorClass highlightColor]];
|
||||
}
|
||||
|
||||
- (NSColor*) shadowWithLevel: (float)level
|
||||
{
|
||||
return [self blendedColorWithFraction: level
|
||||
ofColor: [NSColor shadowColor]];
|
||||
ofColor: [NSColorClass shadowColor]];
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -975,7 +986,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
// FIXME: We should better use the description
|
||||
NSData *d = [NSArchiver archivedDataWithRootObject: self];
|
||||
|
||||
if (d)
|
||||
if (d != nil)
|
||||
[pasteBoard setData: d forType: NSColorPboardType];
|
||||
}
|
||||
|
||||
|
@ -997,6 +1008,11 @@ NSColor* systemColorWithName(NSString *name)
|
|||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (Class) classForCoder
|
||||
{
|
||||
return NSColorClass;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
@ -1004,7 +1020,8 @@ NSColor* systemColorWithName(NSString *name)
|
|||
|
||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||
{
|
||||
// To be albe to read old archives we keep this method
|
||||
if ([aDecoder versionForClassName: @"NSColor"] < 3)
|
||||
{
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
|
@ -1025,7 +1042,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
NSString *color_name;
|
||||
BOOL is_clear;
|
||||
|
||||
RELEASE(self);
|
||||
DESTROY(self);
|
||||
|
||||
// Version 1
|
||||
[aDecoder decodeValueOfObjCType: @encode(float) at: &red];
|
||||
|
@ -1049,31 +1066,81 @@ NSColor* systemColorWithName(NSString *name)
|
|||
[aDecoder decodeValueOfObjCType: @encode(int) at: &active_component];
|
||||
[aDecoder decodeValueOfObjCType: @encode(int) at: &valid_components];
|
||||
|
||||
if ([colorspace_name isEqual:@"NSDeviceCMYKColorSpace"]) {
|
||||
return [NSColor colorWithDeviceCyan:cyan
|
||||
magenta:magenta
|
||||
yellow:yellow
|
||||
black:black
|
||||
alpha:alpha];
|
||||
if ([colorspace_name isEqualToString: @"NSDeviceCMYKColorSpace"])
|
||||
{
|
||||
self = [NSColorClass colorWithDeviceCyan: cyan
|
||||
magenta: magenta
|
||||
yellow: yellow
|
||||
black: black
|
||||
alpha: alpha];
|
||||
}
|
||||
else if ([colorspace_name isEqual:@"NSDeviceWhiteColorSpace"]) {
|
||||
return [NSColor colorWithDeviceWhite:white alpha:alpha];
|
||||
else if ([colorspace_name isEqualToString: @"NSDeviceWhiteColorSpace"])
|
||||
{
|
||||
self = [NSColorClass colorWithDeviceWhite: white alpha: alpha];
|
||||
}
|
||||
else if ([colorspace_name isEqual:@"NSCalibratedWhiteColorSpace"]) {
|
||||
return [NSColor colorWithCalibratedWhite:white alpha:alpha];
|
||||
else if ([colorspace_name isEqualToString:
|
||||
@"NSCalibratedWhiteColorSpace"])
|
||||
{
|
||||
self = [NSColorClass colorWithCalibratedWhite:white alpha: alpha];
|
||||
}
|
||||
else if ([colorspace_name isEqual:@"NSDeviceRGBColorSpace"]) {
|
||||
return [NSColor colorWithDeviceRed:red green:green blue:blue alpha:alpha];
|
||||
else if ([colorspace_name isEqualToString: @"NSDeviceRGBColorSpace"])
|
||||
{
|
||||
self = [NSColorClass colorWithDeviceRed: red
|
||||
green: green
|
||||
blue: blue
|
||||
alpha: alpha];
|
||||
}
|
||||
else if ([colorspace_name isEqual:@"NSCalibratedRGBColorSpace"]) {
|
||||
return [NSColor colorWithCalibratedRed:red green:green blue:blue alpha:alpha];
|
||||
else if ([colorspace_name isEqualToString: @"NSCalibratedRGBColorSpace"])
|
||||
{
|
||||
self = [NSColorClass colorWithCalibratedRed: red
|
||||
green: green
|
||||
blue: blue
|
||||
alpha: alpha];
|
||||
}
|
||||
else if ([colorspace_name isEqual:@"NSNamedColorSpace"]) {
|
||||
return [NSColor colorWithCatalogName: catalog_name
|
||||
else if ([colorspace_name isEqualToString: @"NSNamedColorSpace"])
|
||||
{
|
||||
self = [NSColorClass colorWithCatalogName: catalog_name
|
||||
colorName: color_name];
|
||||
}
|
||||
|
||||
return RETAIN(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *csName = [aDecoder decodeObject];
|
||||
|
||||
RELEASE(self);
|
||||
if ([csName isEqualToString: @"NSDeviceCMYKColorSpace"])
|
||||
{
|
||||
self = [GSDeviceCMYKColor alloc];
|
||||
}
|
||||
else if ([csName isEqualToString: @"NSDeviceRGBColorSpace"])
|
||||
{
|
||||
self = [GSDeviceRGBColor alloc];
|
||||
}
|
||||
else if ([csName isEqualToString: @"NSDeviceWhiteColorSpace"])
|
||||
{
|
||||
self = [GSDeviceWhiteColor alloc];
|
||||
}
|
||||
else if ([csName isEqualToString: @"NSCalibratedWhiteColorSpace"])
|
||||
{
|
||||
self = [GSCalibratedWhiteColor alloc];
|
||||
}
|
||||
else if ([csName isEqualToString: @"NSCalibratedRGBColorSpace"])
|
||||
{
|
||||
self = [GSCalibratedRGBColor alloc];
|
||||
}
|
||||
else if ([csName isEqualToString: @"NSNamedColorSpace"])
|
||||
{
|
||||
self = [GSNamedColor alloc];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Unknown colorspace name in decoded color");
|
||||
return nil;
|
||||
}
|
||||
return [self initWithCoder: aDecoder];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1341,8 +1408,8 @@ NSColor* systemColorWithName(NSString *name)
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace
|
||||
device:(NSDictionary *)deviceDescription
|
||||
- (NSColor *)colorUsingColorSpaceName: (NSString *)colorSpace
|
||||
device: (NSDictionary *)deviceDescription
|
||||
{
|
||||
NSColorList *list;
|
||||
NSColor *real;
|
||||
|
@ -1373,6 +1440,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
//
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeObject: [self colorSpaceName]];
|
||||
[aCoder encodeObject: _catalog_name];
|
||||
[aCoder encodeObject: _color_name];
|
||||
}
|
||||
|
@ -1541,6 +1609,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
//
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeObject: [self colorSpaceName]];
|
||||
[aCoder encodeValueOfObjCType: @encode(float) at: &_white_component];
|
||||
[aCoder encodeValueOfObjCType: @encode(float) at: &_alpha_component];
|
||||
}
|
||||
|
@ -1824,6 +1893,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
//
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeObject: [self colorSpaceName]];
|
||||
[aCoder encodeValueOfObjCType: @encode(float) at: &_cyan_component];
|
||||
[aCoder encodeValueOfObjCType: @encode(float) at: &_magenta_component];
|
||||
[aCoder encodeValueOfObjCType: @encode(float) at: &_yellow_component];
|
||||
|
@ -2060,6 +2130,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
//
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeObject: [self colorSpaceName]];
|
||||
[aCoder encodeValueOfObjCType: @encode(float) at: &_red_component];
|
||||
[aCoder encodeValueOfObjCType: @encode(float) at: &_green_component];
|
||||
[aCoder encodeValueOfObjCType: @encode(float) at: &_blue_component];
|
||||
|
@ -2420,6 +2491,7 @@ NSColor* systemColorWithName(NSString *name)
|
|||
//
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeObject: [self colorSpaceName]];
|
||||
[aCoder encodeObject: _pattern];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue