From 6123e28d45fff8dbc57b6f670f01ab797dc8a29f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rivaille Date: Fri, 1 Mar 2002 14:41:59 +0000 Subject: [PATCH] Source/NSBundleAdditions.m Headers/gnustep/gui/NSNibLoading.h git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@12931 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 12 ++++ Headers/gnustep/gui/NSNibLoading.h | 1 + Source/NSBundleAdditions.m | 98 ++++++++++++++++++++++++------ 3 files changed, 94 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 987a64889..c13fedba3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2002-03-01 Pierre-Yves Rivaille + + * Source/NSBundleAdditions.m + ([GSNibItem -initWithCoder:]): + ([GSNibItem -encodeWithCoder:]): + new encoding (support for autoresizingMask). + ([GSNibItem +initialize]): + ([GSCustomView +initialize]): + new methods, set the version number. + * Headers/gnustep/gui/NSNibLoading.h: + new autoresizingMask ivar in GSNibItem. + 2002-02-28 Pierre-Yves Rivaille * Headers/gnustep/gui/NSEvent.h: diff --git a/Headers/gnustep/gui/NSNibLoading.h b/Headers/gnustep/gui/NSNibLoading.h index 29bcc1e83..19586e1b4 100644 --- a/Headers/gnustep/gui/NSNibLoading.h +++ b/Headers/gnustep/gui/NSNibLoading.h @@ -85,6 +85,7 @@ { NSString *theClass; NSRect theFrame; + unsigned int autoresizingMask; } @end diff --git a/Source/NSBundleAdditions.m b/Source/NSBundleAdditions.m index bb0cb1cb5..7224ca909 100644 --- a/Source/NSBundleAdditions.m +++ b/Source/NSBundleAdditions.m @@ -50,6 +50,8 @@ #include #include +static const int currentVersion = 1; + @implementation NSNibConnector - (void) dealloc @@ -590,6 +592,13 @@ Class gmodel_class(void) @end @implementation GSNibItem ++ (void) initialize +{ + if (self == [GSNibItem class]) + { + [self setVersion: currentVersion]; + } +} - (void) dealloc { @@ -601,37 +610,92 @@ Class gmodel_class(void) { [aCoder encodeObject: theClass]; [aCoder encodeRect: theFrame]; + [aCoder encodeValueOfObjCType: @encode(unsigned int) + at: &autoresizingMask]; } - (id) initWithCoder: (NSCoder*)aCoder { - id obj; - Class cls; + int version = [aCoder versionForClassName: + NSStringFromClass([self class])]; - [aCoder decodeValueOfObjCType: @encode(id) at: &theClass]; - theFrame = [aCoder decodeRect]; - - cls = NSClassFromString(theClass); - if (cls == nil) + if (version == 1) { - [NSException raise: NSInternalInconsistencyException - format: @"Unable to find class '%@'", theClass]; + id obj; + Class cls; + unsigned int mask; + + [aCoder decodeValueOfObjCType: @encode(id) at: &theClass]; + theFrame = [aCoder decodeRect]; + [aCoder decodeValueOfObjCType: @encode(unsigned int) + at: &mask]; + + cls = NSClassFromString(theClass); + if (cls == nil) + { + [NSException raise: NSInternalInconsistencyException + format: @"Unable to find class '%@'", theClass]; + } + + obj = [cls allocWithZone: [self zone]]; + if (theFrame.size.height > 0 && theFrame.size.width > 0) + obj = [obj initWithFrame: theFrame]; + else + obj = [obj init]; + + if ([obj respondsToSelector: @selector(setAutoresizingMask:)]) + { + [obj setAutoresizingMask: mask]; + } + + RELEASE(self); + return obj; + } + else if (version == 0) + { + id obj; + Class cls; + + [aCoder decodeValueOfObjCType: @encode(id) at: &theClass]; + theFrame = [aCoder decodeRect]; + + cls = NSClassFromString(theClass); + if (cls == nil) + { + [NSException raise: NSInternalInconsistencyException + format: @"Unable to find class '%@'", theClass]; + } + + obj = [cls allocWithZone: [self zone]]; + if (theFrame.size.height > 0 && theFrame.size.width > 0) + obj = [obj initWithFrame: theFrame]; + else + obj = [obj init]; + + RELEASE(self); + return obj; } - - obj = [cls allocWithZone: [self zone]]; - if (theFrame.size.height > 0 && theFrame.size.width > 0) - obj = [obj initWithFrame: theFrame]; else - obj = [obj init]; - - RELEASE(self); - return obj; + { + NSLog(@"no initWithCoder for this version"); + RELEASE(self); + return nil; + } } @end + @implementation GSCustomView ++ (void) initialize +{ + if (self == [GSCustomView class]) + { + [self setVersion: currentVersion]; + } +} + - (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder];