Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 271 lines (228 sloc) 9.189 kb
adcd4de @danwood More progress on async loading
danwood authored
1 /*
2 iMedia Browser Framework <http://karelia.com/imedia/>
3
a63baee @danwood update copyrights to 2011. Fix a couple of files that were not inden…
danwood authored
4 Copyright (c) 2005-2011 by Karelia Software et al.
adcd4de @danwood More progress on async loading
danwood authored
5
6 iMedia Browser is based on code originally developed by Jason Terhorst,
7 further developed for Sandvox by Greg Hulands, Dan Wood, and Terrence Talbot.
8 The new architecture for version 2.0 was developed by Peter Baumgartner.
9 Contributions have also been made by Matt Gough, Martin Wennerberg and others
10 as indicated in source files.
11
12 The iMedia Browser Framework is licensed under the following terms:
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in all or substantial portions of the Software without restriction, including
17 without limitation the rights to use, copy, modify, merge, publish,
18 distribute, sublicense, and/or sell copies of the Software, and to permit
19 persons to whom the Software is furnished to do so, subject to the following
20 conditions:
21
e34e1b6 @danwood BORING ....
danwood authored
22 Redistributions of source code must retain the original terms stated here,
23 including this list of conditions, the disclaimer noted below, and the
a63baee @danwood update copyrights to 2011. Fix a couple of files that were not inden…
danwood authored
24 following copyright notice: Copyright (c) 2005-2011 by Karelia Software et al.
adcd4de @danwood More progress on async loading
danwood authored
25
e34e1b6 @danwood BORING ....
danwood authored
26 Redistributions in binary form must include, in an end-user-visible manner,
27 e.g., About window, Acknowledgments window, or similar, either a) the original
28 terms stated here, including this list of conditions, the disclaimer noted
29 below, and the aforementioned copyright notice, or b) the aforementioned
30 copyright notice and a link to karelia.com/imedia.
adcd4de @danwood More progress on async loading
danwood authored
31
e34e1b6 @danwood BORING ....
danwood authored
32 Neither the name of Karelia Software, nor Sandvox, nor the names of
33 contributors to iMedia Browser may be used to endorse or promote products
34 derived from the Software without prior and express written permission from
35 Karelia Software or individual contributors, as appropriate.
adcd4de @danwood More progress on async loading
danwood authored
36
37 Disclaimer: THE SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS
38 "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
39 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
40 AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
41 LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF
42 CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH, THE
43 SOFTWARE OR THE USE OF, OR OTHER DEALINGS IN, THE SOFTWARE.
44 */
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
45
135075f Added an author line in the header of each source file. This is done …
Peter Baumgartner authored
46
47 // Author: Dan Wood
48
49
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
50 #import "IMBDynamicTableView.h"
dbec1f2 Preparing to add some 10.6/10.5 variant behavior to the pasteboard be…
Daniel Jalkut authored
51 #import "IMBCommon.h"
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
52
03527b6 @danwood Point out where we are defining interfaces to non-public SPIs, appare…
danwood authored
53 @interface NSTableView(NotPublicSoThisMightBeAProblemForTheMAS)
ef66f63 @danwood Slightly more progress on link parsers. Got the 10.5-style combo tab…
danwood authored
54 // Define this so we can call through to super, for when we are running Snow Leopard
55 - (void)reloadDataForRowIndexes:(NSIndexSet *)rowIndexes columnIndexes:(NSIndexSet *)columnIndexes;
56 @end
57
58 @interface IMBDynamicTableView()
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
59
60 - (void)_removeCachedViewForRow:(NSInteger)row;
61 - (void)_removeCachedViewsInIndexSet:(NSIndexSet *)rowIndexes;
62
63 @end
64
65 @implementation IMBDynamicTableView
66
67 @dynamic delegate;
68
adcd4de @danwood More progress on async loading
danwood authored
69 - (id)initWithCoder:(NSCoder *)coder
70 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
71 self = [super initWithCoder:coder];
72 return self;
73 }
74
adcd4de @danwood More progress on async loading
danwood authored
75 - (void)dealloc
76 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
77 [_viewsInVisibleRows release];
78 _viewsInVisibleRows = nil;
79 [super dealloc];
80 }
81
518d7b8 @danwood Separate out the thumbnail and metadata loading operations so that th…
danwood authored
82 - (BOOL)wantsThumbnails;
83 {
84 return NO; // subclass can override.
85 }
86
adcd4de @danwood More progress on async loading
danwood authored
87 - (void)_ensureVisibleRowsIsCreated
88 {
89 if (_viewsInVisibleRows == nil)
90 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
91 _viewsInVisibleRows = [NSMutableDictionary new];
92 }
93 }
94
adcd4de @danwood More progress on async loading
danwood authored
95 - (void)viewWillDraw
96 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
97 // We have to call super first in case the NSTableView does some layout in -viewWillDraw
98 [super viewWillDraw];
99
100 // Calculate the new visible rows and let the delegate do any extra work it wants to
101 NSRange newVisibleRows = [self rowsInRect:self.visibleRect];
102 BOOL visibleRowsNeedsUpdate = !NSEqualRanges(newVisibleRows, _visibleRows);
103 NSRange oldVisibleRows = _visibleRows;
adcd4de @danwood More progress on async loading
danwood authored
104 if (visibleRowsNeedsUpdate)
105 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
106 _visibleRows = newVisibleRows;
107 // Give the delegate a chance to do any pre-loading or special work that it wants to do
adcd4de @danwood More progress on async loading
danwood authored
108 if ([[self delegate] respondsToSelector:@selector(dynamicTableView:changedVisibleRowsFromRange:toRange:)])
109 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
110 [[self delegate] dynamicTableView:self changedVisibleRowsFromRange:oldVisibleRows toRange:newVisibleRows];
111 }
112 // We always have to update our views if the visible area changed
113 _viewsNeedUpdate = YES;
114 }
115
adcd4de @danwood More progress on async loading
danwood authored
116 if (_viewsNeedUpdate)
117 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
118 _viewsNeedUpdate = NO;
119 // Update any views that the delegate wants to give us
adcd4de @danwood More progress on async loading
danwood authored
120 if ([[self delegate] respondsToSelector:@selector(dynamicTableView:viewForRow:)])
121 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
122
adcd4de @danwood More progress on async loading
danwood authored
123 if (visibleRowsNeedsUpdate)
124 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
125 // First, remove any views that are no longer before our new visible rows
126 NSMutableIndexSet *rowIndexesToRemove = [NSMutableIndexSet indexSetWithIndexesInRange:oldVisibleRows];
127 // Remove any rows from the set that are STILL visible; we want a resulting index set that has the views which are no longer on screen.
128 [rowIndexesToRemove removeIndexesInRange:newVisibleRows];
129 // Remove those views which are no longer visible
130 [self _removeCachedViewsInIndexSet:rowIndexesToRemove];
131 }
132
133 [self _ensureVisibleRowsIsCreated];
134
135 // Finally, update and add in any new views given to us by the delegate. Use [NSNull null] for things that don't have a view at a particular row
adcd4de @danwood More progress on async loading
danwood authored
136 for (NSInteger row = _visibleRows.location; row < NSMaxRange(_visibleRows); row++)
137 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
138 NSNumber *key = [NSNumber numberWithInteger:row];
139 id view = [_viewsInVisibleRows objectForKey:key];
adcd4de @danwood More progress on async loading
danwood authored
140 if (view == nil)
141 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
142 // We don't already have a view at that row
143 view = [[self delegate] dynamicTableView:self viewForRow:row];
adcd4de @danwood More progress on async loading
danwood authored
144 if (view != nil)
145 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
146 [self addSubview:view];
de48954 @danwood mostly some cleanup of a method name that a global search and replace…
danwood authored
147 }
148 else
adcd4de @danwood More progress on async loading
danwood authored
149 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
150 // Use null as a place holder so we don't call the delegate again until the row is relaoded
151 view = [NSNull null];
152 }
153 [_viewsInVisibleRows setObject:view forKey:key];
154 }
155 }
156 }
157 }
158 }
159
adcd4de @danwood More progress on async loading
danwood authored
160 - (void)_removeCachedViewForRow:(NSInteger)row
161 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
162 _viewsNeedUpdate = YES;
adcd4de @danwood More progress on async loading
danwood authored
163 if (_viewsInVisibleRows != nil)
164 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
165 NSNumber *key = [NSNumber numberWithInteger:row];
166 id view = [_viewsInVisibleRows objectForKey:key];
adcd4de @danwood More progress on async loading
danwood authored
167 if (view != nil)
168 {
169 if (view != [NSNull null])
170 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
171 [view removeFromSuperview];
172 }
173 [_viewsInVisibleRows removeObjectForKey:key];
174 }
175 }
176 }
177
adcd4de @danwood More progress on async loading
danwood authored
178 - (void)_removeCachedViewsInIndexSet:(NSIndexSet *)rowIndexes
179 {
180 if (rowIndexes != nil)
181 {
182 for (NSInteger row = [rowIndexes firstIndex]; row != NSNotFound; row = [rowIndexes indexGreaterThanIndex:row])
183 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
184 [self _removeCachedViewForRow:row];
185 }
186 }
187 }
188
adcd4de @danwood More progress on async loading
danwood authored
189 - (void)_removeAllCachedViews
190 {
191 if (_viewsInVisibleRows != nil)
192 {
193 for (id view in [_viewsInVisibleRows allValues])
194 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
195 [view removeFromSuperview];
196 }
197 [_viewsInVisibleRows release];
198 _viewsInVisibleRows = nil;
199 }
200 }
201
202 // Reset our visible row cache when we reload things
adcd4de @danwood More progress on async loading
danwood authored
203 - (void)reloadData
204 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
205 [self _removeAllCachedViews];
206 _visibleRows = NSMakeRange(NSNotFound, 0);
207 [super reloadData];
208 }
209
adcd4de @danwood More progress on async loading
danwood authored
210 - (void)noteHeightOfRowsWithIndexesChanged:(NSIndexSet *)indexSet
211 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
212 // We replace all cached views, as their offsets may change
213 [self _removeAllCachedViews];
214 _visibleRows = NSMakeRange(NSNotFound, 0);
215 [super noteHeightOfRowsWithIndexesChanged:indexSet];
216 }
217
adcd4de @danwood More progress on async loading
danwood authored
218 // Snow Leopard Only, so we implement our own if we're not running snow leopard.
219
220 - (void)reloadDataForRowIndexes:(NSIndexSet *)rowIndexes columnIndexes:(NSIndexSet *)columnIndexes
221 {
222 [self _removeCachedViewsInIndexSet:rowIndexes];
223
27b160d Renamed 10.6 compile time and runtime checking macros to be more read…
Peter Baumgartner authored
224 if (IMBRunningOnSnowLeopardOrNewer())
adcd4de @danwood More progress on async loading
danwood authored
225 {
226 [super reloadDataForRowIndexes:rowIndexes columnIndexes:columnIndexes];
227 }
228 else
229 {
ef66f63 @danwood Slightly more progress on link parsers. Got the 10.5-style combo tab…
danwood authored
230 // LEOPARD implementation. Ignore the columns; mark the whole row dirty.
231 NSRect dirtyRect = NSZeroRect;
232 NSUInteger currentIndex = [rowIndexes firstIndex];
233 while (currentIndex != NSNotFound)
234 {
235 NSRect rowDirtyRect = [self rectOfRow:currentIndex];
236 dirtyRect = NSUnionRect(dirtyRect, rowDirtyRect);
237 currentIndex = [rowIndexes indexGreaterThanIndex:currentIndex];
238 }
239 [self setNeedsDisplayInRect:dirtyRect];
adcd4de @danwood More progress on async loading
danwood authored
240 }
241 }
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
242
adcd4de @danwood More progress on async loading
danwood authored
243 - (void)setDelegate:(id <IMBDynamicTableViewDelegate>)delegate
244 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
245 [super setDelegate:delegate];
246 }
247
adcd4de @danwood More progress on async loading
danwood authored
248 - (id <IMBDynamicTableViewDelegate>)delegate
249 {
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
250 return (id <IMBDynamicTableViewDelegate>)[super delegate];
251 }
252
adcd4de @danwood More progress on async loading
danwood authored
253 // Method called after KVO detects a change, to reload the table row.
254 - (void)_reloadRow:(NSNumber *)aRowNumber
255 {
256 NSInteger row = [aRowNumber intValue];
257 if (row != NSNotFound)
258 {
259 [self reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
260 }
261
262 }
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
263
59a7e74 @danwood Trying to diagnose; I overrode draggingSourceOperationMaskForLocal to…
danwood authored
264 // Make external drags work
265 - (NSDragOperation) draggingSourceOperationMaskForLocal:(BOOL)inLocal
266 {
267 return NSDragOperationCopy;
268 }
269
6350b30 @danwood Preliminary combo view with asynchronous loading.
danwood authored
270 @end
Something went wrong with that request. Please try again.