Skip to content

Commit

Permalink
Merge branch 'master' of github.com:280north/cappuccino
Browse files Browse the repository at this point in the history
  • Loading branch information
aljungberg committed Jul 18, 2011
2 parents 93135e7 + 147d928 commit f54f8df
Show file tree
Hide file tree
Showing 61 changed files with 10,398 additions and 34 deletions.
3 changes: 3 additions & 0 deletions AppKit/CPAnimation.j
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ ACTUAL_FRAME_RATE = 0;

if ([_delegate respondsToSelector:@selector(animation:valueForProgress:)])
return [_delegate animation:self valueForProgress:t];

if (_animationCurve == CPAnimationLinear)
return t;

var c1 = [],
c2 = [];
Expand Down
15 changes: 8 additions & 7 deletions AppKit/CPViewAnimation.j
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,28 @@ CPViewAnimationFadeOutEffect = @"CPViewAnimationFadeOutEffect";
view = [self _targetView:dictionary],
startFrame = [self _startFrame:dictionary],
endFrame = [self _endFrame:dictionary],
differenceFrame = _CGRectMakeZero();
differenceFrame = _CGRectMakeZero(),
value = [super currentValue];

differenceFrame.origin.x = endFrame.origin.x - startFrame.origin.x;
differenceFrame.origin.y = endFrame.origin.y - startFrame.origin.y;
differenceFrame.size.width = endFrame.size.width - startFrame.size.width;
differenceFrame.size.height = endFrame.size.height - startFrame.size.height;

var intermediateFrame = _CGRectMakeZero();
intermediateFrame.origin.x = startFrame.origin.x + differenceFrame.origin.x * progress;
intermediateFrame.origin.y = startFrame.origin.y + differenceFrame.origin.y * progress;
intermediateFrame.size.width = startFrame.size.width + differenceFrame.size.width * progress;
intermediateFrame.size.height = startFrame.size.height + differenceFrame.size.height * progress;
intermediateFrame.origin.x = startFrame.origin.x + differenceFrame.origin.x * value;
intermediateFrame.origin.y = startFrame.origin.y + differenceFrame.origin.y * value;
intermediateFrame.size.width = startFrame.size.width + differenceFrame.size.width * value;
intermediateFrame.size.height = startFrame.size.height + differenceFrame.size.height * value;

[view setFrame:intermediateFrame];

// Update the view's alpha value
var effect = [self _effect:dictionary];
if (effect === CPViewAnimationFadeInEffect)
[view setAlphaValue:1.0 * progress];
[view setAlphaValue:1.0 * value];
else if (effect === CPViewAnimationFadeOutEffect)
[view setAlphaValue:1.0 + ( 0.0 - 1.0 ) * progress];
[view setAlphaValue:1.0 + ( 0.0 - 1.0 ) * value];

if (progress === 1.0)
[self _targetView:view setHidden:_CGRectIsNull(endFrame) || [view alphaValue] === 0.0];
Expand Down
9 changes: 9 additions & 0 deletions AppKit/Platform/CPPlatformString.j
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@
#include "DOM/CPPlatformString.j"
#else
@implementation CPPlatformString : CPBasePlatformString

+ (CGSize)sizeOfString:(CPString)aString withFont:(CPFont)aFont forWidth:(float)aWidth
{
return _CGSizeMakeZero();
}

+ (CPDictionary)metricsOfFont:(CPFont)aFont
{
return [CPDictionary dictionaryWithObjectsAndKeys:0, @"ascender", 0, @"descender", 0, @"lineHeight"];
}

@end
#endif
15 changes: 11 additions & 4 deletions Foundation/CPDictionary.j
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,18 @@
for (; i < count; i++)
{
var thisValue = value[i];

if (thisValue.constructor === Object)
newValue.push([CPDictionary dictionaryWithJSObject:thisValue recursively:YES]);

if (thisValue === null)
{
newValue.push([CPNull null]);
}
else
newValue.push(thisValue);
{
if (thisValue.constructor === Object)
newValue.push([CPDictionary dictionaryWithJSObject:thisValue recursively:YES]);
else
newValue.push(thisValue);
}
}

value = newValue;
Expand Down
5 changes: 2 additions & 3 deletions Foundation/CPKeyedArchiver.j
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,10 @@ var _CPKeyedArchiverStringClass = Nil,

for (; i < _objects.length; ++i)
{
var object = _objects[i],
theClass = [object classForKeyedArchiver];
var object = _objects[i];

// Do whatever with the class, yo.
// We call willEncodeObject previously.
// We called willEncodeObject previously.

_plistObject = _plistObjects[[_UIDs objectForKey:[object UID]]];
[object encodeWithCoder:self];
Expand Down
16 changes: 10 additions & 6 deletions Foundation/CPPredicate/CPComparisonPredicate.j
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,18 @@ var CPComparisonPredicateModifier,
reg = new RegExp(rhs.escapeForRegExp(),commut);
return reg.test(lhs);

case CPBeginsWithPredicateOperatorType: var range = CPMakeRange(0,[rhs length]);
if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch;
if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch;
case CPBeginsWithPredicateOperatorType: var range = CPMakeRange(0, MIN([lhs length], [rhs length]));
if (_options & CPCaseInsensitivePredicateOption)
string_compare_options |= CPCaseInsensitiveSearch;
if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;
return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame);

case CPEndsWithPredicateOperatorType: var range = CPMakeRange([lhs length] - [rhs length],[rhs length]);
if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch;
if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch;
case CPEndsWithPredicateOperatorType: var range = CPMakeRange(MAX([lhs length] - [rhs length], 0), MIN([lhs length], [rhs length]));
if (_options & CPCaseInsensitivePredicateOption)
string_compare_options |= CPCaseInsensitiveSearch;
if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;
return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame);

case CPCustomSelectorPredicateOperatorType: return [lhs performSelector:_customSelector withObject:rhs];
Expand Down
22 changes: 22 additions & 0 deletions Tests/Foundation/CPPredicateTest.j
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@
[self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be true"];
}

- (void)testBeginsWithEndsWithPredicate
{
// This always worked
var data = ["To", "Tom", "Tomb", "Tomboy"],
pred = [CPPredicate predicateWithFormat:@"SELF beginsWith 'To'"],
result = [data filteredArrayUsingPredicate:pred];

[self assertTrue:result.length === 4 message:"'" + [pred description] + "' should return [\"To\", \"Tom\", \"Tomb\", \"Tomboy\"]"];

// Make sure beginsWith comparison string longer than source strings works
pred = [CPPredicate predicateWithFormat:@"SELF beginsWith 'Tomb'"];
result = [data filteredArrayUsingPredicate:pred];

[self assertTrue:[result isEqual:["Tomb", "Tomboy"]] message:"'" + [pred description] + "' should return [\"Tomb\", \"Tomboy\"]"];

// Make sure endsWith comparison string longer than source strings works
pred = [CPPredicate predicateWithFormat:@"SELF endsWith 'boy'"];
result = [data filteredArrayUsingPredicate:pred];

[self assertTrue:[result isEqual:["Tomboy"]] message:"'" + [pred description] + "' should return [\"Tomboy\"]"];
}

