4

I want to change the image used when I drag an item from a view- and datasource-based NSOutlineView, but can't seem to find a hook. I've tried modifying

- (void)dragImage:(NSImage *)anImage at:(NSPoint)viewLocation offset:(NSSize)initialOffset event:(NSEvent *)event pasteboard:(NSPasteboard *)pboard source:(id)sourceObj slideBack:(BOOL)slideFlag

in the rowViews, in the tableCellViews, and in a subclass of NSOutlineView itself, but to no avail.

Does anyone know where the default image (it's obviously taken from the tableCellView's image and textfield) is coming from?

Jay
  • 6,572
  • 3
  • 37
  • 65
pickwick
  • 3,134
  • 22
  • 30

2 Answers2

2

It turns out that the image is obtained from NSTableCellView. So the hook is to override -(NSArray *)draggingImageComponents in a subclass of that.

pickwick
  • 3,134
  • 22
  • 30
0

It's slightly awkward:
From your data source you can set the images on the NSDraggingSession instance you're passed via parameger e.g. to tableView:draggingSession:willBeginAtPoint:forRowIndexes:.

You can then use the enumerateDraggingItemsWithOptions:forView:classes:searchOptions:usingBlock: method on the NSDraggingSession instance to change the actual drag images of your NSDraggingItems:

   [session enumerateDraggingItemsWithOptions:NSDraggingItemEnumerationConcurrent
                                      forView:tableView
                                      classes:[NSArray arrayWithObject:[NSPasteboardItem class]]
                                searchOptions:nil
                                   usingBlock:^(NSDraggingItem *draggingItem, NSInteger index, BOOL *stop)
    {
       [draggingItem setDraggingFrame:NSMakeRect(0, 0, myWidth, myHeight)
                             contents:myFunkyDragImage];
    }];
Jay
  • 6,572
  • 3
  • 37
  • 65
  • for the records : dont use NSMakeRect(0, 0, myWidth, myHeight) the frame is !! don't ever try to use either session.dragginglocation – Xav Jan 11 '16 at 02:59
  • @Xav ?? Why wouldn't you? Works like a breeze in our code base across numerous OS versions – Jay Jan 13 '16 at 17:07