Permalink
Browse files

fixed a drag and drop issue related to focusing another window; added…

… layoutSubviews method to PXListViewCell; added reloadRowAtIndex method; removed PXLog log messages
  • Loading branch information...
jivadevoe authored and Alex Rozanski committed Apr 27, 2011
1 parent c0c719a commit 91307a86dd4c67bc039cc042b39de80e0944a459
@@ -38,5 +38,6 @@ typedef NSInteger PXIsDragStartResult;
- (void)enqueueCell:(PXListViewCell*)cell;
- (void)contentViewBoundsDidChange:(NSNotification*)notification;
+-(void)layoutCellsForResizeEvent;
@end
@@ -218,8 +218,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 )
@@ -336,7 +336,6 @@ -(void) setShowsDropHighlight: (BOOL)inState
-(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (PXListViewDropHighlight*)outDropHighlight
{
- PXLog( @"====================" );
*outDropHighlight = PXListViewDropOn;
if( _numberOfRows > 0 )
@@ -346,14 +345,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,
@@ -363,42 +360,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;
@@ -407,7 +393,6 @@ -(NSUInteger) indexOfRowAtPoint: (NSPoint)pos returningProposedDropHighlight: (P
}
else
{
- PXLog( @"*** ON %d", NSUIntegerMax );
return NSUIntegerMax;
}
}
@@ -433,8 +418,6 @@ -(PXListViewCell*) cellForDropHighlight: (PXListViewDropHighlight*)dhl row: (NSU
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
- PXLog( @"draggingEntered" );
-
NSDragOperation theOperation = NSDragOperationNone;
NSUInteger oldDropRow = _dropRow;
@@ -443,14 +426,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 )
{
@@ -463,23 +443,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;
@@ -488,15 +461,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
@@ -508,15 +478,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];
}
View
@@ -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;
View
@@ -106,6 +106,13 @@ - (void)setDelegate:(id<PXListViewDelegate>)delegate
}
}
+-(void)reloadRowAtIndex:(NSInteger)inIndex;
+{
+ [self cacheCellLayout];
+ [self layoutCells];
+ //[self layoutCellsForResizeEvent];
+}
+
- (void)reloadData
{
id <PXListViewDelegate> delegate = [self delegate];
@@ -235,6 +242,11 @@ - (PXListViewCell*)visibleCellForRow:(NSUInteger)row
return outCell;
}
+-(PXListViewCell *)cellForRowAtIndex:(NSUInteger)inIndex
+{
+ return [self visibleCellForRow:inIndex];
+}
+
- (NSArray*)visibleCellsForRowIndexes:(NSIndexSet*)rows
{
NSMutableArray *theCells = [NSMutableArray array];
@@ -494,6 +506,7 @@ - (void)layoutCells
{
NSInteger row = [cell row];
[cell setFrame:[self rectOfRow:row]];
+ [cell layoutSubviews];
}
NSRect bounds = [self bounds];
@@ -598,6 +611,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
@@ -627,6 +641,7 @@ -(void)layoutCellsForResizeEvent
_currentRange = [self visibleRange];
}
+
-(void)viewDidEndLiveResize
{
[super viewDidEndLiveResize];
View
@@ -35,4 +35,6 @@
- (id)initWithReusableIdentifier:(NSString*)identifier;
- (void)prepareForReuse;
+-(void)layoutSubviews;
+
@end
View
@@ -144,6 +144,14 @@ - (void)prepareForReuse
_dropHighlight = PXListViewDropNowhere;
}
+
+#pragma mark layout
+
+-(void)layoutSubviews;
+{
+
+}
+
#pragma mark -
#pragma mark Accessibility

0 comments on commit 91307a8

Please sign in to comment.