mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-21 01:40:41 +00:00
CPFormatter support for CPControl.
This commit is contained in:
+21
-1
@@ -89,6 +89,8 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
int _sendActionOn;
|
||||
BOOL _sendsActionOnEndEditing @accessors(property=sendsActionOnEndEditing);
|
||||
|
||||
CPFormatter _formatter @accessors(property=formatter);
|
||||
|
||||
// Mouse Tracking Support
|
||||
BOOL _continuousTracking;
|
||||
BOOL _trackingWasWithinFrame;
|
||||
@@ -502,6 +504,15 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
*/
|
||||
- (CPString)stringValue
|
||||
{
|
||||
var formatted;
|
||||
|
||||
if (_formatter)
|
||||
{
|
||||
formatted = [_formatter stringForObjectValue:_value];
|
||||
if (formatted !== nil && formatted !== undefined)
|
||||
return formatted;
|
||||
}
|
||||
|
||||
return (_value === undefined || _value === nil) ? "" : String(_value);
|
||||
}
|
||||
|
||||
@@ -510,7 +521,16 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
*/
|
||||
- (void)setStringValue:(CPString)anObject
|
||||
{
|
||||
[self setObjectValue:anObject];
|
||||
var value = anObject;
|
||||
|
||||
if (_formatter)
|
||||
{
|
||||
var formattedValue = nil;
|
||||
if ([_formatter getObjectValue:@ref(formattedValue) forString:value errorDescription:NULL])
|
||||
value = formattedValue;
|
||||
}
|
||||
|
||||
[self setObjectValue:value];
|
||||
}
|
||||
|
||||
- (void)takeDoubleValueFrom:(id)sender
|
||||
|
||||
@@ -109,6 +109,27 @@ CPNumberFormatterRoundHalfUp = CPRoundPlain;
|
||||
return parseFloat(string);
|
||||
}
|
||||
|
||||
- (CPString)stringForObjectValue:(id)anObject
|
||||
{
|
||||
if ([anObject isKindOfClass:[CPNumber class]])
|
||||
return [self stringFromNumber:anObject];
|
||||
else
|
||||
return [anObject description];
|
||||
}
|
||||
|
||||
- (CPString)editingStringForObjectValue:(id)anObject
|
||||
{
|
||||
return [self stringForObjectValue:anObject];
|
||||
}
|
||||
|
||||
- (BOOL)getObjectValue:(id)anObject forString:(CPString)aString errorDescription:(CPString)anError
|
||||
{
|
||||
// TODO Error handling.
|
||||
var value = [self numberFromString:aString];
|
||||
@deref(anObject, value);
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return the perMillSymbol if set, otherwise the locale default.
|
||||
|
||||
Reference in New Issue
Block a user