diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 61e68082d..a48c11c39 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -589,9 +589,7 @@ _mouseDownEvent = anEvent; var location = [self convertPoint:[anEvent locationInWindow] fromView:nil], - row = FLOOR(location.y / (_itemSize.height + _verticalMargin)), - column = FLOOR(location.x / (_itemSize.width + _horizontalMargin)), - index = row * _numberOfColumns + column; + index = [self _indexAtPoint:location]; if (index >= 0 && index < _items.length) { @@ -727,6 +725,28 @@ return _delegate; } +/*! + @ignore +*/ +- (CPMenu)menuForEvent:(CPEvent)theEvent +{ + if (![[self delegate] respondsToSelector:@selector(collectionView:menuForItemAtIndex:)]) + return [super menuForEvent:theEvent]; + + var location = [self convertPoint:[theEvent locationInWindow] fromView:nil], + index = [self _indexAtPoint:location]; + + return [_delegate collectionView:self menuForItemAtIndex:index]; +} + +- (int)_indexAtPoint:(CGPoint)thePoint +{ + var row = FLOOR(thePoint.y / (_itemSize.height + _verticalMargin)), + column = FLOOR(thePoint.x / (_itemSize.width + _horizontalMargin)); + + return row * _numberOfColumns + column; +} + - (CPCollectionViewItem)itemAtIndex:(unsigned)anIndex { return [_items objectAtIndex:anIndex];