Skip to content

Commit

Permalink
Merge branch 'mouseUpDownWithModifierFlags' into dragNDrop+hovering
Browse files Browse the repository at this point in the history
Conflicts:
	JNWCollectionView/JNWCollectionViewFramework.m
  • Loading branch information
kettch committed Jun 2, 2016
2 parents 916315b + 5bf26cb commit 15ce41a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
11 changes: 7 additions & 4 deletions JNWCollectionView/JNWCollectionViewFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewScrollPosition) {
@protocol JNWCollectionViewDelegate <NSObject>

@optional
/// Tells the delegate that the mouse is down inside of the item at the specified index path.
- (void)collectionView:(JNWCollectionView *)collectionView mouseDownInItemAtIndexPath:(NSIndexPath *)indexPath;
/// Tells the delegate that the mouse is down inside of the item at the specified index path with specific modifier flags.
- (void)collectionView:(JNWCollectionView *)collectionView mouseDownInItemAtIndexPath:(NSIndexPath *)indexPath withModifierFlags:(NSEventModifierFlags)modFlags;

/// Tells the delegate that the mouse click originating from the item at the specified index path is now up.
/// Tells the delegate that the mouse click originating from the item at the specified index path is now up with specific modifier flags.
///
/// The mouse up event can occur outside of the originating cell.
- (void)collectionView:(JNWCollectionView *)collectionView mouseUpInItemAtIndexPath:(NSIndexPath *)indexPath;
- (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
19 changes: 17 additions & 2 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 @@ -137,7 +139,9 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
- (void)setDelegate:(id<JNWCollectionViewDelegate>)delegate {
_delegate = delegate;
_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:)];
Expand Down Expand Up @@ -1018,8 +1022,13 @@ - (void)mouseDownInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(N
NSLog(@"***index path not found for selection.");
}

if (_collectionViewFlags.delegateMouseDown) {
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 @@ -1034,9 +1043,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 15ce41a

Please sign in to comment.