added support for NSInteger values in accessors to match Cocoa

This commit is contained in:
Pauli Ojala 2011-09-06 13:52:17 +03:00
parent 4f75d89a93
commit ea181f19ae
4 changed files with 52 additions and 9 deletions

View File

@ -149,6 +149,7 @@ enum {
-(int)intValue;
-(float)floatValue;
-(double)doubleValue;
-(NSInteger)integerValue;
-(NSAttributedString *)attributedStringValue;
-(id)representedObject;
-(NSControlSize)controlSize;
@ -195,16 +196,19 @@ enum {
-(void)setIntValue:(int)value;
-(void)setFloatValue:(float)value;
-(void)setDoubleValue:(double)value;
-(void)setIntegerValue:(NSInteger)value;
-(void)setAttributedStringValue:(NSAttributedString *)value;
-(void)setRepresentedObject:(id)object;
-(void)setControlSize:(NSControlSize)size;
-(void)setFocusRingType:(NSFocusRingType)focusRingType;
-(void)setBackgroundStyle:(NSBackgroundStyle)value;
-(void)takeObjectValueFrom:sender;
-(void)takeStringValueFrom:sender;
-(void)takeIntValueFrom:sender;
-(void)takeFloatValueFrom:sender;
-(void)takeObjectValueFrom:(id)sender;
-(void)takeStringValueFrom:(id)sender;
-(void)takeIntValueFrom:(id)sender;
-(void)takeFloatValueFrom:(id)sender;
-(void)takeDoubleValueFrom:(id)sender;
-(void)takeIntegerValueFrom:(id)sender;
-(NSSize)cellSize;
-(NSSize)cellSizeForBounds:(NSRect)rect;

View File

@ -316,6 +316,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return [_objectValue doubleValue];
}
-(NSInteger)integerValue {
NSString *objString = ([_objectValue isKindOfClass:[NSAttributedString class]]) ? [_objectValue string] : (NSString *)_objectValue;
if([objString isKindOfClass:[NSString class]])
{
NSInteger i = 0;
[[NSScanner localizedScannerWithString:objString] scanInteger:&i];
return i;
}
else
return [_objectValue integerValue];
}
-(NSAttributedString *)attributedStringValue {
if([_objectValue isKindOfClass:[NSAttributedString class]])
return _objectValue;
@ -586,6 +598,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[self setObjectValue:[NSNumber numberWithDouble:value]];
}
-(void)setIntegerValue:(NSInteger)value {
[self setObjectValue:[NSNumber numberWithInteger:value]];
}
-(void)setAttributedStringValue:(NSAttributedString *)value {
value=[value copy];
@ -630,6 +646,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[self setFloatValue:[sender floatValue]];
}
-(void)takeDoubleValueFrom:sender {
[self setDoubleValue:[sender doubleValue]];
}
-(void)takeIntegerValueFrom:sender {
[self setIntegerValue:[sender integerValue]];
}
-(NSSize)cellSize {
return NSMakeSize(10000,10000);
}

View File

@ -47,6 +47,7 @@ APPKIT_EXPORT NSString * const NSControlTextDidEndEditingNotification;
-(int)intValue;
-(float)floatValue;
-(double)doubleValue;
-(NSInteger)integerValue;
-selectedCell;
-(int)selectedTag;
@ -74,13 +75,15 @@ APPKIT_EXPORT NSString * const NSControlTextDidEndEditingNotification;
-(void)setIntValue:(int)value;
-(void)setFloatValue:(float)value;
-(void)setDoubleValue:(double)value;
-(void)setIntegerValue:(NSInteger)anInteger;
-(void)setAttributedStringValue:(NSAttributedString *)value;
-(void)takeObjectValueFrom:sender;
-(void)takeStringValueFrom:sender;
-(void)takeIntValueFrom:sender;
-(void)takeFloatValueFrom:sender;
-(void)takeDoubleValueFrom:sender;
-(void)takeObjectValueFrom:(id)sender;
-(void)takeStringValueFrom:(id)sender;
-(void)takeIntValueFrom:(id)sender;
-(void)takeFloatValueFrom:(id)sender;
-(void)takeDoubleValueFrom:(id)sender;
-(void)takeIntegerValueFrom:(id)sender;
-(void)selectCell:(NSCell *)cell;

View File

@ -161,6 +161,10 @@ static NSMutableDictionary *cellClassDictionary = nil;
return [[self selectedCell] doubleValue];
}
-(NSInteger)integerValue {
return [[self selectedCell] integerValue];
}
-selectedCell {
return _cell;
}
@ -271,6 +275,10 @@ static NSMutableDictionary *cellClassDictionary = nil;
[self setObjectValue:[NSNumber numberWithDouble:value]];
}
-(void)setIntegerValue:(NSInteger)value {
[self setObjectValue:[NSNumber numberWithInteger:value]];
}
-(void)setAttributedStringValue:(NSAttributedString *)value {
[self setObjectValue:value];
}
@ -295,6 +303,10 @@ static NSMutableDictionary *cellClassDictionary = nil;
[self setDoubleValue:[sender doubleValue]];
}
-(void)takeIntegerValueFrom:sender {
[self setIntegerValue:[sender integerValue]];
}
-(void)selectCell:(NSCell *)cell {
if (_cell == cell) {
[_cell setState:YES];