-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathJAListView.h
140 lines (113 loc) · 5.83 KB
/
JAListView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// JAListView.h
// JAListView
//
// Created by Josh Abernathy on 9/29/10.
// Copyright 2010 Maybe Apps. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "JAEdgeInsets.h"
@class JAListView;
@class JAListViewItem;
extern NSString * const JAListViewDraggingPasteboardType;
@protocol JAListViewDataSource <NSObject>
- (NSUInteger)numberOfItemsInListView:(JAListView *)listView;
- (JAListViewItem *)listView:(JAListView *)listView viewAtIndex:(NSUInteger)index;
@end
@protocol JAListViewDelegate <NSObject>
@optional
/**
* Mouse down/up doesn't necessarily mean the view will be selected. These methods will always get called regardless of the return value of -listView:shouldSelectView:.
*/
- (void)listView:(JAListView *)listView mouseDownOnView:(JAListViewItem *)view withEvent:(NSEvent *)event;
- (void)listView:(JAListView *)listView mouseUpOnView:(JAListViewItem *)view withEvent:(NSEvent *)event;
- (void)listView:(JAListView *)listView rightMouseDownOnView:(JAListViewItem *)view withEvent:(NSEvent *)event;
/**
* A view being selected doesn't necessarily mean it was selected by a click. For instance, keyboard selection will also trigger these events. If the selection is coming from a click, then -listView:willSelectView: gets called on mouse down and -listView:didSelectView: will get called on mouse up while still inside the view.
*/
- (BOOL)listView:(JAListView *)listView shouldSelectView:(JAListViewItem *)view;
- (void)listView:(JAListView *)listView willSelectView:(JAListViewItem *)view;
- (void)listView:(JAListView *)listView didSelectView:(JAListViewItem *)view;
- (void)listView:(JAListView *)listView didDeselectView:(JAListViewItem *)view;
- (void)listView:(JAListView *)listView didRemoveView:(JAListViewItem *)view;
@end
@protocol JAListViewDraggingSourceDelegate <NSObject>
- (BOOL)listView:(JAListView *)listView shouldDragView:(JAListViewItem *)view;
- (void)listView:(JAListView *)listView didStartDraggingView:(JAListViewItem *)view;
- (void)listView:(JAListView *)listView didEndDraggingView:(JAListViewItem *)view;
@end
@protocol JAListViewDraggingDestinationDelegate <NSObject>
- (BOOL)listView:(JAListView *)listView shouldAcceptViews:(NSArray *)draggedViews location:(NSPoint)location;
- (void)listView:(JAListView *)listView dragEntered:(NSArray *)draggedViews location:(NSPoint)location;
- (void)listView:(JAListView *)listView dragUpdated:(NSArray *)draggedViews location:(NSPoint)location;
- (void)listView:(JAListView *)listView dragEnded:(NSArray *)draggedViews location:(NSPoint)location;
- (void)listView:(JAListView *)listView dragExited:(NSArray *)draggedViews location:(NSPoint)location;
@end
@interface JAListView : NSView {
NSMutableArray *cachedViews;
NSArray *cachedVisibleViews;
CGFloat heightForAllContent;
id<JAListViewDataSource> dataSource;
id<JAListViewDelegate> delegate;
id<JAListViewDraggingSourceDelegate> draggingSourceDelegate;
id<JAListViewDraggingDestinationDelegate> draggingDestinationDelegate;
BOOL canCallDataSourceInParallel;
NSPoint margin;
CGFloat *cachedLocations;
__weak JAListViewItem *viewBeingSelected;
NSColor *backgroundColor;
BOOL isResizingManually;
BOOL conditionallyUseLayerBacking;
}
- (void)setup;
- (void)reloadData;
- (void)reloadDataAnimated:(BOOL)animated;
- (void)reloadDataWithAnimation:(void (^)(NSView *newSuperview, NSArray *viewsToAdd, NSArray *viewsToRemove, NSArray *viewsToMove))animationBlock;
- (void)reloadLayout;
- (void)reloadLayoutAnimated:(BOOL)animated;
- (void)reloadLayoutWithAnimation:(void (^)(NSView *newSuperview, NSArray *viewsToAdd, NSArray *viewsToRemove, NSArray *viewsToMove))animationBlock;
- (NSUInteger)numberOfViews;
- (JAListViewItem *)viewAtIndex:(NSUInteger)index;
- (NSInteger)indexForView:(JAListViewItem *)view;
- (BOOL)isViewVisible:(JAListViewItem *)view;
- (BOOL)containsViewItem:(JAListViewItem *)viewItem;
- (JAListViewItem *)viewAtPoint:(NSPoint)point;
/*
* Default implementation returns proposedY. Subclasses could implement this to adjust the Y location for the view.
*/
- (CGFloat)yForView:(JAListViewItem *)view proposedY:(CGFloat)proposedY;
/**
* Default implementation returns proposedHeight. Subclasses could implement this to adjust the height of the view.
*/
- (CGFloat)heightForView:(JAListViewItem *)view proposedHeight:(CGFloat)proposedHeight;
- (CGFloat)cachedYLocationForView:(JAListViewItem *)view;
/**
* Will call the delegate's listView:didSelectView: but not listView:shouldSelectView: or listView:willSelectView:.
*/
- (void)selectView:(JAListViewItem *)view;
/**
* Will call the delegate's listView:didDeselectView:.
*/
- (void)deselectView:(JAListViewItem *)view;
/**
* Will call the delegate's listView:didDeselectView: for each of the selected views.
*/
- (void)deselectAllViews;
- (void)markViewBeingUsedForInertialScrolling:(JAListViewItem *)newView;
- (void)unmarkViewBeingUsedForInertialScrolling:(JAListViewItem *)view;
- (void)clearViewsBeingUsedForInertialScrolling;
@property (nonatomic, readonly) NSScrollView *scrollView;
@property (nonatomic, assign) IBOutlet id<JAListViewDataSource> dataSource;
@property (nonatomic, assign) IBOutlet id<JAListViewDelegate> delegate;
@property (nonatomic, assign) IBOutlet id<JAListViewDraggingSourceDelegate> draggingSourceDelegate;
@property (nonatomic, assign) IBOutlet id<JAListViewDraggingDestinationDelegate> draggingDestinationDelegate;
@property (nonatomic, assign) BOOL canCallDataSourceInParallel;
@property (nonatomic, readonly) NSArray *visibleViews;
@property (nonatomic, assign) NSPoint margin;
@property (nonatomic, assign) JAEdgeInsets padding;
@property (nonatomic, retain) NSColor *backgroundColor;
@property (nonatomic, readonly) CGFloat heightForAllContent;
@property (nonatomic, assign) BOOL conditionallyUseLayerBacking;
@property (nonatomic, readonly) NSArray *selectedViews;
@property (nonatomic, assign) BOOL allowNoSelection;
@end