/**
nibNamed
. If the bundle
* argument is nil
, then the main bundle is used to resolve
* the path, otherwise the bundle which is supplied will be used.
*/
- (instancetype) initWithNibNamed: (NSNibName)nibNamed
bundle: (NSBundle *)bundle
{
if ((self = [super init]) != nil)
{
NSString *fileName = nil;
// Keep the bundle for resource creation
ASSIGN(_bundle, bundle);
if (bundle == nil)
{
bundle = [NSBundle mainBundle];
}
// initialize the bundle...
fileName = [bundle pathForNibResource: nibNamed];
if (fileName == nil)
{
DESTROY(self);
return nil;
}
// load the nib data into memory...
[self _readNibData: fileName];
}
return self;
}
- (instancetype) initWithNibData: (NSData *)nibData
bundle: (NSBundle *)bundle
{
if ((self = [super init]) != nil)
{
ASSIGN(_bundle, bundle);
ASSIGN(_nibData, nibData);
// FIXME: Hardcode the most likely loader
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: @"nib"]);
}
return self;
}
/**
* This is a GNUstep specific method. This method is used when the caller
* wants the objects instantiated in the nib to be stored in the given
* zone
.
*/
- (BOOL) instantiateNibWithExternalNameTable: (NSDictionary *)externalNameTable
withZone: (NSZone *)zone
{
return [_loader loadModelData: _nibData
externalNameTable: externalNameTable
withZone: zone];
}
/**
* This method instantiates the nib file. The externalNameTable dictionary
* accepts the NSNibOwner and NSNibTopLevelObjects entries described earlier.
* It is recommended, for subclasses whose purpose is to change the behaviour
* of nib loading, to override this method.
*/
- (BOOL) instantiateNibWithExternalNameTable: (NSDictionary *)externalNameTable
{
return [self instantiateNibWithExternalNameTable: externalNameTable
withZone: NSDefaultMallocZone()];
}
/**
* This method instantiates the nib file. It utilizes the
* instantiateNibWithExternalNameTable: method to, in a convenient way,
* allow the user to specify both keys accepted by the
* nib loading process.
*/
- (BOOL) instantiateNibWithOwner: (id)owner
topLevelObjects: (NSArray **)topLevelObjects
{
NSMutableDictionary *externalNameTable = [NSMutableDictionary dictionary];
// add the necessary things to the table...
[externalNameTable setObject: owner forKey: NSNibOwner];
if (topLevelObjects != 0)
{
*topLevelObjects = [NSMutableArray array];
[externalNameTable setObject: *topLevelObjects forKey: NSNibTopLevelObjects];
}
return [self instantiateNibWithExternalNameTable: externalNameTable];
}
- (BOOL) instantiateWithOwner: (id)owner
topLevelObjects: (NSArray **)topLevelObjects
{
return [self instantiateNibWithOwner: owner topLevelObjects: topLevelObjects];
}
- (id) initWithCoder: (NSCoder *)coder
{
if ((self = [super init]) != nil)
{
//
// NOTE: This is okay, since the only encodings which will ever be built into
// the gui library are nib and gorm. GModel only supports certain
// objects and is going to be deprecated in the future. There just so
// happens to be a one to one correspondence here.
//
if ([coder allowsKeyedCoding])
{
// TODO_NIB: Need to verify this key...
ASSIGN(_nibData, [coder decodeObjectForKey: @"NSData"]);
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: @"nib"]);
}
else
{
// this is sort of a kludge...
[coder decodeValueOfObjCType: @encode(id)
at: &_nibData];
ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: @"gorm"]);
}
}
return self;
}
- (void) encodeWithCoder: (NSCoder *)coder
{
if ([coder allowsKeyedCoding])
{
// TODO_NIB: Need to verify this key...
[coder encodeObject: _nibData
forKey: @"NSData"];
}
else
{
[coder encodeValueOfObjCType: @encode(id)
at: &_nibData];
}
}
- (void) dealloc
{
RELEASE(_nibData);
RELEASE(_loader);
TEST_RELEASE(_bundle);
[super dealloc];
}
@end