gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTableView -rowAtPoint:


From: Matt Rice
Subject: NSTableView -rowAtPoint:
Date: Sat, 4 Nov 2006 09:33:23 -0800 (PST)

conflicts with vertical motion patch but is buggy
without it... (added some checks around code it
removes)

and while dragging rows that have been selected by
periodic events last it will do something weird to the
selection... this is fixed by removing selection on
drag
(done by vertical motion patch).

it changes -rowAtPoint: to return -1 if on an invalid
row
but still gives the last row a little bit area below
it (i don't know if i really like this behaviour
but... thats what it was there for)

and changes places to handle the invalid row.

anyhow with the current code where the table view is
always as big as the clip view i think this behaviour
is better... it was kindof weird to select the last
row when you were nowhere near it.


 
__________________________________________________________________________________________
Check out the New Yahoo! Mail - Fire up a more powerful email and get things 
done faster. 
(http://advision.webevents.yahoo.com/mailbeta) 
Index: NSTableView.m
===================================================================
--- NSTableView.m       (revision 24019)
+++ NSTableView.m       (working copy)
@@ -3210,9 +3210,6 @@
     {
       flag = YES;
     }
-  
-  [self scrollRowToVisible: rowIndex];
-  [self scrollColumnToVisible: columnIndex];
 
   if (rowIndex != _selectedRow)
     {
@@ -3227,6 +3224,9 @@
                   format: @"Row/column out of index in edit"];
     }
   
+  [self scrollRowToVisible: rowIndex];
+  [self scrollColumnToVisible: columnIndex];
+  
   if (_textObject != nil)
     {
       [self validateEditing];
@@ -3521,7 +3521,7 @@
       NSEvent *lastEvent;
       NSIndexSet *oldSelectedRows;
       BOOL startedPeriodicEvents = NO;
-      BOOL mouseUp = NO;
+      BOOL mouseAbove = NO;
       BOOL done = NO;
       BOOL mouseMoved = NO;
       BOOL draggingPossible = [self _isDraggingSource];
@@ -3639,8 +3639,9 @@
 
              if (draggingPossible == YES)
                {
-                 if (mouseLocationWin.y - initialLocation.y > 2
-                     || mouseLocationWin.y - initialLocation.y < -2)
+                 if (![_selectedRows containsIndex:currentRow]
+                     && (mouseLocationWin.y - initialLocation.y > 2
+                     || mouseLocationWin.y - initialLocation.y < -2))
                    {
                      draggingPossible = NO;
                    }
@@ -3650,22 +3651,9 @@
                      oldRow = currentRow;
                      currentRow = [self rowAtPoint: mouseLocationView];
                      
-                     if (![_selectedRows containsIndex: currentRow])
+                     if (currentRow != -1
+                         && [self _startDragOperationWithEvent:theEvent])
                        {
-                         /* Mouse drag in a row that wasn't selected.
-                            select the new row before dragging */
-                         computeNewSelection(self,
-                                             oldSelectedRows, 
-                                             _selectedRows,
-                                             originalRow,
-                                             oldRow,
-                                             currentRow,
-                                             &_selectedRow,
-                                             selectionMode);
-                       }
-
-                     if ([self _startDragOperationWithEvent:theEvent])
-                       {
                          return;
                        }
                      else
@@ -3719,29 +3707,35 @@
                           withPeriod: oldPeriod];
                  startedPeriodicEvents = YES;
                  if (mouseLocationWin.y <= minYVisible) 
-                   mouseUp = NO;
+                   mouseAbove = NO;
                  else
-                   mouseUp = YES;
+                   mouseAbove = YES;
                }
              break;
            case NSPeriodic:
-             if (mouseUp == NO)
+             if (mouseAbove == NO)
                {
                  /* mouse below the table */
-                 if (currentRow < _numberOfRows - 1)
+                 if (currentRow == -1 && oldRow != -1)
+                   currentRow = oldRow + 1;
+                 
+                 if (currentRow != -1 && currentRow < _numberOfRows - 1)
                    {
                      oldRow = currentRow;
                      currentRow++;
                      [self scrollRowToVisible: currentRow];
                      if (draggingPossible == NO)
-                       shouldComputeNewSelection = YES;
+                       shouldComputeNewSelection = YES;
                    }
                }
              else
                {
-                 if (currentRow > 0)
+                 /* mouse above the table */
+                 if (currentRow == -1 && oldRow != -1)
+                   currentRow = oldRow - 1;
+                 
+                 if (currentRow != -1 && currentRow > 0)
                    {
-                     /* mouse above the table */
                      oldRow = currentRow;
                      currentRow--;
                      [self scrollRowToVisible: currentRow];
@@ -3761,11 +3755,9 @@
                  originalRow = currentRow;
                }
              
-             if (currentRow == -1)
+             if (currentRow >= 0 && currentRow < _numberOfRows)
                {
-                 currentRow = _numberOfRows - 1;
-               }
-             computeNewSelection(self,
+                 computeNewSelection(self,
                                  oldSelectedRows, 
                                  _selectedRows,
                                  originalRow,
@@ -3773,6 +3765,7 @@
                                  currentRow,
                                  &_selectedRow,
                                  selectionMode);
+               }
              [self displayIfNeeded];
            }
          
@@ -3975,11 +3968,16 @@
       int return_value;
 
       aPoint.y -= _bounds.origin.y;
-      return_value = (int) (aPoint.y / _rowHeight);
+      return_value = (int)(aPoint.y / _rowHeight);
       /* This could happen if point lies on the grid line or below the last 
row */
+
       if (return_value >= _numberOfRows)
        {
-         return_value = _numberOfRows - 1;
+         /* give a little leeway on the last row */
+         if (return_value == _numberOfRows && fmod(aPoint.y, _rowHeight) < 8)
+           return_value = _numberOfRows - 1;
+         else
+           return_value = -1;
        }
       return return_value;
     }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]