View NSOutlineView

I want to change the image used when I drag an element from an NSOutlineView based on the view and data source, but cannot find the hook. I tried to modify

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

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

Does anyone know where the default image comes from (it is obviously taken from the tableCellView image and text field)?

+4
source share
2 answers

It turns out that the image is obtained from NSTableCellView. Therefore, the interception is (NSArray *) draggingImageComponents in a subclass of this.

+2
source

A bit uncomfortable:
From your source, you can set the images in the NSDraggingSession instance that you transmitted using paramedia, for example. before tableView:draggingSession:willBeginAtPoint:forRowIndexes:

You can then use the enumerateDraggingItemsWithOptions:forView:classes:searchOptions:usingBlock: instance of the NSDraggingSession to modify the actual drag and drop 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]; }]; 
0
source

Source: https://habr.com/ru/post/1439904/


All Articles