--- NSOutlineView.m.org	Thu Feb  5 13:55:45 2004
+++ NSOutlineView.m	Thu Feb 12 14:27:23 2004
@@ -575,9 +575,14 @@
   return _outlineTableColumn;
 }
 
+/***************************************************
+ * Andreas Heppel <aheppel@web.de>: Made parent a pointer to id
+ * so as to be able to return the found parent of the given item.
+ * All occurrences of parent were changed to *parent.
+ ***************************************************/
 - (BOOL)_findItem: (id)item
        childIndex: (int *)index
-	 ofParent: (id)parent
+	 ofParent: (id *)parent
 {
   NSArray *allKeys = NSAllMapTableKeys(_itemDict);
   BOOL hasChildren = NO;
@@ -586,7 +591,7 @@
 
   // initial values for return parameters
   *index = NSNotFound;
-  parent = nil;
+  *parent = nil;
   
   if([allKeys containsObject: item])
     {
@@ -599,7 +604,7 @@
 
       if((*index = [childArray indexOfObject: item]) != NSNotFound)
 	{
-	  parent = object;
+	  *parent = object;
 	  break;
 	}
     }
@@ -633,12 +638,21 @@
   // find the item
   haschildren = [self _findItem: object
 		   childIndex: &index
-		   ofParent: parent];
+		   ofParent: &parent];
+
+  /************************************************
+   * Andreas Heppel <aheppel@web.de>:
+   * Here we should check, whether the item was found. Just to make
+   * sure. But maybe it is wanted to run into an exception here to
+   * show the programmer that something is wrong?
+   ************************************************/
+  if (index == NSNotFound)
+    return;
 
   dsobj = [_dataSource outlineView: self
 		       child: index
 		       ofItem: parent];
-  
+
   obj = NSMapGet(_itemDict, parent);
   [obj removeObject: item];
   [obj insertObject: dsobj atIndex: index];
@@ -653,10 +667,33 @@
 	{
 	  DESTROY(_items); 
 	}
+      /***************************************************
+       * Andreas Heppel <aheppel@web.de>:
+       * IMHO this array should be created newly.
+       ***************************************************/
+      _items = [[NSMutableArray alloc] init]; 
 
       // regenerate the _items array based on the new dictionary
       [self _openItem: nil];
     }      
+  else
+    {
+      /***************************************************
+       * Andreas Heppel <aheppel@web.de>:
+       * We must set this up in any case. It might be that the
+       * call to outlineView:child:ofItem returns a new object. Thus,
+       * we must update _items and _levelOfItems to make sure that the
+       * old item is removed and the new one is inserted.
+       ***************************************************/
+      if (item != dsobj)
+        {
+          index = [_items indexOfObject: item];
+          [_items removeObject: item];
+          [_items insertObject: dsobj atIndex: index];
+          NSMapInsert(_levelOfItems, dsobj, NSMapGet(_levelOfItems, item));
+          NSMapRemove(_levelOfItems, item);
+        }
+    }
 }
 
 /**
@@ -1354,6 +1391,13 @@
   [self displayIfNeeded];
 }
 
+
+/***************************************************
+ * Andreas Heppel <aheppel@web.de>:
+ * draggingUpdated now saves and returns the return
+ * value from its delegate's method 
+ * outlineView:validateDrop:proposedItem:proposedChildIndex:
+ ***************************************************/
 - (unsigned int) draggingUpdated: (id <NSDraggingInfo>) sender
 {
   NSPoint p = [sender draggingLocation];
@@ -1364,6 +1408,7 @@
   int levelBefore;
   int levelAfter;
   int level;
+  NSDragOperation dragOperation = [sender draggingSourceOperationMask];
 
   p = [self convertPoint: p fromView: nil];
   verticalQuarterPosition = 
@@ -1467,7 +1512,7 @@
 	{
 	  //NSLog(@"currentDropLevel %d, currentDropRow %d",
 	  //currentDropLevel, currentDropRow);
-	  [_dataSource outlineView: self
+	  dragOperation = [_dataSource outlineView: self
 		       validateDrop: sender
 		       proposedItem: item
 		       proposedChildIndex: childIndex];
@@ -1561,7 +1606,7 @@
     }
 
 
-  return NSDragOperationCopy;
+  return dragOperation;
 }
 
 - (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
