Modularized the first part of -draggingUpdated: into several smaller methods

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@36167 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Quentin Mathe 2013-02-19 15:18:53 +00:00
parent b263e0d435
commit fea485cea2
2 changed files with 46 additions and 30 deletions

View file

@ -1,3 +1,10 @@
2013-02-19 Quentin Mathe <quentin.mathe@gmail.com>
* Source/NSTableView.m (-draggingUpdated:): Modularized the first part of
the method into several smaller methods -_dropRowFromQuarterPosition:,
-_setDropOperationAndRow:usingPositionInRow:atPoint: and
_scrollRowAtPointToVisible:.
2013-02-18 Riccardo Mottola <rm@gnu.org>
* Tools/make_services.m (main)

View file

@ -6189,48 +6189,32 @@ This method is deprecated, use -columnIndexesInRect:. */
[self displayIfNeeded];
}
- (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
/* This is a crude method of scrolling the view while dragging so the user can
drag to any cell even if it's not visible. Unfortunately we don't receive
events when the drag is outside the view, so the pointer must still be in the
view to drag. */
- (void) _scrollRowAtPointToVisible: (NSPoint)p
{
NSPoint p = [sender draggingLocation];
NSRect newRect;
int row;
int quarterPosition, positionInRow;
int currentRow;
NSDragOperation dragOperation;
NSInteger currentRow;
p = [self convertPoint: p fromView: nil];
/* This is a crude method of scrolling the view while dragging so
the user can drag to any cell even if it's not
visible. Unfortunately we don't receive events when the drag is
outside the view, so the pointer must still be in the view to
drag.
*/
if (p.y < NSMinY([self visibleRect])+3)
if (p.y < NSMinY([self visibleRect]) + 3)
{
currentRow = [self rowAtPoint: p] - 1;
if (currentRow > 0)
[self scrollRowToVisible: currentRow];
}
else if (p.y > NSMaxY([self visibleRect])-3)
else if (p.y > NSMaxY([self visibleRect]) - 3)
{
currentRow = [self rowAtPoint: p] + 1;
if (currentRow < _numberOfRows)
[self scrollRowToVisible: currentRow];
}
}
positionInRow = (int)(p.y - _bounds.origin.y) % (int)_rowHeight;
quarterPosition = (p.y - _bounds.origin.y) / _rowHeight * 4.;
if ((quarterPosition - oldDropRow * 4 <= 2) &&
(quarterPosition - oldDropRow * 4 >= -3))
{
row = oldDropRow;
}
else
{
row = (quarterPosition + 2) / 4;
}
- (void) _setDropOperationAndRow: (NSInteger)row
usingPositionInRow: (NSInteger)positionInRow
atPoint: (NSPoint)p
{
// Are we in the two middle quarters of the row? Use TableViewDropOn
if ((positionInRow > _rowHeight / 4 && positionInRow <= (3 * _rowHeight) / 4)
|| row > _numberOfRows)
@ -6245,8 +6229,33 @@ This method is deprecated, use -columnIndexesInRect:. */
currentDropRow = row;
currentDropOperation = NSTableViewDropAbove;
}
}
- (NSInteger) _dropRowFromQuarterPosition: (NSInteger)quarterPosition
{
if ((quarterPosition - oldDropRow * 4 <= 2) &&
(quarterPosition - oldDropRow * 4 >= -3))
{
return oldDropRow;
}
else
{
return (quarterPosition + 2) / 4;
}
}
- (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
{
NSPoint p = [self convertPoint: [sender draggingLocation] fromView: nil];
NSRect newRect;
NSInteger positionInRow = (NSInteger)(p.y - _bounds.origin.y) % (int)_rowHeight;
NSInteger quarterPosition = (NSInteger)(p.y - _bounds.origin.y) / _rowHeight * 4.;
NSInteger row = [self _dropRowFromQuarterPosition: quarterPosition];
NSDragOperation dragOperation = [sender draggingSourceOperationMask];
[self _scrollRowAtPointToVisible: p];
[self _setDropOperationAndRow: row usingPositionInRow: positionInRow atPoint: p];
dragOperation = [sender draggingSourceOperationMask];
if ((lastQuarterPosition != quarterPosition)
|| (currentDragOperation != dragOperation))
{