Post

Replies

Boosts

Views

Activity

No drop with NSDraggingSession
In the "mouseDown" (or MouseDreagged) code below Enclosure is a NSView subclass. xcode report 2 warnings: pb_item setDataProvider:self forTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSPasteboardTypePDF, @"LN_PboardType", nil]]; Sending 'Enclosure *' to parameter of incompatible type 'id _Nonnull' NSDraggingSession *draggingSession = [self beginDraggingSessionWithItems:[NSArray arrayWithObject:drag_item] event:drag_event source:self]; Sending 'Enclosure *' to parameter of incompatible type 'id _Nonnull' The application fail at: drag_item = [[NSDraggingItem alloc] initWithPasteboardWriter:pb_item]; Pasteboard item data provider <Enclosure: 0x7f849ec74e70> must conform to NSPasteboardItemDataProviderProtocol [General] There are 0 items on the pasteboard, but 1 drag images. There must be 1 draggingItem per pasteboardItem. However if in the line of code above "pb_item" is replaced by "drag_image" drag work fine (but without drop). The z_drag image follow the mouse correctly and "endedAtPoint" is called when the mouse button is released. Where is the error ? Any suggestion will be appreciate... BigSur, xcode 12.4 - (void)mouseDown:(NSEvent *)drag_event /* or mouseDragged:(NSEvent *)drag_event */ { NSImage *drag_image; NSPoint drag_position; NSDraggingItem *drag_item; NSPasteboardItem *pb_item; pb_item = [[NSPasteboardItem alloc] init]; [pb_item setDataProvider:self forTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, NSPasteboardTypePDF, @"LN_PboardType", nil]]; drag_image = [NSImage imageNamed:@"z_drag.jpg"]; drag_item = [[NSDraggingItem alloc] initWithPasteboardWriter:pb_item]; drag_position = [self convertPoint:[drag_event locationInWindow] fromView:nil]; drag_position.x -= [drag_image size].width/2; drag_position.y -= [drag_image size].height/2; [drag_item setDraggingFrame:NSMakeRect(drag_position.x, drag_position.y, drag_image.size.width, drag_image.size.height) contents:drag_image]; NSDraggingSession *draggingSession = [self beginDraggingSessionWithItems:[NSArray arrayWithObject:drag_item] event:drag_event source:self]; [draggingSession setAnimatesToStartingPositionsOnCancelOrFail:YES]; [draggingSession setDraggingFormation:NSDraggingFormationNone]; } - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context { switch (context) { case NSDraggingContextWithinApplication: return NSDragOperationCopy; case NSDraggingContextOutsideApplication: return NSDragOperationMove; } return NSDragOperationNone; } - (void)draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation { NSPoint mouse_point; mouse_point = [session draggingLocation]; switch (operation) { case NSDragOperationDelete: break; default: break; } }
0
0
673
Jul ’22