Implemented [refusesFirstResponder] and [setRefusesFirstResponder:].

Changed [setEnabled:], [setAlignment:], [setFont:] and all
[setXXValue:] methods to conform to the spec. Removed the
[copyWithZone:] method.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8431 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2000-12-24 14:07:06 +00:00
parent e2080f1aa3
commit f369ead740

View file

@ -37,11 +37,14 @@
#include <AppKit/NSWindow.h> #include <AppKit/NSWindow.h>
#include <AppKit/NSApplication.h> #include <AppKit/NSApplication.h>
#include <AppKit/NSCell.h> #include <AppKit/NSCell.h>
#include <AppKit/NSActionCell.h>
/* /*
* Class variables * Class variables
*/ */
static Class usedCellClass;
static Class cellClass; static Class cellClass;
static Class actionCellClass;
@implementation NSControl @implementation NSControl
@ -55,6 +58,8 @@ static Class cellClass;
NSDebugLog(@"Initialize NSControl class\n"); NSDebugLog(@"Initialize NSControl class\n");
[self setVersion: 1]; [self setVersion: 1];
cellClass = [NSCell class]; cellClass = [NSCell class];
usedCellClass = cellClass;
actionCellClass = [NSActionCell class];
} }
} }
@ -63,12 +68,12 @@ static Class cellClass;
*/ */
+ (Class) cellClass + (Class) cellClass
{ {
return cellClass; return usedCellClass;
} }
+ (void) setCellClass: (Class)factoryId + (void) setCellClass: (Class)factoryId
{ {
cellClass = factoryId ? factoryId : [NSCell class]; usedCellClass = factoryId ? factoryId : cellClass;
} }
/* /*
@ -76,9 +81,12 @@ static Class cellClass;
*/ */
- (id) initWithFrame: (NSRect)frameRect - (id) initWithFrame: (NSRect)frameRect
{ {
NSCell *cell = [[[self class] cellClass] new];
[super initWithFrame: frameRect]; [super initWithFrame: frameRect];
[self setCell: AUTORELEASE([[[self class] cellClass] new])]; [self setCell: cell];
_tag = 0; RELEASE(cell);
//_tag = 0;
return self; return self;
} }
@ -89,22 +97,6 @@ static Class cellClass;
[super dealloc]; [super dealloc];
} }
/*
* Creating copies
*/
- (id) copyWithZone: (NSZone*)zone
{
id c = NSCopyObject(self, 0, zone);
NSCell *o = [_cell copy];
/* Prevents the original cell from being released */
((NSControl *)c)->_cell = nil;
[c setCell: o];
RELEASE(o);
return c;
}
/* /*
* Setting the Control's Cell * Setting the Control's Cell
*/ */
@ -115,7 +107,7 @@ static Class cellClass;
- (void) setCell: (NSCell *)aCell - (void) setCell: (NSCell *)aCell
{ {
if (aCell != nil && [aCell isKindOfClass: [NSCell class]] == NO) if (aCell != nil && [aCell isKindOfClass: cellClass] == NO)
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"attempt to set non-cell object for control cell"]; format: @"attempt to set non-cell object for control cell"];
@ -133,6 +125,9 @@ static Class cellClass;
- (void) setEnabled: (BOOL)flag - (void) setEnabled: (BOOL)flag
{ {
[[self selectedCell] setEnabled: flag]; [[self selectedCell] setEnabled: flag];
if (!flag)
[self abortEditing];
[self setNeedsDisplay: YES];
} }
/* /*
@ -145,7 +140,12 @@ static Class cellClass;
- (int) selectedTag - (int) selectedTag
{ {
return [[self selectedCell] tag]; NSCell *selected = [self selectedCell];
if (selected == nil)
return -1;
else
return [selected tag];
} }
/* /*
@ -153,6 +153,7 @@ static Class cellClass;
*/ */
- (double) doubleValue - (double) doubleValue
{ {
// The validation is performed by the NSActionCell
return [[self selectedCell] doubleValue]; return [[self selectedCell] doubleValue];
} }
@ -166,6 +167,11 @@ static Class cellClass;
return [[self selectedCell] intValue]; return [[self selectedCell] intValue];
} }
- (NSString *) stringValue
{
return [[self selectedCell] stringValue];
}
- (id) objectValue - (id) objectValue
{ {
return [[self selectedCell] objectValue]; return [[self selectedCell] objectValue];
@ -173,34 +179,57 @@ static Class cellClass;
- (void) setDoubleValue: (double)aDouble - (void) setDoubleValue: (double)aDouble
{ {
NSCell *selected = [self selectedCell];
[self abortEditing]; [self abortEditing];
[[self selectedCell] setDoubleValue: aDouble]; [selected setDoubleValue: aDouble];
[self setNeedsDisplay: YES]; if (![selected isKindOfClass: actionCellClass])
[self setNeedsDisplay: YES];
} }
- (void) setFloatValue: (float)aFloat - (void) setFloatValue: (float)aFloat
{ {
NSCell *selected = [self selectedCell];
[self abortEditing]; [self abortEditing];
[[self selectedCell] setFloatValue: aFloat]; [selected setFloatValue: aFloat];
[self setNeedsDisplay: YES]; if (![selected isKindOfClass: actionCellClass])
[self setNeedsDisplay: YES];
} }
- (void) setIntValue: (int)anInt - (void) setIntValue: (int)anInt
{ {
NSCell *selected = [self selectedCell];
[self abortEditing]; [self abortEditing];
[[self selectedCell] setIntValue: anInt]; [selected setIntValue: anInt];
[self setNeedsDisplay: YES]; if (![selected isKindOfClass: actionCellClass])
[self setNeedsDisplay: YES];
}
- (void) setStringValue: (NSString *)aString
{
NSCell *selected = [self selectedCell];
[self abortEditing];
[selected setStringValue: aString];
if (![selected isKindOfClass: actionCellClass])
[self setNeedsDisplay: YES];
} }
- (void) setObjectValue: (id)anObject - (void) setObjectValue: (id)anObject
{ {
NSCell *selected = [self selectedCell];
[self abortEditing]; [self abortEditing];
[[self selectedCell] setObjectValue: anObject]; [selected setObjectValue: anObject];
[self setNeedsDisplay: YES]; if (![selected isKindOfClass: actionCellClass])
[self setNeedsDisplay: YES];
} }
- (void) setNeedsDisplay - (void) setNeedsDisplay
@ -208,19 +237,6 @@ static Class cellClass;
[super setNeedsDisplay: YES]; [super setNeedsDisplay: YES];
} }
- (void) setStringValue: (NSString *)aString
{
[self abortEditing];
[[self selectedCell] setStringValue: aString];
[self setNeedsDisplay: YES];
}
- (NSString *) stringValue
{
return [[self selectedCell] stringValue];
}
/* /*
* Interacting with Other Controls * Interacting with Other Controls
*/ */
@ -262,7 +278,7 @@ static Class cellClass;
if (_cell) if (_cell)
return [_cell alignment]; return [_cell alignment];
else else
return NSLeftTextAlignment; return NSNaturalTextAlignment;
} }
- (NSFont *) font - (NSFont *) font
@ -277,25 +293,36 @@ static Class cellClass;
{ {
if (_cell) if (_cell)
{ {
[self abortEditing];
[_cell setAlignment: mode]; [_cell setAlignment: mode];
[self setNeedsDisplay: YES]; if (![_cell isKindOfClass: actionCellClass])
[self setNeedsDisplay: YES];
} }
} }
- (void) setFont: (NSFont *)fontObject - (void) setFont: (NSFont *)fontObject
{ {
// TODO: Complete
if (_cell) if (_cell)
[_cell setFont: fontObject]; {
NSText *editor = [self currentEditor];
[_cell setFont: fontObject];
if (editor != nil)
[editor setFont: fontObject];
}
} }
- (void) setFloatingPointFormat: (BOOL)autoRange - (void) setFloatingPointFormat: (BOOL)autoRange
left: (unsigned)leftDigits left: (unsigned)leftDigits
right: (unsigned)rightDigits right: (unsigned)rightDigits
{ {
// TODO: Complete [self abortEditing];
[_cell setFloatingPointFormat: autoRange left: leftDigits [_cell setFloatingPointFormat: autoRange left: leftDigits
right: rightDigits]; right: rightDigits];
if (![_cell isKindOfClass: actionCellClass])
[self setNeedsDisplay: YES];
} }
/* /*
@ -360,7 +387,10 @@ static Class cellClass;
- (void) selectCell: (NSCell *)aCell - (void) selectCell: (NSCell *)aCell
{ {
if (_cell == aCell) if (_cell == aCell)
[_cell setState: 1]; {
[_cell setState: 1];
[self setNeedsDisplay: YES];
}
} }
- (void) updateCell: (NSCell *)aCell - (void) updateCell: (NSCell *)aCell
@ -372,10 +402,6 @@ static Class cellClass;
{ {
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
- (void) performClick: (id)sender
{
[_cell performClick: sender];
}
/* /*
* Target and Action * Target and Action
@ -392,10 +418,8 @@ static Class cellClass;
- (BOOL) sendAction: (SEL)theAction to: (id)theTarget - (BOOL) sendAction: (SEL)theAction to: (id)theTarget
{ {
NSApplication *theApp = [NSApplication sharedApplication];
if (theAction) if (theAction)
return [theApp sendAction: theAction to: theTarget from: self]; return [NSApp sendAction: theAction to: theTarget from: self];
else else
return NO; return NO;
} }
@ -438,6 +462,24 @@ static Class cellClass;
return _tag; return _tag;
} }
/*
* Activation
*/
- (void) performClick: (id)sender
{
[_cell performClick: sender];
}
- (BOOL)refusesFirstResponder
{
return [[self selectedCell] refusesFirstResponder];
}
- (void)setRefusesFirstResponder:(BOOL)flag
{
[[self selectedCell] setRefusesFirstResponder: flag];
}
/* /*
* Tracking the Mouse * Tracking the Mouse
*/ */
@ -457,7 +499,10 @@ static Class cellClass;
return; return;
if (_ignoresMultiClick && ([theEvent clickCount] > 1)) if (_ignoresMultiClick && ([theEvent clickCount] > 1))
[super mouseDown: theEvent]; {
[super mouseDown: theEvent];
return;
}
if ([_cell isContinuous]) if ([_cell isContinuous])
oldActionMask = [_cell sendActionOn: 0]; oldActionMask = [_cell sendActionOn: 0];
@ -541,6 +586,7 @@ static Class cellClass;
[aCoder encodeValueOfObjCType: @encode(int) at: &_tag]; [aCoder encodeValueOfObjCType: @encode(int) at: &_tag];
[aCoder encodeObject: _cell]; [aCoder encodeObject: _cell];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_ignoresMultiClick];
} }
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
@ -549,6 +595,7 @@ static Class cellClass;
[aDecoder decodeValueOfObjCType: @encode(int) at: &_tag]; [aDecoder decodeValueOfObjCType: @encode(int) at: &_tag];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_cell]; [aDecoder decodeValueOfObjCType: @encode(id) at: &_cell];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_ignoresMultiClick];
return self; return self;
} }