Skip to content

Commit

Permalink
Merge branch 'hovering' into dragNDrop+hovering
Browse files Browse the repository at this point in the history
Conflicts:
	JNWCollectionView/JNWCollectionViewCell.m
	JNWCollectionView/JNWCollectionViewFramework.m
  • Loading branch information
kettch committed Jun 2, 2016
2 parents 15ce41a + 0f3fa89 commit b2a7fb1
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 deletions.
2 changes: 1 addition & 1 deletion JNWCollectionView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
AB38E38D17DF099A00D50B3C /* JNWScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWScrollView.m; path = external/JNWScrollView/JNWScrollView.m; sourceTree = SOURCE_ROOT; };
AB39819C1731A1B50062B2E0 /* JNWCollectionViewReusableView+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JNWCollectionViewReusableView+Private.h"; path = "JNWCollectionView/JNWCollectionViewReusableView+Private.h"; sourceTree = SOURCE_ROOT; };
AB3C71E8170CA8D3004A91DB /* JNWCollectionViewFramework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWCollectionViewFramework.h; path = JNWCollectionView/JNWCollectionViewFramework.h; sourceTree = SOURCE_ROOT; };
AB3C71E9170CA8D3004A91DB /* JNWCollectionViewFramework.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWCollectionViewFramework.m; path = JNWCollectionView/JNWCollectionViewFramework.m; sourceTree = SOURCE_ROOT; usesTabs = 1; };
AB3C71E9170CA8D3004A91DB /* JNWCollectionViewFramework.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWCollectionViewFramework.m; path = JNWCollectionView/JNWCollectionViewFramework.m; sourceTree = SOURCE_ROOT; };
AB3C71EA170CA8D3004A91DB /* JNWCollectionView+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JNWCollectionView+Private.h"; path = "JNWCollectionView/JNWCollectionView+Private.h"; sourceTree = SOURCE_ROOT; };
AB3C71EB170CA8D3004A91DB /* JNWCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWCollectionViewCell.h; path = JNWCollectionView/JNWCollectionViewCell.h; sourceTree = SOURCE_ROOT; };
AB3C71EC170CA8D3004A91DB /* JNWCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWCollectionViewCell.m; path = JNWCollectionView/JNWCollectionViewCell.m; sourceTree = SOURCE_ROOT; };
Expand Down
3 changes: 3 additions & 0 deletions JNWCollectionView/JNWCollectionView+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

- (void)mouseDownInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event;
- (void)mouseUpInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event;
- (void)mouseMovedInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event;
- (void)mouseExitedInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event;
- (void)mouseEnteredInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event;
- (void)doubleClickInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event;
- (void)rightClickInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event;

Expand Down
4 changes: 4 additions & 0 deletions JNWCollectionView/JNWCollectionViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
/// effects to the selection process.
@property (nonatomic, assign) BOOL selected;

/// Sets the hovering state with no animation. Subclassers should override this method to add side
/// effects to the hovering process.
@property (nonatomic, assign) BOOL hovered;

/// Calls -setSelected:, animating any changes to the content of the background view, such as
/// settting the background iamge or color.
- (void)setSelected:(BOOL)selected animated:(BOOL)animate;
Expand Down
28 changes: 28 additions & 0 deletions JNWCollectionView/JNWCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ - (void)didLayoutWithFrame:(CGRect)frame {
// for subclasses
}

- (void)updateTrackingAreas {
[[self.trackingAreas copy] enumerateObjectsUsingBlock:^(NSTrackingArea * _Nonnull trackingArea, NSUInteger idx, BOOL * _Nonnull stop) {
[self removeTrackingArea:trackingArea];
}];

NSTrackingAreaOptions options = (NSTrackingActiveAlways | NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved);
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self bounds] options:options owner:self userInfo:nil];
[self addTrackingArea:area];
}

- (NSView *)contentView {
if (_contentView == nil) {
_contentView = [[NSView alloc] initWithFrame:self.bounds];
Expand Down Expand Up @@ -186,6 +196,24 @@ - (void)mouseUp:(NSEvent *)theEvent {
}
}

- (void)mouseMoved:(NSEvent *)theEvent {
[super mouseMoved:theEvent];

[self.collectionView mouseMovedInCollectionViewCell:self withEvent:theEvent];
}

- (void)mouseEntered:(NSEvent *)theEvent {
[super mouseMoved:theEvent];

[self.collectionView mouseEnteredInCollectionViewCell:self withEvent:theEvent];
}

- (void)mouseExited:(NSEvent *)theEvent {
[super mouseMoved:theEvent];

[self.collectionView mouseExitedInCollectionViewCell:self withEvent:theEvent];
}

- (void)rightMouseDown:(NSEvent *)theEvent {
[self.collectionView rightClickInCollectionViewCell:self withEvent:theEvent];
}
Expand Down
9 changes: 9 additions & 0 deletions JNWCollectionView/JNWCollectionViewFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewScrollPosition) {
- (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.");

/// Tells the delegate that the mouse moved inside the specified index path cell.
- (void)collectionView:(JNWCollectionView *)collectionView mouseMovedInItemAtIndexPath:(NSIndexPath *)indexPath withModifierFlags:(NSEventModifierFlags)modFlags;

/// Tells the delegate that the mouse entered in the specified index path cell.
- (void)collectionView:(JNWCollectionView *)collectionView mouseEnteredInItemAtIndexPath:(NSIndexPath *)indexPath withModifierFlags:(NSEventModifierFlags)modFlags;

/// Tells the delegate that the mouse exited from the specified index path cell.
- (void)collectionView:(JNWCollectionView *)collectionView mouseExitedInItemAtIndexPath:(NSIndexPath *)indexPath withModifierFlags:(NSEventModifierFlags)modFlags;

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

Expand Down
44 changes: 39 additions & 5 deletions JNWCollectionView/JNWCollectionViewFramework.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ @interface JNWCollectionView() {
unsigned int delegateMouseDownWithModifiers:1;
unsigned int delegateMouseUp:1;
unsigned int delegateMouseUpWithModifiers:1;
unsigned int delegateMouseMoved:1;
unsigned int delegateMouseEntered:1;
unsigned int delegateMouseExited:1;
unsigned int delegateShouldSelect:1;
unsigned int delegateDidSelect:1;
unsigned int delegateShouldDeselect:1;
Expand Down Expand Up @@ -142,6 +145,9 @@ - (void)setDelegate:(id<JNWCollectionViewDelegate>)delegate {
_collectionViewFlags.delegateMouseUpWithModifiers = [delegate respondsToSelector:@selector(collectionView:mouseUpInItemAtIndexPath: withModifierFlags:)];
_collectionViewFlags.delegateMouseDown = [delegate respondsToSelector:@selector(collectionView:mouseDownInItemAtIndexPath:)];
_collectionViewFlags.delegateMouseDownWithModifiers = [delegate respondsToSelector:@selector(collectionView:mouseDownInItemAtIndexPath:withModifierFlags:)];
_collectionViewFlags.delegateMouseMoved = [delegate respondsToSelector:@selector(collectionView:mouseMovedInItemAtIndexPath:withModifierFlags:)];
_collectionViewFlags.delegateMouseEntered = [delegate respondsToSelector:@selector(collectionView:mouseEnteredInItemAtIndexPath:withModifierFlags:)];
_collectionViewFlags.delegateMouseExited = [delegate respondsToSelector:@selector(collectionView:mouseExitedInItemAtIndexPath: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 @@ -505,10 +511,10 @@ - (NSArray *)indexPathsForVisibleItems {
}

- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(JNWCollectionViewScrollPosition)scrollPosition animated:(BOOL)animated {
if (_collectionViewFlags.delegateShouldScroll && ![self.delegate collectionView:self shouldScrollToItemAtIndexPath:indexPath]) {
return;
}
if (_collectionViewFlags.delegateShouldScroll && ![self.delegate collectionView:self shouldScrollToItemAtIndexPath:indexPath]) {
return;
}

CGRect rect = [self rectForItemAtIndexPath:indexPath];
CGRect visibleRect = self.documentVisibleRect;

Expand Down Expand Up @@ -967,7 +973,7 @@ - (void)selectItemAtIndexPath:(NSIndexPath *)indexPath
selectionType:(JNWCollectionViewSelectionType)selectionType {
if (indexPath == nil)
return;
NSMutableSet *indexesToSelect = [NSMutableSet set];

if (selectionType == JNWCollectionViewSelectionTypeSingle) {
Expand Down Expand Up @@ -1055,6 +1061,34 @@ - (void)mouseUpInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSE
}
}

- (void)mouseMovedInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event {
if (_collectionViewFlags.delegateMouseMoved) {
NSIndexPath *indexPath = [self indexPathForCell:cell];
[self.delegate collectionView:self mouseMovedInItemAtIndexPath:indexPath withModifierFlags:event.modifierFlags];
}
}

- (void)mouseEnteredInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event {
if (_collectionViewFlags.delegateMouseEntered) {
NSIndexPath *indexPath = [self indexPathForCell:cell];
[self.delegate collectionView:self mouseEnteredInItemAtIndexPath:indexPath withModifierFlags:event.modifierFlags];
}

[[self.visibleCellsMap allValues] enumerateObjectsUsingBlock:^(JNWCollectionViewCell *cell, NSUInteger index, BOOL *stop) {
cell.hovered = NO;
}];
cell.hovered = YES;
}

- (void)mouseExitedInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event {
if (_collectionViewFlags.delegateMouseExited) {
NSIndexPath *indexPath = [self indexPathForCell:cell];
[self.delegate collectionView:self mouseExitedInItemAtIndexPath:indexPath withModifierFlags:event.modifierFlags];
}

cell.hovered = NO;
}

- (void)doubleClickInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(NSEvent *)event {
if (_collectionViewFlags.delegateDidDoubleClick) {
NSIndexPath *indexPath = [self indexPathForCell:cell];
Expand Down

0 comments on commit b2a7fb1

Please sign in to comment.