Index: Source/NSOutlineView.m
===================================================================
--- Source/NSOutlineView.m	(revision 26829)
+++ Source/NSOutlineView.m	(working copy)
@@ -948,9 +948,10 @@
 - (void) setDropItem: (id) item
       dropChildIndex: (int) childIndex
 {
-  int row = [_items indexOfObject: item];
+  int lastRow = ([_items count] - 1);
+  int row = (item != nil ? [_items indexOfObject: item] : lastRow);
   id itemAfter;
-
+NSLog(@"setDropItem %@ index %d", item, index);
   if (row == NSNotFound)
     {
       return;
@@ -969,6 +970,8 @@
       currentDropRow = [_items indexOfObject: itemAfter];
       currentDropLevel = [self levelForItem: itemAfter];
     }
+
+NSLog(@"setDropItem drop row %d level %d", currentDropRow, currentDropLevel);
 }
 
 /*
@@ -997,24 +1000,24 @@
   NSPoint p = [sender draggingLocation];
   NSRect newRect;
   int row;
-  int verticalQuarterPosition;
+  int verticalQuarterPosition, positionInRow;
   int horizontalHalfPosition;
   int levelBefore;
   int levelAfter;
   int level;
   NSDragOperation dragOperation = [sender draggingSourceOperationMask];
- 
+
   p = [self convertPoint: p fromView: nil];
   verticalQuarterPosition = 
     (p.y - _bounds.origin.y) / _rowHeight * 4.;
   horizontalHalfPosition = 
     (p.x - _bounds.origin.y) / _indentationPerLevel * 2.;
 
-
-  if ((verticalQuarterPosition - oldProposedDropRow * 4 <= 2) &&
-      (verticalQuarterPosition - oldProposedDropRow * 4 >= -3))
+  NSLog(@"oldDropRow %d oldProposedDropRow %d verticalQuarterPosition %d p %f %f", oldDropRow, oldProposedDropRow, verticalQuarterPosition, p.x, p.y);
+  if ((verticalQuarterPosition - oldDropRow * 4 <= 2) &&
+      (verticalQuarterPosition - oldDropRow * 4 >= -3))
     {
-      row = oldProposedDropRow;
+      row = oldDropRow;
     }
   else
     {
@@ -1026,7 +1029,7 @@
 
   //NSLog(@"horizontalHalfPosition = %d", horizontalHalfPosition);
   
-  //NSLog(@"dropRow %d", row);
+  NSLog(@"dropRow %d", row);
 
   if (row == 0)
     {
@@ -1071,6 +1074,7 @@
       //NSLog(@"horizontalHalfPosition = %d", horizontalHalfPosition);
       //NSLog(@"verticalQuarterPosition = %d", verticalQuarterPosition);
       
+#if 0
       currentDropRow = row;
       currentDropLevel = level;
 
@@ -1098,9 +1102,65 @@
         
         childIndex = j;
       }
+#endif
 
+  // Are we in the two middle quarters of the row? Use NSOutlineViewDropOnItemIndex
+  positionInRow = (int)(p.y - _bounds.origin.y) % (int)_rowHeight;
+  int yPositionInRow = positionInRow;
+  int quarterPositionInRow = (int)(yPositionInRow / 4) + 1;
+//NSLog(@"p.y %f bounds.y %f row height %f pInRow %d _rowHeight/4 %f (3*_rowHeight)/4) %f",
+//	p.y, _bounds.origin.y, _rowHeight, positionInRow, _rowHeight/4, (3*_rowHeight)/4);
+//NSLog(@"quarterPositionInRow %d", quarterPositionInRow);
+  //if (positionInRow > _rowHeight/4 && positionInRow <= (3*_rowHeight)/4)
+  if (positionInRow > _rowHeight/4 && positionInRow <= (3*_rowHeight)/4)
+    {
+currentDropRow  = (int)(p.y - _bounds.origin.y) / (int)_rowHeight;
+      childIndex = NSOutlineViewDropOnItemIndex;
+      currentDropLevel = NSOutlineViewDropOnItemIndex;
+    }
+  else // drop above
+    {
+      currentDropRow = row;
+      currentDropLevel = level;
+    }
 
-      oldProposedDropRow = currentDropRow;
+      {
+        int i;
+        int j = 0;
+        int lvl;
+        for (i = row - 1; i >= 0; i--)
+          {
+            lvl = [self levelForRow: i];
+            if (lvl == level - 1)
+              {
+                break;
+              }
+            else if (lvl == level)
+              {
+                j++;
+              }
+          }
+        NSLog(@"found %d (proposed childIndex = %d)", i, j);
+        if (currentDropLevel == NSOutlineViewDropOnItemIndex)
+          item = [self itemAtRow: currentDropRow];
+        else 
+          {
+            if (i == -1)
+              item = nil;
+             else
+              item = [self itemAtRow: i];
+        
+            childIndex = j;
+          }
+      }
+
+  /* Pass -1 if the mouse is moved below the last row */
+  /*if (item == nil && ((verticalQuarterPosition + 2) / 4) > _numberOfRows)
+    {
+      childIndex = NSOutlineViewDropOnItemIndex;
+      currentDropRow = NSOutlineViewDropOnItemIndex;
+    }*/
+
       if ([_dataSource respondsToSelector: 
                          @selector(outlineView:validateDrop:proposedItem:proposedChildIndex:)])
         {
@@ -1119,10 +1179,16 @@
           
           [[NSColor darkGrayColor] set];
           
-          //NSLog(@"currentDropLevel %d, currentDropRow %d", 
-          //currentDropLevel, currentDropRow);
-                  
-          if (currentDropLevel != NSOutlineViewDropOnItemIndex)
+          NSLog(@"currentDropLevel %d, currentDropRow %d", 
+          currentDropLevel, currentDropRow);
+         /*if (currentDropRow == NSOutlineViewDropOnItemIndex) // && currentDropLevel == NSOutlineViewDropOnItemIndex
+	       {
+	         newRect = [self bounds];
+	         NSFrameRectWithWidth(newRect, 2.0);
+	         oldDraggingRect = newRect;
+	         currentDropRow = _numberOfRows;
+	        }
+          else*/ if (currentDropLevel != NSOutlineViewDropOnItemIndex)
             {
               if (currentDropRow == 0)
                 {