mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 22:00:38 +00:00
Changes necessary in the gui library to implement custom class support.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14660 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7dde67abce
commit
9b79751a63
5 changed files with 819 additions and 35 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
2002-10-06 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Source/NSBundleAdditions.m: Implemented the following classes:
|
||||
NSWindowTemplate, NSViewTemplate, NSControlTemplate, NSTextTemplate,
|
||||
NSTextViewTemplate, NSMenuTemplate, GSClassSwapper. These classes
|
||||
are used to allow the .gorm files to have placeholders for custom
|
||||
classes defined by the developer. This is similar to the approach
|
||||
used in OPENSTEP 4.2/Mach and MOSX.
|
||||
* Headers/gnustep/gui/NSNibLoading.h: Removed declarations for classes
|
||||
which should be considered private to GNUstep.
|
||||
* Headers/gnustep/gui/GSNibTemplates.h: Moved GSNibContainer,
|
||||
GSNibItem, GSCustomView here. Added declarations for new template
|
||||
classes.
|
||||
|
||||
2002-10-04 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Source/NSBrowser.m: Implement non-separated columns.
|
||||
|
|
134
Headers/gnustep/gui/GSNibTemplates.h
Normal file
134
Headers/gnustep/gui/GSNibTemplates.h
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
GSNibTemplates.h
|
||||
|
||||
Copyright (C) 1997, 1999 Free Software Foundation, Inc.
|
||||
|
||||
Author: Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
Date: 2002
|
||||
|
||||
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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _GNUstep_H_GSNibTemplates
|
||||
#define _GNUstep_H_GSNibTemplates
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/NSMenu.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSText.h>
|
||||
#include <AppKit/NSTextView.h>
|
||||
#include <AppKit/NSControl.h>
|
||||
#include <AppKit/NSButton.h>
|
||||
|
||||
@class NSString;
|
||||
@class NSDictionary;
|
||||
@class NSMutableDictionary;
|
||||
|
||||
/*
|
||||
* This is the class that holds objects within a nib.
|
||||
*/
|
||||
@interface GSNibContainer : NSObject <NSCoding>
|
||||
{
|
||||
NSMutableDictionary *nameTable;
|
||||
NSMutableArray *connections;
|
||||
BOOL _isAwake;
|
||||
}
|
||||
- (void) awakeWithContext: (NSDictionary*)context;
|
||||
- (NSMutableDictionary*) nameTable;
|
||||
- (NSMutableArray*) connections;
|
||||
@end
|
||||
|
||||
/*
|
||||
* Template classes
|
||||
*/
|
||||
|
||||
@interface GSNibItem : NSObject <NSCoding>
|
||||
{
|
||||
NSString *theClass;
|
||||
NSRect theFrame;
|
||||
unsigned int autoresizingMask;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface GSCustomView : GSNibItem <NSCoding>
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
// templates
|
||||
@protocol GSTemplate
|
||||
- (void) setClassName: (NSString *)className;
|
||||
- (NSString *)className;
|
||||
- (id) instantiateObject: (NSCoder *)coder;
|
||||
@end
|
||||
|
||||
@interface NSWindowTemplate : NSWindow <GSTemplate>
|
||||
{
|
||||
NSString *_className;
|
||||
BOOL _deferFlag;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSViewTemplate : NSView <GSTemplate>
|
||||
{
|
||||
NSString *_className;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSTextTemplate : NSText <GSTemplate>
|
||||
{
|
||||
NSString *_className;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSTextViewTemplate : NSTextView <GSTemplate>
|
||||
{
|
||||
NSString *_className;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSMenuTemplate : NSMenu <GSTemplate>
|
||||
{
|
||||
NSString *_className;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSControlTemplate : NSControl <GSTemplate>
|
||||
{
|
||||
NSString *_className;
|
||||
id _delegate;
|
||||
id _dataSource;
|
||||
BOOL _usesDataSource;
|
||||
NSButtonType _buttonType;
|
||||
NSBezelStyle _bezelStyle;
|
||||
BOOL _bordered;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface GSClassSwapper : NSObject
|
||||
{
|
||||
NSString *_className;
|
||||
id _template;
|
||||
}
|
||||
- (NSString *) className;
|
||||
- (void) setClassName: (NSString *)name;
|
||||
- (id) template;
|
||||
- (void) setTemplate: (id)template;
|
||||
@end
|
||||
|
||||
#endif /* _GNUstep_H_GSNibTemplates */
|
|
@ -62,38 +62,7 @@
|
|||
|
||||
#ifndef NO_GNUSTEP
|
||||
- (NSString *) pathForNibResource: (NSString *)fileName;
|
||||
#endif
|
||||
#endif // NO_GNUSTEP
|
||||
@end
|
||||
|
||||
#ifndef NO_GNUSTEP
|
||||
|
||||
/*
|
||||
* This is the class that holds objects within a nib.
|
||||
*/
|
||||
@interface GSNibContainer : NSObject <NSCoding>
|
||||
{
|
||||
NSMutableDictionary *nameTable;
|
||||
NSMutableArray *connections;
|
||||
BOOL _isAwake;
|
||||
}
|
||||
- (void) awakeWithContext: (NSDictionary*)context;
|
||||
- (NSMutableDictionary*) nameTable;
|
||||
- (NSMutableArray*) connections;
|
||||
@end
|
||||
|
||||
@interface GSNibItem : NSObject <NSCoding>
|
||||
{
|
||||
NSString *theClass;
|
||||
NSRect theFrame;
|
||||
unsigned int autoresizingMask;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface GSCustomView : GSNibItem <NSCoding>
|
||||
{
|
||||
}
|
||||
@end
|
||||
#endif /* NO_GNUSTEP */
|
||||
|
||||
#endif /* _GNUstep_H_NSNibLoading */
|
||||
|
||||
|
|
|
@ -319,6 +319,7 @@ GSServicesManager.h \
|
|||
GSTextConverter.h \
|
||||
GSTrackingRect.h \
|
||||
GSHelpManagerPanel.h \
|
||||
GSNibTemplates.h \
|
||||
$(AUTOGSDOC_HEADERS) \
|
||||
IMConnectors.h \
|
||||
IMCustomObject.h \
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
*/
|
||||
|
||||
#include <gnustep/gui/config.h>
|
||||
#include <Foundation/NSClassDescription.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
|
@ -43,17 +44,26 @@
|
|||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSKeyValueCoding.h>
|
||||
#include <AppKit/NSApplication.h>
|
||||
#include <AppKit/NSMenu.h>
|
||||
#include <AppKit/NSControl.h>
|
||||
#include <AppKit/NSImage.h>
|
||||
#include <AppKit/NSSound.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSTextView.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/NSNibConnector.h>
|
||||
#include <AppKit/NSNibLoading.h>
|
||||
#include <AppKit/GSNibTemplates.h>
|
||||
#include <AppKit/IMLoading.h>
|
||||
|
||||
//
|
||||
// For the template classes since they need to know about any and all subclasses
|
||||
// of the parent classes covered by them.
|
||||
//
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
static const int currentVersion = 1;
|
||||
|
||||
@implementation NSNibConnector
|
||||
|
@ -250,7 +260,7 @@ Class gmodel_class(void)
|
|||
NS_DURING
|
||||
{
|
||||
NSData *data = [NSData dataWithContentsOfFile: fileName];
|
||||
|
||||
NSDebugLog(@"Loaded data...");
|
||||
if (data != nil)
|
||||
{
|
||||
unarchiver = [[NSUnarchiver alloc] initForReadingWithData: data];
|
||||
|
@ -258,12 +268,14 @@ Class gmodel_class(void)
|
|||
{
|
||||
id obj;
|
||||
|
||||
NSDebugLog(@"Invoking unarchiver");
|
||||
[unarchiver setObjectZone: zone];
|
||||
obj = [unarchiver decodeObject];
|
||||
if (obj != nil)
|
||||
{
|
||||
if ([obj isKindOfClass: [GSNibContainer class]])
|
||||
{
|
||||
NSDebugLog(@"Calling awakeWithContext");
|
||||
[obj awakeWithContext: context];
|
||||
/*
|
||||
*Ok - it's all done now - just retain the nib container
|
||||
|
@ -284,6 +296,7 @@ Class gmodel_class(void)
|
|||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"Exception occured while loading model: %@",[localException reason]);
|
||||
TEST_RELEASE(unarchiver);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
@ -666,9 +679,7 @@ Class gmodel_class(void)
|
|||
|
||||
@end
|
||||
|
||||
|
||||
@implementation GSCustomView
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [GSCustomView class])
|
||||
|
@ -687,3 +698,658 @@ Class gmodel_class(void)
|
|||
return [super initWithCoder: aCoder];
|
||||
}
|
||||
@end
|
||||
|
||||
// Template for any class which derives from NSWindow.
|
||||
@implementation NSWindowTemplate
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSWindowTemplate class])
|
||||
{
|
||||
[self setVersion: 0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_className);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- init
|
||||
{
|
||||
[super init];
|
||||
|
||||
// Start initially with the highest level class...
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
|
||||
// defer flag...
|
||||
_deferFlag = NO;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &_deferFlag];
|
||||
// return [super _initWithCoder: aCoder defer: YES];
|
||||
return [super initWithCoder: aCoder];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_deferFlag];
|
||||
[super encodeWithCoder: aCoder];
|
||||
}
|
||||
|
||||
- (id) awakeAfterUsingCoder: (NSCoder *)coder
|
||||
{
|
||||
return [self instantiateObject: coder];
|
||||
}
|
||||
|
||||
- (id) instantiateObject: (NSCoder *)coder
|
||||
{
|
||||
id obj = nil;
|
||||
Class aClass = NSClassFromString(_className);
|
||||
|
||||
if (aClass == nil)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Unable to find class '%@'", _className];
|
||||
}
|
||||
|
||||
obj = [[aClass allocWithZone: [self zone]]
|
||||
initWithContentRect: [self frame]
|
||||
styleMask: [self styleMask]
|
||||
backing: [self backingType]
|
||||
defer: _deferFlag];
|
||||
|
||||
// NSLog(@"Instantiated window %@",obj);
|
||||
|
||||
[obj setBackgroundColor: [self backgroundColor]];
|
||||
[obj setContentView: [self contentView]];
|
||||
[obj setFrameAutosaveName: [self frameAutosaveName]];
|
||||
[obj setHidesOnDeactivate: [self hidesOnDeactivate]];
|
||||
[obj setInitialFirstResponder: [self initialFirstResponder]];
|
||||
[obj setAutodisplay: [self isAutodisplay]];
|
||||
[obj setReleasedWhenClosed: [self isReleasedWhenClosed]];
|
||||
[obj _setVisible: [self isVisible]];
|
||||
[obj setTitle: [self title]];
|
||||
[obj setFrame: [self frame] display: NO];
|
||||
|
||||
RELEASE(self);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// setters and getters...
|
||||
- (void) setClassName: (NSString *)name
|
||||
{
|
||||
ASSIGN(_className, name);
|
||||
}
|
||||
|
||||
- (NSString *)className
|
||||
{
|
||||
return _className;
|
||||
}
|
||||
|
||||
- (BOOL)deferFlag
|
||||
{
|
||||
return _deferFlag;
|
||||
}
|
||||
|
||||
- (void)setDeferFlag: (BOOL)flag
|
||||
{
|
||||
_deferFlag = flag;
|
||||
}
|
||||
@end
|
||||
|
||||
// Template for any classes which derive from NSView
|
||||
@implementation NSViewTemplate
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSViewTemplate class])
|
||||
{
|
||||
[self setVersion: 0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_className);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- initWithFrame: (NSRect)frame
|
||||
{
|
||||
// Start initially with the highest level class...
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
[super initWithFrame: frame];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- init
|
||||
{
|
||||
// Start initially with the highest level class...
|
||||
[super init];
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[super initWithCoder: aCoder];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[super encodeWithCoder: aCoder];
|
||||
}
|
||||
|
||||
- (id) awakeAfterUsingCoder: (NSCoder *)coder
|
||||
{
|
||||
return [self instantiateObject: coder];
|
||||
}
|
||||
|
||||
- (id) instantiateObject: (NSCoder *)coder
|
||||
{
|
||||
Class aClass = NSClassFromString(_className);
|
||||
NSRect theFrame = [self frame];
|
||||
id obj = nil;
|
||||
|
||||
if (aClass == nil)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Unable to find class '%@'", _className];
|
||||
}
|
||||
|
||||
obj = [[aClass allocWithZone: NSDefaultMallocZone()]
|
||||
initWithFrame: theFrame];
|
||||
|
||||
// set the attributes for the view
|
||||
[obj setBounds: [self bounds]];
|
||||
|
||||
RELEASE(self);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// setters and getters
|
||||
- (void) setClassName: (NSString *)name
|
||||
{
|
||||
ASSIGN(_className, name);
|
||||
}
|
||||
|
||||
- (NSString *)className
|
||||
{
|
||||
return _className;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// Template for any classes which derive from NSText
|
||||
@implementation NSTextTemplate
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSTextTemplate class])
|
||||
{
|
||||
[self setVersion: 0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_className);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- initWithFrame: (NSRect)frame
|
||||
{
|
||||
// Start initially with the highest level class...
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
[super initWithFrame: frame];
|
||||
return self;
|
||||
}
|
||||
|
||||
- init
|
||||
{
|
||||
// Start initially with the highest level class...
|
||||
[super init];
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[super initWithCoder: aCoder];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[super encodeWithCoder: aCoder];
|
||||
}
|
||||
|
||||
- (id) awakeAfterUsingCoder: (NSCoder *)coder
|
||||
{
|
||||
return [self instantiateObject: coder];
|
||||
}
|
||||
|
||||
- (id) instantiateObject: (NSCoder *)coder
|
||||
{
|
||||
Class aClass = NSClassFromString(_className);
|
||||
NSRect theFrame = [self frame];
|
||||
id obj = nil;
|
||||
|
||||
if (aClass == nil)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Unable to find class '%@'", _className];
|
||||
}
|
||||
|
||||
obj = [[aClass allocWithZone: NSDefaultMallocZone()]
|
||||
initWithFrame: theFrame];
|
||||
|
||||
// set the attributes for the view
|
||||
[obj setBounds: [self bounds]];
|
||||
|
||||
// set the attributes for text
|
||||
[obj setBackgroundColor: [self backgroundColor]];
|
||||
[obj setDrawsBackground: [self drawsBackground]];
|
||||
[obj setEditable: [self isEditable]];
|
||||
[obj setSelectable: [self isSelectable]];
|
||||
[obj setFieldEditor: [self isFieldEditor]];
|
||||
[obj setRichText: [self isRichText]];
|
||||
[obj setImportsGraphics: [self importsGraphics]];
|
||||
[obj setDelegate: [self delegate]];
|
||||
|
||||
RELEASE(self);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// accessor methods...
|
||||
- (void) setClassName: (NSString *)name
|
||||
{
|
||||
ASSIGN(_className, name);
|
||||
}
|
||||
|
||||
- (NSString *)className
|
||||
{
|
||||
return _className;
|
||||
}
|
||||
@end
|
||||
|
||||
// Template for any classes which derive from NSTextView
|
||||
@implementation NSTextViewTemplate
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSTextViewTemplate class])
|
||||
{
|
||||
[self setVersion: 0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_className);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- initWithFrame: (NSRect)frame
|
||||
{
|
||||
// Start initially with the highest level class...
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
[super initWithFrame: frame];
|
||||
return self;
|
||||
}
|
||||
|
||||
- init
|
||||
{
|
||||
[super init];
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[super initWithCoder: aCoder];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[super encodeWithCoder: aCoder];
|
||||
}
|
||||
|
||||
- (id) awakeAfterUsingCoder: (NSCoder *)coder
|
||||
{
|
||||
return [self instantiateObject: coder];
|
||||
}
|
||||
|
||||
- (id) instantiateObject: (NSCoder *)coder
|
||||
{
|
||||
Class aClass = NSClassFromString(_className);
|
||||
NSRect theFrame = [self frame];
|
||||
id obj = nil;
|
||||
|
||||
if (aClass == nil)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Unable to find class '%@'", _className];
|
||||
}
|
||||
|
||||
obj = [[aClass allocWithZone: NSDefaultMallocZone()]
|
||||
initWithFrame: theFrame];
|
||||
|
||||
// set the attributes for the view
|
||||
[obj setBounds: [self bounds]];
|
||||
|
||||
// set the attributes for text
|
||||
[obj setBackgroundColor: [self backgroundColor]];
|
||||
[obj setDrawsBackground: [self drawsBackground]];
|
||||
[obj setEditable: [self isEditable]];
|
||||
[obj setSelectable: [self isSelectable]];
|
||||
[obj setFieldEditor: [self isFieldEditor]];
|
||||
[obj setRichText: [self isRichText]];
|
||||
[obj setImportsGraphics: [self importsGraphics]];
|
||||
[obj setDelegate: [self delegate]];
|
||||
|
||||
// text view
|
||||
[obj setRulerVisible: [self isRulerVisible]];
|
||||
[obj setInsertionPointColor: [self insertionPointColor]];
|
||||
|
||||
RELEASE(self);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// accessors
|
||||
- (void) setClassName: (NSString *)name
|
||||
{
|
||||
ASSIGN(_className, name);
|
||||
}
|
||||
|
||||
- (NSString *)className
|
||||
{
|
||||
return _className;
|
||||
}
|
||||
@end
|
||||
|
||||
// Template for any classes which derive from NSMenu.
|
||||
@implementation NSMenuTemplate
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSMenuTemplate class])
|
||||
{
|
||||
[self setVersion: 0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_className);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- init
|
||||
{
|
||||
[super init];
|
||||
// Start initially with the highest level class...
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[super initWithCoder: aCoder];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[super encodeWithCoder: aCoder];
|
||||
}
|
||||
|
||||
- (id) awakeAfterUsingCoder: (NSCoder *)coder
|
||||
{
|
||||
return [self instantiateObject: coder];
|
||||
}
|
||||
|
||||
- (id) instantiateObject: (NSCoder *)coder
|
||||
{
|
||||
Class aClass = NSClassFromString(_className);
|
||||
id obj = nil;
|
||||
|
||||
if (aClass == nil)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Unable to find class '%@'", _className];
|
||||
}
|
||||
|
||||
obj = [[aClass allocWithZone: NSDefaultMallocZone()] init];
|
||||
|
||||
// copy attributes
|
||||
[obj setAutoenablesItems: [self autoenablesItems]];
|
||||
[obj setTitle: [self title]];
|
||||
|
||||
RELEASE(self);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// accessors
|
||||
- (void) setClassName: (NSString *)name
|
||||
{
|
||||
ASSIGN(_className, name);
|
||||
}
|
||||
|
||||
- (NSString *)className
|
||||
{
|
||||
return _className;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
// Template for any classes which derive from NSControl
|
||||
@implementation NSControlTemplate
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSControlTemplate class])
|
||||
{
|
||||
[self setVersion: 0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_className);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- initWithFrame: (NSRect)frame
|
||||
{
|
||||
// Start initially with the highest level class...
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
[super initWithFrame: frame];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- init
|
||||
{
|
||||
// Start initially with the highest level class...
|
||||
[super init];
|
||||
ASSIGN(_className, NSStringFromClass([super class]));
|
||||
RETAIN(_className);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[aCoder decodeValueOfObjCType: @encode(id) at: &_delegate];
|
||||
[super initWithCoder: aCoder];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[aCoder encodeValueOfObjCType: @encode(id) at: &_delegate];
|
||||
[super encodeWithCoder: aCoder];
|
||||
}
|
||||
|
||||
- (id) awakeAfterUsingCoder: (NSCoder *)coder
|
||||
{
|
||||
return [self instantiateObject: coder];
|
||||
}
|
||||
|
||||
- (id) instantiateObject: (NSCoder *)coder
|
||||
{
|
||||
Class aClass = NSClassFromString(_className);
|
||||
NSRect theFrame = [self frame];
|
||||
id obj = nil;
|
||||
|
||||
if (aClass == nil)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Unable to find class '%@'", _className];
|
||||
}
|
||||
|
||||
obj = [[aClass allocWithZone: NSDefaultMallocZone()]
|
||||
initWithFrame: theFrame];
|
||||
|
||||
// set the attributes for the view
|
||||
[obj setBounds: [self bounds]];
|
||||
|
||||
// set the attributes for the control
|
||||
[obj setDoubleValue: [self doubleValue]];
|
||||
[obj setFloatValue: [self floatValue]];
|
||||
[obj setIntValue: [self intValue]];
|
||||
[obj setObjectValue: [self objectValue]];
|
||||
[obj setStringValue: [self stringValue]];
|
||||
[obj setTag: [self tag]];
|
||||
[obj setFont: [self font]];
|
||||
[obj setAlignment: [self alignment]];
|
||||
[obj setEnabled: [self isEnabled]];
|
||||
|
||||
// since only some controls have delegates, we need to test...
|
||||
if([obj respondsToSelector: @selector(setDelegate:)])
|
||||
{
|
||||
[obj setDelegate: _delegate];
|
||||
}
|
||||
|
||||
// since only some controls have data sources, we need to test...
|
||||
if([obj respondsToSelector: @selector(setDataSource:)])
|
||||
{
|
||||
[obj setDataSource: _dataSource];
|
||||
}
|
||||
|
||||
// since only some controls have data sources, we need to test...
|
||||
if([obj respondsToSelector: @selector(setUsesDataSource:)])
|
||||
{
|
||||
[obj setUsesDataSource: _usesDataSource];
|
||||
}
|
||||
|
||||
// for buttons...
|
||||
if([obj respondsToSelector: @selector(setButtonType:)] )
|
||||
{
|
||||
[obj setButtonType: _buttonType];
|
||||
[obj setBezelStyle: _bezelStyle];
|
||||
[obj setBordered: _bordered];
|
||||
}
|
||||
|
||||
RELEASE(self);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// accessors
|
||||
- (void) setClassName: (NSString *)name
|
||||
{
|
||||
ASSIGN(_className, name);
|
||||
}
|
||||
|
||||
- (NSString *)className
|
||||
{
|
||||
return _className;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
// This class uses the templates above to persist the correct type of
|
||||
// custom object into the nib file.
|
||||
@implementation GSClassSwapper
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [GSClassSwapper class])
|
||||
{
|
||||
[self setVersion: 0];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
_className = nil;
|
||||
_template = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[aCoder decodeValueOfObjCType: @encode(id) at: &_template];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(id) at: &_className];
|
||||
[aCoder encodeValueOfObjCType: @encode(id) at: &_template];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_className);
|
||||
RELEASE(_template);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *) className
|
||||
{
|
||||
return _className;
|
||||
}
|
||||
|
||||
- (void) setClassName: (NSString *)name
|
||||
{
|
||||
ASSIGN(_className, name);
|
||||
}
|
||||
|
||||
- (id) template
|
||||
{
|
||||
return _template;
|
||||
}
|
||||
|
||||
- (void) setTemplate: (id)template
|
||||
{
|
||||
ASSIGN(_template, template);
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue