From ea181f19aee75ffd347dc0ac9ca1fc2941ac1135 Mon Sep 17 00:00:00 2001 From: Pauli Ojala Date: Tue, 6 Sep 2011 13:52:17 +0300 Subject: [PATCH] added support for NSInteger values in accessors to match Cocoa --- AppKit/NSCell.h | 12 ++++++++---- AppKit/NSCell.m | 24 ++++++++++++++++++++++++ AppKit/NSControl.h | 13 ++++++++----- AppKit/NSControl.m | 12 ++++++++++++ 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/AppKit/NSCell.h b/AppKit/NSCell.h index 4eab546b..267c94d1 100755 --- a/AppKit/NSCell.h +++ b/AppKit/NSCell.h @@ -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; diff --git a/AppKit/NSCell.m b/AppKit/NSCell.m index 1868d65b..74ea649b 100755 --- a/AppKit/NSCell.m +++ b/AppKit/NSCell.m @@ -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); } diff --git a/AppKit/NSControl.h b/AppKit/NSControl.h index ace99fea..3338d1c4 100755 --- a/AppKit/NSControl.h +++ b/AppKit/NSControl.h @@ -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; diff --git a/AppKit/NSControl.m b/AppKit/NSControl.m index e7e92ded..64aa35c2 100755 --- a/AppKit/NSControl.m +++ b/AppKit/NSControl.m @@ -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];