1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSColorWell.m
|
|
|
|
|
1996-12-05 16:16:21 +00:00
|
|
|
NSControl for selecting and display a single color value.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Date: 1996
|
|
|
|
|
|
|
|
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
|
1996-10-18 17:14:13 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1996-05-30 20:03:15 +00:00
|
|
|
*/
|
|
|
|
|
1997-09-23 22:43:24 +00:00
|
|
|
#include <gnustep/gui/config.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSColorWell.h>
|
1997-03-05 01:11:17 +00:00
|
|
|
#include <AppKit/NSColor.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-10-09 22:55:31 +00:00
|
|
|
#define ASSIGN(a, b) \
|
|
|
|
[b retain]; \
|
|
|
|
[a release]; \
|
|
|
|
a = b;
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSColorWell
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
if (self == [NSColorWell class])
|
|
|
|
{
|
|
|
|
// Initial version
|
|
|
|
[self setVersion:1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
1997-03-05 01:11:17 +00:00
|
|
|
- initWithFrame:(NSRect)frameRect
|
|
|
|
{
|
|
|
|
[super initWithFrame: frameRect];
|
|
|
|
|
|
|
|
is_bordered = YES;
|
|
|
|
is_active = NO;
|
1997-10-09 22:55:31 +00:00
|
|
|
ASSIGN(the_color, [NSColor blackColor]);
|
1997-03-05 01:11:17 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-10-09 22:55:31 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[the_color release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Drawing
|
|
|
|
//
|
1996-12-05 16:16:21 +00:00
|
|
|
- (void)drawRect:(NSRect)rect
|
|
|
|
{
|
1997-03-20 19:28:14 +00:00
|
|
|
NSDebugLog(@"NSColorWell drawRect: %f %f %f %f\n", rect.origin.x,
|
|
|
|
rect.origin.y,
|
|
|
|
rect.size.width, rect.size.height);
|
1996-12-05 16:16:21 +00:00
|
|
|
|
1997-03-05 01:11:17 +00:00
|
|
|
// Draw border
|
|
|
|
if (is_bordered)
|
|
|
|
[self drawBorderRect: rect];
|
|
|
|
|
|
|
|
// Draw the color inside
|
1996-12-05 16:16:21 +00:00
|
|
|
[self drawWellInside: rect];
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
- (void)drawWellInside:(NSRect)insideRect
|
1996-12-05 16:16:21 +00:00
|
|
|
{
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Activating
|
|
|
|
//
|
|
|
|
- (void)activate:(BOOL)exclusive
|
1996-12-05 16:16:21 +00:00
|
|
|
{
|
|
|
|
is_active = YES;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)deactivate
|
1996-12-05 16:16:21 +00:00
|
|
|
{
|
|
|
|
is_active = NO;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (BOOL)isActive
|
|
|
|
{
|
1996-12-05 16:16:21 +00:00
|
|
|
return is_active;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Managing Color
|
|
|
|
//
|
|
|
|
- (NSColor *)color
|
|
|
|
{
|
1996-12-05 16:16:21 +00:00
|
|
|
return the_color;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setColor:(NSColor *)color
|
1996-12-05 16:16:21 +00:00
|
|
|
{
|
1997-10-09 22:55:31 +00:00
|
|
|
ASSIGN(the_color, color);
|
1996-12-05 16:16:21 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)takeColorFrom:(id)sender
|
1996-12-05 16:16:21 +00:00
|
|
|
{
|
|
|
|
if ([sender respondsToSelector:@selector(color)])
|
1997-10-09 22:55:31 +00:00
|
|
|
ASSIGN(the_color, [sender color]);
|
1996-12-05 16:16:21 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Managing Borders
|
|
|
|
//
|
|
|
|
- (BOOL)isBordered
|
|
|
|
{
|
1996-12-05 16:16:21 +00:00
|
|
|
return is_bordered;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBordered:(BOOL)bordered
|
1996-12-05 16:16:21 +00:00
|
|
|
{
|
|
|
|
is_bordered = bordered;
|
|
|
|
[self display];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
|
|
|
- (void)encodeWithCoder:aCoder
|
|
|
|
{
|
|
|
|
[super encodeWithCoder:aCoder];
|
1996-12-05 16:16:21 +00:00
|
|
|
[aCoder encodeObject: the_color];
|
|
|
|
[aCoder encodeValueOfObjCType:@encode(BOOL) at: &is_active];
|
|
|
|
[aCoder encodeValueOfObjCType:@encode(BOOL) at: &is_bordered];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- initWithCoder:aDecoder
|
|
|
|
{
|
|
|
|
[super initWithCoder:aDecoder];
|
1996-12-05 16:16:21 +00:00
|
|
|
the_color = [aDecoder decodeObject];
|
|
|
|
[aDecoder decodeValueOfObjCType:@encode(BOOL) at: &is_active];
|
|
|
|
[aDecoder decodeValueOfObjCType:@encode(BOOL) at: &is_bordered];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
1997-03-05 01:11:17 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// GNUstep backend methods
|
|
|
|
//
|
|
|
|
@implementation NSColorWell (GNUstepBackend)
|
|
|
|
|
|
|
|
- (void)drawBorderRect:(NSRect)aRect
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|