From 82be5a661e929eeac061b93446b693172a3f911a Mon Sep 17 00:00:00 2001 From: Michal Zaborowski Date: Tue, 12 Jan 2016 19:51:13 +0100 Subject: [PATCH] Fix Issue #153 Wrong contentInsets when connected mouse --- .../JNWCollectionViewFramework.m | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/JNWCollectionView/JNWCollectionViewFramework.m b/JNWCollectionView/JNWCollectionViewFramework.m index 67cdd03..2d2d2f0 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.m +++ b/JNWCollectionView/JNWCollectionViewFramework.m @@ -115,6 +115,12 @@ static void JNWCollectionViewCommonInit(JNWCollectionView *collectionView) { collectionView.backgroundColor = NSColor.whiteColor; collectionView.drawsBackground = YES; + + [[NSNotificationCenter defaultCenter] addObserver:collectionView selector:@selector(preferredScrollerStyleDidChangeNotification:) name:NSPreferredScrollerStyleDidChangeNotification object:nil]; +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSPreferredScrollerStyleDidChangeNotification object:nil]; } - (id)initWithFrame:(NSRect)frameRect { @@ -131,9 +137,23 @@ - (id)initWithCoder:(NSCoder *)aDecoder { return self; } +#pragma mark Notifications + +- (void)preferredScrollerStyleDidChangeNotification:(NSNotification *)note { + NSView *documentView = self.documentView; + + if (!CGSizeEqualToSize(NSSizeToCGSize(documentView.frame.size), NSSizeToCGSize(self.contentSize))) { + CGRect documentFrame = documentView.frame; + documentFrame.size.width = self.contentSize.width; + documentView.frame = documentFrame; + + [self.collectionViewLayout invalidateLayout]; + } +} + #pragma mark Delegate and data source -- (void)setDelegate:(id)delegate { +- (void)setDelegate:(id)delegate { _delegate = delegate; _collectionViewFlags.delegateMouseUp = [delegate respondsToSelector:@selector(collectionView:mouseUpInItemAtIndexPath:)]; _collectionViewFlags.delegateMouseDown = [delegate respondsToSelector:@selector(collectionView:mouseDownInItemAtIndexPath:)];