mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-15 21:14:29 +00:00
New: use @ref and @deref instead of Ref.h throughout Cappuccino.
This commit is contained in:
1 parent
9b4c126534
commit
f4096b94a7
14 files changed
+40
-83
No files matched your search
@@ -21,7 +21,6 @@
|
||||
*/
|
||||
|
||||
#import "../Foundation/CPRange.h"
|
||||
#import "../Foundation/Ref.h"
|
||||
|
||||
@import <Foundation/CPArray.j>
|
||||
@import <Foundation/CPData.j>
|
||||
@@ -501,7 +500,7 @@ var HORIZONTAL_MARGIN = 2;
|
||||
|
||||
[self _updateMinMaxItemSizeIfNeeded];
|
||||
|
||||
[self _computeGridWithSize:frameSize count:AT_REF(count)];
|
||||
[self _computeGridWithSize:frameSize count:@ref(count)];
|
||||
|
||||
//CPLog.debug("frameSize="+CPStringFromSize(frameSize) + "itemSize="+CPStringFromSize(itemSize) + " ncols=" + colsRowsCount[0] +" nrows="+ colsRowsCount[1]+" displayCount="+ colsRowsCount[2]);
|
||||
|
||||
@@ -1032,7 +1031,7 @@ var HORIZONTAL_MARGIN = 2;
|
||||
- (CPDragOperation)draggingEntered:(id)draggingInfo
|
||||
{
|
||||
var dropIndex = -1,
|
||||
dropIndexRef = AT_REF(dropIndex),
|
||||
dropIndexRef = @ref(dropIndex),
|
||||
dragOp = [self _validateDragWithInfo:draggingInfo dropIndex:dropIndexRef dropOperation:1];
|
||||
|
||||
dropIndex = dropIndexRef();
|
||||
@@ -1050,7 +1049,7 @@ var HORIZONTAL_MARGIN = 2;
|
||||
return _currentDragOperation;
|
||||
|
||||
var dropIndex,
|
||||
dropIndexRef = AT_REF(dropIndex);
|
||||
dropIndexRef = @ref(dropIndex);
|
||||
|
||||
var dragOperation = [self _validateDragWithInfo:draggingInfo dropIndex:dropIndexRef dropOperation:1];
|
||||
|
||||
@@ -1068,7 +1067,7 @@ var HORIZONTAL_MARGIN = 2;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(collectionView:validateDrop:proposedIndex:dropOperation:)])
|
||||
{
|
||||
var dropIndexRef2 = AT_REF(dropIndex);
|
||||
var dropIndexRef2 = @ref(dropIndex);
|
||||
|
||||
result = [_delegate collectionView:self validateDrop:draggingInfo proposedIndex:dropIndexRef2 dropOperation:dropOperation];
|
||||
|
||||
|
||||
+2
-4
@@ -20,8 +20,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#import "../Foundation/Ref.h"
|
||||
|
||||
@import <Foundation/CPFormatter.j>
|
||||
@import <Foundation/CPTimer.j>
|
||||
|
||||
@@ -553,10 +551,10 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
{
|
||||
value = nil;
|
||||
|
||||
if ([_formatter getObjectValue:AT_REF(value) forString:aString errorDescription:nil] === NO)
|
||||
if ([_formatter getObjectValue:@ref(value) forString:aString errorDescription:nil] === NO)
|
||||
{
|
||||
// If the given string is non-empty and doesn't work, Cocoa tries an empty string.
|
||||
if (!aString || [_formatter getObjectValue:AT_REF(value) forString:@"" errorDescription:nil] === NO)
|
||||
if (!aString || [_formatter getObjectValue:@ref(value) forString:@"" errorDescription:nil] === NO)
|
||||
value = undefined; // Means the value is invalid
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#import "../Foundation/Ref.h"
|
||||
|
||||
@import "CPControl.j"
|
||||
@import "CPStringDrawing.j"
|
||||
@import "CPCompatibility.j"
|
||||
@@ -72,15 +70,15 @@ function CPTextFieldBlurFunction(anEvent, owner, domElement, inputElement, resig
|
||||
}, 0.0);
|
||||
}
|
||||
|
||||
CPTextFieldHandleBlur(anEvent, AT_REF(owner));
|
||||
AT_DEREF(didBlurRef, YES);
|
||||
CPTextFieldHandleBlur(anEvent, @ref(owner));
|
||||
@deref(didBlurRef) = YES;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function CPTextFieldHandleBlur(anEvent, ownerRef)
|
||||
{
|
||||
AT_DEREF(ownerRef, nil);
|
||||
@deref(ownerRef) = nil;
|
||||
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
}
|
||||
@@ -236,7 +234,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
CPTextFieldInputOwner._DOMElement,
|
||||
CPTextFieldDOMInputElement,
|
||||
CPTextFieldInputResigning,
|
||||
AT_REF(CPTextFieldInputDidBlur));
|
||||
@ref(CPTextFieldInputDidBlur));
|
||||
};
|
||||
|
||||
if (CPFeatureIsCompatible(CPInputOnInputEventFeature))
|
||||
@@ -778,7 +776,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
|
||||
var error = @"";
|
||||
|
||||
if ([self _setStringValue:aValue isNewValue:NO errorDescription:AT_REF(error)] === NO)
|
||||
if ([self _setStringValue:aValue isNewValue:NO errorDescription:@ref(error)] === NO)
|
||||
{
|
||||
var acceptInvalidValue = NO;
|
||||
|
||||
@@ -1045,7 +1043,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
{
|
||||
var object = nil;
|
||||
|
||||
if ([formatter getObjectValue:AT_REF(object) forString:aValue errorDescription:anError])
|
||||
if ([formatter getObjectValue:@ref(object) forString:aValue errorDescription:anError])
|
||||
objectValue = object;
|
||||
else
|
||||
{
|
||||
@@ -1084,7 +1082,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
|
||||
// Formatting failed, get an "empty" object by formatting an empty string.
|
||||
// If that fails, the value is undefined.
|
||||
if ([formatter getObjectValue:AT_REF(value) forString:@"" errorDescription:nil] === NO)
|
||||
if ([formatter getObjectValue:@ref(value) forString:@"" errorDescription:nil] === NO)
|
||||
value = undefined;
|
||||
|
||||
[super setObjectValue:value];
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
*/
|
||||
|
||||
#import "../Foundation/CPRange.h"
|
||||
#import "../Foundation/Ref.h"
|
||||
|
||||
@import <Foundation/CPCharacterSet.j>
|
||||
@import <Foundation/CPIndexSet.j>
|
||||
@@ -667,7 +666,7 @@ CPTokenFieldDeleteButtonType = 1;
|
||||
CPTokenFieldInputOwner ? [CPTokenFieldInputOwner._tokenScrollView documentView]._DOMElement : nil,
|
||||
CPTokenFieldDOMInputElement,
|
||||
CPTokenFieldInputResigning,
|
||||
AT_REF(CPTokenFieldInputDidBlur));
|
||||
@ref(CPTokenFieldInputDidBlur));
|
||||
};
|
||||
|
||||
// FIXME make this not onblur
|
||||
|
||||
@@ -618,7 +618,7 @@ var concat = Array.prototype.concat,
|
||||
var index = 0,
|
||||
count = [self count],
|
||||
shouldStop = NO,
|
||||
shouldStopRef = AT_REF(shouldStop);
|
||||
shouldStopRef = @ref(shouldStop);
|
||||
|
||||
for (; index < count; ++index)
|
||||
{
|
||||
@@ -648,7 +648,7 @@ var concat = Array.prototype.concat,
|
||||
|
||||
for (; index !== stop; index += increment)
|
||||
{
|
||||
aFunction([self objectAtIndex:index], index, AT_REF(shouldStop));
|
||||
aFunction([self objectAtIndex:index], index, @ref(shouldStop));
|
||||
|
||||
if (shouldStop)
|
||||
return;
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#import "Ref.h"
|
||||
|
||||
@import "CPDate.j"
|
||||
@import "CPString.j"
|
||||
@import "CPFormatter.j"
|
||||
@@ -104,7 +102,7 @@ CPDateFormatterFullStyle = 4;
|
||||
{
|
||||
// TODO Error handling.
|
||||
var value = [self dateFromString:aString];
|
||||
AT_DEREF(anObject, value);
|
||||
@deref(anObject) = value;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
@import "CPException.j"
|
||||
@import "CPNull.j"
|
||||
@import "CPObject.j"
|
||||
#import "Ref.h"
|
||||
|
||||
//FIXME: After release of 0.9.7 remove below variable
|
||||
var CPDictionaryShowNilDeprecationMessage = YES;
|
||||
@@ -459,7 +458,7 @@ var CPDictionaryShowNilDeprecationMessage = YES;
|
||||
key = nil,
|
||||
value = nil,
|
||||
shouldStop = NO,
|
||||
stopRef = AT_REF(shouldStop);
|
||||
stopRef = @ref(shouldStop);
|
||||
|
||||
for (; index !== stop; index += increment)
|
||||
{
|
||||
@@ -749,7 +748,7 @@ var CPDictionaryShowNilDeprecationMessage = YES;
|
||||
- (void)enumerateKeysAndObjectsUsingBlock:(Function /*(id aKey, id anObject, @ref BOOL stop)*/)aFunction
|
||||
{
|
||||
var shouldStop = NO,
|
||||
shouldStopRef = AT_REF(shouldStop),
|
||||
shouldStopRef = @ref(shouldStop),
|
||||
keys = self._keys,
|
||||
count = self._count;
|
||||
|
||||
|
||||
+11
-13
@@ -33,8 +33,6 @@
|
||||
make sure that you cannot configure the public subclasses CPDateFormatter and CPNumberFormatter to satisfy your requirements.
|
||||
*/
|
||||
|
||||
#import "Ref.h"
|
||||
|
||||
@import "CPException.j"
|
||||
@import "CPObject.j"
|
||||
|
||||
@@ -124,10 +122,10 @@
|
||||
*/
|
||||
- (BOOL)isPartialStringValid:(CPString)aPartialString newEditingString:(CPStringRef)aNewString errorDescription:(CPStringRef)anError
|
||||
{
|
||||
AT_DEREF(aPartialString, nil);
|
||||
@deref(aPartialString) = nil;
|
||||
|
||||
if (anError)
|
||||
AT_DEREF(anError, nil);
|
||||
@deref(anError) = nil;
|
||||
|
||||
return YES;
|
||||
}
|
||||
@@ -137,32 +135,32 @@
|
||||
not necessarily at the end of the string, and preserve the selection (or set a different one, such as selecting the erroneous part of
|
||||
the string the user has typed).
|
||||
|
||||
In a subclass implementation, evaluate aPartialString according to the context. Return \c YES if aPartialString is acceptable and \c NO if aPartialString
|
||||
is unacceptable. Assign a new string by reference to aPartialString and a new range by reference to aProposedSelectedRange and return \c NO if you want to replace the string and
|
||||
In a subclass implementation, evaluate aPartialStringRef according to the context. Return \c YES if aPartialStringRef is acceptable and \c NO if aPartialStringRef
|
||||
is unacceptable. Assign a new string by reference to aPartialStringRef and a new range by reference to aProposedSelectedRangeRef and return \c NO if you want to replace the string and
|
||||
change the selection range. If you return \c NO, you can also return by reference a CPString object (in anError) that explains the reason why the
|
||||
validation failed; the delegate (if any) of the CPControl can then respond to the failure in
|
||||
control:didFailToValidatePartialString:errorDescription:.
|
||||
|
||||
@param aPartialString The new string to validate.
|
||||
@param aProposedSelectedRange The selection range that will be used if the string is accepted or replaced.
|
||||
@param aPartialStringRef The new string to validate.
|
||||
@param aProposedSelectedRangeRef The selection range that will be used if the string is accepted or replaced.
|
||||
@param originalString The original string, before the proposed change.
|
||||
@param originalSelectedRange The selection range over which the change is to take place.
|
||||
@param anError If non-nil, if validation fails contains an CPString object that describes the problem.
|
||||
@return \c YES if aPartialString is acceptable, otherwise \c NO.
|
||||
@return \c YES if aPartialStringRef is acceptable, otherwise \c NO.
|
||||
|
||||
*/
|
||||
- (BOOL)isPartialStringValid:(CPStringRef)aPartialString proposedSelectedRange:(CPRangeRef)aProposedSelectedRange originalString:(CPString)originalString originalSelectedRange:(CPRange)originalSelectedRange errorDescription:(CPStringRef)anError
|
||||
- (BOOL)isPartialStringValid:(CPStringRef)aPartialStringRef proposedSelectedRange:(CPRangeRef)aProposedSelectedRangeRef originalString:(CPString)originalString originalSelectedRange:(CPRange)originalSelectedRange errorDescription:(CPStringRef)anError
|
||||
{
|
||||
var newString = nil,
|
||||
valid = [self isPartialStringValid:aPartialString newEditingString:AT_REF(newString) errorDescription:anError];
|
||||
valid = [self isPartialStringValid:aPartialStringRef newEditingString:@ref(newString) errorDescription:anError];
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
AT_DEREF(aPartialString, newString);
|
||||
@deref(aPartialStringRef) = newString;
|
||||
|
||||
// If a new string is passed back, the selection is always put at the end
|
||||
if (newString !== nil)
|
||||
AT_DEREF(aProposedSelectedRange, CPMakeRange(newString.length, 0));
|
||||
@deref(aProposedSelectedRangeRef) = CPMakeRange(newString.length, 0);
|
||||
}
|
||||
|
||||
return valid;
|
||||
|
||||
@@ -548,7 +548,7 @@
|
||||
{
|
||||
if (_CPLocationInRange(rangeIndex, enumerationRange))
|
||||
{
|
||||
aFunction(rangeIndex, AT_REF(shouldStop));
|
||||
aFunction(rangeIndex, @ref(shouldStop));
|
||||
if (shouldStop)
|
||||
return;
|
||||
}
|
||||
@@ -629,7 +629,7 @@
|
||||
{
|
||||
if (_CPLocationInRange(rangeIndex, aRange))
|
||||
{
|
||||
if (aPredicate(rangeIndex, AT_REF(shouldStop)))
|
||||
if (aPredicate(rangeIndex, @ref(shouldStop)))
|
||||
return rangeIndex;
|
||||
|
||||
if (shouldStop)
|
||||
@@ -690,7 +690,7 @@
|
||||
{
|
||||
if (_CPLocationInRange(rangeIndex, aRange))
|
||||
{
|
||||
if (aPredicate(rangeIndex, AT_REF(shouldStop)))
|
||||
if (aPredicate(rangeIndex, @ref(shouldStop)))
|
||||
[indexesPassingTest addIndex:rangeIndex];
|
||||
|
||||
if (shouldStop)
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#import "Ref.h"
|
||||
|
||||
@import "CPString.j"
|
||||
@import "CPFormatter.j"
|
||||
@import "CPDecimalNumber.j"
|
||||
@@ -183,7 +181,7 @@ var NumberRegex = new RegExp('(-)?(\\d*)(\\.(\\d*))?');
|
||||
return [self stringForObjectValue:anObject];
|
||||
}
|
||||
|
||||
- (BOOL)getObjectValue:(id)anObject forString:(CPString)aString errorDescription:(CPString)anError
|
||||
- (BOOL)getObjectValue:(id)anObjectRef forString:(CPString)aString errorDescription:(CPString)anErrorRef
|
||||
{
|
||||
// allows an empty string to pass without validation
|
||||
if (aString === @"")
|
||||
@@ -202,13 +200,13 @@ var NumberRegex = new RegExp('(-)?(\\d*)(\\.(\\d*))?');
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (anError)
|
||||
AT_DEREF(anError, error);
|
||||
if (anErrorRef)
|
||||
@deref(anErrorRef) = error;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
AT_DEREF(anObject, value);
|
||||
@deref(anObjectRef) = value;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Ref.h
|
||||
* Foundation
|
||||
*
|
||||
* Created by Alexander Ljungberg.
|
||||
* Copyright 2011, WireLoad Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
Temporary macros to substitute for @ref and @deref functionality in a future version of Objective-J. Since these are C macros rather than a part of Preprocessor.js they can only be used within Cappuccino itself.
|
||||
*/
|
||||
|
||||
// @ref
|
||||
#define AT_REF(x) function(__input) { if (arguments.length) return x = __input; return x; }
|
||||
// @deref (kind of)
|
||||
#define AT_DEREF(x, ...) x(##__VA_ARGS__)
|
||||
@@ -621,7 +621,7 @@
|
||||
{
|
||||
[output setValue:anObject forKey:"" + idx];
|
||||
if ([output count] > 1)
|
||||
stop(YES); // AT_DEREF(stop, YES) - FIXME Replace with proper @ref @deref when in ObjJ.
|
||||
@deref(stop) = YES;
|
||||
}
|
||||
output = [CPMutableDictionary dictionary];
|
||||
|
||||
|
||||
@@ -374,7 +374,7 @@
|
||||
{
|
||||
[output setValue:anObject forKey:aKey];
|
||||
if ([output count] > 1)
|
||||
stop(YES); // AT_DEREF(stop, YES) - FIXME Replace with proper @ref @deref when in ObjJ.
|
||||
@deref(stop) = YES;
|
||||
}
|
||||
|
||||
[input1 enumerateKeysAndObjectsUsingBlock:stoppingFunction];
|
||||
|
||||
@@ -542,7 +542,7 @@ function descriptionWithoutEntity(aString)
|
||||
{
|
||||
visitedIndexes.push(idx);
|
||||
if (visitedIndexes.length >= 2)
|
||||
stop(YES); // AT_DEREF(stop, YES) - FIXME Replace with proper @ref @deref when in ObjJ.
|
||||
@deref(stop) = YES;
|
||||
}
|
||||
|
||||
[set0 enumerateIndexesUsingBlock:aBlock];
|
||||
|
||||
Reference in new issue
Block a user