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
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GormCustomView.h"
|
|
|
|
#include <AppKit/NSColor.h>
|
|
|
|
#include <AppKit/NSGraphics.h>
|
|
|
|
#include <AppKit/NSFont.h>
|
|
|
|
|
2003-03-03 09:15:48 +00:00
|
|
|
#include <AppKit/NSNibLoading.h>
|
2003-08-10 03:36:27 +00:00
|
|
|
#include <GNUstepGUI/GSNibTemplates.h>
|
2002-09-21 15:24:59 +00:00
|
|
|
|
2002-03-01 14:42:15 +00:00
|
|
|
@class GSCustomView;
|
|
|
|
|
2001-10-03 17:38:46 +00:00
|
|
|
@implementation GormCustomView
|
|
|
|
|
|
|
|
- (id)initWithFrame:(NSRect)frameRect
|
|
|
|
{
|
|
|
|
self = [super initWithFrame: frameRect];
|
|
|
|
|
|
|
|
[self setBackgroundColor: [NSColor darkGrayColor]];
|
|
|
|
[self setTextColor: [NSColor whiteColor]];
|
|
|
|
[self setDrawsBackground: YES];
|
|
|
|
[self setAlignment: NSCenterTextAlignment];
|
2004-04-03 18:21:54 +00:00
|
|
|
[self setFont: [NSFont boldSystemFontOfSize: 0]];
|
2001-10-03 17:38:46 +00:00
|
|
|
[self setEditable: NO];
|
|
|
|
[self setClassName: @"CustomView"];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) inspectorClassName
|
|
|
|
{
|
|
|
|
return @"GormFilesOwnerInspector";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setClassName: (NSString *)aName
|
|
|
|
{
|
|
|
|
[self setStringValue: aName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) className
|
|
|
|
{
|
|
|
|
return [self stringValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This needs to be coded like a GSNibItem. How do we make sure this
|
|
|
|
* tracks changes in GSNibItem coding?
|
|
|
|
*/
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
|
|
|
[aCoder encodeObject: [self stringValue]];
|
|
|
|
[aCoder encodeRect: _frame];
|
2002-03-01 14:42:15 +00:00
|
|
|
[aCoder encodeValueOfObjCType: @encode(unsigned int)
|
|
|
|
at: &_autoresizingMask];
|
2001-10-03 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2002-03-01 14:42:15 +00:00
|
|
|
int version = [aCoder versionForClassName:
|
|
|
|
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;
|
|
|
|
}
|
2001-10-03 17:38:46 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2002-09-21 15:24:59 +00:00
|
|
|
@interface GormTestCustomView : GSNibItem <NSCoding>
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GormTestCustomView
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
|
|
|
id obj;
|
|
|
|
Class cls;
|
|
|
|
unsigned int mask;
|
|
|
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &theClass];
|
|
|
|
theFrame = [aCoder decodeRect];
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned int)
|
|
|
|
at: &mask];
|
|
|
|
|
|
|
|
cls = NSClassFromString(theClass);
|
|
|
|
if (cls == nil)
|
|
|
|
{
|
|
|
|
cls = [NSView class];
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (![self isKindOfClass: [GSCustomView class]])
|
|
|
|
{
|
|
|
|
RETAIN(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|