Skip to content

Commit

Permalink
Restoring old delegate calls and making them deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
kettch committed Jun 1, 2016
1 parent 41087ce commit 5bf26cb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions JNWCollectionView/JNWCollectionViewFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewScrollPosition) {
/// The mouse up event can occur outside of the originating cell.
- (void)collectionView:(JNWCollectionView *)collectionView mouseUpInItemAtIndexPath:(NSIndexPath *)indexPath withModifierFlags:(NSEventModifierFlags)modFlags;

- (void)collectionView:(JNWCollectionView *)collectionView mouseDownInItemAtIndexPath:(NSIndexPath *)indexPath __deprecated_msg("Use collectionView:mouseDownInItemAtIndexPath:withModifierFlags: instead.");
- (void)collectionView:(JNWCollectionView *)collectionView mouseUpInItemAtIndexPath:(NSIndexPath *)indexPath __deprecated_msg("Use collectionView:mouseUpInItemAtIndexPath:withModifierFlags: instead.");

/// Asks the delegate if the item at the specified index path should be selected.
- (BOOL)collectionView:(JNWCollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath;

Expand Down
31 changes: 23 additions & 8 deletions JNWCollectionView/JNWCollectionViewFramework.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ @interface JNWCollectionView() {
unsigned int dataSourceViewForSupplementaryView:1;

unsigned int delegateMouseDown:1;
unsigned int delegateMouseDownWithModifiers:1;
unsigned int delegateMouseUp:1;
unsigned int delegateMouseUpWithModifiers:1;
unsigned int delegateShouldSelect:1;
unsigned int delegateDidSelect:1;
unsigned int delegateShouldDeselect:1;
Expand Down Expand Up @@ -135,17 +137,19 @@ - (id)initWithCoder:(NSCoder *)aDecoder {

- (void)setDelegate:(id<JNWCollectionViewDelegate>)delegate {
_delegate = delegate;
_collectionViewFlags.delegateMouseUp = [delegate respondsToSelector:@selector(collectionView:mouseUpInItemAtIndexPath: withModifierFlags:)];
_collectionViewFlags.delegateMouseDown = [delegate respondsToSelector:@selector(collectionView:mouseDownInItemAtIndexPath:withModifierFlags:)];
_collectionViewFlags.delegateMouseUp = [delegate respondsToSelector:@selector(collectionView:mouseUpInItemAtIndexPath:)];
_collectionViewFlags.delegateMouseUpWithModifiers = [delegate respondsToSelector:@selector(collectionView:mouseUpInItemAtIndexPath: withModifierFlags:)];
_collectionViewFlags.delegateMouseDown = [delegate respondsToSelector:@selector(collectionView:mouseDownInItemAtIndexPath:)];
_collectionViewFlags.delegateMouseDownWithModifiers = [delegate respondsToSelector:@selector(collectionView:mouseDownInItemAtIndexPath:withModifierFlags:)];
_collectionViewFlags.delegateShouldSelect = [delegate respondsToSelector:@selector(collectionView:shouldSelectItemAtIndexPath:)];
_collectionViewFlags.delegateDidSelect = [delegate respondsToSelector:@selector(collectionView:didSelectItemAtIndexPath:)];
_collectionViewFlags.delegateShouldDeselect = [delegate respondsToSelector:@selector(collectionView:shouldDeselectItemAtIndexPath:)];
_collectionViewFlags.delegateDidDeselect = [delegate respondsToSelector:@selector(collectionView:didDeselectItemAtIndexPath:)];
_collectionViewFlags.delegateDidDoubleClick = [delegate respondsToSelector:@selector(collectionView:didDoubleClickItemAtIndexPath:)];
_collectionViewFlags.delegateDidRightClick = [delegate respondsToSelector:@selector(collectionView:didRightClickItemAtIndexPath:)];
_collectionViewFlags.delegateDidEndDisplayingCell = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:)];
_collectionViewFlags.delegateShouldScroll = [delegate respondsToSelector:@selector(collectionView:shouldScrollToItemAtIndexPath:)];
_collectionViewFlags.delegateDidScroll = [delegate respondsToSelector:@selector(collectionView:didScrollToItemAtIndexPath:)];
_collectionViewFlags.delegateDidEndDisplayingCell = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:)];
_collectionViewFlags.delegateShouldScroll = [delegate respondsToSelector:@selector(collectionView:shouldScrollToItemAtIndexPath:)];
_collectionViewFlags.delegateDidScroll = [delegate respondsToSelector:@selector(collectionView:didScrollToItemAtIndexPath:)];
}

- (void)setDataSource:(id<JNWCollectionViewDataSource>)dataSource {
Expand Down Expand Up @@ -1014,8 +1018,13 @@ - (void)mouseDownInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(N
NSLog(@"***index path not found for selection.");
}

if (_collectionViewFlags.delegateMouseDown) {
[self.delegate collectionView:self mouseDownInItemAtIndexPath:indexPath withModifierFlags:event.modifierFlags];
if (_collectionViewFlags.delegateMouseDownWithModifiers) {
[self.delegate collectionView:self mouseDownInItemAtIndexPath:indexPath withModifierFlags:event.modifierFlags];
} else if (_collectionViewFlags.delegateMouseDown) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self.delegate collectionView:self mouseDownInItemAtIndexPath:indexPath];
#pragma clang diagnostic pop
}

// Detect if modifier flags are held down.
Expand All @@ -1030,9 +1039,15 @@ - (void)mouseDownInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(N
}

- (void)mouseUpInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event {
if (_collectionViewFlags.delegateMouseUp) {
if (_collectionViewFlags.delegateMouseUpWithModifiers) {
NSIndexPath *indexPath = [self indexPathForCell:cell];
[self.delegate collectionView:self mouseUpInItemAtIndexPath:indexPath withModifierFlags:event.modifierFlags];
} else if (_collectionViewFlags.delegateMouseUp) {
NSIndexPath *indexPath = [self indexPathForCell:cell];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self.delegate collectionView:self mouseUpInItemAtIndexPath:indexPath];
#pragma clang diagnostic pop
}
}

Expand Down

0 comments on commit 5bf26cb

Please sign in to comment.