-
-
Save curthard89/a9a103a7e6849240b6907afa86b95198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// IJGridView.h | |
// IconJar | |
// | |
// Created by Curtis Hard on 15/05/2014. | |
// Copyright (c) 2014 Curtis Hard. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "IJGridViewSectionCell.h" | |
#import "IJGridViewCell.h" | |
#import "IJGridViewScrollView.h" | |
#import "IJScrollView.h" | |
#import "IJLayerClipView.h" | |
#import "IJGridViewUtils.h" | |
typedef struct { | |
NSInteger section; | |
NSInteger index; | |
} IJFastIndexPath; | |
IJFastIndexPath * IJFastIndexPathCreate( NSInteger section, NSInteger index ); | |
void IJFastIndexPathFree( IJFastIndexPath * path ); | |
@interface NSIndexPath (IJGridView) | |
+ (NSIndexPath*)indexPathForIndex:(NSUInteger)row | |
section:(NSUInteger)section; | |
- (NSUInteger)section; | |
- (NSUInteger)index; | |
+ (NSIndexSet *)indexPathForColumn:(NSUInteger)column | |
row:(NSUInteger)row; | |
- (NSUInteger)column; | |
- (NSUInteger)row; | |
@end | |
@class IJGridView; | |
@protocol IJGridViewDataSource <NSObject> | |
@required | |
- (IJGridViewSectionCell*)gridView:(IJGridView*)view cellForSection:(NSInteger)section; | |
- (NSInteger)gridView:(IJGridView*)view numberOfItemsInSection:(NSInteger)sectionIndex; | |
- (IJGridViewCell*)gridView:(IJGridView*)view cellForItemAtIndexPath:(NSIndexPath*)indexPath; | |
- (id)gridView:(IJGridView *)view itemForIndexPath:(NSIndexPath *)path; | |
@optional | |
- (void)gridView:(IJGridView *)gridView didForceTouchItemAtIndexPath:(NSIndexPath *)path; | |
- (NSInteger)numberOfSectionsInGridView:(IJGridView*)gridView; | |
- (IJGridViewDrawingState)gridView:(IJGridView *)gridView wantsDrawingStateWithProposedDrawingState:(IJGridViewDrawingState)proposedState; | |
- (NSMenu *)gridView:(IJGridView *)view menuForItemsAtIndexPaths:(NSArray *)indexPaths contextItem:(NSIndexPath *)path; | |
- (NSString *)gridView:(IJGridView *)view tooltipForItemAtIndexPath:(NSIndexPath *)indexPath; | |
- (void)gridView:(IJGridView *)view didChangeToScreen:(NSScreen *)screen; | |
- (void)gridView:(IJGridView *)view handleSpaceBarEvent:(NSEvent *)event; | |
- (void)gridView:(IJGridView *)view didDoubleClickWithEvent:(NSEvent *)event | |
contextItem:(NSIndexPath *)path; | |
- (void)gridView:(IJGridView *)view wantsRenameForIndexPaths:(NSArray *)indexPaths; | |
- (void)gridView:(IJGridView *)view wantsCopyToPasteboardForIndexPaths:(NSArray *)indexPaths; | |
- (void)gridView:(IJGridView *)view wantsDeleteForIndexPaths:(NSArray *)indexPaths; | |
- (BOOL)gridView:(IJGridView *)view wantsDragForIndexPaths:(NSArray *)indexPaths event:(NSEvent *)event localisedPoint:(NSPoint)point; | |
- (void)gridView:(IJGridView *)view liveResizeDidChange:(BOOL)flag; | |
- (void)gridView:(IJGridView *)view willShowSection:(NSInteger)section shownBefore:(BOOL)flag; | |
- (void)gridView:(IJGridView *)view willHideSection:(NSInteger)section; | |
- (void)gridView:(IJGridView *)view didSelectItemsAtIndexPaths:(NSArray *)paths; | |
- (void)gridView:(IJGridView *)view dragEntered:(BOOL)entered; | |
- (void)gridView:(IJGridView *)view mouseEnteredIndexPath:(NSIndexPath *)path; | |
- (void)gridView:(IJGridView *)view mouseExitedIndexPath:(NSIndexPath *)path; | |
- (NSDragOperation)gridView:(IJGridView *)view validateDrop:(id<NSDraggingInfo>)info proposedIndexPath:(NSIndexPath *)path; | |
- (BOOL)gridView:(IJGridView *)view acceptDrop:(id<NSDraggingInfo>)info indexPath:(NSIndexPath *)path; | |
- (CGFloat)gridView:(IJGridView *)view clampMaginationByZoomingIn:(BOOL)flag; | |
- (NSSize)gridView:(IJGridView *)view itemSizeWithProposedSize:(NSSize)size drawingState:(IJGridViewDrawingState)state; | |
- (void)gridView:(IJGridView *)view prefetchItemsAtIndexPaths:(NSArray *)paths; | |
- (BOOL)gridView:(IJGridView *)view validateMenuItem:(NSMenuItem *)menuItem; | |
@end | |
typedef NS_OPTIONS(NSInteger, IJGridViewKeyboardDirection) { | |
IJGridViewKeyboardDirectionUp, | |
IJGridViewKeyboardDirectionDown, | |
IJGridViewKeyboardDirectionLeft, | |
IJGridViewKeyboardDirectionRight | |
}; | |
@interface IJGridView : NSVisualEffectView { | |
BOOL allowsMultiSelection; | |
BOOL liveGridResize; | |
BOOL darkMode; | |
CGFloat sectionHeaderHeight; | |
NSSize itemSize; | |
CGFloat itemMargin; | |
BOOL displaySectionHeaders; | |
NSView * maxYAccessoryView; | |
@private | |
NSRange _lastCurrentRange; | |
BOOL _dragging; | |
BOOL _inNativeLiveResize; | |
NSRange _currentRange; | |
NSInteger _numberOfItems; | |
NSInteger _numberOfSections; | |
NSInteger* _numberOfItemsInSection; | |
NSInteger* _numberIndexInSection; | |
NSInteger* _columnsIndex; | |
NSInteger* _rowIndex; | |
NSRange* _sectionRanges; | |
CGRect* _cellFrames; | |
CGRect* _sectionFrames; | |
NSInteger* _sectionsIndex; | |
NSInteger** _gridIndexes; | |
NSInteger _numberOfRows; | |
id<IJGridViewDataSource> _dataSource; | |
BOOL* _sectionsOnScreen; | |
BOOL* _shownSections; | |
BOOL shouldAnimateLoadIn; | |
BOOL _ignoreFrameCheck; | |
NSMutableDictionary* _reusableCells; | |
NSMutableDictionary* _cacheCells; | |
NSMutableDictionary* _sectionCells; | |
NSMutableSet * _selection; | |
NSIndexPath * _multiSelectedPath; | |
NSIndexPath * _keyboardMultiSelectPath; | |
NSMutableDictionary * _indexPathIndexes; | |
NSMutableDictionary * _indexPathIndex; | |
NSMutableDictionary * _idCells; | |
NSTimer * _selectionTimer; | |
NSTimer * _scrollTimer; | |
IJFastIndexPath ** _indexPathsForIndex; | |
NSInteger ** _indexForIndexPath; | |
NSRect _proposedFrameRect; | |
NSInteger _allocatedColumnCount; | |
NSInteger _allocatedRowCount; | |
NSInteger * _allocatedIndexPathCount; | |
NSInteger _scrollIndex; | |
CALayer * _marqueLayer; | |
NSMutableIndexSet * _marqueSet; | |
NSIndexSet * _tempMarqueSet; | |
CGFloat _screenScale; | |
BOOL _scrolling; | |
// dragging | |
NSPoint _mouseDownPoint; | |
BOOL _mouseDownCmdWasDown; | |
BOOL _mouseDownShiftWasDown; | |
BOOL _mouseEventsWereDisabled; | |
// events | |
NSTrackingArea * _mouseTrackingArea; | |
IJGridViewCell * _mouseHoverCell; | |
IJGridViewCell * _mouseDownCell; | |
struct { | |
unsigned int willShowSection: 1; | |
unsigned int willHideSection: 1; | |
unsigned int liveResize: 1; | |
unsigned int magnification: 1; | |
unsigned int redrawState: 1; | |
unsigned int validateDrop: 1; | |
unsigned int acceptDrop: 1; | |
unsigned int dragEntered: 1; | |
unsigned int screenChanged: 1; | |
unsigned int proposedItemSize: 1; | |
unsigned int prefetchItems: 1; | |
unsigned int mouseEnteredPath: 1; | |
unsigned int mouseExitedPath: 1; | |
unsigned int wantsDrag: 1; | |
unsigned int doubleClick: 1; | |
unsigned int validatesMenuItem: 1; | |
unsigned int wantsRename: 1; | |
unsigned int wantsDelete: 1; | |
unsigned int wantsCopy: 1; | |
unsigned int pressureChange: 1; | |
} _respondsTo; | |
} | |
@property (nonatomic, assign) CGFloat sectionHeaderHeight; | |
@property (nonatomic, assign) NSSize itemSize; | |
@property (nonatomic, assign) CGFloat itemMargin; | |
@property (nonatomic, assign) BOOL displaySectionHeaders; | |
@property (nonatomic, assign) BOOL liveGridResize; | |
@property (nonatomic, assign ) BOOL allowsMultiSelection; | |
@property (nonatomic, retain ) NSView * maxYAccessoryView; | |
@property (nonatomic, assign) BOOL shouldAnimateLoadIn; | |
@property (nonatomic, assign) BOOL darkMode; | |
+ (CGFloat)animationTime; | |
+ (CAMediaTimingFunction *)timingFunction; | |
- (void)setWillFrequentlyChangeSize:(BOOL)flag; | |
- (void)setDataSource:(id<IJGridViewDataSource>)newSource; | |
- (void)scrollToTop; | |
- (void)reloadData:(BOOL)scrollToTop; | |
- (void)reloadData; | |
- (void)propagateSelectionChanges; | |
- (void)clearCellCache; | |
- (void)relayout; | |
- (void)endDrag; | |
- (void)deselectAll; | |
- (BOOL)inNativeLiveResize; | |
- (void)updateItemSize; | |
- (void)selectIndexPaths:(NSArray<NSIndexPath *> *)paths | |
byExtendingSelection:(BOOL)extend; | |
- (NSArray<NSIndexPath *>*)visibleIndexPaths; | |
- (NSImage *)imageOfDragItemAtIndexPath:(NSIndexPath *)path; | |
- (id)dequeueReusableCellWithIdentifier:(NSString*)identifier; | |
- (NSInteger)sectionForItemAtIndex:(NSInteger)index; | |
- (NSInteger)sectionIndexForItemAtIndex:(NSInteger)index; | |
- (NSInteger)sectionForPoint:(NSPoint)point; | |
- (NSRange)rangeOfSectionsInRect:(CGRect)containRect; | |
- (NSIndexSet *)indexesOfItemsInRect:(CGRect)containRect; | |
- (CGRect)rectForItemAtIndex:(NSInteger)index; | |
- (NSRange)rangeOfItemsInRect:(CGRect)containRect; | |
- (NSIndexPath *)indexPathForPoint:(NSPoint)point; | |
- (NSRect)frameOfItemAtPathOnScreen:(NSIndexPath *)path; | |
- (NSRect)boundsOfItemAtPathOnScreen:(NSIndexPath *)path; | |
- (NSArray *)selectedItemsIndexPaths; | |
- (NSArray *)visibleCells; | |
- (void)scrollIndexPathToVisible:(NSIndexPath *)path; | |
- (void)checkResponderForDisplayUpdates; | |
- (void)reloadItemAtIndexPath:(NSIndexPath *)path; | |
- (void)reloadItemsAtIndexPaths:(NSArray *)paths; | |
- (void)reloadSections; | |
- (void)visuallyReloadAllItems; | |
- (void)purgeCells; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment