1997-01-29 16:07:56 +00:00
|
|
|
|
/*
|
|
|
|
|
NSBundle.m
|
|
|
|
|
|
|
|
|
|
Implementation of NSBundle Additions
|
|
|
|
|
|
1999-01-15 10:14:28 +00:00
|
|
|
|
Copyright (C) 1997, 1999 Free Software Foundation, Inc.
|
1997-01-29 16:07:56 +00:00
|
|
|
|
|
|
|
|
|
Author: Simon Frankau <sgf@frankau.demon.co.uk>
|
|
|
|
|
Date: 1997
|
1999-01-15 10:14:28 +00:00
|
|
|
|
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
Date: 1999
|
1997-01-29 16:07:56 +00:00
|
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 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
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
1999-09-09 02:56:20 +00:00
|
|
|
|
License along with this library;
|
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-01-29 16:07:56 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1997-09-23 22:43:24 +00:00
|
|
|
|
#include <gnustep/gui/config.h>
|
1999-01-15 10:14:28 +00:00
|
|
|
|
#include <Foundation/NSArchiver.h>
|
1999-01-17 08:14:03 +00:00
|
|
|
|
#include <Foundation/NSArray.h>
|
1997-01-29 16:07:56 +00:00
|
|
|
|
#include <Foundation/NSBundle.h>
|
1999-01-15 10:14:28 +00:00
|
|
|
|
#include <Foundation/NSCoder.h>
|
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
|
#include <Foundation/NSEnumerator.h>
|
1999-01-17 08:14:03 +00:00
|
|
|
|
#include <Foundation/NSInvocation.h>
|
1999-01-15 10:14:28 +00:00
|
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
1999-11-29 11:45:50 +00:00
|
|
|
|
#include <Foundation/NSFileManager.h>
|
1999-01-15 10:14:28 +00:00
|
|
|
|
#include <Foundation/NSString.h>
|
1999-11-29 11:45:50 +00:00
|
|
|
|
#include <Foundation/NSUserDefaults.h>
|
|
|
|
|
#include <AppKit/NSControl.h>
|
1999-09-02 11:28:47 +00:00
|
|
|
|
#include <AppKit/NSImage.h>
|
1999-01-17 08:14:03 +00:00
|
|
|
|
#include <AppKit/NSView.h>
|
1999-11-29 11:45:50 +00:00
|
|
|
|
#include <AppKit/NSNibConnector.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
|
#include <AppKit/NSNibLoading.h>
|
1997-01-29 16:07:56 +00:00
|
|
|
|
|
1999-11-29 11:45:50 +00:00
|
|
|
|
|
|
|
|
|
@implementation NSNibConnector
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
RELEASE(_src);
|
|
|
|
|
RELEASE(_dst);
|
|
|
|
|
RELEASE(_tag);
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) destination
|
|
|
|
|
{
|
|
|
|
|
return _dst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
[aCoder encodeObject: _src];
|
|
|
|
|
[aCoder encodeObject: _dst];
|
|
|
|
|
[aCoder encodeObject: _tag];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) establishConnection
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_src];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_dst];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_tag];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString*) label
|
|
|
|
|
{
|
|
|
|
|
return _tag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) replaceObject: (id)anObject withObject: (id)anotherObject
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) source
|
|
|
|
|
{
|
|
|
|
|
return _src;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setDestination: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
ASSIGN(_dst, anObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setLabel: (NSString*)label
|
|
|
|
|
{
|
|
|
|
|
ASSIGN(_tag, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setSource: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
ASSIGN(_src, anObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSNibControlConnector
|
|
|
|
|
- (void) establishConnection
|
|
|
|
|
{
|
|
|
|
|
SEL sel = NSSelectorFromString(_tag);
|
|
|
|
|
|
|
|
|
|
[_src setTarget: _dst];
|
|
|
|
|
[_src setAction: sel];
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSNibOutletConnector
|
|
|
|
|
- (void) establishConnection
|
|
|
|
|
{
|
|
|
|
|
NSString *selName;
|
|
|
|
|
SEL sel;
|
|
|
|
|
|
|
|
|
|
selName = [NSString stringWithFormat: @"set%@:", [_tag capitalizedString]];
|
|
|
|
|
sel = NSSelectorFromString(selName);
|
|
|
|
|
|
|
|
|
|
if ([_src respondsToSelector: sel])
|
|
|
|
|
{
|
|
|
|
|
[_src performSelector: sel withObject: _dst];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Use the GNUstep additional function to set the instance variable
|
|
|
|
|
* directly.
|
|
|
|
|
* FIXME - need some way to do this for libFoundation and Foundation
|
|
|
|
|
* based systems.
|
|
|
|
|
*/
|
|
|
|
|
GSSetInstanceVariable(_src, _tag, (void*)&_dst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-01-29 16:07:56 +00:00
|
|
|
|
@implementation NSBundle (NSBundleAdditions)
|
|
|
|
|
|
1999-11-29 11:45:50 +00:00
|
|
|
|
- (NSString*) pathForImageResource: (NSString*)name
|
1997-01-29 16:07:56 +00:00
|
|
|
|
{
|
1999-09-02 11:28:47 +00:00
|
|
|
|
NSString *ext = [name pathExtension];
|
|
|
|
|
NSString *path = nil;
|
|
|
|
|
|
|
|
|
|
if (ext != nil)
|
|
|
|
|
{
|
|
|
|
|
name = [name stringByDeletingPathExtension];
|
|
|
|
|
path = [self pathForResource: name ofType: ext];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSArray *types = [NSImage imageUnfilteredFileTypes];
|
|
|
|
|
unsigned c = [types count];
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; path == nil && i < c; i++)
|
|
|
|
|
{
|
|
|
|
|
ext = [types objectAtIndex: i];
|
|
|
|
|
path = [self pathForResource: name ofType: ext];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return path;
|
1997-01-29 16:07:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-15 10:14:28 +00:00
|
|
|
|
+ (BOOL) loadNibFile: (NSString *)fileName
|
|
|
|
|
externalNameTable: (NSDictionary *)context
|
|
|
|
|
withZone: (NSZone *)zone
|
1997-01-29 16:07:56 +00:00
|
|
|
|
{
|
1999-01-15 10:14:28 +00:00
|
|
|
|
NSData *data;
|
|
|
|
|
BOOL loaded = NO;
|
|
|
|
|
|
|
|
|
|
data = [NSData dataWithContentsOfFile: fileName];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
if (data != nil)
|
1999-01-15 10:14:28 +00:00
|
|
|
|
{
|
|
|
|
|
NSUnarchiver *unarchiver;
|
|
|
|
|
|
1999-04-15 04:47:54 +00:00
|
|
|
|
unarchiver = [[NSUnarchiver alloc] initForReadingWithData: data];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
if (unarchiver != nil)
|
1999-01-15 10:14:28 +00:00
|
|
|
|
{
|
|
|
|
|
id obj;
|
|
|
|
|
|
|
|
|
|
[unarchiver setObjectZone: zone];
|
|
|
|
|
obj = [unarchiver decodeObject];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
if (obj != nil)
|
1999-01-15 10:14:28 +00:00
|
|
|
|
{
|
|
|
|
|
if ([obj isKindOfClass: [GSNibContainer class]])
|
|
|
|
|
{
|
|
|
|
|
GSNibContainer *container = obj;
|
1999-11-29 11:45:50 +00:00
|
|
|
|
NSMutableDictionary *nameTable = [container nameTable];
|
|
|
|
|
NSMutableArray *connections = [container connections];
|
1999-01-15 10:14:28 +00:00
|
|
|
|
NSEnumerator *enumerator;
|
1999-11-29 11:45:50 +00:00
|
|
|
|
NSNibConnector *connection;
|
1999-01-15 10:14:28 +00:00
|
|
|
|
NSString *key;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Go through the table of objects in the nib and
|
|
|
|
|
* retain each one (except ones that are overridden
|
|
|
|
|
* by values from the 'context table' and retain them
|
|
|
|
|
* so they will persist after the container is gone.
|
1999-11-29 11:45:50 +00:00
|
|
|
|
* Add local entries into name table.
|
1999-01-15 10:14:28 +00:00
|
|
|
|
*/
|
|
|
|
|
enumerator = [nameTable keyEnumerator];
|
|
|
|
|
while ((key = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([context objectForKey: key] == nil)
|
|
|
|
|
{
|
1999-11-29 11:45:50 +00:00
|
|
|
|
RETAIN([nameTable objectForKey: key]);
|
1999-01-15 10:14:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
|
[nameTable addEntriesFromDictionary: context];
|
1999-01-15 10:14:28 +00:00
|
|
|
|
|
|
|
|
|
/*
|
1999-11-29 11:45:50 +00:00
|
|
|
|
* Now establish all connections by taking the names
|
|
|
|
|
* stored in the connection objects, and replaciong them
|
|
|
|
|
* with the corresponding values from the name table
|
|
|
|
|
* before telling the connections to establish themselves.
|
|
|
|
|
*/
|
|
|
|
|
enumerator = [connections objectEnumerator];
|
|
|
|
|
while ((connection = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
id val;
|
|
|
|
|
|
|
|
|
|
val = [nameTable objectForKey: [connection source]];
|
|
|
|
|
[connection setSource: val];
|
|
|
|
|
val = [nameTable objectForKey: [connection destination]];
|
|
|
|
|
[connection setDestination: val];
|
|
|
|
|
[connection establishConnection];
|
|
|
|
|
[connection establishConnection];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now tell all the objects that they have been loaded from
|
|
|
|
|
* a nib.
|
1999-01-15 10:14:28 +00:00
|
|
|
|
*/
|
|
|
|
|
enumerator = [nameTable keyEnumerator];
|
|
|
|
|
while ((key = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([context objectForKey: key] == nil)
|
|
|
|
|
{
|
|
|
|
|
id o;
|
|
|
|
|
|
|
|
|
|
o = [nameTable objectForKey: key];
|
|
|
|
|
if ([o respondsToSelector: @selector(awakeFromNib)])
|
|
|
|
|
{
|
|
|
|
|
[o awakeFromNib];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Ok - it's all done now - the nib container will
|
|
|
|
|
* be released when the unarchiver is released, so
|
|
|
|
|
* we will just be left with the real nib contents.
|
|
|
|
|
*/
|
|
|
|
|
loaded = YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Nib '%@' without container object!", fileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
|
RELEASE(unarchiver);
|
1999-01-15 10:14:28 +00:00
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
|
RELEASE(data);
|
1999-01-15 10:14:28 +00:00
|
|
|
|
}
|
|
|
|
|
return loaded;
|
1997-01-29 16:07:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-01-15 10:14:28 +00:00
|
|
|
|
+ (BOOL) loadNibNamed: (NSString *)aNibName
|
|
|
|
|
owner: (id)owner
|
1997-01-29 16:07:56 +00:00
|
|
|
|
{
|
1999-01-15 10:14:28 +00:00
|
|
|
|
NSDictionary *table;
|
|
|
|
|
NSBundle *bundle;
|
|
|
|
|
NSString *file;
|
|
|
|
|
|
|
|
|
|
if (owner == nil || aNibName == nil)
|
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
|
|
table = [NSDictionary dictionaryWithObject: owner forKey: @"NSOwner"];
|
|
|
|
|
file = [aNibName stringByDeletingPathExtension];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
bundle = [self bundleForClass: [owner class]];
|
|
|
|
|
if (bundle == nil)
|
1999-01-15 10:14:28 +00:00
|
|
|
|
{
|
1999-11-29 11:45:50 +00:00
|
|
|
|
bundle = [self mainBundle];
|
1999-01-15 10:14:28 +00:00
|
|
|
|
}
|
1999-11-29 11:45:50 +00:00
|
|
|
|
return [bundle loadNibFile: aNibName
|
|
|
|
|
externalNameTable: table
|
|
|
|
|
withZone: [owner zone]];
|
1997-01-29 16:07:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-29 11:45:50 +00:00
|
|
|
|
- (BOOL) loadNibFile: (NSString*)fileName
|
|
|
|
|
externalNameTable: (NSDictionary*)context
|
|
|
|
|
withZone: (NSZone*)zone
|
|
|
|
|
{
|
|
|
|
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
|
|
|
|
NSMutableArray *array = [NSMutableArray arrayWithCapacity: 8];
|
|
|
|
|
NSArray *languages = [NSUserDefaults userLanguages];
|
|
|
|
|
NSString *rootPath = [self bundlePath];
|
|
|
|
|
NSString *primary;
|
|
|
|
|
NSString *language;
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
NSString *ext;
|
|
|
|
|
|
|
|
|
|
ext = [fileName pathExtension];
|
|
|
|
|
fileName = [fileName stringByDeletingPathExtension];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Build an array of resource paths that differs from the normal order -
|
|
|
|
|
* we want a localized file in preference to a generic one.
|
|
|
|
|
*/
|
|
|
|
|
primary = [rootPath stringByAppendingPathComponent: @"Resources"];
|
|
|
|
|
enumerator = [languages objectEnumerator];
|
|
|
|
|
while ((language = [enumerator nextObject]))
|
|
|
|
|
{
|
|
|
|
|
NSString *langDir;
|
|
|
|
|
|
|
|
|
|
langDir = [NSString stringWithFormat: @"%@.lproj", language];
|
|
|
|
|
[array addObject: [primary stringByAppendingPathComponent: langDir]];
|
|
|
|
|
}
|
|
|
|
|
[array addObject: primary];
|
|
|
|
|
primary = rootPath;
|
|
|
|
|
enumerator = [languages objectEnumerator];
|
|
|
|
|
while ((language = [enumerator nextObject]))
|
|
|
|
|
{
|
|
|
|
|
NSString *langDir;
|
|
|
|
|
|
|
|
|
|
langDir = [NSString stringWithFormat: @"%@.lproj", language];
|
|
|
|
|
[array addObject: [primary stringByAppendingPathComponent: langDir]];
|
|
|
|
|
}
|
|
|
|
|
[array addObject: primary];
|
|
|
|
|
|
|
|
|
|
enumerator = [array objectEnumerator];
|
|
|
|
|
while ((rootPath = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
|
|
rootPath = [rootPath stringByAppendingPathComponent: fileName];
|
|
|
|
|
if ([ext isEqualToString: @""] == NO)
|
|
|
|
|
{
|
|
|
|
|
path = [rootPath stringByAppendingPathExtension: ext];
|
|
|
|
|
if ([mgr isReadableFileAtPath: path] == NO)
|
|
|
|
|
{
|
|
|
|
|
path = [rootPath stringByAppendingPathExtension: @".gorm"];
|
|
|
|
|
if ([mgr isReadableFileAtPath: path] == NO)
|
|
|
|
|
{
|
|
|
|
|
path = [rootPath stringByAppendingPathExtension: @".nib"];
|
|
|
|
|
if ([mgr isReadableFileAtPath: path] == NO)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return [NSBundle loadNibFile: path
|
|
|
|
|
externalNameTable: context
|
|
|
|
|
withZone: (NSZone*)zone];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
1997-01-29 16:07:56 +00:00
|
|
|
|
@end
|
1997-02-18 00:29:25 +00:00
|
|
|
|
|
1999-01-15 10:14:28 +00:00
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
|
|
1999-01-15 10:14:28 +00:00
|
|
|
|
/*
|
|
|
|
|
* The GSNibContainer class manages the internals os a nib file.
|
|
|
|
|
*/
|
|
|
|
|
@implementation GSNibContainer
|
1999-11-29 11:45:50 +00:00
|
|
|
|
|
|
|
|
|
- (NSMutableArray*) connections
|
|
|
|
|
{
|
|
|
|
|
return connections;
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-15 10:14:28 +00:00
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
1999-11-29 11:45:50 +00:00
|
|
|
|
RELEASE(nameTable);
|
|
|
|
|
RELEASE(connections);
|
1999-01-15 10:14:28 +00:00
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
[super encodeWithCoder: aCoder];
|
|
|
|
|
[aCoder encodeObject: nameTable];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
[aCoder encodeObject: connections];
|
1999-01-15 10:14:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
if ((self = [super init]) != nil)
|
|
|
|
|
{
|
|
|
|
|
nameTable = [[NSMutableDictionary alloc] initWithCapacity: 8];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
connections = [[NSMutableArray alloc] initWithCapacity: 8];
|
1999-01-15 10:14:28 +00:00
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithCoder: aCoder];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &nameTable];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &connections];
|
1999-01-15 10:14:28 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSMutableDictionary*) nameTable
|
|
|
|
|
{
|
|
|
|
|
return nameTable;
|
|
|
|
|
}
|
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1999-01-17 08:14:03 +00:00
|
|
|
|
@implementation GSNibItem
|
1999-11-29 11:45:50 +00:00
|
|
|
|
|
1999-01-17 08:14:03 +00:00
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
1999-11-29 11:45:50 +00:00
|
|
|
|
RELEASE(theClass);
|
|
|
|
|
[super dealloc];
|
1999-01-17 08:14:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-29 11:45:50 +00:00
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
1999-01-17 08:14:03 +00:00
|
|
|
|
{
|
1999-11-29 11:45:50 +00:00
|
|
|
|
[super encodeWithCoder: aCoder];
|
|
|
|
|
[aCoder encodeObject: theClass];
|
|
|
|
|
[aCoder encodeRect: theFrame];
|
1999-01-17 08:14:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
|
|
|
|
id obj;
|
|
|
|
|
Class cls;
|
|
|
|
|
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &theClass];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
theFrame = [aCoder decodeRect];
|
1999-01-17 08:14:03 +00:00
|
|
|
|
|
|
|
|
|
cls = NSClassFromString(theClass);
|
1999-11-29 11:45:50 +00:00
|
|
|
|
if (cls == nil)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
|
format: @"Unable to find class '%@'", theClass];
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-17 08:14:03 +00:00
|
|
|
|
obj = [cls allocWithZone: [self zone]];
|
1999-11-29 11:45:50 +00:00
|
|
|
|
if (theFrame.size.height > 0 && theFrame.size.width > 0)
|
|
|
|
|
obj = [obj initWithFrame: theFrame];
|
1999-01-17 08:14:03 +00:00
|
|
|
|
else
|
|
|
|
|
obj = [obj init];
|
|
|
|
|
|
1999-11-29 11:45:50 +00:00
|
|
|
|
RELEASE(self);
|
1999-01-17 08:14:03 +00:00
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|