27 @protocol CPControlTextEditingDelegate <
CPObject>
39 @
typedef CPControlSize
44 @
typedef CPLineBreakMode
52 @
typedef CPVerticalTextAlignment
58 @
typedef CPImageScaling
68 @
typedef CPCellImagePosition
106 BOOL _sendsActionOnEndEditing;
109 BOOL _continuousTracking;
110 BOOL _trackingWasWithinFrame;
111 unsigned _trackingMouseDownFlags;
112 CGPoint _previousTrackingLocation;
114 CPControlSize _controlSize;
116 CPWritingDirection _baseWritingDirection;
128 @"text-shadow-offset": CGSizeMakeZero(),
131 @"min-size": CGSizeMakeZero(),
132 @"max-size": CGSizeMake(-1.0, -1.0),
133 @"nib2cib-adjustment-frame": CGRectMakeZero()
142 [
self exposeBinding:@"value"];
143 [
self exposeBinding:@"objectValue"];
144 [
self exposeBinding:@"stringValue"];
145 [
self exposeBinding:@"integerValue"];
146 [
self exposeBinding:@"intValue"];
147 [
self exposeBinding:@"doubleValue"];
148 [
self exposeBinding:@"floatValue"];
150 [
self exposeBinding:@"enabled"];
153 + (Class)_binderClassForBinding:(
CPString)aBinding
155 if (aBinding === CPValueBinding)
156 return [_CPValueBinder class];
157 else if ([aBinding hasPrefix:CPEnabledBinding])
160 return [
super _binderClassForBinding:aBinding];
166 - (void)_continuouslyReverseSetBinding
168 var binderClass = [[
self class] _binderClassForBinding:CPValueBinding],
169 theBinding = [binderClass getBinding:CPValueBinding forObject:self];
171 if ([theBinding continuouslyUpdatesValue])
172 [theBinding reverseSetValueFor:@"objectValue"];
175 - (void)_reverseSetBinding
177 var binderClass = [[
self class] _binderClassForBinding:CPValueBinding],
178 theBinding = [binderClass getBinding:CPValueBinding forObject:self];
180 [theBinding reverseSetValueFor:@"objectValue"];
183 - (id)initWithFrame:(CGRect)aFrame
190 _trackingMouseDownFlags = 0;
197 #pragma mark Control Size 202 - (CPControlSize)controlSize
211 - (void)setControlSize:(CPControlSize)aControlSize
213 if (_controlSize === aControlSize)
217 _controlSize = aControlSize;
230 switch (_controlSize)
249 - (void)_sizeToControlSize
251 var frameSize = [
self frameSize],
252 minSize = [
self currentValueForThemeAttribute:@"min-size"],
253 maxSize = [
self currentValueForThemeAttribute:@"max-size"];
255 if (minSize.width > 0)
257 frameSize.width = MAX(minSize.width, frameSize.width);
259 if (maxSize.width > 0)
260 frameSize.width = MIN(maxSize.width, frameSize.width);
263 if (minSize.height > 0)
265 frameSize.height = MAX(minSize.height, frameSize.height);
267 if (maxSize.height > 0)
268 frameSize.height = MIN(maxSize.height, frameSize.height);
271 [
self setFrameSize:frameSize];
282 - (void)setAction:(
SEL)anAction
300 - (void)setTarget:(
id)aTarget
319 - (BOOL)sendAction:(
SEL)anAction to:(
id)anObject
321 [
self _reverseSetBinding];
324 [binding invokeAction];
326 return [CPApp sendAction:anAction to:anObject from:self];
329 - (int)sendActionOn:(
int)mask
331 var previousMask = _sendActionOn;
333 _sendActionOn = mask;
350 - (void)setContinuous:(BOOL)flag
362 - (BOOL)tracksMouseOutsideOfFrame
369 var type = [anEvent
type],
377 _trackingMouseDownFlags = 0;
395 if (!_trackingWasWithinFrame)
398 else if (_continuousTracking)
399 _continuousTracking = [
self continueTracking:_previousTrackingLocation
at:currentLocation];
405 [CPApp setTarget:self selector:@selector(trackMouse:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
408 if ((_sendActionOn & (1 << type)) && isWithinFrame)
411 _trackingWasWithinFrame = isWithinFrame;
412 _previousTrackingLocation = currentLocation;
415 - (void)setState:(CPInteger)state
419 - (CPInteger)nextState
429 - (void)performClick:(
id)sender
431 if (![
self isEnabled])
455 - (void)unhighlightButtonTimerDidFinish:(
id)sender
463 - (unsigned)mouseDownFlags
465 return _trackingMouseDownFlags;
468 - (BOOL)startTrackingAt:(CGPoint)aPoint
475 - (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint
480 - (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
498 if (![
self isEnabled])
506 if (![
self isEnabled])
534 - (void)setObjectValue:(
id)anObject
547 var floatValue = parseFloat(_value, 10);
548 return isNaN(floatValue) ? 0.0 : floatValue;
554 - (void)setFloatValue:(
float)aValue
562 - (double)doubleValue
564 var doubleValue = parseFloat(_value, 10);
565 return isNaN(doubleValue) ? 0.0 : doubleValue;
571 - (void)setDoubleValue:(
double)anObject
581 var intValue = parseInt(_value, 10);
582 return isNaN(intValue) ? 0.0 : intValue;
588 - (void)setIntValue:(
int)anObject
598 var intValue = parseInt(_value, 10);
599 return isNaN(intValue) ? 0.0 : intValue;
605 - (void)setIntegerValue:(
int)anObject
615 if (_formatter && _value !== undefined)
617 var formattedValue = [
self hasThemeState:CPThemeStateEditing] ? [_formatter editingStringForObjectValue:_value] : [_formatter stringForObjectValue:_value];
619 if (formattedValue !== nil && formattedValue !== undefined)
620 return formattedValue;
623 return (_value === undefined || _value === nil) ?
@"" : String(_value);
632 if (aString === nil || aString === undefined)
634 CPLog.warn(
"nil or undefined sent to CPControl -setStringValue");
644 if ([_formatter getObjectValue:@ref(value) forString:aString errorDescription:nil] === NO)
647 if (!aString || [_formatter getObjectValue:@ref(value) forString:
@"" errorDescription:nil] === NO)
657 - (void)takeDoubleValueFrom:(
id)sender
659 if ([sender respondsToSelector:
@selector(doubleValue)])
664 - (void)takeFloatValueFrom:(
id)sender
666 if ([sender respondsToSelector:
@selector(floatValue)])
670 - (void)takeIntegerValueFrom:(
id)sender
672 if ([sender respondsToSelector:
@selector(integerValue)])
676 - (void)takeIntValueFrom:(
id)sender
678 if ([sender respondsToSelector:
@selector(intValue)])
682 - (void)takeObjectValueFrom:(
id)sender
684 if ([sender respondsToSelector:
@selector(objectValue)])
688 - (void)takeStringValueFrom:(
id)sender
690 if ([sender respondsToSelector:
@selector(stringValue)])
697 if ([note
object] !=
self)
706 if ([note
object] !=
self)
715 if ([note
object] !=
self)
718 [
self _reverseSetBinding];
728 - (unsigned)_currentTextMovement
730 var currentEvent = [CPApp currentEvent],
731 keyCode = [currentEvent keyCode],
732 modifierFlags = [currentEvent modifierFlags];
776 - (void)setAlignment:(CPTextAlignment)alignment
784 - (CPTextAlignment)alignment
786 return [
self valueForThemeAttribute:@"alignment"];
798 - (void)setVerticalAlignment:(CPTextVerticalAlignment)alignment
806 - (CPTextVerticalAlignment)verticalAlignment
808 return [
self valueForThemeAttribute:@"vertical-alignment"];
823 - (void)setLineBreakMode:(CPLineBreakMode)mode
831 - (CPLineBreakMode)lineBreakMode
833 return [
self valueForThemeAttribute:@"line-break-mode"];
851 return [
self valueForThemeAttribute:@"text-color"];
867 return [
self valueForThemeAttribute:@"text-shadow-color"];
875 - (void)setTextShadowOffset:(CGSize)offset
883 - (CGSize)textShadowOffset
885 return [
self valueForThemeAttribute:@"text-shadow-offset"];
901 return [
self valueForThemeAttribute:@"font"];
917 - (void)setImagePosition:(CPCellImagePosition)position
925 - (CPCellImagePosition)imagePosition
927 return [
self valueForThemeAttribute:@"image-position"];
940 - (void)setImageScaling:(CPImageScaling)scaling
948 - (CPUInteger)imageScaling
950 return [
self valueForThemeAttribute:@"image-scaling"];
959 - (void)setEnabled:(BOOL)isEnabled
972 return ![
self hasThemeState:CPThemeStateDisabled];
980 - (void)highlight:(BOOL)shouldHighlight
990 - (void)setHighlighted:(BOOL)isHighlighted
1001 - (BOOL)isHighlighted
1003 return [
self hasThemeState:CPThemeStateHighlighted];
1008 #pragma mark Base writing direction 1014 - (void)setBaseWritingDirection:(CPWritingDirection)writingDirection
1016 if (writingDirection == _baseWritingDirection)
1019 [
self willChangeValueForKey:@"baseWritingDirection"];
1020 _baseWritingDirection = writingDirection;
1021 [
self didChangeValueForKey:@"baseWritingDirection"];
1027 switch (_baseWritingDirection)
1045 _DOMElement.style.direction = style;
1056 - (void)updateTrackingAreas
1058 if (_controlTrackingArea)
1062 options:CPTrackingMouseEnteredAndExited | CPTrackingActiveInKeyWindow | CPTrackingInVisibleRect
1082 __Deprecated__CPImageViewImageKey =
@"CPImageViewImageKey";
1098 [
self setObjectValue:[aCoder decodeObjectForKey:CPControlValueKey]];
1100 [
self setTarget:[aCoder decodeObjectForKey:CPControlTargetKey]];
1101 [
self setAction:[aCoder decodeObjectForKey:CPControlActionKey]];
1103 [
self sendActionOn:[aCoder decodeIntForKey:CPControlSendActionOnKey]];
1106 [
self setFormatter:[aCoder decodeObjectForKey:CPControlFormatterKey]];
1108 [
self setControlSize:[aCoder decodeIntForKey:CPControlControlSizeKey]];
1125 if (_sendsActionOnEndEditing)
1126 [aCoder encodeBool:_sendsActionOnEndEditing forKey:CPControlSendsActionOnEndEditingKey];
1130 if (objectValue !== nil)
1131 [aCoder encodeObject:objectValue forKey:CPControlValueKey];
1133 if (_target !== nil)
1134 [aCoder encodeConditionalObject:_target forKey:CPControlTargetKey];
1136 if (_action !== nil)
1137 [aCoder encodeObject:_action forKey:CPControlActionKey];
1139 [aCoder encodeInt:_sendActionOn forKey:CPControlSendActionOnKey];
1141 if (_formatter !== nil)
1142 [aCoder encodeObject:_formatter forKey:CPControlFormatterKey];
1144 [aCoder encodeInt:_controlSize forKey:CPControlControlSizeKey];
1146 [aCoder encodeInt:_baseWritingDirection forKey:CPControlBaseWrittingDirectionKey];
1152 var _CPControlSizeIdentifiers = [],
1153 _CPControlCachedColorWithPatternImages = {},
1154 _CPControlCachedThreePartImagePattern = {};
1156 _CPControlSizeIdentifiers[CPRegularControlSize] =
"Regular";
1157 _CPControlSizeIdentifiers[CPSmallControlSize] =
"Small";
1158 _CPControlSizeIdentifiers[CPMiniControlSize] =
"Mini";
1160 function _CPControlIdentifierForControlSize(aControlSize)
1162 return _CPControlSizeIdentifiers[aControlSize];
1165 function _CPControlColorWithPatternImage(sizes, aClassName)
1168 count = arguments.length,
1171 for (; index < count; ++index)
1174 var color = _CPControlCachedColorWithPatternImages[identifier];
1182 _CPControlCachedColorWithPatternImages[identifier] = color;
1188 function _CPControlThreePartImagePattern(isVertical, sizes, aClassName)
1191 count = arguments.length,
1194 for (; index < count; ++index)
1197 var color = _CPControlCachedThreePartImagePattern[identifier];
1204 sizes = sizes[identifier];
1212 _CPControlCachedThreePartImagePattern[identifier] = color;
1233 _formatter = aValue;
1239 - (BOOL)sendsActionOnEndEditing
1241 return _sendsActionOnEndEditing;
1247 - (void)setSendsActionOnEndEditing:(BOOL)aValue
1249 _sendsActionOnEndEditing = aValue;
1255 - (CPWritingDirection)baseWritingDirection
1257 return _baseWritingDirection;
1263 - (void)setBaseWritingDirection:(CPWritingDirection)aValue
1265 _baseWritingDirection = aValue;
id initWithFrame:(CGRect aFrame)
CPControlSelectedBackgroundColor
CPControlHighlightedBackgroundColor
BOOL tracksMouseOutsideOfFrame()
id initWithImageSlices:isVertical:(CPArray imageSlices, [isVertical] BOOL isVertical)
void setAction:(SEL anAction)
BOOL setThemeState:(ThemeState aState)
FrameUpdater prototype identifier
CPThemeStateControlSizeMini
void trackMouse:(CPEvent anEvent)
void postNotificationName:object:userInfo:(CPString aNotificationName, [object] id anObject, [userInfo] CPDictionary aUserInfo)
An object representation of nil.
id initWithCoder:(CPCoder aCoder)
CPFont systemFontOfSize:(CGSize aSize)
void setTarget:(id aTarget)
CPColor colorWithPatternImage:(CPImage anImage)
BOOL startTrackingAt:(CGPoint aPoint)
CPLineBreakByTruncatingHead
CPWritingDirectionRightToLeft
void setBaseWritingDirection:(CPWritingDirection writingDirection)
CGPoint locationInWindow()
CPLineBreakByCharWrapping
void setIntValue:(int anObject)
void setControlSize:(CPControlSize aControlSize)
int sendActionOn:(int mask)
CPImageScaleProportionallyDown
void setValue:forThemeAttribute:(id aValue, [forThemeAttribute] CPString aName)
CPNotificationCenter defaultCenter()
void setFormatter:(CPFormatter aValue)
A mutable key-value pair collection.
function ThemeState(stateNames)
CPImageScaleAxesIndependently
CPLineBreakByTruncatingMiddle
CPControlTextDidChangeNotification
An immutable string (collection of characters).
CGPoint convertPoint:fromView:(CGPoint aPoint, [fromView] CPView aView)
CPCellImagePosition CPNoImage
var CPControlControlStateKey
BOOL sendAction:to:(SEL anAction, [to] id anObject)
void setFloatValue:(float aValue)
id initWithContentsOfFile:size:(CPString aFilename, [size] CGSize aSize)
CPControlDisabledBackgroundColor
CPBinder getBinding:forObject:(CPString aBinding, [forObject] id anObject)
void setNeedsDisplay:(BOOL aFlag)
void setObjectValue:(id anObject)
void encodeWithCoder:(CPCoder aCoder)
CPVerticalTextAlignment CPTopVerticalTextAlignment
void setStringValue:(CPString aString)
A notification that can be posted to a CPNotificationCenter.
void setHighlighted:(BOOL isHighlighted)
CPTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:(CPTimeInterval seconds, [target] id aTarget, [selector] SEL aSelector, [userInfo] id userInfo, [repeats] BOOL shouldRepeat)
CPLineBreakByTruncatingTail
BOOL continueTracking:at:(CGPoint lastPoint, [at] CGPoint aPoint)
CPImageScaling CPScaleProportionally
CPWritingDirectionLeftToRight
void highlight:(BOOL shouldHighlight)
CPBottomVerticalTextAlignment
var CPControlSendsActionOnEndEditingKey
void setSendsActionOnEndEditing:(BOOL aValue)
CPControlNormalBackgroundColor
A timer object that can send a message after the given time interval.
Defines methods for use when archiving & restoring (enc/decoding).
void updateTrackingAreas()
CPControlSize CPRegularControlSize
BOOL unsetThemeState:(ThemeState aState)
Sends messages (CPNotification) between objects.
var CPControlSendActionOnKey
void addTrackingArea:(CPTrackingArea trackingArea)
var CPControlFormatterKey
CPControlTextDidEndEditingNotification
CPTextAlignment CPLeftTextAlignment
CPControlTextDidBeginEditingNotification
CPBundle bundleForClass:(Class aClass)
CPLineBreakMode CPLineBreakByWordWrapping
var CPControlBaseWrittingDirectionKey
CPThemeStateControlSizeSmall
CPThemeStateControlSizeRegular
void setDoubleValue:(double anObject)
CPTrackingArea initWithRect:options:owner:userInfo:(CGRect aRect, [options] CPTrackingAreaOptions options, [owner] id owner, [userInfo] CPDictionary userInfo)
void setIntegerValue:(int anObject)
var CPControlIsEnabledKey
void setState:(CPInteger state)
CPWritingDirection CPWritingDirectionNatural
var CPControlControlSizeKey
CPImageScaleProportionallyUpOrDown
void removeTrackingArea:(CPTrackingArea trackingArea)
void stopTracking:at:mouseIsUp:(CGPoint lastPoint, [at] CGPoint aPoint, [mouseIsUp] BOOL mouseIsUp)
CPCenterVerticalTextAlignment