From 72169e54d88e4b1ce25007edea9fafa1339a4cdd Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 13 Jun 2013 13:24:30 +0100 Subject: [PATCH] New: nib2cib support for runtime attributes of point, size, rect and range types. This change adds nib2cib support for `NSValue` when the value represents a NSPoint, NSSize, NSRect or an NSRange, which enables user defined runtime attributes of these types to be set in Xcode and then properly decoded in a Cappuccino app. --- Tools/nib2cib/NSFoundation.j | 1 + Tools/nib2cib/NSValue.j | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 Tools/nib2cib/NSValue.j diff --git a/Tools/nib2cib/NSFoundation.j b/Tools/nib2cib/NSFoundation.j index 26cc8fc45..e6dcc414c 100644 --- a/Tools/nib2cib/NSFoundation.j +++ b/Tools/nib2cib/NSFoundation.j @@ -32,3 +32,4 @@ @import "NSNull.j" @import "NSNumberFormatter.j" @import "NSSet.j" +@import "NSValue.j" diff --git a/Tools/nib2cib/NSValue.j b/Tools/nib2cib/NSValue.j new file mode 100644 index 000000000..55732290a --- /dev/null +++ b/Tools/nib2cib/NSValue.j @@ -0,0 +1,59 @@ +/* + * NSValue.j + * nib2cib + * + * Created by Alexander Ljungberg. + * Copyright 2013, SlevenBits Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import +@import +@import +@import +@import + +@import + +var NSPointNSValueType = 1, + NSSizeNSValueType = 2, + NSRectNSValueType = 3, + NSRangeNSValueType = 4; + +@implementation NSValue : CPObject +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + var type = [aCoder decodeIntForKey:@"NS.special"]; + + switch (type) + { + case NSPointNSValueType: + return [[CPValue alloc] initWithJSObject:CGPointFromString([aCoder decodeObjectForKey:@"NS.pointval"])]; + case NSSizeNSValueType: + return [[CPValue alloc] initWithJSObject:CGSizeFromString([aCoder decodeObjectForKey:@"NS.sizeval"])]; + case NSRectNSValueType: + return [[CPValue alloc] initWithJSObject:CGRectFromString([aCoder decodeObjectForKey:@"NS.rectval"])]; + case NSRangeNSValueType: + return [[CPValue alloc] initWithJSObject:CPMakeRange([aCoder decodeIntForKey:@"NS.rangeval.location"], [aCoder decodeIntForKey:@"NS.rangeval.length"])]; + default: + [CPException raise:CPInvalidUnarchiveOperationException format:@"NSValue type %d is not supported by nib2cib.", type]; + } +} + +@end