diff --git a/AppKit/CPAccordionView.j b/AppKit/CPAccordionView.j index f7e10f17a..c9bcf71a7 100644 --- a/AppKit/CPAccordionView.j +++ b/AppKit/CPAccordionView.j @@ -96,12 +96,12 @@ return _items; } -- (void)addItem:(CPAccordionItem)anItem +- (void)addItem:(CPAccordionViewItem)anItem { [self insertItem:anItem atIndex:_items.length]; } -- (void)insertItem:(CPAccordionItem)anItem atIndex:(CPInteger)anIndex +- (void)insertItem:(CPAccordionViewItem)anItem atIndex:(CPInteger)anIndex { // FIXME: SHIFT ITEMS RIGHT [_expandedItemIndexes addIndex:anIndex]; @@ -122,7 +122,7 @@ [self setNeedsLayout]; } -- (void)removeItem:(CPAccordionItem)anItem +- (void)removeItem:(CPAccordionViewItem)anItem { [self removeItemAtIndex:[_items indexOfObjectIdenticalTo:anItem]]; } diff --git a/AppKit/CPBox.j b/AppKit/CPBox.j index 07a78c759..05500b550 100644 --- a/AppKit/CPBox.j +++ b/AppKit/CPBox.j @@ -162,7 +162,6 @@ CPGrooveBorder = 3; [aView setFrame:CGRectInset([self bounds], _contentMargin.width + _borderWidth, _contentMargin.height + _borderWidth)]; [self replaceSubview:_contentView with:aView]; - [aView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable]; _contentView = aView; } diff --git a/AppKit/CPCompatibility.j b/AppKit/CPCompatibility.j index 16e266086..4e67c0356 100644 --- a/AppKit/CPCompatibility.j +++ b/AppKit/CPCompatibility.j @@ -65,8 +65,6 @@ CPInputTypeCanBeChangedFeature = 1 << 25; CPHTML5DragAndDropSourceYOffBy1 = 1 << 26; - - var USER_AGENT = "", PLATFORM_ENGINE = CPUnknownBrowserEngine, PLATFORM_FEATURES = 0; @@ -75,7 +73,7 @@ var USER_AGENT = "", PLATFORM_FEATURES |= CPInputTypeCanBeChangedFeature; -if (typeof window != "undfined" && typeof window.navigator != "undefined") +if (typeof window !== "undefined" && typeof window.navigator !== "undefined") USER_AGENT = window.navigator.userAgent; // Opera diff --git a/AppKit/CPDragServer.j b/AppKit/CPDragServer.j index 6ae6871d9..06f8d2435 100644 --- a/AppKit/CPDragServer.j +++ b/AppKit/CPDragServer.j @@ -127,7 +127,7 @@ var CPDragServerDraggingInfo = nil; @end var CPDraggingSource_draggedImage_movedTo_ = 1 << 0, - CPDraggingSource_draggedImage_endAt_operation_ = 1 << 1, + CPDraggingSource_draggedImage_endedAt_operation_ = 1 << 1, CPDraggingSource_draggedView_movedTo_ = 1 << 2, CPDraggingSource_draggedView_endedAt_operation_ = 1 << 3; @@ -267,7 +267,7 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0, if (![CPPlatform supportsDragAndDrop]) [_draggedWindow orderOut:self]; - if (_implementedDraggingSourceMethods & CPDraggingSource_draggedImage_endAt_operation_) + if (_implementedDraggingSourceMethods & CPDraggingSource_draggedImage_endedAt_operation_) [_draggingSource draggedImage:[_draggedView image] endedAt:aLocation operation:anOperation]; else if (_implementedDraggingSourceMethods & CPDraggingSource_draggedView_endedAt_operation_) [_draggingSource draggedView:_draggedView endedAt:aLocation operation:anOperation]; @@ -342,8 +342,8 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0, if ([_draggingSource respondsToSelector:@selector(draggedImage:movedTo:)]) _implementedDraggingSourceMethods |= CPDraggingSource_draggedImage_movedTo_; - if ([_draggingSource respondsToSelector:@selector(draggedImage:endAt:operation:)]) - _implementedDraggingSourceMethods |= CPDraggingSource_draggedImage_endAt_operation_; + if ([_draggingSource respondsToSelector:@selector(draggedImage:endedAt:operation:)]) + _implementedDraggingSourceMethods |= CPDraggingSource_draggedImage_endedAt_operation_; } else { diff --git a/AppKit/CPEvent.j b/AppKit/CPEvent.j index 8a7ccfd0b..a60a05114 100644 --- a/AppKit/CPEvent.j +++ b/AppKit/CPEvent.j @@ -128,7 +128,7 @@ var _CPEventPeriodicEventPeriod = 0, BOOL _isARepeat; unsigned _keyCode; DOMEvent _DOMEvent; - + float _deltaX; float _deltaY; float _deltaZ; @@ -345,7 +345,10 @@ var _CPEventPeriodicEventPeriod = 0, */ - (int)buttonNumber { - return _buttonNumber; + if (_type === CPRightMouseDown || _type === CPRightMouseUp || _type === CPRightMouseDragged) + return 1; + + return 0; } /*! diff --git a/AppKit/CPScreen.j b/AppKit/CPScreen.j index 4d0b7b3c8..dccfbdb17 100644 --- a/AppKit/CPScreen.j +++ b/AppKit/CPScreen.j @@ -1,8 +1,8 @@ @import - #import "CoreGraphics/CGGeometry.h" +#import "Platform/Platform.h" @implementation CPScreen : CPObject { @@ -10,7 +10,11 @@ - (CGRect)visibleFrame { +#if PLATFORM(DOM) return _CGRectMake(window.screen.availLeft, window.screen.availTop, window.screen.availWidth, window.screen.availHeight); +#else + return _CGRectMakeZero(); +#endif } @end \ No newline at end of file diff --git a/Foundation/CPArray.j b/Foundation/CPArray.j index 39ab864b3..949b900ac 100755 --- a/Foundation/CPArray.j +++ b/Foundation/CPArray.j @@ -453,10 +453,19 @@ @return the index of the object, or \c CPNotFound if it was not found. */ - (unsigned)indexOfObject:(id)anObject sortedByFunction:(Function)aFunction context:(id)aContext +{ + var result = [self _indexOfObject:anObject sortedByFunction:aFunction context:aContext]; + return result >= 0 ? result : CPNotFound; +} + +- (unsigned)_indexOfObject:(id)anObject sortedByFunction:(Function)aFunction context:(id)aContext { if (!aFunction || anObject === undefined) return CPNotFound; + if (length === 0) + return -1; + var mid, c, first = 0, last = length - 1; while (first <= last) { @@ -476,7 +485,7 @@ } } - return CPNotFound; + return -first-1; } /*! @@ -644,8 +653,8 @@ { if (self === anArray) return YES; - - if(length != anArray.length) + + if (anArray === nil || length !== anArray.length) return NO; var index = 0, @@ -972,6 +981,28 @@ [self insertObject:objects[index] atIndex:currentIndex]; } +- (unsigned)insertObject:(id)anObject inArraySortedByDescriptors:(CPArray)descriptors +{ + var index = [self _indexOfObject:anObject sortedByFunction:function(lhs, rhs) + { + var i = 0, + count = [descriptors count], + result = CPOrderedSame; + + while (i < count) + if((result = [descriptors[i++] compareObject:lhs withObject:rhs]) != CPOrderedSame) + return result; + + return result; + } context:nil]; + + if (index < 0) + index = -index-1; + + [self insertObject:anObject atIndex:index]; + return index; +} + /*! Replaces the element at \c anIndex with \c anObject. The current element at position \c anIndex will be removed from the array. diff --git a/Objective-J/Preprocessor.js b/Objective-J/Preprocessor.js index d90a71b07..b95b4e61b 100644 --- a/Objective-J/Preprocessor.js +++ b/Objective-J/Preprocessor.js @@ -34,6 +34,8 @@ var TOKEN_ACCESSORS = "accessors", TOKEN_SUPER = "super", TOKEN_VAR = "var", TOKEN_IN = "in", + TOKEN_PRAGMA = "pragma", + TOKEN_MARK = "mark", TOKEN_EQUAL = '=', TOKEN_PLUS = '+', @@ -50,6 +52,7 @@ var TOKEN_ACCESSORS = "accessors", TOKEN_OPEN_BRACKET = '[', TOKEN_DOUBLE_QUOTE = '"', TOKEN_PREPROCESSOR = '@', + TOKEN_HASH = '#', TOKEN_CLOSE_BRACKET = ']', TOKEN_QUESTION_MARK = '?', TOKEN_OPEN_PARENTHESIS = '(', @@ -363,6 +366,29 @@ Preprocessor.prototype.directive = function(tokens, aStringBuffer, allowedDirect return buffer; } +Preprocessor.prototype.hash = function(tokens, aStringBuffer) +{ + // Grab the next token, C preprocessor directives follow '#' immediately. + var buffer = aStringBuffer ? aStringBuffer : new StringBuffer(), + token = tokens.next(); + + // #pragma (C Preprocessor directive) + if (token === TOKEN_PRAGMA) + { + token = tokens.skip_whitespace(); + + // '#pragma mark' directive is used in Xcode editor for creating labels, + // which is irrelevant to Cappuccino - just swallow this line + if (token === TOKEN_MARK) + { + while ((token = tokens.next()).indexOf("\n") < 0); + } + } + // if not a #pragma directive, it should not be processed here + else + throw new SyntaxError(this.error_message("*** Expected \"pragma\" to follow # but instead saw \"" + token + "\".")); +} + Preprocessor.prototype.implementation = function(tokens, /*StringBuffer*/ aStringBuffer) { var buffer = aStringBuffer, @@ -542,6 +568,11 @@ Preprocessor.prototype.implementation = function(tokens, /*StringBuffer*/ aStrin CONCAT(instance_methods, this.method(tokens, ivar_names)); } + // If we reach a # symbol, we may be at a C preprocessor directive. + else if (token == TOKEN_HASH) + { + this.hash(tokens, buffer); + } // Check if we've reached @end... else if (token == TOKEN_PREPROCESSOR) { @@ -896,6 +927,10 @@ Preprocessor.prototype.preprocess = function(tokens, /*StringBuffer*/ aStringBuf // If we reach an @ symbol, we are at a preprocessor directive. else if (token == TOKEN_PREPROCESSOR) this.directive(tokens, buffer); + + // If we reach a # symbol, we may be at a C preprocessor directive. + else if (token == TOKEN_HASH) + this.hash(tokens, buffer); // If we reach a bracket, we will either be preprocessing a message send, a literal // array, or an array index. diff --git a/Tests/Foundation/CPArrayTest.j b/Tests/Foundation/CPArrayTest.j index f195d99f8..c9894fc10 100644 --- a/Tests/Foundation/CPArrayTest.j +++ b/Tests/Foundation/CPArrayTest.j @@ -155,6 +155,61 @@ } } +- (void)testInsertObjectInArraySortedByDescriptors +{ + var descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:YES]]; + var array = [1, 3, 5]; + + [array insertObject: 0 inArraySortedByDescriptors:descriptors]; + [self assert:[0, 1, 3, 5] equals:array]; + + array = [1, 3, 5]; + [array insertObject: 2 inArraySortedByDescriptors:descriptors]; + [self assert:[1, 2, 3, 5] equals:array]; + + array = [1, 3, 5]; + [array insertObject: 1 inArraySortedByDescriptors:descriptors]; + [self assert:[1, 1, 3, 5] equals:array]; + + array = [1, 3, 5]; + [array insertObject: 6 inArraySortedByDescriptors:descriptors]; + [self assert:[1, 3, 5, 6] equals:array]; + + array = [1, 3, 5]; + [array insertObject: 3 inArraySortedByDescriptors:descriptors]; + [self assert:[1, 3, 3, 5] equals:array]; + + array = []; + [array insertObject: 3 inArraySortedByDescriptors:descriptors]; + [self assert:[3] equals:array]; + + descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:NO]]; + + array = [5, 3, 1]; + [array insertObject: 0 inArraySortedByDescriptors:descriptors]; + [self assert:[5, 3, 1, 0] equals:array]; + + array = [5, 3, 1]; + [array insertObject: 2 inArraySortedByDescriptors:descriptors]; + [self assert:[5, 3, 2, 1] equals:array]; + + array = [5, 3, 1]; + [array insertObject: 1 inArraySortedByDescriptors:descriptors]; + [self assert:[5, 3, 1, 1] equals:array]; + + array = [5, 3, 1]; + [array insertObject: 6 inArraySortedByDescriptors:descriptors]; + [self assert:[6, 5, 3, 1] equals:array]; + + array = [5, 3, 1]; + [array insertObject: 3 inArraySortedByDescriptors:descriptors]; + [self assert:[5, 3, 3, 1] equals:array]; + + array = []; + [array insertObject: 3 inArraySortedByDescriptors:descriptors]; + [self assert:[3] equals:array]; +} + - (void)testInitWithArrayCopyItems { var a = [[CopyableObject new], 2, 3]; @@ -163,6 +218,16 @@ [self assert:a notEqual:b]; } +- (void)testIsEqualToArray +{ + var a = [1, 2, 3], + b = [5]; + + [self assertTrue:[a isEqualToArray:a]]; + [self assertFalse:[a isEqualToArray:b]]; + [self assertFalse:[a isEqualToArray:nil]]; +} + @end @implementation CPArray (reverse)