Use best possible non-custom superclass when loading a nib that has a custom view with subviews.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@23118 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2006-07-02 04:55:30 +00:00
parent fd10b886b4
commit ebab43f63f
3 changed files with 68 additions and 5 deletions

View file

@ -1,3 +1,10 @@
2006-07-02 00:53 Gregory John Casamento <greg_casamento@yahoo.com>
* GormCore/GormCustomView.[hm]: If CustomView includes some
subviews in a nib file make the custom view into the best possible
superclass of the custom class indicated. Also store the className
in a variable instead of depending on "stringValue".
2006-06-24 20:49 Gregory John Casamento <greg_casamento@yahoo.com>
* GormCore/GormNibWrapperLoader.m: Make _isTopLevelObject: into

View file

@ -29,6 +29,7 @@
@interface GormCustomView : NSTextField
{
NSString *className;
}
- (void) setClassName: (NSString *)aName;

View file

@ -54,6 +54,12 @@
return self;
}
- (void) dealloc
{
RELEASE(className);
[super dealloc];
}
- (NSString*) inspectorClassName
{
return @"GormFilesOwnerInspector";
@ -66,12 +72,36 @@
- (void) setClassName: (NSString *)aName
{
ASSIGN(className, aName);
[self setStringValue: aName];
}
- (NSString *) className
{
return [self stringValue];
return className;
}
- (Class) bestPossibleSuperClass
{
Class cls = [NSView class];
GormClassManager *classManager = [(id<Gorm>)NSApp classManager];
if([classManager isSuperclass: @"NSView" linkedToClass: className])
{
NSString *superClass = [classManager nonCustomSuperClassOf: className];
// get the superclass if one exists...
if(superClass != nil)
{
cls = NSClassFromString(superClass);
if(cls == nil)
{
cls = [NSView class];
}
}
}
return cls;
}
/*
@ -91,10 +121,34 @@
if([aCoder allowsKeyedCoding])
{
NSCustomView *customView = [[NSCustomView alloc] initWithCoder: aCoder];
[self initWithFrame: [customView frame]];
NSArray *subviews = [customView subviews];
// get the classname...
[self setClassName: [customView className]];
_autoresizingMask = [customView autoresizingMask];
// if the custom view has subviews....
if(subviews != nil && [subviews count] > 0)
{
Class cls = [self bestPossibleSuperClass];
id replacementView = [[cls alloc] initWithFrame: [customView frame]];
NSEnumerator *en = [[customView subviews] objectEnumerator];
id v = nil;
[replacementView setAutoresizingMask: [customView autoresizingMask]];
while((v = [en nextObject]) != nil)
{
[replacementView addSubview: v];
}
return replacementView;
}
else
{
[self initWithFrame: [customView frame]];
_autoresizingMask = [customView autoresizingMask];
}
RELEASE(customView);
return self;
}
else
@ -143,7 +197,7 @@
@implementation GormTestCustomView
- (Class) _bestPossibleSuperClass
- (Class) bestPossibleSuperClass
{
Class cls = [NSView class];
GormClassManager *classManager = [(id<Gorm>)NSApp classManager];
@ -171,6 +225,7 @@
return cls;
}
- (id) initWithCoder: (NSCoder*)aCoder
{
id obj;
@ -187,7 +242,7 @@
if([classManager isSuperclass: @"NSOpenGLView" linkedToClass: theClass] ||
[theClass isEqual: @"NSOpenGLView"] || cls == nil)
{
cls = [self _bestPossibleSuperClass];
cls = [self bestPossibleSuperClass];
}
obj = [cls allocWithZone: [self zone]];