39 @
typedef CPTextAlignment
46 @
typedef CPControlSize
51 @
typedef CPLineBreakMode
59 @
typedef CPVerticalTextAlignment
65 @
typedef CPImageScaling
75 @
typedef CPCellImagePosition
113 BOOL _sendsActionOnEndEditing;
116 BOOL _continuousTracking;
117 BOOL _trackingWasWithinFrame;
118 unsigned _trackingMouseDownFlags;
119 CGPoint _previousTrackingLocation;
121 CPControlSize _controlSize;
133 @"text-shadow-offset": CGSizeMakeZero(),
136 @"min-size": CGSizeMakeZero(),
137 @"max-size": CGSizeMake(-1.0, -1.0),
138 @"nib2cib-adjustment-frame": CGRectMakeZero()
158 + (Class)_binderClassForBinding:(
CPString)aBinding
161 return [_CPValueBinder class];
165 return [
super _binderClassForBinding:aBinding];
171 - (void)_continuouslyReverseSetBinding
173 var binderClass = [[
self class] _binderClassForBinding:CPValueBinding],
174 theBinding = [binderClass getBinding:CPValueBinding forObject:self];
176 if ([theBinding continuouslyUpdatesValue])
177 [theBinding reverseSetValueFor:@"objectValue"];
180 - (void)_reverseSetBinding
182 var binderClass = [[
self class] _binderClassForBinding:CPValueBinding],
183 theBinding = [binderClass getBinding:CPValueBinding forObject:self];
185 [theBinding reverseSetValueFor:@"objectValue"];
188 - (id)initWithFrame:(CGRect)aFrame
195 _trackingMouseDownFlags = 0;
203 #pragma mark Control Size
208 - (CPControlSize)controlSize
217 - (void)setControlSize:(CPControlSize)aControlSize
219 if (_controlSize === aControlSize)
223 _controlSize = aControlSize;
255 - (void)_sizeToControlSize
257 var frameSize = [
self frameSize],
258 minSize = [
self currentValueForThemeAttribute:@"min-size"],
259 maxSize = [
self currentValueForThemeAttribute:@"max-size"];
261 if (minSize.width > 0)
263 frameSize.width = MAX(minSize.width, frameSize.width);
265 if (maxSize.width > 0)
266 frameSize.width = MIN(maxSize.width, frameSize.width);
269 if (minSize.height > 0)
271 frameSize.height = MAX(minSize.height, frameSize.height);
273 if (maxSize.height > 0)
274 frameSize.height = MIN(maxSize.height, frameSize.height);
277 [
self setFrameSize:frameSize];
288 - (void)setAction:(
SEL)anAction
306 - (void)setTarget:(
id)aTarget
325 - (BOOL)sendAction:(
SEL)anAction to:(
id)anObject
327 [
self _reverseSetBinding];
330 [binding invokeAction];
332 return [CPApp sendAction:anAction to:anObject from:self];
335 - (int)sendActionOn:(
int)mask
337 var previousMask = _sendActionOn;
339 _sendActionOn = mask;
356 - (void)setContinuous:(BOOL)flag
368 - (BOOL)tracksMouseOutsideOfFrame
375 var type = [anEvent
type],
383 _trackingMouseDownFlags = 0;
401 if (!_trackingWasWithinFrame)
404 else if (_continuousTracking)
405 _continuousTracking = [
self continueTracking:_previousTrackingLocation
at:currentLocation];
411 [CPApp setTarget:self selector:@selector(trackMouse:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
414 if ((_sendActionOn & (1 << type)) && isWithinFrame)
417 _trackingWasWithinFrame = isWithinFrame;
418 _previousTrackingLocation = currentLocation;
421 - (void)setState:(CPInteger)state
425 - (CPInteger)nextState
435 - (void)performClick:(
id)sender
437 if (![
self isEnabled])
461 - (void)unhighlightButtonTimerDidFinish:(
id)sender
469 - (unsigned)mouseDownFlags
471 return _trackingMouseDownFlags;
474 - (BOOL)startTrackingAt:(CGPoint)aPoint
481 - (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint
486 - (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
504 if (![
self isEnabled])
512 if (![
self isEnabled])
540 - (void)setObjectValue:(
id)anObject
553 var floatValue = parseFloat(_value, 10);
554 return isNaN(floatValue) ? 0.0 : floatValue;
560 - (void)setFloatValue:(
float)aValue
568 - (double)doubleValue
570 var doubleValue = parseFloat(_value, 10);
571 return isNaN(doubleValue) ? 0.0 : doubleValue;
577 - (void)setDoubleValue:(
double)anObject
587 var intValue = parseInt(_value, 10);
588 return isNaN(intValue) ? 0.0 : intValue;
594 - (void)setIntValue:(
int)anObject
604 var intValue = parseInt(_value, 10);
605 return isNaN(intValue) ? 0.0 : intValue;
611 - (void)setIntegerValue:(
int)anObject
621 if (_formatter && _value !== undefined)
623 var formattedValue = [
self hasThemeState:CPThemeStateEditing] ? [_formatter editingStringForObjectValue:_value] : [_formatter stringForObjectValue:_value];
625 if (formattedValue !== nil && formattedValue !== undefined)
626 return formattedValue;
629 return (_value === undefined || _value === nil) ?
@"" : String(_value);
638 if (aString === nil || aString === undefined)
640 CPLog.warn(
"nil or undefined sent to CPControl -setStringValue");
650 if ([_formatter getObjectValue:@ref(value) forString:aString errorDescription:nil] === NO)
653 if (!aString || [_formatter getObjectValue:@ref(value) forString:
@"" errorDescription:nil] === NO)
663 - (void)takeDoubleValueFrom:(
id)sender
665 if ([sender respondsToSelector:
@selector(doubleValue)])
670 - (void)takeFloatValueFrom:(
id)sender
672 if ([sender respondsToSelector:
@selector(floatValue)])
676 - (void)takeIntegerValueFrom:(
id)sender
678 if ([sender respondsToSelector:
@selector(integerValue)])
682 - (void)takeIntValueFrom:(
id)sender
684 if ([sender respondsToSelector:
@selector(intValue)])
688 - (void)takeObjectValueFrom:(
id)sender
690 if ([sender respondsToSelector:
@selector(objectValue)])
694 - (void)takeStringValueFrom:(
id)sender
696 if ([sender respondsToSelector:
@selector(stringValue)])
703 if ([note
object] !=
self)
712 if ([note
object] !=
self)
721 if ([note
object] !=
self)
724 [
self _reverseSetBinding];
734 - (unsigned)_currentTextMovement
736 var currentEvent = [CPApp currentEvent],
737 keyCode = [currentEvent keyCode],
738 modifierFlags = [currentEvent modifierFlags];
782 - (void)setAlignment:(CPTextAlignment)alignment
790 - (CPTextAlignment)alignment
804 - (void)setVerticalAlignment:(CPTextVerticalAlignment)alignment
812 - (CPTextVerticalAlignment)verticalAlignment
829 - (void)setLineBreakMode:(CPLineBreakMode)mode
837 - (CPLineBreakMode)lineBreakMode
881 - (void)setTextShadowOffset:(CGSize)offset
889 - (CGSize)textShadowOffset
923 - (void)setImagePosition:(CPCellImagePosition)position
931 - (CPCellImagePosition)imagePosition
946 - (void)setImageScaling:(CPImageScaling)scaling
954 - (CPUInteger)imageScaling
965 - (void)setEnabled:(BOOL)isEnabled
986 - (void)highlight:(BOOL)shouldHighlight
996 - (void)setHighlighted:(BOOL)isHighlighted
1007 - (BOOL)isHighlighted
1024 __Deprecated__CPImageViewImageKey =
@"CPImageViewImageKey";
1040 [
self setObjectValue:[aCoder decodeObjectForKey:CPControlValueKey]];
1042 [
self setTarget:[aCoder decodeObjectForKey:CPControlTargetKey]];
1043 [
self setAction:[aCoder decodeObjectForKey:CPControlActionKey]];
1045 [
self sendActionOn:[aCoder decodeIntForKey:CPControlSendActionOnKey]];
1048 [
self setFormatter:[aCoder decodeObjectForKey:CPControlFormatterKey]];
1050 [
self setControlSize:[aCoder decodeIntForKey:CPControlControlSizeKey]];
1065 if (_sendsActionOnEndEditing)
1066 [aCoder encodeBool:_sendsActionOnEndEditing forKey:CPControlSendsActionOnEndEditingKey];
1070 if (objectValue !== nil)
1071 [aCoder encodeObject:objectValue forKey:CPControlValueKey];
1073 if (_target !== nil)
1074 [aCoder encodeConditionalObject:_target forKey:CPControlTargetKey];
1076 if (_action !== nil)
1077 [aCoder encodeObject:_action forKey:CPControlActionKey];
1079 [aCoder encodeInt:_sendActionOn forKey:CPControlSendActionOnKey];
1081 if (_formatter !== nil)
1082 [aCoder encodeObject:_formatter forKey:CPControlFormatterKey];
1084 [aCoder encodeInt:_controlSize forKey:CPControlControlSizeKey];
1089 var _CPControlSizeIdentifiers = [],
1090 _CPControlCachedColorWithPatternImages = {},
1091 _CPControlCachedThreePartImagePattern = {};
1093 _CPControlSizeIdentifiers[CPRegularControlSize] =
"Regular";
1094 _CPControlSizeIdentifiers[CPSmallControlSize] =
"Small";
1095 _CPControlSizeIdentifiers[CPMiniControlSize] =
"Mini";
1097 function _CPControlIdentifierForControlSize(aControlSize)
1099 return _CPControlSizeIdentifiers[aControlSize];
1102 function _CPControlColorWithPatternImage(sizes, aClassName)
1105 count = arguments.length,
1108 for (; index < count; ++index)
1109 identifier += arguments[index];
1111 var color = _CPControlCachedColorWithPatternImages[identifier];
1119 _CPControlCachedColorWithPatternImages[identifier] = color;
1125 function _CPControlThreePartImagePattern(isVertical, sizes, aClassName)
1128 count = arguments.length,
1131 for (; index < count; ++index)
1132 identifier += arguments[index];
1134 var color = _CPControlCachedThreePartImagePattern[identifier];
1139 path = aClassName + "/" + identifier;
1141 sizes = sizes[identifier];
1149 _CPControlCachedThreePartImagePattern[identifier] = color;
1170 _formatter = aValue;
1176 - (BOOL)sendsActionOnEndEditing
1178 return _sendsActionOnEndEditing;
1184 - (void)setSendsActionOnEndEditing:(BOOL)aValue
1186 _sendsActionOnEndEditing = aValue;