2001-10-03 17:38:46 +00:00
|
|
|
/* GormCustomView - Visual representation of a custom view placeholder
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Author: Adam Fedor <fedor@gnu.org>
|
|
|
|
* Date: 2001
|
|
|
|
*
|
|
|
|
* This file is part of GNUstep.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-11-05 23:44:36 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-10-03 17:38:46 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-05-26 03:37:38 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
2001-10-03 17:38:46 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-20 23:44:20 +00:00
|
|
|
#include <GormCore/GormCustomView.h>
|
|
|
|
#include <GormCore/GormPrivate.h>
|
|
|
|
#include <GormCore/GormOpenGLView.h>
|
|
|
|
|
2001-10-03 17:38:46 +00:00
|
|
|
#include <AppKit/NSColor.h>
|
|
|
|
#include <AppKit/NSGraphics.h>
|
|
|
|
#include <AppKit/NSFont.h>
|
2003-03-03 09:15:48 +00:00
|
|
|
#include <AppKit/NSNibLoading.h>
|
2005-06-20 23:44:20 +00:00
|
|
|
|
2008-12-02 07:54:31 +00:00
|
|
|
#include <GNUstepGUI/GSGormLoading.h>
|
|
|
|
#include <GNUstepGUI/GSNibLoading.h>
|
2002-09-21 15:24:59 +00:00
|
|
|
|
2002-03-01 14:42:15 +00:00
|
|
|
@class GSCustomView;
|
|
|
|
|
2009-01-31 23:37:33 +00:00
|
|
|
@interface CustomView : NSView
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CustomView
|
|
|
|
- (id) initWithFrame: (NSRect)frame
|
|
|
|
{
|
|
|
|
if((self = [super initWithFrame: frame]) != nil)
|
|
|
|
{
|
|
|
|
// Replace the CustomView with an NSView of the same dimensions.
|
2012-04-20 16:03:21 +00:00
|
|
|
self = (id)[[NSView alloc] initWithFrame: frame];
|
2009-01-31 23:37:33 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2001-10-03 17:38:46 +00:00
|
|
|
@implementation GormCustomView
|
|
|
|
|
|
|
|
- (id)initWithFrame:(NSRect)frameRect
|
|
|
|
{
|
|
|
|
self = [super initWithFrame: frameRect];
|
2006-10-05 02:39:50 +00:00
|
|
|
if(self != nil)
|
|
|
|
{
|
|
|
|
[self setBackgroundColor: [NSColor darkGrayColor]];
|
|
|
|
[self setTextColor: [NSColor whiteColor]];
|
|
|
|
[self setDrawsBackground: YES];
|
|
|
|
[self setAlignment: NSCenterTextAlignment];
|
|
|
|
[self setFont: [NSFont boldSystemFontOfSize: 0]];
|
|
|
|
[self setEditable: NO];
|
|
|
|
[self setSelectable: NO];
|
|
|
|
[self setClassName: @"CustomView"];
|
|
|
|
}
|
2001-10-03 17:38:46 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-07-02 04:55:30 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
RELEASE(className);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2001-10-03 17:38:46 +00:00
|
|
|
- (NSString*) inspectorClassName
|
|
|
|
{
|
|
|
|
return @"GormFilesOwnerInspector";
|
|
|
|
}
|
|
|
|
|
2004-04-18 04:07:06 +00:00
|
|
|
- (NSString*) classInspectorClassName
|
|
|
|
{
|
|
|
|
return @"GormFilesOwnerInspector";
|
|
|
|
}
|
|
|
|
|
2001-10-03 17:38:46 +00:00
|
|
|
- (void) setClassName: (NSString *)aName
|
|
|
|
{
|
2006-07-02 04:55:30 +00:00
|
|
|
ASSIGN(className, aName);
|
2001-10-03 17:38:46 +00:00
|
|
|
[self setStringValue: aName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) className
|
|
|
|
{
|
2006-07-02 04:55:30 +00:00
|
|
|
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;
|
2001-10-03 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This needs to be coded like a GSNibItem. How do we make sure this
|
|
|
|
* tracks changes in GSNibItem coding?
|
|
|
|
*/
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2009-01-31 23:37:33 +00:00
|
|
|
if([aCoder allowsKeyedCoding])
|
2006-08-09 06:31:12 +00:00
|
|
|
{
|
2009-01-31 23:37:33 +00:00
|
|
|
GormClassManager *classManager = [(id<Gorm>)NSApp classManager];
|
|
|
|
NSString *extension = nil;
|
|
|
|
|
|
|
|
ASSIGNCOPY(extension,[classManager nonCustomSuperClassOf: className]);
|
|
|
|
|
|
|
|
[aCoder encodeObject: className forKey: @"NSClassName"];
|
|
|
|
[aCoder encodeRect: [self frame] forKey: @"NSFrame"];
|
|
|
|
|
|
|
|
if(extension != nil)
|
2006-08-11 05:55:16 +00:00
|
|
|
{
|
2009-01-31 23:37:33 +00:00
|
|
|
[aCoder encodeObject: extension forKey: @"NSExtension"];
|
2006-08-11 05:55:16 +00:00
|
|
|
}
|
2009-01-31 23:37:33 +00:00
|
|
|
|
|
|
|
if([self nextResponder] != nil)
|
2006-08-11 05:55:16 +00:00
|
|
|
{
|
2009-01-31 23:37:33 +00:00
|
|
|
[aCoder encodeObject: [self nextResponder] forKey: @"NSNextResponder"];
|
2006-08-11 05:55:16 +00:00
|
|
|
}
|
2009-01-31 23:37:33 +00:00
|
|
|
|
|
|
|
if([self superview] != nil)
|
|
|
|
{
|
|
|
|
[aCoder encodeObject: [self superview] forKey: @"NSSuperview"];
|
|
|
|
}
|
|
|
|
|
|
|
|
RELEASE(extension);
|
2006-08-09 06:31:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-31 23:37:33 +00:00
|
|
|
[aCoder encodeObject: [self stringValue]];
|
|
|
|
[aCoder encodeRect: _frame];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(unsigned int)
|
|
|
|
at: &_autoresizingMask];
|
2006-08-09 06:31:12 +00:00
|
|
|
}
|
2001-10-03 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2006-06-10 13:34:44 +00:00
|
|
|
if([aCoder allowsKeyedCoding])
|
2002-03-01 14:42:15 +00:00
|
|
|
{
|
2006-06-10 13:34:44 +00:00
|
|
|
NSCustomView *customView = [[NSCustomView alloc] initWithCoder: aCoder];
|
2006-07-02 04:55:30 +00:00
|
|
|
NSArray *subviews = [customView subviews];
|
|
|
|
|
|
|
|
// 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];
|
|
|
|
}
|
2006-07-09 15:19:44 +00:00
|
|
|
|
|
|
|
// get the classname...
|
|
|
|
[self setClassName: [customView className]];
|
2006-07-19 03:09:16 +00:00
|
|
|
// _super_view = [customView superview];
|
|
|
|
// _window = [customView window];
|
2006-07-09 15:19:44 +00:00
|
|
|
|
2006-06-10 13:34:44 +00:00
|
|
|
RELEASE(customView);
|
2006-07-02 04:55:30 +00:00
|
|
|
|
2006-06-17 14:56:02 +00:00
|
|
|
return self;
|
2002-03-01 14:42:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-04 15:02:25 +00:00
|
|
|
NSInteger version = [aCoder versionForClassName:
|
2006-06-10 13:34:44 +00:00
|
|
|
NSStringFromClass([GSCustomView class])];
|
|
|
|
|
|
|
|
if (version == 1)
|
|
|
|
{
|
|
|
|
NSString *string;
|
|
|
|
// do not decode super. We need to maintain mapping to NibItems
|
|
|
|
string = [aCoder decodeObject];
|
|
|
|
_frame = [aCoder decodeRect];
|
|
|
|
[self initWithFrame: _frame];
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned int)
|
|
|
|
at: &_autoresizingMask];
|
|
|
|
[self setClassName: string];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
else if (version == 0)
|
|
|
|
{
|
|
|
|
NSString *string;
|
|
|
|
// do not decode super. We need to maintain mapping to NibItems
|
|
|
|
string = [aCoder decodeObject];
|
|
|
|
_frame = [aCoder decodeRect];
|
|
|
|
|
|
|
|
[self initWithFrame: _frame];
|
|
|
|
[self setClassName: string];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog(@"no initWithCoder for version");
|
|
|
|
RELEASE(self);
|
|
|
|
return nil;
|
|
|
|
}
|
2002-03-01 14:42:15 +00:00
|
|
|
}
|
2006-06-10 13:34:44 +00:00
|
|
|
return nil;
|
2001-10-03 17:38:46 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2002-09-21 15:24:59 +00:00
|
|
|
@interface GormTestCustomView : GSNibItem <NSCoding>
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GormTestCustomView
|
|
|
|
|
2006-07-02 04:55:30 +00:00
|
|
|
- (Class) bestPossibleSuperClass
|
2004-08-28 15:05:35 +00:00
|
|
|
{
|
|
|
|
Class cls = [NSView class];
|
2005-03-31 03:01:36 +00:00
|
|
|
GormClassManager *classManager = [(id<Gorm>)NSApp classManager];
|
2004-08-28 15:05:35 +00:00
|
|
|
|
2005-06-20 23:44:20 +00:00
|
|
|
if([classManager isSuperclass: @"NSOpenGLView" linkedToClass: theClass] ||
|
|
|
|
[theClass isEqual: @"NSOpenGLView"])
|
|
|
|
{
|
|
|
|
cls = [GormOpenGLView class];
|
|
|
|
}
|
|
|
|
else if([classManager isSuperclass: @"NSView" linkedToClass: theClass])
|
2004-08-28 15:05:35 +00:00
|
|
|
{
|
2004-08-28 20:45:47 +00:00
|
|
|
NSString *superClass = [classManager nonCustomSuperClassOf: theClass];
|
|
|
|
|
|
|
|
// get the superclass if one exists...
|
|
|
|
if(superClass != nil)
|
2004-08-28 15:05:35 +00:00
|
|
|
{
|
2004-08-28 20:45:47 +00:00
|
|
|
cls = NSClassFromString(superClass);
|
|
|
|
if(cls == nil)
|
|
|
|
{
|
|
|
|
cls = [NSView class];
|
|
|
|
}
|
2004-08-28 15:05:35 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-28 20:45:47 +00:00
|
|
|
|
2004-08-28 15:05:35 +00:00
|
|
|
return cls;
|
|
|
|
}
|
|
|
|
|
2006-07-02 04:55:30 +00:00
|
|
|
|
2002-09-21 15:24:59 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
|
|
|
id obj;
|
|
|
|
Class cls;
|
2013-11-04 15:02:25 +00:00
|
|
|
NSUInteger mask;
|
2005-06-20 23:44:20 +00:00
|
|
|
GormClassManager *classManager = [(id<Gorm>)NSApp classManager];
|
2002-09-21 15:24:59 +00:00
|
|
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &theClass];
|
|
|
|
theFrame = [aCoder decodeRect];
|
2013-11-04 15:02:25 +00:00
|
|
|
[aCoder decodeValueOfObjCType: @encode(NSUInteger)
|
2002-09-21 15:24:59 +00:00
|
|
|
at: &mask];
|
|
|
|
|
|
|
|
cls = NSClassFromString(theClass);
|
2005-06-20 23:44:20 +00:00
|
|
|
if([classManager isSuperclass: @"NSOpenGLView" linkedToClass: theClass] ||
|
|
|
|
[theClass isEqual: @"NSOpenGLView"] || cls == nil)
|
2002-09-21 15:24:59 +00:00
|
|
|
{
|
2006-07-02 04:55:30 +00:00
|
|
|
cls = [self bestPossibleSuperClass];
|
2002-09-21 15:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
obj = [cls allocWithZone: [self zone]];
|
|
|
|
if (theFrame.size.height > 0 && theFrame.size.width > 0)
|
|
|
|
obj = [obj initWithFrame: theFrame];
|
|
|
|
else
|
|
|
|
obj = [obj init];
|
|
|
|
|
|
|
|
if ([obj respondsToSelector: @selector(setAutoresizingMask:)])
|
|
|
|
{
|
|
|
|
[obj setAutoresizingMask: mask];
|
|
|
|
}
|
|
|
|
|
2005-06-20 23:44:20 +00:00
|
|
|
/*
|
2002-09-21 15:24:59 +00:00
|
|
|
if (![self isKindOfClass: [GSCustomView class]])
|
|
|
|
{
|
|
|
|
RETAIN(obj);
|
|
|
|
}
|
2005-06-20 23:44:20 +00:00
|
|
|
*/
|
|
|
|
|
2002-09-21 15:24:59 +00:00
|
|
|
RELEASE(self);
|
|
|
|
return obj;
|
|
|
|
}
|
2003-01-04 00:17:43 +00:00
|
|
|
|
2003-01-10 01:57:56 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
2003-01-04 00:17:43 +00:00
|
|
|
{
|
|
|
|
// nothing to do. This is a class for testing custom views only. GJC
|
|
|
|
}
|
2002-09-21 15:24:59 +00:00
|
|
|
@end
|
|
|
|
|