- (void)testNilComparisons
{
// Custom Selector Predicate
Expand Down
150 changes: 150 additions & 0 deletions Tests/Manual/predicateWithFormat/AppController.j
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* AppController.j
* predicateWithFormat
*
* Created by aparajita on May 25, 2011.
* Copyright 2011, Victory-Heart Productions All rights reserved.
*/

@import <Foundation/CPObject.j>

var usesNewCode = NO;

@implementation AppController : CPObject
{
CPWindow theWindow;
CPPopUpButton dataMenu;
CPPopUpButton comparisonMenu;
CPPopUpButton nameMenu;
CPTextField resultsField;
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
useNewCode = usesNewCode;
}

- (void)awakeFromCib
{
}

- (BOOL)useNewCode
{
return usesNewCode;
}

- (void)setUseNewCode:(BOOL)flag
{
usesNewCode = flag;
}

- (void)search:(id)sender
{
var results = @"";

try
{
var format = [CPString stringWithFormat:@"SELF %@ %%@", [comparisonMenu titleOfSelectedItem]],
predicate = [CPPredicate predicateWithFormat:format, [nameMenu titleOfSelectedItem]],
data = [[dataMenu titleOfSelectedItem]],
searchResults = [data filteredArrayUsingPredicate:predicate],

results = searchResults.join("\n");
[resultsField setTextColor:[CPColor blackColor]];
}
catch (ex)
{
results = [ex reason];
[resultsField setTextColor:[CPColor redColor]];
}

[resultsField setStringValue:@"Result: " + results];
}

@end

var CPComparisonPredicateModifier,
CPPredicateOperatorType;

@implementation CPComparisonPredicate (test)

- (BOOL)_evaluateValue:lhs rightValue:rhs
{
var leftIsNil = (lhs == nil || [lhs isEqual:[CPNull null]]),
rightIsNil = (rhs == nil || [rhs isEqual:[CPNull null]]);

if ((leftIsNil || rightIsNil) && _type != CPCustomSelectorPredicateOperatorType)
return (leftIsNil == rightIsNil &&
(_type == CPEqualToPredicateOperatorType ||
_type == CPLessThanOrEqualToPredicateOperatorType ||
_type == CPGreaterThanOrEqualToPredicateOperatorType));

var string_compare_options = 0;

// left and right should be casted first [CAST()] following 10.5 rules.
switch (_type)
{
case CPLessThanPredicateOperatorType: return ([lhs compare:rhs] == CPOrderedAscending);
case CPLessThanOrEqualToPredicateOperatorType: return ([lhs compare:rhs] != CPOrderedDescending);
case CPGreaterThanPredicateOperatorType: return ([lhs compare:rhs] == CPOrderedDescending);
case CPGreaterThanOrEqualToPredicateOperatorType: return ([lhs compare:rhs] != CPOrderedAscending);
case CPEqualToPredicateOperatorType: return [lhs isEqual:rhs];
case CPNotEqualToPredicateOperatorType: return (![lhs isEqual:rhs]);

case CPMatchesPredicateOperatorType: var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g";
if (_options & CPDiacriticInsensitivePredicateOption)
{
lhs = lhs.stripDiacritics();
rhs = rhs.stripDiacritics();
}
return (new RegExp(rhs,commut)).test(lhs);

case CPLikePredicateOperatorType: if (_options & CPDiacriticInsensitivePredicateOption)
{
lhs = lhs.stripDiacritics();
rhs = rhs.stripDiacritics();
}
var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g",
reg = new RegExp(rhs.escapeForRegExp(),commut);
return reg.test(lhs);

case CPBeginsWithPredicateOperatorType: var range = usesNewCode ? CPMakeRange(0, MIN([lhs length], [rhs length])) : CPMakeRange(0,[rhs length]);
if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch;
if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch;
return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame);

case CPEndsWithPredicateOperatorType: var range = usesNewCode ? CPMakeRange(MAX([lhs length] - [rhs length], 0), MIN([lhs length], [rhs length])) : CPMakeRange([lhs length] - [rhs length],[rhs length]);
if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch;
if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch;
return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame);

case CPCustomSelectorPredicateOperatorType: return [lhs performSelector:_customSelector withObject:rhs];

case CPInPredicateOperatorType: var a = lhs; // swap
lhs = rhs;
rhs = a;
case CPContainsPredicateOperatorType: if (![lhs isKindOfClass:[CPString class]])
{
if (![lhs respondsToSelector: @selector(objectEnumerator)])
[CPException raise:CPInvalidArgumentException reason:@"The left/right hand side for a CONTAINS/IN operator must be a collection or a string"];

return [lhs containsObject:rhs];
}

if (_options & CPCaseInsensitivePredicateOption)
string_compare_options |= CPCaseInsensitiveSearch;
if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;

return ([lhs rangeOfString:rhs options:string_compare_options].location != CPNotFound);

case CPBetweenPredicateOperatorType: if ([rhs count] < 2)
[CPException raise:CPInvalidArgumentException reason:@"The right hand side for a BETWEEN operator must contain 2 objects"];

return ([lhs compare:rhs[0]] == CPOrderedDescending && [lhs compare:rhs[1]] == CPOrderedAscending);

default: return NO;
}
}

@end
10 changes: 10 additions & 0 deletions Tests/Manual/predicateWithFormat/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Main cib file base name</key>
<string>MainMenu.cib</string>
<key>CPBundleName</key>
<string>test</string>
</dict>
</plist>
Loading

0 comments on commit f54f8df

Please sign in to comment.