mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-26 11:01:03 +00:00
Cleaned drop handling code a bit more in NSTableView
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@36170 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3145e67066
commit
231105f428
2 changed files with 32 additions and 34 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2013-02-19 Quentin Mathe <quentin.mathe@gmail.com>
|
||||||
|
|
||||||
|
* Source/NSTableView.m (-_drawDropIndicator,
|
||||||
|
-_setDropOperationAndRow:usingPositionInRow:atPoint:, -draggingUpdated:):
|
||||||
|
Cleaned code a bit more.
|
||||||
|
|
||||||
2013-02-19 Quentin Mathe <quentin.mathe@gmail.com>
|
2013-02-19 Quentin Mathe <quentin.mathe@gmail.com>
|
||||||
|
|
||||||
* Source/NSTableView.m (-draggingUpdated:): Don't update the drop row and
|
* Source/NSTableView.m (-draggingUpdated:): Don't update the drop row and
|
||||||
|
|
|
@ -6204,7 +6204,6 @@ This method is deprecated, use -columnIndexesInRect:. */
|
||||||
newRect = [self bounds];
|
newRect = [self bounds];
|
||||||
NSFrameRectWithWidth(newRect, 2.0);
|
NSFrameRectWithWidth(newRect, 2.0);
|
||||||
oldDraggingRect = newRect;
|
oldDraggingRect = newRect;
|
||||||
currentDropRow = _numberOfRows;
|
|
||||||
}
|
}
|
||||||
else if (currentDropOperation == NSTableViewDropAbove)
|
else if (currentDropOperation == NSTableViewDropAbove)
|
||||||
{
|
{
|
||||||
|
@ -6241,10 +6240,6 @@ This method is deprecated, use -columnIndexesInRect:. */
|
||||||
newRect.origin.x -= _intercellSpacing.height / 2;
|
newRect.origin.x -= _intercellSpacing.height / 2;
|
||||||
newRect.size.height += _intercellSpacing.height;
|
newRect.size.height += _intercellSpacing.height;
|
||||||
|
|
||||||
oldDraggingRect = newRect;
|
|
||||||
oldDraggingRect.origin.y -= 1;
|
|
||||||
oldDraggingRect.size.height += 2;
|
|
||||||
|
|
||||||
newRect.size.height -= 1;
|
newRect.size.height -= 1;
|
||||||
newRect.origin.x += 3;
|
newRect.origin.x += 3;
|
||||||
newRect.size.width -= 3;
|
newRect.size.width -= 3;
|
||||||
|
@ -6256,14 +6251,11 @@ This method is deprecated, use -columnIndexesInRect:. */
|
||||||
//newRect.size.width -= 2;
|
//newRect.size.width -= 2;
|
||||||
newRect.size.height += 1;
|
newRect.size.height += 1;
|
||||||
}
|
}
|
||||||
else
|
NSFrameRectWithWidth(newRect, 2.0);
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
NSFrameRectWithWidth(newRect, 2.0);
|
|
||||||
// NSRectFill(newRect);
|
|
||||||
|
|
||||||
|
oldDraggingRect = newRect;
|
||||||
|
oldDraggingRect.origin.y -= 1;
|
||||||
|
oldDraggingRect.size.height += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
[_window flushWindow];
|
[_window flushWindow];
|
||||||
|
@ -6292,24 +6284,22 @@ view to drag. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSInteger) _computedRowAtPoint: (NSPoint)p
|
||||||
|
{
|
||||||
|
return (NSInteger)(p.y - _bounds.origin.y) / (NSInteger)_rowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) _setDropOperationAndRow: (NSInteger)row
|
- (void) _setDropOperationAndRow: (NSInteger)row
|
||||||
usingPositionInRow: (NSInteger)positionInRow
|
usingPositionInRow: (NSInteger)positionInRow
|
||||||
atPoint: (NSPoint)p
|
atPoint: (NSPoint)p
|
||||||
{
|
{
|
||||||
// Are we in the two middle quarters of the row? Use TableViewDropOn
|
NSParameterAssert(row > -1);
|
||||||
if ((positionInRow > _rowHeight / 4 && positionInRow <= (3 * _rowHeight) / 4)
|
BOOL isPositionInsideMiddleQuartersOfRow =
|
||||||
|| row > _numberOfRows)
|
(positionInRow > _rowHeight / 4 && positionInRow <= (3 * _rowHeight) / 4);
|
||||||
{
|
BOOL isDropOn = (row > _numberOfRows || isPositionInsideMiddleQuartersOfRow);
|
||||||
currentDropRow = (int)(p.y - _bounds.origin.y) / (int)_rowHeight;
|
|
||||||
currentDropOperation = NSTableViewDropOn;
|
[self setDropRow: (isDropOn ? [self _computedRowAtPoint: p] : row)
|
||||||
if (currentDropRow >= _numberOfRows)
|
dropOperation: (isDropOn ? NSTableViewDropOn : NSTableViewDropAbove)];
|
||||||
currentDropRow = -1;
|
|
||||||
}
|
|
||||||
else // drop above
|
|
||||||
{
|
|
||||||
currentDropRow = row;
|
|
||||||
currentDropOperation = NSTableViewDropAbove;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger) _dropRowFromQuarterPosition: (NSInteger)quarterPosition
|
- (NSInteger) _dropRowFromQuarterPosition: (NSInteger)quarterPosition
|
||||||
|
@ -6329,7 +6319,7 @@ view to drag. */
|
||||||
{
|
{
|
||||||
NSPoint p = [self convertPoint: [sender draggingLocation] fromView: nil];
|
NSPoint p = [self convertPoint: [sender draggingLocation] fromView: nil];
|
||||||
NSInteger positionInRow = (NSInteger)(p.y - _bounds.origin.y) % (int)_rowHeight;
|
NSInteger positionInRow = (NSInteger)(p.y - _bounds.origin.y) % (int)_rowHeight;
|
||||||
NSInteger quarterPosition = (NSInteger)(p.y - _bounds.origin.y) / _rowHeight * 4.;
|
NSInteger quarterPosition = (NSInteger)([self _computedRowAtPoint: p] * 4.);
|
||||||
NSInteger row = [self _dropRowFromQuarterPosition: quarterPosition];
|
NSInteger row = [self _dropRowFromQuarterPosition: quarterPosition];
|
||||||
NSDragOperation dragOperation = [sender draggingSourceOperationMask];
|
NSDragOperation dragOperation = [sender draggingSourceOperationMask];
|
||||||
BOOL isSameDropTargetThanBefore = (lastQuarterPosition == quarterPosition
|
BOOL isSameDropTargetThanBefore = (lastQuarterPosition == quarterPosition
|
||||||
|
@ -6340,10 +6330,15 @@ view to drag. */
|
||||||
if (isSameDropTargetThanBefore)
|
if (isSameDropTargetThanBefore)
|
||||||
return currentDragOperation;
|
return currentDragOperation;
|
||||||
|
|
||||||
|
/* Remember current drop target */
|
||||||
currentDragOperation = dragOperation;
|
currentDragOperation = dragOperation;
|
||||||
lastQuarterPosition = quarterPosition;
|
lastQuarterPosition = quarterPosition;
|
||||||
|
|
||||||
[self _setDropOperationAndRow: row usingPositionInRow: positionInRow atPoint: p];
|
/* The user can retarget this default drog using -setDropRow:dropOperation:
|
||||||
|
in -tableView:validateDrop:proposedRow:proposedDropOperation:. */
|
||||||
|
[self _setDropOperationAndRow: row
|
||||||
|
usingPositionInRow: positionInRow
|
||||||
|
atPoint: p];
|
||||||
|
|
||||||
if ([_dataSource respondsToSelector:
|
if ([_dataSource respondsToSelector:
|
||||||
@selector(tableView:validateDrop:proposedRow:proposedDropOperation:)])
|
@selector(tableView:validateDrop:proposedRow:proposedDropOperation:)])
|
||||||
|
@ -6354,16 +6349,13 @@ view to drag. */
|
||||||
proposedDropOperation: currentDropOperation];
|
proposedDropOperation: currentDropOperation];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The user might retarget the drop using -setDropRow:dropOperation: in
|
/* -setDropRow:dropOperation: can changes both currentDropRow and
|
||||||
-tableView:validateDrop:proposedRow:proposedOperation:.
|
|
||||||
|
|
||||||
-setDropRow:dropOperation: can changes both currentDropRow and
|
|
||||||
currentDropOperation. Whether we have to redraw the drop indicator depends
|
currentDropOperation. Whether we have to redraw the drop indicator depends
|
||||||
on this change. */
|
on this change. */
|
||||||
if (currentDropRow != oldDropRow || currentDropOperation != oldDropOperation)
|
if (currentDropRow != oldDropRow || currentDropOperation != oldDropOperation)
|
||||||
{
|
{
|
||||||
[self _drawDropIndicator];
|
[self _drawDropIndicator];
|
||||||
oldDropRow = currentDropRow;
|
oldDropRow = (currentDropRow > -1 ? currentDropRow : _numberOfRows);
|
||||||
oldDropOperation = currentDropOperation;
|
oldDropOperation = currentDropOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue