diff --git a/Classes/PXListView+Private.h b/Classes/PXListView+Private.h index b3464f0..65d2e96 100644 --- a/Classes/PXListView+Private.h +++ b/Classes/PXListView+Private.h @@ -38,5 +38,6 @@ typedef NSInteger PXIsDragStartResult; - (void)enqueueCell:(PXListViewCell*)cell; - (void)contentViewBoundsDidChange:(NSNotification*)notification; +-(void)layoutCellsForResizeEvent; @end diff --git a/Classes/PXListView+UserInteraction.m b/Classes/PXListView+UserInteraction.m index 8cc83db..e3c70fe 100644 --- a/Classes/PXListView+UserInteraction.m +++ b/Classes/PXListView+UserInteraction.m @@ -211,8 +211,8 @@ - (void)handleMouseDown:(NSEvent*)theEvent inCell:(PXListViewCell*)theCell // Ce - (void)handleMouseDownOutsideCells: (NSEvent*)theEvent { #pragma unused(theEvent) - [[self window] makeFirstResponder: self]; - + //[[self window] makeFirstResponder: self]; + // if( _allowsEmptySelection ) [self deselectRows]; else if( _numberOfRows > 1 ) @@ -329,7 +329,6 @@ -(void) setShowsDropHighlight: (BOOL)inState -(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (PXListViewDropHighlight*)outDropHighlight { - PXLog( @"====================" ); *outDropHighlight = PXListViewDropOn; if( _numberOfRows > 0 ) @@ -339,14 +338,12 @@ -(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (P { if( _cellYOffsets[x] > pos.y ) { - PXLog( @"cellYOffset[%ld] = %f > %f", x, _cellYOffsets[x], pos.y ); break; } idx = x; } - PXLog( @"idx = %ld", idx ); CGFloat cellHeight = 0, cellOffset = 0, @@ -356,8 +353,6 @@ -(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (P cellOffset = _cellYOffsets[idx]; nextCellOffset = _cellYOffsets[idx+1]; cellHeight = nextCellOffset -cellOffset; - if( cellHeight < 0 ) - PXLog( @"Urk. (1)" ); } else if( idx < _numberOfRows && _numberOfRows > 0 ) // drag is somewhere close to or beyond end of list. { @@ -365,8 +360,6 @@ -(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (P cellHeight = [theCell frame].size.height; cellOffset = [theCell frame].origin.y; nextCellOffset = cellOffset +cellHeight; - if( cellHeight < 0 ) - PXLog( @"Urk. (2)" ); } else if( idx >= _numberOfRows && _numberOfRows > 0 ) // drag is somewhere close to or beyond end of list. { @@ -374,24 +367,17 @@ -(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (P cellOffset = [[self documentView] frame].size.height; nextCellOffset = cellOffset; idx = NSUIntegerMax; - if( cellHeight < 0 ) - PXLog( @"Urk. (3)" ); } - PXLog( @"cellHeight = %f", cellHeight ); if( pos.y < (cellOffset +(cellHeight / 6.0)) ) { *outDropHighlight = PXListViewDropAbove; - PXLog( @"*** ABOVE %ld", idx ); } else if( pos.y > (nextCellOffset -(cellHeight / 6.0)) ) { idx++; *outDropHighlight = PXListViewDropAbove; - PXLog( @"*** ABOVE %ld (below %d)", idx, idx -1 ); } - else - PXLog( @"*** ON %ld", idx ); if( idx > _numberOfRows ) idx = NSUIntegerMax; @@ -400,7 +386,6 @@ -(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (P } else { - PXLog( @"*** ON %d", NSUIntegerMax ); return NSUIntegerMax; } } @@ -426,8 +411,6 @@ -(PXListViewCell*) cellForDropHighlight: (PXListViewDropHighlight*)dhl row: (NSU - (NSDragOperation)draggingEntered:(id )sender { - PXLog( @"draggingEntered" ); - NSDragOperation theOperation = NSDragOperationNone; NSUInteger oldDropRow = _dropRow; @@ -436,14 +419,11 @@ - (NSDragOperation)draggingEntered:(id )sender if( [_delegate respondsToSelector: @selector(listView:validateDrop:proposedRow:proposedDropHighlight:)] ) { NSPoint dragMouse = [[self documentView] convertPoint: [sender draggingLocation] fromView: nil]; - PXLog( @"dragMouse = %@", NSStringFromPoint(dragMouse) ); _dropRow = [self indexOfRowAtPoint: dragMouse returningProposedDropHighlight: &_dropHighlight]; theOperation = [_delegate listView: self validateDrop: sender proposedRow: _dropRow proposedDropHighlight: _dropHighlight]; } - - PXLog( @"op = %lu, row = %ld, hl = %lu", theOperation, _dropRow, _dropHighlight ); if( theOperation != NSDragOperationNone ) { @@ -456,14 +436,9 @@ - (NSDragOperation)draggingEntered:(id )sender [oldCell setDropHighlight: PXListViewDropNowhere]; [newCell setDropHighlight: _dropHighlight]; PXListViewDropHighlight dropHL = ((_dropRow == _numberOfRows) ? PXListViewDropAbove : PXListViewDropOn); - PXLog( @"TOTAL DROP %s", dropHL == PXListViewDropOn ? "on" : "above" ); [[self documentView] setDropHighlight: dropHL]; } - else - PXLog(@"TOTAL DROP unchanged"); } - else - PXLog( @"TOTAL DROP NOWHERE" ); return theOperation; } @@ -471,8 +446,6 @@ - (NSDragOperation)draggingEntered:(id )sender - (NSDragOperation)draggingUpdated:(id )sender /* if the destination responded to draggingEntered: but not to draggingUpdated: the return value from draggingEntered: is used */ { - PXLog( @"draggingUpdated" ); - NSDragOperation theOperation = NSDragOperationNone; NSUInteger oldDropRow = _dropRow; @@ -481,15 +454,12 @@ - (NSDragOperation)draggingUpdated:(id )sender /* if the destina if( [_delegate respondsToSelector: @selector(listView:validateDrop:proposedRow:proposedDropHighlight:)] ) { NSPoint dragMouse = [[self documentView] convertPoint: [sender draggingLocation] fromView: nil]; - PXLog( @"dragMouse = %@", NSStringFromPoint(dragMouse) ); _dropRow = [self indexOfRowAtPoint: dragMouse returningProposedDropHighlight: &_dropHighlight]; theOperation = [_delegate listView: self validateDrop: sender proposedRow: _dropRow proposedDropHighlight: _dropHighlight]; } - NSLog( @"op = %lu, row = %ld, hl = %lu", theOperation, _dropRow, _dropHighlight ); - if( theOperation != NSDragOperationNone ) { if( oldDropRow != _dropRow @@ -501,15 +471,11 @@ - (NSDragOperation)draggingUpdated:(id )sender /* if the destina [oldCell setDropHighlight: PXListViewDropNowhere]; [newCell setDropHighlight: _dropHighlight]; PXListViewDropHighlight dropHL = ((_dropRow == _numberOfRows) ? PXListViewDropAbove : PXListViewDropOn); - NSLog( @"TOTAL DROP %s", dropHL == PXListViewDropOn ? "on" : "above" ); [[self documentView] setDropHighlight: dropHL]; } - else - PXLog(@"TOTAL DROP unchanged"); } else { - PXLog( @"TOTAL DROP NOWHERE" ); [self setShowsDropHighlight: NO]; } @@ -556,6 +522,11 @@ - (void)draggingEnded:(id )sender [oldCell setDropHighlight: PXListViewDropNowhere]; [self setShowsDropHighlight: NO]; + + for(PXListViewCell *cell in [self visibleCells]) + { + [cell setDropHighlight:PXListViewDropNowhere]; + } } diff --git a/Classes/PXListView.h b/Classes/PXListView.h index 3f3ba1a..db37ce6 100644 --- a/Classes/PXListView.h +++ b/Classes/PXListView.h @@ -60,10 +60,13 @@ @property (nonatomic, assign) BOOL usesLiveResize; - (void)reloadData; +-(void)reloadRowAtIndex:(NSInteger)inIndex; - (PXListViewCell*)dequeueCellWithReusableIdentifier:(NSString*)identifier; - (NSArray*)visibleCells; +-(PXListViewCell *)cellForRowAtIndex:(NSUInteger)inIndex; + - (NSRange)visibleRange; - (NSRect)rectOfRow:(NSUInteger)row; - (void)deselectRows; diff --git a/Classes/PXListView.m b/Classes/PXListView.m index fb802c5..746cebb 100644 --- a/Classes/PXListView.m +++ b/Classes/PXListView.m @@ -91,9 +91,7 @@ - (void)dealloc - (void)setDelegate:(id)delegate { - [_delegate removeObserver:_delegate - name:PXListViewSelectionDidChange - object:self]; + [[NSNotificationCenter defaultCenter] removeObserver:_delegate name:PXListViewSelectionDidChange object:self]; _delegate = delegate; @@ -105,6 +103,13 @@ - (void)setDelegate:(id)delegate } } +-(void)reloadRowAtIndex:(NSInteger)inIndex; +{ + [self cacheCellLayout]; + [self layoutCells]; + //[self layoutCellsForResizeEvent]; +} + - (void)reloadData { id delegate = [self delegate]; @@ -312,6 +317,11 @@ - (PXListViewCell*)visibleCellForRow:(NSUInteger)row return outCell; } +-(PXListViewCell *)cellForRowAtIndex:(NSUInteger)inIndex +{ + return [self visibleCellForRow:inIndex]; +} + - (NSArray*)visibleCellsForRowIndexes:(NSIndexSet*)rows { NSMutableArray *theCells = [NSMutableArray array]; @@ -495,6 +505,7 @@ - (void)layoutCells { NSInteger row = [cell row]; [cell setFrame:[self rectOfRow:row]]; + [cell layoutSubviews]; } NSRect bounds = [self bounds]; @@ -596,23 +607,56 @@ - (void)scrollRowToVisible:(NSUInteger)row - (void)viewWillStartLiveResize { _widthPriorToResize = NSWidth([self contentViewRect]); + if([self usesLiveResize]) + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowSizing:) name:NSSplitViewDidResizeSubviewsNotification object:self.superview]; } -- (void)viewDidEndLiveResize +-(void)layoutCellsForResizeEvent { - [super viewDidEndLiveResize]; - - //If we use live resize the view will already be up to date - if(![self usesLiveResize]) { - //Change the layout of the cells - [_visibleCells removeAllObjects]; - [[self documentView] setSubviews:[NSArray array]]; + //Change the layout of the cells + [_visibleCells removeAllObjects]; + [[self documentView] setSubviews:[NSArray array]]; + + [self cacheCellLayout]; + [self addCellsFromVisibleRange]; + + if ([_delegate conformsToProtocol:@protocol(PXListViewDelegate)]) + { + CGFloat totalHeight = 0; + + for (NSUInteger i = 0; i < _numberOfRows; i++) + { + CGFloat cellHeight = [_delegate listView:self heightOfRow:i]; + totalHeight += cellHeight +[self cellSpacing]; + } - [self cacheCellLayout]; - [self addCellsFromVisibleRange]; + _totalHeight = totalHeight; - _currentRange = [self visibleRange]; + NSRect bounds = [self bounds]; + CGFloat documentHeight = _totalHeight > NSHeight(bounds) ? _totalHeight:(NSHeight(bounds) - 2); + + [[self documentView] setFrame:NSMakeRect(0.0f, 0.0f, NSWidth([self contentViewRect]), documentHeight)]; } + + _currentRange = [self visibleRange]; +} + +-(void)viewDidEndLiveResize +{ + [super viewDidEndLiveResize]; + + //If we use live resize the view will already be up to date + if (![self usesLiveResize]) + { + [self layoutCellsForResizeEvent]; + } + if ([self usesLiveResize]) + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSSplitViewDidResizeSubviewsNotification object:self.superview]; +} + +-(void)windowSizing:(NSNotification *)inNot +{ + [self layoutCellsForResizeEvent]; } #pragma mark - diff --git a/Classes/PXListViewCell.h b/Classes/PXListViewCell.h index a1e247c..44b3835 100644 --- a/Classes/PXListViewCell.h +++ b/Classes/PXListViewCell.h @@ -35,4 +35,6 @@ - (id)initWithReusableIdentifier:(NSString*)identifier; - (void)prepareForReuse; +-(void)layoutSubviews; + @end diff --git a/Classes/PXListViewCell.m b/Classes/PXListViewCell.m index 3f68940..736f665 100644 --- a/Classes/PXListViewCell.m +++ b/Classes/PXListViewCell.m @@ -144,6 +144,14 @@ - (void)prepareForReuse _dropHighlight = PXListViewDropNowhere; } + +#pragma mark layout + +-(void)layoutSubviews; +{ + +} + #pragma mark - #pragma mark Accessibility