Problem with DragItem / DragPicture multiple objects

I’m having problems with a DragItem, generated with Listbox.DragRow, on Mac 10.14, when I generate multiple rows for the purpose of displaying pictures for each row, as is common with Mac.

The problem is that every rowpicture displayed by the Mac shows only the last picture I create. Every row looks the same.

I do this (code shortened) in Listbox.DragRow:

d.DragPicture = P(0)
For i = 0 To numRows - 1
d.AddItem(0, 0, 20, 20)
// now the current row is the new one added, as far as I understand it
d.DragPicture = P(i + 1)

How do I get every row to display a different graphic; P(0…)?

You have to create one large picture and then pad it out.

Use me.selcount and me.rowheight to calculate the height of the final image. Then use me.trueWindow.bitmapForCaching to create the correct DPI version of the image.

Then either the documentation is wrong, or it’s a bug. From the DragItem entry:

“Alternatively you can not provide the picture in the constructor and then set the DragPicture property for each [item] you add with AddItem. On MacOS this results in these separate images being vertically stacked to indicate each item being dragged. This can be more useful if your individual drag items are unique or distinct.”

Bug or wrong doc?

Couldn’t say, just that in my experience I’ve found creating one single image to work most reliably.

So should the code be more like this?

numRows = LB.SelCount
P = LB.TrueWindow.bitmapForCaching(LB.Width, numRows * LB.RowHeight)

For i = 0 To numRows - 1
DrawToDragPic(P, LB, i)

For i = 1 To numRows - 2
d.AddItem(0, 0, 20, 20)
d.AddItem(0, 0, 20, 20)
d.DragPicture = P

That seems about right.

Looks really bizarre.

Here’s the test project.

Test Drag Picture

odd but when I run your example on my machine I get a hard OS crash

Process:               Test Drag Picture.debug [57059]
Path:                  /Users/USER/Downloads/*/Test Drag Drag Picture.debug
Identifier:            com.mycompany.testdragpicture
Version:               ??? (
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           Test Drag Picture.debug [57059]
User ID:               501

Date/Time:             2020-08-22 09:34:12.037 -0600
OS Version:            Mac OS X 10.15.6 (19G2021)
Report Version:        12
Bridge OS Version:     4.6 (17P6610)
Anonymous UUID:        0F0B83EB-BB66-3337-7E31-C659E43657EB

Time Awake Since Boot: 240000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue:

Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Illegal instruction: 4
Termination Reason:    Namespace SIGNAL, Code 0x4
Terminating Process:   exc handler [57059]

Application Specific Information:
Crashing on exception: There are 0 items on the pasteboard, but 2 drag images. There must be 1 draggingItem per pasteboardItem.

Application Specific Backtrace 1:
0   CoreFoundation                      0x00007fff2e4feb57 __exceptionPreprocess + 250
1   libobjc.A.dylib                     0x00007fff673455bf objc_exception_throw + 48
2   CoreFoundation                      0x00007fff2e4fe9b5 +[NSException raise:format:] + 189
3   AppKit                              0x00007fff2c16c73f -[NSDraggingSession(NSInternal) _initWithPasteboard:draggingItems:clippingRect:source:] + 222
4   AppKit                              0x00007fff2bcbe9c0 -[NSCoreDragManager beginDraggingSessionWithItems:fromWindow:withClipRect:event:source:] + 1813
5   AppKit                              0x00007fff2bfc46ad -[NSView(NSDrag) beginDraggingSessionWithItems:event:source:] + 259
6   XojoFramework                       0x0000000107d16d6a _Z16CocoaPerformDragP14DragItemObject + 2886
7   XojoFramework                       0x0000000107e84f7a _ZN14RuntimeListbox20PerformDragOperationEl + 948
8   XojoFramework                       0x0000000107e84b9f _ZN14RuntimeListbox13HandleRowDragEl + 113
9   XojoFramework                       0x0000000107e85375 _ZN14RuntimeListbox14HandleRowClickEiRK10MouseEvent + 455
10  XojoFramework                       0x0000000107e447e3 _ZN9NuListbox11HandleClickERK10MouseEvent + 325
11  XojoFramework                       0x0000000107d664f5 _ZNSt3__16__treeINS_12__value_typeI6RBAutoS2_EENS_19__map_value_compareIS2_S3_12AutoLessThanLb0EEENS_9allocatorIS3_EEE12__find_equalIS2_EERPNS_16__tree_node_baseIPvEERPNS_15__tree_end_nodeISE_EERKT_ + 8041
12  XojoFramework                       0x0000000107d61695 _ZN19TextOutputStreamImp9WriteLineERK4Text + 14815
13  AppKit                              0x00007fff2b92e5f0 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 4914
14  AppKit                              0x00007fff2b898e21 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2612
15  AppKit                              0x00007fff2b8981c9 -[NSWindow(NSEventRouting) sendEvent:] + 349
16  XojoFramework                       0x0000000107d62805 _ZN19TextOutputStreamImp9WriteLineERK4Text + 19279
17  AppKit                              0x00007fff2b896554 -[NSApplication(NSEvent) sendEvent:] + 352
18  XojoFramework                       0x0000000107d51fe1 _Z29CocoaFinishApplicationStartupv + 1945
19  Test Drag Picture.debug             0x0000000107ab4305 Application._CallFunctionWithExceptionHandling%%o<Application>p + 181
20  XojoFramework                       0x0000000107ee1e7d _Z33CallFunctionWithExceptionHandlingPFvvE + 262
21  XojoFramework                       0x0000000107d51f5c _Z29CocoaFinishApplicationStartupv + 1812

This is a bug. It worked on older versions of Xojo correctly, not in newer releases or later macOS versions. See <>

Fix it, Norm! =)

Thanks, I added to your report.

Odd, your example does nothing. I can’t get any drag picture to show up. 10.15.3 with Xojo 2019r3.

I know. I did this in 10.14. My code does what Sam suggested, making one picture and adding it at the end. As Jason said, doing it normally just has the same picture for every Item in the DragItem. Bug.

The example from the Feedback report shows the duplicate images. But your example does nothing.

It seems I had made some assumptions that caused this confusion and for that I apologize.

In the situations where I had faced a similar problem, my complete solution was to combine everything into a single drag item. This may not actually apply in your situation, as it depends on the end result of the drag.

When I modified your code to closer match my solution, the image does at least look right. But all the drag contents are now in a single item. If you can modify your dropObject event to parse them out, then this will work. Otherwise if you need each item to be separate, you may be out of luck until Xojo fix the problem.
Dim i As Integer
Dim numRows, DragPicHeight As Integer
DIm P As Picture

numRows = Me.SelCount
DragPicHeight = numRows * Me.RowHeight

P = Me.TrueWindow.bitmapForCaching(Me.Width, DragPicHeight)

For i = 0 To numRows - 1
  DrawToDragPic(P, Me, i)

Dim rows() as string

Dim n as integer = me.listcount -1
For l as integer = 0 to n
  if me.selected( l ) then rows.append me.cell( l, 0 )

drag.text        = join( rows, endofLine )
drag.dragPicture = p

return True

So abandon AddItem for the time being… But if I’m dragging (say) 4-5 FolderItems, I need separate Items in the DragItem. That can be hacked around, however the other problem it invokes is that I have to give up the nice NUMBER graphic the Mac introduces of the amount of items being dragged. Unless (I haven’t tried this yet) on a single item a number doesn’t appear.

And unfortunately this isn’t fixed in 2020r1. Hopefully the wait isn’t long.