From bf9ffb8a95dfbe9963ec8a48f406aeca6c2c20ca Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 14 Sep 2008 13:40:58 -0700 Subject: [PATCH] Add missing setX and X methods on CPControl. Moved the logic for setStringValue to setObjectValue on CPTextField. Now, all setX's call setObject. We store native objects, and cast to the appropriate type in the getter methods. --- AppKit/CPControl.j | 66 +++++++++++++++++++++++++++++++++++++++++++- AppKit/CPTextField.j | 19 ++++++++----- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/AppKit/CPControl.j b/AppKit/CPControl.j index d76594e3b..421b89b08 100644 --- a/AppKit/CPControl.j +++ b/AppKit/CPControl.j @@ -282,7 +282,71 @@ var CPControlBlackColor = [CPColor blackColor]; */ - (void)setFloatValue:(float)aValue { - _value = aValue; + [self setObjectValue:aValue]; +} + +/* + Returns the receiver's object value +*/ +- (id)objectValue +{ + return _value; +} + +/* + Set's the receiver's object value +*/ +- (void)setObjectValue:(id)anObject +{ + _value = anObject; +} + +/* + Returns the receiver's double value +*/ +- (id)doubleValue +{ + return [self floatValue]; +} + +/* + Set's the receiver's double value +*/ +- (void)setDoubleValue:(id)anObject +{ + [self setObjectValue:anObject]; +} + +/* + Returns the receiver's int value +*/ +- (id)intValue +{ + return _value ? parseInt(_value, 10) : 0; +} + +/* + Set's the receiver's int value +*/ +- (void)setIntValue:(id)anObject +{ + [self setObjectValue:anObject]; +} + +/* + Returns the receiver's int value +*/ +- (id)stringValue +{ + return _value ? ""+_value : ""; +} + +/* + Set's the receiver's int value +*/ +- (void)setStringValue:(id)anObject +{ + [self setObjectValue:anObject]; } - (void)setBackgroundColor:(CPColor)aColor diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index 2737de94a..f1ba2d329 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -432,23 +432,28 @@ var _CPTextFieldSquareBezelColor = nil; return [[self class] _inputElement].value; #endif - return [_value string]; + return [self stringValue]; } /* - Sets the string the text field. + @ignore */ -- (void)setStringValue:(CPString)aStringValue +- (void)setObjectValue:(id)aValue { - _value = aStringValue; + [super setObjectValue:aValue]; #if PLATFORM(DOM) - var cssString = _value ? [_value cssString] : @""; + var displayString = ""; + + if ([aValue respondsToSelector:@selector(string)]) + displayString = [aValue string]; + else + displayString += aValue; if (CPFeatureIsCompatible(CPJavascriptInnerTextFeature)) - _DOMTextElement.innerText = cssString; + _DOMTextElement.innerText = displayString; else if (CPFeatureIsCompatible(CPJavascriptTextContentFeature)) - _DOMTextElement.textContent = cssString; + _DOMTextElement.textContent = displayString; #endif }