Skip to content

Commit

Permalink
fixed a drag and drop issue related to focusing another window; added…
Browse files Browse the repository at this point in the history
… layoutSubviews method to PXListViewCell; added reloadRowAtIndex method; removed PXLog log messages
  • Loading branch information
jivadevoe committed Apr 27, 2011
1 parent df16a08 commit b660abd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
1 change: 1 addition & 0 deletions Classes/PXListView+Private.h
Expand Up @@ -38,5 +38,6 @@ typedef NSInteger PXIsDragStartResult;
- (void)enqueueCell:(PXListViewCell*)cell;

- (void)contentViewBoundsDidChange:(NSNotification*)notification;
-(void)layoutCellsForResizeEvent;

@end
38 changes: 2 additions & 36 deletions Classes/PXListView+UserInteraction.m
Expand Up @@ -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 )
Expand Down Expand Up @@ -329,7 +329,6 @@ -(void) setShowsDropHighlight: (BOOL)inState

-(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (PXListViewDropHighlight*)outDropHighlight
{
PXLog( @"====================" );
*outDropHighlight = PXListViewDropOn;

if( _numberOfRows > 0 )
Expand All @@ -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,
Expand All @@ -356,42 +353,31 @@ -(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.
{
PXListViewCell* theCell = [self visibleCellForRow: idx];
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.
{
cellHeight = 0;
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;
Expand All @@ -400,7 +386,6 @@ -(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (P
}
else
{
PXLog( @"*** ON %d", NSUIntegerMax );
return NSUIntegerMax;
}
}
Expand All @@ -426,8 +411,6 @@ -(PXListViewCell*) cellForDropHighlight: (PXListViewDropHighlight*)dhl row: (NSU

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
PXLog( @"draggingEntered" );

NSDragOperation theOperation = NSDragOperationNone;

NSUInteger oldDropRow = _dropRow;
Expand All @@ -436,14 +419,11 @@ - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)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 )
{
Expand All @@ -456,23 +436,16 @@ - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)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;
}


- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)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;
Expand All @@ -481,15 +454,12 @@ - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)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
Expand All @@ -501,15 +471,11 @@ - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)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];
}

Expand Down
3 changes: 3 additions & 0 deletions Classes/PXListView.h
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions Classes/PXListView.m
Expand Up @@ -105,6 +105,13 @@ - (void)setDelegate:(id<PXListViewDelegate>)delegate
}
}

-(void)reloadRowAtIndex:(NSInteger)inIndex;
{
[self cacheCellLayout];
[self layoutCells];
//[self layoutCellsForResizeEvent];
}

- (void)reloadData
{
id <PXListViewDelegate> delegate = [self delegate];
Expand Down Expand Up @@ -312,6 +319,11 @@ - (PXListViewCell*)visibleCellForRow:(NSUInteger)row
return outCell;
}

-(PXListViewCell *)cellForRowAtIndex:(NSUInteger)inIndex
{
return [self visibleCellForRow:inIndex];
}

- (NSArray*)visibleCellsForRowIndexes:(NSIndexSet*)rows
{
NSMutableArray *theCells = [NSMutableArray array];
Expand Down Expand Up @@ -495,6 +507,7 @@ - (void)layoutCells
{
NSInteger row = [cell row];
[cell setFrame:[self rectOfRow:row]];
[cell layoutSubviews];
}

NSRect bounds = [self bounds];
Expand Down Expand Up @@ -599,6 +612,7 @@ - (void)viewWillStartLiveResize
if([self usesLiveResize])
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowSizing:) name:NSSplitViewDidResizeSubviewsNotification object:self.superview];
}

-(void)layoutCellsForResizeEvent
{
//Change the layout of the cells
Expand Down Expand Up @@ -628,6 +642,7 @@ -(void)layoutCellsForResizeEvent

_currentRange = [self visibleRange];
}

-(void)viewDidEndLiveResize
{
[super viewDidEndLiveResize];
Expand Down
2 changes: 2 additions & 0 deletions Classes/PXListViewCell.h
Expand Up @@ -35,4 +35,6 @@
- (id)initWithReusableIdentifier:(NSString*)identifier;
- (void)prepareForReuse;

-(void)layoutSubviews;

@end
8 changes: 8 additions & 0 deletions Classes/PXListViewCell.m
Expand Up @@ -144,6 +144,14 @@ - (void)prepareForReuse
_dropHighlight = PXListViewDropNowhere;
}


#pragma mark layout

-(void)layoutSubviews;
{

}

#pragma mark -
#pragma mark Accessibility

Expand Down

0 comments on commit b660abd

Please sign in to comment.