1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSActionCell.m
|
|
|
|
|
|
|
|
Abstract cell for target/action paradigm
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
Copyright (C) 1996-1999 Free Software Foundation, Inc.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
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 <Foundation/NSCoder.h>
|
|
|
|
#include <AppKit/NSActionCell.h>
|
|
|
|
#include <AppKit/NSControl.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
@implementation NSActionCell
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
static Class controlClass;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class methods
|
|
|
|
*/
|
|
|
|
+ (void) initialize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
if (self == [NSActionCell class])
|
|
|
|
{
|
1996-07-11 00:59:30 +00:00
|
|
|
NSDebugLog(@"Initialize NSActionCell class\n");
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
controlClass = [NSControl class];
|
|
|
|
[self setVersion: 1];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
/*
|
|
|
|
* Instance methods
|
|
|
|
*/
|
|
|
|
- (id) init
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
[super init];
|
1999-12-13 02:33:14 +00:00
|
|
|
_target = nil;
|
|
|
|
_action = NULL;
|
|
|
|
_tag = 0;
|
1999-12-13 16:10:51 +00:00
|
|
|
_control_view = nil;
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (id) initImageCell: (NSImage*)anImage
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-07-14 14:53:25 +00:00
|
|
|
[super initImageCell: anImage];
|
1999-12-13 02:33:14 +00:00
|
|
|
_target = nil;
|
|
|
|
_action = NULL;
|
|
|
|
_tag = 0;
|
1999-12-13 16:10:51 +00:00
|
|
|
_control_view = nil;
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (id) initTextCell: (NSString*)aString
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-07-14 14:53:25 +00:00
|
|
|
[super initTextCell: aString];
|
1999-12-13 02:33:14 +00:00
|
|
|
_target = nil;
|
|
|
|
_action = NULL;
|
|
|
|
_tag = 0;
|
1999-12-13 16:10:51 +00:00
|
|
|
_control_view = nil;
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
/*
|
|
|
|
* Configuring an NSActionCell
|
|
|
|
*/
|
|
|
|
- (void) setAlignment: (NSTextAlignment)mode
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 16:10:51 +00:00
|
|
|
_cell.text_align = mode;
|
1999-12-13 02:33:14 +00:00
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setBezeled: (BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
_cell.is_bezeled = flag;
|
|
|
|
if (_cell.is_bezeled)
|
|
|
|
_cell.is_bordered = NO;
|
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setBordered: (BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
_cell.is_bordered = flag;
|
|
|
|
if (_cell.is_bordered)
|
|
|
|
_cell.is_bezeled = NO;
|
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setEnabled: (BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
_cell.is_enabled = flag;
|
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setFloatingPointFormat: (BOOL)autoRange
|
|
|
|
left: (unsigned int)leftDigits
|
|
|
|
right: (unsigned int)rightDigits
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
_cell.float_autorange = autoRange;
|
|
|
|
_cell_float_left = leftDigits;
|
|
|
|
_cell_float_right = rightDigits;
|
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setFont: (NSFont*)fontObject
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-07-14 14:53:25 +00:00
|
|
|
[super setFont: fontObject];
|
1999-12-13 02:33:14 +00:00
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setImage: (NSImage*)image
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-07-14 14:53:25 +00:00
|
|
|
[super setImage: image];
|
1999-12-13 02:33:14 +00:00
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
/*
|
|
|
|
* Manipulating NSActionCell Values
|
|
|
|
*/
|
|
|
|
- (void) setStringValue: (NSString*)aString
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-07-14 14:53:25 +00:00
|
|
|
[super setStringValue: aString];
|
1999-12-13 02:33:14 +00:00
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setDoubleValue: (double)aDouble
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-07-14 14:53:25 +00:00
|
|
|
[super setDoubleValue: aDouble];
|
1999-12-13 02:33:14 +00:00
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setFloatValue: (float)aFloat
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-07-14 14:53:25 +00:00
|
|
|
[super setFloatValue: aFloat];
|
1999-12-13 02:33:14 +00:00
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setIntValue: (int)anInt
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-07-14 14:53:25 +00:00
|
|
|
[super setIntValue: anInt];
|
1999-12-13 02:33:14 +00:00
|
|
|
if (_control_view)
|
|
|
|
if ([_control_view isKindOfClass: controlClass])
|
|
|
|
[(NSControl *)_control_view updateCell: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
/*
|
|
|
|
* Target and Action
|
|
|
|
*/
|
|
|
|
- (SEL) action
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
return _action;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setAction: (SEL)aSelector
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
_action = aSelector;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-10-09 22:55:31 +00:00
|
|
|
/* NSActionCell does not retain its target! */
|
1999-07-14 14:53:25 +00:00
|
|
|
- (void) setTarget: (id)anObject
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
_target = anObject;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (id) target
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
return _target;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
/*
|
|
|
|
* Assigning a Tag
|
|
|
|
*/
|
|
|
|
- (void) setTag: (int)anInt
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
_tag = anInt;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
- (int) tag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-13 02:33:14 +00:00
|
|
|
return _tag;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1997-04-22 18:23:58 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
NSActionCell *c = [super copyWithZone: zone];
|
1997-04-22 18:23:58 +00:00
|
|
|
|
1999-12-13 02:33:14 +00:00
|
|
|
c->_tag = _tag;
|
|
|
|
c->_target = _target;
|
|
|
|
c->_action = _action;
|
1999-12-13 16:10:51 +00:00
|
|
|
c->_control_view = _control_view;
|
1997-04-22 18:23:58 +00:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
1999-12-13 16:10:51 +00:00
|
|
|
-(NSView *)controlView
|
|
|
|
{
|
|
|
|
return _control_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
|
|
|
{
|
|
|
|
if (_control_view != controlView)
|
|
|
|
_control_view = controlView;
|
|
|
|
|
|
|
|
[super drawWithFrame: cellFrame
|
|
|
|
inView: controlView];
|
|
|
|
}
|
|
|
|
|
1999-07-14 14:53:25 +00:00
|
|
|
/*
|
|
|
|
* NSCoding protocol
|
|
|
|
*/
|
1999-03-02 08:58:30 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[super encodeWithCoder: aCoder];
|
1999-12-13 02:33:14 +00:00
|
|
|
[aCoder encodeValueOfObjCType: @encode(int) at: &_tag];
|
|
|
|
[aCoder encodeConditionalObject: _target];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(SEL) at: &_action];
|
1999-12-13 16:10:51 +00:00
|
|
|
[aCoder encodeConditionalObject: _control_view];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[super initWithCoder: aDecoder];
|
1999-12-13 02:33:14 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: @encode(int) at: &_tag];
|
|
|
|
_target = [aDecoder decodeObject];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action];
|
1999-12-13 16:10:51 +00:00
|
|
|
_control_view = [aDecoder decodeObject];
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|