Couldn't be easier with Cocoa:
Start by telling the NSOutlineView that it should receive drops. awakeFromNib in your window controller is normally a good place for this. Replace the ... below with whatever type you want to drag to the outline view. Either use the constants from NSPasteboard.h (NSStringPboardType, NSFilenamesPboardType, ...) or use your own type (like @"MyUniqueDragType") if you're going to drag a type of data that isn't covered by the standard types.
Code:
[myOutlineView registerForDraggedTypes:[NSArray arrayWithObjects:..., nil]];
Next add the following methods to your datasource for the NSTableView and NSOutlineView respectively (normally they are both the same as the window controller):
Code:
- (BOOL)tableView:(NSTableView *)tv writeRows:(NSArray*)rows
toPasteboard:(NSPasteboard*)pboard
{
// this is a trivial example that always puts the string foo
// on the pasteboard when dragging
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
[pboard setString:@"foo" forType:NSStringPboardType];
return YES;
}
- (NSDragOperation)outlineView:(NSOutlineView*)olv validateDrop:(id <NSDraggingInfo>)info
proposedItem:(id)item proposedChildIndex:(int)index
{
// depending on info you might refuse the drag (return NSDragOperationNone)
// or use some other operation
return NSDragOperationGeneric;
}
- (BOOL)outlineView:(NSOutlineView*)olv acceptDrop:(id <NSDraggingInfo>)info
item:(id)item childIndex:(int)index
{
// this is where you normally add the dragged object to the
// data hierarchy for the outline view
NSPasteboard *pb = [info draggingPasteboard];
NSString *s = [pb stringForType:NSStringPboardType];
NSLog(@"drop accepted: %@", s);
return YES;
}
Hope this helps
/Tobias