2003-10-25 20:50:08 +00:00
|
|
|
/** <title>GSNibCompatibility</title>
|
|
|
|
|
|
|
|
<abstract>
|
2006-05-20 22:12:46 +00:00
|
|
|
These are templates for use with OSX Nib files. These classes are the
|
|
|
|
templates and other things which are needed for reading/writing nib files.
|
2003-10-25 20:50:08 +00:00
|
|
|
</abstract>
|
|
|
|
|
|
|
|
Copyright (C) 1997, 1999 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Gregory John Casamento
|
2006-05-20 22:12:46 +00:00
|
|
|
Date: 2003, 2005
|
2003-10-25 20:50:08 +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
|
|
|
|
License along with this library;
|
|
|
|
If not, write to the Free Software Foundation,
|
2005-05-26 02:52:46 +00:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-10-25 20:50:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Foundation/NSClassDescription.h>
|
|
|
|
#include <Foundation/NSArchiver.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSBundle.h>
|
|
|
|
#include <Foundation/NSCoder.h>
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
#include <Foundation/NSEnumerator.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSInvocation.h>
|
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
|
|
|
#include <Foundation/NSPathUtilities.h>
|
|
|
|
#include <Foundation/NSFileManager.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSUserDefaults.h>
|
|
|
|
#include <Foundation/NSKeyValueCoding.h>
|
2004-02-24 19:31:33 +00:00
|
|
|
#include <Foundation/NSKeyedArchiver.h>
|
2003-10-25 20:50:08 +00:00
|
|
|
#include "AppKit/AppKit.h"
|
|
|
|
#include <GNUstepBase/GSObjCRuntime.h>
|
|
|
|
#include <GNUstepGUI/GSNibCompatibility.h>
|
2006-05-20 22:12:46 +00:00
|
|
|
#include <GNUstepGUI/GSInstantiator.h>
|
2004-06-26 00:53:01 +00:00
|
|
|
|
2003-10-25 20:50:08 +00:00
|
|
|
@implementation NSWindowTemplate
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSWindowTemplate class])
|
|
|
|
{
|
|
|
|
[self setVersion: 0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
RELEASE(_title);
|
|
|
|
RELEASE(_viewClass);
|
|
|
|
RELEASE(_windowClass);
|
|
|
|
RELEASE(_view);
|
|
|
|
RELEASE(_autosaveName);
|
2003-10-25 20:50:08 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if ([coder allowsKeyedCoding])
|
2004-02-15 18:23:13 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if ([coder containsValueForKey: @"NSViewClass"])
|
|
|
|
{
|
|
|
|
ASSIGN(_viewClass, [coder decodeObjectForKey: @"NSViewClass"]);
|
|
|
|
}
|
|
|
|
if ([coder containsValueForKey: @"NSWindowClass"])
|
2004-02-24 19:31:33 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_windowClass, [coder decodeObjectForKey: @"NSWindowClass"]);
|
2004-02-24 19:31:33 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
if ([coder containsValueForKey: @"NSWindowStyleMask"])
|
2004-02-24 19:31:33 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
_windowStyle = [coder decodeIntForKey: @"NSWindowStyleMask"];
|
|
|
|
}
|
|
|
|
if([coder containsValueForKey: @"NSWindowBacking"])
|
|
|
|
{
|
|
|
|
_backingStoreType = [coder decodeIntForKey: @"NSWindowBacking"];
|
2004-02-24 19:31:33 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
if ([coder containsValueForKey: @"NSWindowView"])
|
2004-02-15 18:23:13 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_view, [coder decodeObjectForKey: @"NSWindowView"]);
|
2004-02-15 18:23:13 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
if ([coder containsValueForKey: @"NSWTFlags"])
|
2004-02-15 18:23:13 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
unsigned long flags = [coder decodeIntForKey: @"NSWTFlags"];
|
|
|
|
memcpy((void *)&_flags,(void *)&flags,sizeof(struct _GSWindowTemplateFlags));
|
2004-02-15 18:23:13 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
if ([coder containsValueForKey: @"NSMinSize"])
|
2004-02-24 19:31:33 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
_minSize = [coder decodeSizeForKey: @"NSMinSize"];
|
|
|
|
}
|
|
|
|
if ([coder containsValueForKey: @"NSMaxSize"])
|
|
|
|
{
|
|
|
|
_maxSize = [coder decodeSizeForKey: @"NSMaxSize"];
|
|
|
|
}
|
|
|
|
if ([coder containsValueForKey: @"NSWindowRect"])
|
|
|
|
{
|
|
|
|
_windowRect = [coder decodeRectForKey: @"NSWindowRect"];
|
|
|
|
}
|
|
|
|
if ([coder containsValueForKey: @"NSFrameAutosaveName"])
|
|
|
|
{
|
|
|
|
ASSIGN(_autosaveName, [coder decodeObjectForKey: @"NSFrameAutosaveName"]);
|
|
|
|
}
|
|
|
|
if ([coder containsValueForKey: @"NSWindowTitle"])
|
|
|
|
{
|
|
|
|
ASSIGN(_title, [coder decodeObjectForKey: @"NSWindowTitle"]);
|
|
|
|
_windowStyle |= NSTitledWindowMask;
|
2004-02-24 19:31:33 +00:00
|
|
|
}
|
2004-02-15 18:23:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
|
|
|
|
NSStringFromClass([coder class])];
|
2004-02-24 19:31:33 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
return self;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder *)aCoder
|
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if ([aCoder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
unsigned long flags = 0;
|
|
|
|
|
|
|
|
memcpy((void *)&flags,(void *)&_flags,sizeof(unsigned long));
|
|
|
|
|
|
|
|
[aCoder encodeObject: _viewClass forKey: @"NSViewClass"];
|
|
|
|
[aCoder encodeObject: _windowClass forKey: @"NSWindowClass"];
|
|
|
|
[aCoder encodeInt: _windowStyle forKey: @"NSWindowStyleMask"];
|
|
|
|
[aCoder encodeInt: _backingStoreType forKey: @"NSWindowBacking"];
|
|
|
|
[aCoder encodeObject: _view forKey: @"NSWindowView"];
|
|
|
|
[aCoder encodeInt: flags forKey: @"NSWTFlags"];
|
|
|
|
[aCoder encodeSize: _minSize forKey: @"NSMinSize"];
|
|
|
|
[aCoder encodeSize: _maxSize forKey: @"NSMaxSize"];
|
|
|
|
[aCoder encodeRect: _windowRect forKey: @"NSWindowRect"];
|
|
|
|
[aCoder encodeObject: _title forKey: @"NSWindowTitle"];
|
|
|
|
[aCoder encodeObject: _autosaveName forKey: @"NSFrameAutosaveName"];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) nibInstantiate
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if(_realObject == nil)
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
Class aClass = NSClassFromString(_windowClass);
|
|
|
|
NSEnumerator *en;
|
|
|
|
id v = nil;
|
|
|
|
|
|
|
|
if (aClass == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Unable to find class '%@'", _windowClass];
|
|
|
|
}
|
|
|
|
|
|
|
|
_realObject = [[aClass allocWithZone: NSDefaultMallocZone()]
|
|
|
|
initWithContentRect: _windowRect
|
|
|
|
styleMask: _windowStyle
|
|
|
|
backing: _backingStoreType
|
|
|
|
defer: _flags.isDeferred
|
|
|
|
screen: nil];
|
|
|
|
|
|
|
|
// set flags...
|
|
|
|
[_realObject setHidesOnDeactivate: _flags.isHiddenOnDeactivate];
|
|
|
|
[_realObject setReleasedWhenClosed: !(_flags.isNotReleasedOnClose)];
|
|
|
|
[_realObject setOneShot: _flags.isOneShot];
|
|
|
|
// [_realObject setVisible: _flags.isVisible]; // this is determined by whether it's in the visible windows array...
|
|
|
|
// [_realObject setWantsToBeColor: _flags.wantsToBeColor]; // not applicable on GNUstep.
|
|
|
|
[_realObject setAutodisplay: YES];
|
|
|
|
[_realObject setDynamicDepthLimit: _flags.dynamicDepthLimit];
|
|
|
|
// [_realObject setAutoPositionMask: _flags.autoPositionMask]; // currently not implemented for nibs
|
|
|
|
// [_realObject setAutoPosition: _flags.autoPosition];
|
|
|
|
[_realObject setDynamicDepthLimit: _flags.dynamicDepthLimit];
|
|
|
|
[_realObject setFrameAutosaveName: _autosaveName];
|
|
|
|
|
|
|
|
// reset attributes...
|
|
|
|
[_realObject setContentView: _view];
|
|
|
|
[_realObject setMinSize: _minSize];
|
|
|
|
[_realObject setMaxSize: _maxSize];
|
|
|
|
[_realObject setTitle: _title];
|
|
|
|
|
|
|
|
// swap out any views which need to be swapped...
|
|
|
|
en = [[[_realObject contentView] subviews] objectEnumerator];
|
|
|
|
while((v = [en nextObject]) != nil)
|
|
|
|
{
|
|
|
|
if([v respondsToSelector: @selector(nibInstantiate)])
|
|
|
|
{
|
|
|
|
[v nibInstantiate];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _realObject;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
// setters and getters
|
|
|
|
- (void) setBackingStoreType: (NSBackingStoreType)type
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
_backingStoreType = type;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSBackingStoreType) backingStoreType
|
|
|
|
{
|
|
|
|
return _backingStoreType;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setDeferred: (BOOL)flag
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
_flags.isDeferred = flag;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (BOOL) isDeferred
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _flags.isDeferred;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setMaxSize: (NSSize)maxSize
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
_maxSize = maxSize;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSSize) maxSize
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _maxSize;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setMinSize: (NSSize)minSize
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
_minSize = minSize;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSSize) minSize
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _minSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setWindowStyle: (unsigned)style
|
|
|
|
{
|
|
|
|
_windowStyle = style;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (unsigned) windowStyle
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _windowStyle;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setTitle: (NSString *) title
|
|
|
|
{
|
|
|
|
ASSIGN(_title, title);
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)title;
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _title;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setViewClass: (NSString *)viewClass
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_viewClass,viewClass);
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)viewClass
|
|
|
|
{
|
|
|
|
return _viewClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setWindowRect: (NSRect)rect
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
_windowRect = rect;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSRect)windowRect
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _windowRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setScreenRect: (NSRect)rect
|
|
|
|
{
|
|
|
|
_screenRect = rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) screenRect
|
|
|
|
{
|
|
|
|
return _screenRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) realObject
|
|
|
|
{
|
|
|
|
return _realObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setView: (id)view
|
|
|
|
{
|
|
|
|
ASSIGN(_view,view);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) view
|
|
|
|
{
|
|
|
|
return _view;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setClassName: (NSString *)name
|
|
|
|
{
|
|
|
|
ASSIGN(_windowClass, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)className
|
|
|
|
{
|
|
|
|
return _windowClass;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Template for any classes which derive from NSView
|
|
|
|
@implementation NSViewTemplate
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSViewTemplate class])
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
[self setVersion: 0];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
self = [super initWithCoder: coder];
|
|
|
|
if(self != nil)
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
_className = [coder decodeObjectForKey: @"NSClassName"];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
|
|
|
|
NSStringFromClass([coder class])];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
[coder encodeObject: (id)_className forKey: @"NSClassName"];
|
|
|
|
}
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id)nibInstantiate
|
|
|
|
{
|
|
|
|
if(_realObject == nil)
|
|
|
|
{
|
|
|
|
Class aClass = NSClassFromString(_className);
|
|
|
|
if(aClass == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Unable to find class '%@'", _className];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_realObject = [[aClass allocWithZone: NSDefaultMallocZone()] initWithFrame: [self frame]];
|
|
|
|
[[self superview] replaceSubview: self with: _realObject]; // replace the old view...
|
|
|
|
}
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
return _realObject;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setters and getters
|
|
|
|
- (void) setClassName: (NSString *)name
|
|
|
|
{
|
|
|
|
ASSIGN(_className, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)className
|
|
|
|
{
|
|
|
|
return _className;
|
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) realObject
|
|
|
|
{
|
|
|
|
return _realObject;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
// Template for any classes which derive from NSText
|
|
|
|
@implementation NSTextTemplate
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSTextTemplate class])
|
|
|
|
{
|
|
|
|
[self setVersion: 0];
|
|
|
|
}
|
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
// Template for any classes which derive from NSTextView
|
|
|
|
@implementation NSTextViewTemplate
|
|
|
|
+ (void) initialize
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if (self == [NSTextViewTemplate class])
|
|
|
|
{
|
|
|
|
[self setVersion: 0];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id)nibInstantiate
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if(_realObject == nil)
|
|
|
|
{
|
|
|
|
Class aClass = NSClassFromString(_className);
|
|
|
|
if(aClass == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Unable to find class '%@'", _className];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_realObject = [[aClass allocWithZone: NSDefaultMallocZone()] initWithFrame: [self frame]];
|
|
|
|
[[self superview] replaceSubview: self with: _realObject]; // replace the old view...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _realObject;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
// Template for any classes which derive from NSMenu.
|
|
|
|
@implementation NSMenuTemplate
|
|
|
|
+ (void) initialize
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if (self == [NSMenuTemplate class])
|
|
|
|
{
|
|
|
|
[self setVersion: 0];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder *)aCoder
|
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return nil;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder *)aCoder
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) nibInstantiate
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return nil;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setClassName: (NSString *)className
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_menuClass, className);
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)className
|
|
|
|
{
|
|
|
|
return _menuClass;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) realObject
|
|
|
|
{
|
|
|
|
return _realObject;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
@implementation NSCustomObject
|
2003-10-25 20:50:08 +00:00
|
|
|
- (void) setClassName: (NSString *)name
|
|
|
|
{
|
|
|
|
ASSIGN(_className, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)className
|
|
|
|
{
|
|
|
|
return _className;
|
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setExtension: (NSString *)name
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_extension, name);
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)extension
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _extension;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setObject: (id)obj
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_object, obj);
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) object
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _object;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]);
|
|
|
|
ASSIGN(_extension, [coder decodeObjectForKey: @"NSExtension"]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
|
|
|
|
NSStringFromClass([coder class])];
|
|
|
|
}
|
|
|
|
return self;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
[coder encodeObject: (id)_className forKey: @"NSClassName"];
|
|
|
|
[coder encodeConditionalObject: (id)_extension forKey: @"NSExtension"];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) nibInstantiate
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if(_object == nil)
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
Class aClass = NSClassFromString(_className);
|
|
|
|
if(aClass == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Unable to find class '%@'", _className];
|
|
|
|
}
|
|
|
|
|
|
|
|
_object = [[aClass allocWithZone: NSDefaultMallocZone()] init];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
return _object;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSCustomView
|
|
|
|
- (void) setClassName: (NSString *)name
|
|
|
|
{
|
|
|
|
ASSIGN(_className, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)className
|
|
|
|
{
|
|
|
|
return _className;
|
|
|
|
}
|
|
|
|
- (void) setExtension: (NSString *)ext;
|
|
|
|
{
|
|
|
|
ASSIGN(_extension, ext);
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)extension
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _extension;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id)nibInstantiate
|
|
|
|
{
|
|
|
|
if(_view == nil)
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
Class aClass = NSClassFromString(_className);
|
|
|
|
if(aClass == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Unable to find class '%@'", _className];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_view = [[aClass allocWithZone: NSDefaultMallocZone()] initWithFrame: [self frame]];
|
|
|
|
[[self superview] replaceSubview: self with: _view]; // replace the old view...
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
return _view;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
self = [super initWithCoder: coder];
|
|
|
|
if(self != nil)
|
|
|
|
{
|
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
_className = [coder decodeObjectForKey: @"NSClassName"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
[coder encodeObject: (id)_className forKey: @"NSClassName"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
@implementation NSCustomResource
|
|
|
|
- (void) setClassName: (NSString *)className
|
|
|
|
{
|
|
|
|
ASSIGN(_className, className);
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)className
|
|
|
|
{
|
|
|
|
return _className;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setResourceName: (NSString *)resourceName
|
|
|
|
{
|
|
|
|
ASSIGN(_resourceName, resourceName);
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)resourceName
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _resourceName;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id)nibInstantiate
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return self;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
id realObject = nil;
|
|
|
|
if([coder allowsKeyedCoding])
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]);
|
|
|
|
ASSIGN(_resourceName, [coder decodeObjectForKey: @"NSResourceName"]);
|
|
|
|
|
|
|
|
// this is a hack, but for now it should do.
|
|
|
|
if([_className isEqual: @"NSSound"])
|
|
|
|
{
|
|
|
|
realObject = [NSSound soundNamed: _resourceName];
|
|
|
|
}
|
|
|
|
else if([_className isEqual: @"NSImage"])
|
|
|
|
{
|
|
|
|
realObject = [NSImage imageNamed: _resourceName];
|
|
|
|
}
|
|
|
|
|
|
|
|
// if an object has been substituted, then release the placeholder.
|
|
|
|
if(realObject != nil)
|
|
|
|
{
|
|
|
|
RELEASE(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
|
|
|
|
NSStringFromClass([coder class])];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
|
|
|
|
return realObject;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
[coder encodeObject: (id)_className forKey: @"NSClassName"];
|
|
|
|
[coder encodeObject: (id)_resourceName forKey: @"NSResourceName"];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSKeyedUnarchiver (NSClassSwapperPrivate)
|
|
|
|
- (BOOL) replaceObject: (id)oldObj withObject: (id)newObj;
|
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
@implementation NSClassSwapper
|
|
|
|
- (void) setTemplate: (id)temp
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_template, temp);
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) template
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _template;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setClassName: (NSString *)className
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_className, className);
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)className
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _className;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (BOOL) isInInterfaceBuilder
|
|
|
|
{
|
|
|
|
return NO;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) instantiateRealObject: (NSCoder *)coder withClassName: (NSString *)className
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
Class aClass = NSClassFromString(className);
|
|
|
|
id object = nil;
|
|
|
|
Class newCellClass = nil;
|
|
|
|
NSString *origCellClassName = nil;
|
|
|
|
Class origCellClass = nil;
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
if(aClass == nil)
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
2006-05-20 22:12:46 +00:00
|
|
|
format: @"NSClassSwapper unable to find class '%@'", className];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
// if this is a class which uses cells, override with the new cellClass, if the
|
|
|
|
// subclass responds to cellClass.
|
|
|
|
if([aClass respondsToSelector: @selector(cellClass)] &&
|
|
|
|
[className isEqualToString: _originalClassName] == NO)
|
|
|
|
{
|
|
|
|
Class origClass = NSClassFromString(_originalClassName);
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
origCellClass = [origClass cellClass];
|
|
|
|
newCellClass = [aClass cellClass];
|
|
|
|
origCellClassName = NSStringFromClass(origCellClass);
|
|
|
|
[(NSKeyedUnarchiver *)coder setClass: newCellClass forClassName: origCellClassName];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
// swap the class...
|
|
|
|
object = [aClass allocWithZone: NSDefaultMallocZone()];
|
|
|
|
[(NSKeyedUnarchiver *)coder replaceObject: self withObject: object];
|
|
|
|
_template = [object initWithCoder: coder];
|
|
|
|
if(object != _template)
|
|
|
|
{
|
|
|
|
[(NSKeyedUnarchiver *)coder replaceObject: object withObject: _template];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
if(newCellClass != nil && origCellClass != nil)
|
|
|
|
{
|
|
|
|
[(NSKeyedUnarchiver *)coder setClass: origCellClass forClassName: nil];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]);
|
|
|
|
ASSIGN(_originalClassName, [coder decodeObjectForKey: @"NSOriginalClassName"]);
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
// build the real object...
|
|
|
|
if([NSClassSwapper isInInterfaceBuilder] == YES)
|
|
|
|
{
|
|
|
|
[self instantiateRealObject: coder withClassName: _originalClassName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self instantiateRealObject: coder withClassName: _className];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
|
|
|
|
NSStringFromClass([coder class])];
|
|
|
|
}
|
|
|
|
|
|
|
|
return _template;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
NSString *originalClassName = NSStringFromClass(_template);
|
|
|
|
[coder encodeObject: (id)_className forKey: @"NSClassName"];
|
|
|
|
[coder encodeObject: (id)originalClassName forKey: @"NSOriginalClassName"];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
/* Correct some instances where the ":" is missing from the method name in the label */
|
|
|
|
@interface NSNibControlConnector (NibCompatibility)
|
|
|
|
- (void) instantiateWithInstantiator: (id<GSInstantiator>)instantiator;
|
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
@implementation NSNibControlConnector (NibCompatibility)
|
|
|
|
- (void) instantiateWithInstantiator: (id<GSInstantiator>)instantiator
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
NSRange colonRange = [_tag rangeOfString: @":"];
|
|
|
|
unsigned int location = colonRange.location;
|
|
|
|
|
|
|
|
if(location == NSNotFound)
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
NSString *newTag = [NSString stringWithFormat: @"%@:",_tag];
|
|
|
|
[self setLabel: (id)newTag];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
|
|
|
|
[super instantiateWithInstantiator: instantiator];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
@implementation NSIBObjectData
|
|
|
|
- (id)instantiateObject: (id)obj
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
id newObject = obj;
|
|
|
|
if([obj respondsToSelector: @selector(nibInstantiate)])
|
|
|
|
{
|
|
|
|
newObject = [obj nibInstantiate];
|
|
|
|
if([newObject respondsToSelector: @selector(awakeFromNib)])
|
|
|
|
{
|
|
|
|
// awaken the object.
|
|
|
|
[newObject awakeFromNib];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newObject;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) nibInstantiateWithOwner: (id)owner
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
[self nibInstantiateWithOwner: owner topLevelObjects: nil];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) nibInstantiateWithOwner: (id)owner topLevelObjects: (NSMutableArray *)topLevelObjects
|
|
|
|
{
|
|
|
|
NSEnumerator *en = [_connections objectEnumerator];
|
|
|
|
id obj = nil;
|
|
|
|
id menu = nil;
|
|
|
|
|
|
|
|
// replace the owner with the actual instance provided.
|
|
|
|
[_root setObject: owner];
|
|
|
|
|
|
|
|
// iterate over connections, instantiate, and then establish them.
|
|
|
|
while((obj = [en nextObject]) != nil)
|
|
|
|
{
|
|
|
|
if([obj respondsToSelector: @selector(instantiateWithInstantiator:)])
|
|
|
|
{
|
|
|
|
[obj instantiateWithInstantiator: self];
|
|
|
|
[obj establishConnection];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
en = [_visibleWindows objectEnumerator];
|
|
|
|
while((obj = [en nextObject]) != nil)
|
|
|
|
{
|
|
|
|
id w = [self instantiateObject: obj];
|
|
|
|
[w orderFront: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
menu = [self objectForName: @"MainMenu"];
|
|
|
|
if(menu != nil)
|
|
|
|
{
|
|
|
|
menu = [self instantiateObject: menu];
|
|
|
|
[NSApp setMainMenu: menu];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) awakeWithContext: (NSDictionary *)context
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
NSMutableArray *tlo = [context objectForKey: @"NSTopLevelObjects"];
|
|
|
|
id owner = [context objectForKey: @"NSOwner"];
|
|
|
|
[self nibInstantiateWithOwner: owner topLevelObjects: tlo];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSMutableArray *) connections
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _connections;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSMutableSet *) topLevelObjects
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return nil;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSMutableDictionary *) nameTable
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return nil;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) objectForName: (NSString *)name
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
NSArray *nameKeys = (NSArray *)NSAllMapTableKeys(_names);
|
|
|
|
NSArray *nameValues = (NSArray *)NSAllMapTableValues(_names);
|
|
|
|
int i = [nameValues indexOfObject: name];
|
|
|
|
id result = nil;
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
if(i != NSNotFound)
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
result = [nameKeys objectAtIndex: i];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *) nameForObject: (id)obj
|
|
|
|
{
|
|
|
|
NSArray *nameKeys = (NSArray *)NSAllMapTableKeys(_names);
|
|
|
|
NSArray *nameValues = (NSArray *)NSAllMapTableValues(_names);
|
|
|
|
int i = [nameKeys indexOfObject: obj];
|
|
|
|
NSString *result = [nameValues objectAtIndex: i];
|
|
|
|
return result;
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
NSArray *accessibilityOidsKeys = (NSArray *)NSAllMapTableKeys(_accessibilityOids);
|
|
|
|
NSArray *accessibilityOidsValues = (NSArray *)NSAllMapTableValues(_accessibilityOids);
|
|
|
|
NSArray *classKeys = (NSArray *)NSAllMapTableKeys(_classes);
|
|
|
|
NSArray *classValues = (NSArray *)NSAllMapTableValues(_classes);
|
|
|
|
NSArray *nameKeys = (NSArray *)NSAllMapTableKeys(_names);
|
|
|
|
NSArray *nameValues = (NSArray *)NSAllMapTableValues(_names);
|
|
|
|
NSArray *objectsKeys = (NSArray *)NSAllMapTableKeys(_objects);
|
|
|
|
NSArray *objectsValues = (NSArray *)NSAllMapTableValues(_objects);
|
|
|
|
NSArray *oidsKeys = (NSArray *)NSAllMapTableKeys(_oids);
|
|
|
|
NSArray *oidsValues = (NSArray *)NSAllMapTableValues(_oids);
|
|
|
|
|
|
|
|
[coder encodeObject: (id)_accessibilityConnectors forKey: @"NSAccessibilityConnectors"];
|
|
|
|
[coder encodeObject: (id) accessibilityOidsKeys forKey: @"NSAccessibilityOidsKeys"];
|
|
|
|
[coder encodeObject: (id) accessibilityOidsValues forKey: @"NSAccessibilityOidsValues"];
|
|
|
|
[coder encodeObject: (id) classKeys forKey: @"NSClassesKeys"];
|
|
|
|
[coder encodeObject: (id) classValues forKey: @"NSClassesValues"];
|
|
|
|
[coder encodeObject: (id) nameKeys forKey: @"NSNamesKeys"];
|
|
|
|
[coder encodeObject: (id) nameValues forKey: @"NSNamesValues"];
|
|
|
|
[coder encodeObject: (id) objectsKeys forKey: @"NSObjectsKeys"];
|
|
|
|
[coder encodeObject: (id) objectsValues forKey: @"NSObjectsValues"];
|
|
|
|
[coder encodeObject: (id) oidsKeys forKey: @"NSOidsKeys"];
|
|
|
|
[coder encodeObject: (id) oidsValues forKey: @"NSOidsValues"];
|
|
|
|
[coder encodeObject: (id) _connections forKey: @"NSConnections"];
|
|
|
|
[coder encodeConditionalObject: (id) _fontManager forKey: @"NSFontManager"];
|
|
|
|
[coder encodeConditionalObject: (id) _framework forKey: @"NSFramework"];
|
|
|
|
[coder encodeObject: (id) _visibleWindows forKey: @"NSVisibleWindows"];
|
|
|
|
[coder encodeInt: _nextOid forKey: @"NSNextOid"];
|
|
|
|
[coder encodeConditionalObject: (id) _root forKey: @"NSRoot"];
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) _buildMap: (NSMapTable *)mapTable
|
|
|
|
withKeys: (NSArray *)keys
|
|
|
|
andValues: (NSArray *)values
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
NSEnumerator *ken = [keys objectEnumerator];
|
|
|
|
NSEnumerator *ven = [values objectEnumerator];
|
|
|
|
id key = nil;
|
|
|
|
id value = nil;
|
|
|
|
|
|
|
|
while((key = [ken nextObject]) != nil && (value = [ven nextObject]) != nil)
|
|
|
|
{
|
|
|
|
NSMapInsert(mapTable, key, value);
|
|
|
|
}
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
ASSIGN(_root, [coder decodeObjectForKey: @"NSRoot"]);
|
|
|
|
ASSIGN(_visibleWindows, (NSMutableArray *)[coder decodeObjectForKey: @"NSVisibleWindows"]);
|
|
|
|
ASSIGN(_accessibilityConnectors, (NSMutableArray *)[coder decodeObjectForKey: @"NSAccessibilityConnectors"]);
|
|
|
|
ASSIGN(_fontManager, [coder decodeObjectForKey: @"NSFontManager"]);
|
|
|
|
ASSIGN(_framework, [coder decodeObjectForKey: @"NSFramework"]);
|
|
|
|
ASSIGN(_connections, (NSMutableArray *)[coder decodeObjectForKey: @"NSConnections"]);
|
|
|
|
_nextOid = [coder decodeIntForKey: @"NSNextOid"];
|
|
|
|
|
|
|
|
{
|
|
|
|
NSArray *objectsKeys = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSObjectsKeys"];
|
|
|
|
NSArray *objectsValues = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSObjectsValues"];
|
|
|
|
NSArray *nameKeys = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSNamesKeys"];
|
|
|
|
NSArray *nameValues = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSNamesValues"];
|
|
|
|
NSArray *oidsKeys = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSOidsKeys"];
|
|
|
|
NSArray *oidsValues = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSOidsValues"];
|
|
|
|
NSArray *classKeys = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSClassesKeys"];
|
|
|
|
NSArray *classValues = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSClassesValues"];
|
|
|
|
NSArray *accessibilityOidsKeys = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSAccessibilityOidsKeys"];
|
|
|
|
NSArray *accessibilityOidsValues = (NSArray *)
|
|
|
|
[coder decodeObjectForKey: @"NSAccessibilityOidsValues"];
|
|
|
|
|
|
|
|
// instantiate the maps..
|
|
|
|
_objects = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
_names = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
_oids = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
_classes = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
_accessibilityOids = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
|
|
|
|
// fill in the maps...
|
|
|
|
[self _buildMap: _accessibilityOids withKeys: accessibilityOidsKeys andValues: accessibilityOidsValues];
|
|
|
|
[self _buildMap: _classes withKeys: classKeys andValues: classValues];
|
|
|
|
[self _buildMap: _names withKeys: nameKeys andValues: nameValues];
|
|
|
|
[self _buildMap: _objects withKeys: objectsKeys andValues: objectsValues];
|
|
|
|
[self _buildMap: _oids withKeys: oidsKeys andValues: oidsValues];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Can't decode %@ with %@.",NSStringFromClass([self class]),
|
|
|
|
NSStringFromClass([coder class])];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) init
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if((self = [super init]) != nil)
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
// instantiate the maps..
|
|
|
|
_objects = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
_names = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
_oids = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
_classes = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
_accessibilityOids = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 2);
|
|
|
|
|
|
|
|
// initialize the objects...
|
|
|
|
_accessibilityConnectors = [[NSMutableArray alloc] init];
|
|
|
|
_connections = [[NSMutableArray alloc] init];
|
|
|
|
_visibleWindows = [[NSMutableArray alloc] init];
|
|
|
|
_framework = nil;
|
|
|
|
_fontManager = nil;
|
|
|
|
_root = nil;
|
|
|
|
_nextOid = 0;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
return self;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
// free the maps.
|
|
|
|
NSFreeMapTable(_objects);
|
|
|
|
NSFreeMapTable(_names);
|
|
|
|
NSFreeMapTable(_oids);
|
|
|
|
NSFreeMapTable(_classes);
|
|
|
|
NSFreeMapTable(_accessibilityOids);
|
|
|
|
|
|
|
|
// free other objects.
|
|
|
|
RELEASE(_accessibilityConnectors);
|
|
|
|
RELEASE(_connections);
|
|
|
|
RELEASE(_fontManager);
|
|
|
|
RELEASE(_framework);
|
|
|
|
RELEASE(_visibleWindows);
|
|
|
|
RELEASE(_root);
|
2003-10-25 20:50:08 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) setRoot: (id) root
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
ASSIGN(_root, root);
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (id) root
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _root;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
@interface NSButtonImageSource : NSObject <NSCoding>
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
NSString *imageName;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)imageName;
|
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
@implementation NSButtonImageSource
|
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
ASSIGN(imageName, [coder decodeObjectForKey: @"NSImageName"]);
|
|
|
|
}
|
|
|
|
RELEASE(self);
|
|
|
|
return [NSImage imageNamed: imageName];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
if([coder allowsKeyedCoding])
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
[coder encodeObject: imageName forKey: @"NSImageName"];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (NSString *)imageName
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return imageName;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
- (void) dealloc
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
RELEASE(imageName);
|
|
|
|
[super dealloc];
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
@end
|
2003-10-25 20:50:08 +00:00
|
|
|
|
2006-05-20 22:12:46 +00:00
|
|
|
// ...dummy/placeholder classes...
|
|
|
|
// overridden in NSTableView to be GSTableCornerView,
|
|
|
|
// but the class needs to be present to be overridden.
|
|
|
|
@interface _NSCornerView : NSView
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation _NSCornerView
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSKeyedUnarchiver (GSNibCompatibilityAdditions)
|
|
|
|
- (NSDictionary *)keyMap;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSKeyedUnarchiver (GSNibCompatibilityAdditions)
|
|
|
|
- (NSDictionary *)keyMap
|
2003-10-25 20:50:08 +00:00
|
|
|
{
|
2006-05-20 22:12:46 +00:00
|
|
|
return _keyMap;
|
2003-10-25 20:50:08 +00:00
|
|
|
}
|
|
|
|
@end
|