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.
This commit is contained in:
Alexander Ljungberg committed 2013-06-13 13:24:36 +01:00
1 parent bf94dd3a6e
commit 72169e54d8
2 files changed
+60

No files matched your search

+1
View File
@@ -32,3 +32,4 @@
@import "NSNull.j"
@import "NSNumberFormatter.j"
@import "NSSet.j"
@import "NSValue.j"
+59
View File
@@ -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 <Foundation/CPException.j>
@import <Foundation/CPKeyedUnarchiver.j>
@import <Foundation/CPObject.j>
@import <Foundation/CPRange.j>
@import <Foundation/CPValue.j>
@import <AppKit/CGGeometry.j>
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