From 4f088cc39f49ca1c387f9288b67176b3ad1ca5b2 Mon Sep 17 00:00:00 2001 From: Martin Fox Date: Fri, 16 Feb 2024 13:18:13 -0800 Subject: [PATCH] Using OS to determine DRAG_DONE operation --- .../main/native-glass/mac/GlassDragSource.h | 4 ++-- .../native-glass/mac/GlassDraggingSource.h | 5 +++-- .../native-glass/mac/GlassDraggingSource.m | 6 +++++- .../src/main/native-glass/mac/GlassView3D.m | 1 - .../main/native-glass/mac/GlassViewDelegate.m | 21 ++++++++++++++++--- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/modules/javafx.graphics/src/main/native-glass/mac/GlassDragSource.h b/modules/javafx.graphics/src/main/native-glass/mac/GlassDragSource.h index 77f3618f741..f872a76229f 100644 --- a/modules/javafx.graphics/src/main/native-glass/mac/GlassDragSource.h +++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassDragSource.h @@ -29,7 +29,7 @@ @protocol GlassDragSourceDelegate - (void)startDrag:(NSDragOperation)operation withItems:(NSArray*)items; -- (void)draggingEnded; +- (void)draggingEnded:(NSDragOperation)operation; @end @@ -41,7 +41,7 @@ + (NSDragOperation)mapJavaMaskToNsOperation:(jint)mask; + (jint)mapNsOperationToJavaMaskExternal:(NSDragOperation)operation; -+ (jint)mapNSOperationToJavaMaskInternal:(NSDragOperation)operation; ++ (jint)mapNsOperationToJavaMaskInternal:(NSDragOperation)operation; + (jint)getRecommendedActionForMaskExternal:(NSDragOperation)operation; + (jint)getRecommendedActionForMaskInternal:(NSDragOperation)operation; diff --git a/modules/javafx.graphics/src/main/native-glass/mac/GlassDraggingSource.h b/modules/javafx.graphics/src/main/native-glass/mac/GlassDraggingSource.h index c86ba1385dd..0e36f0b07c3 100644 --- a/modules/javafx.graphics/src/main/native-glass/mac/GlassDraggingSource.h +++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassDraggingSource.h @@ -25,15 +25,16 @@ #import +#import "GlassDragSource.h" @interface GlassDraggingSource : NSObject { @public NSDragOperation dragOperation; - + id dragDelegate; } -- (GlassDraggingSource*)initWithOperation:(NSDragOperation)operation; +- (GlassDraggingSource*)initWithOperation:(NSDragOperation)operation delegate:(id)delegate; - (void)draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint; - (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint; diff --git a/modules/javafx.graphics/src/main/native-glass/mac/GlassDraggingSource.m b/modules/javafx.graphics/src/main/native-glass/mac/GlassDraggingSource.m index 51fb687361d..1c0b888a330 100644 --- a/modules/javafx.graphics/src/main/native-glass/mac/GlassDraggingSource.m +++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassDraggingSource.m @@ -53,9 +53,11 @@ - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationM return self->dragOperation; } -- (GlassDraggingSource*)initWithOperation:(NSDragOperation)operation +- (GlassDraggingSource*)initWithOperation:(NSDragOperation)operation delegate:(id)delegate { dragOperation = operation; + // The delegate retains this object + dragDelegate = delegate; return self; } @@ -69,6 +71,8 @@ - (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)scree - (void)draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation { + LOG("Dragging session ended"); + [dragDelegate draggingEnded: operation]; } - (BOOL)ignoreModifierKeysForDraggingSession:(NSDraggingSession *)session diff --git a/modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m b/modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m index 5ca3749e2c3..a3c2368c488 100644 --- a/modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m +++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m @@ -570,7 +570,6 @@ - (NSDragOperation)draggingUpdated:(id )sender - (void)draggingEnded:(id )sender { DNDLOG("draggingEnded"); - [self->_delegate draggingEnded]; } - (void)draggingExited:(id )sender diff --git a/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.m b/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.m index 0c023afa91f..4f3d08fea55 100644 --- a/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.m +++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassViewDelegate.m @@ -1076,7 +1076,7 @@ - (void)startDrag:(NSDragOperation)operation withItems:(NSArray [image release]; } - self->draggingSource = [[GlassDraggingSource alloc] initWithOperation:operation]; + self->draggingSource = [[GlassDraggingSource alloc] initWithOperation:operation delegate:self]; NSDraggingSession *session = [self->nsView beginDraggingSessionWithItems:items event:self->lastEvent source:self->draggingSource]; } @@ -1097,7 +1097,7 @@ - (void)synthesizeMouseUp:(NSEventType)type [self sendJavaMouseEvent:theEvent]; } -- (void)draggingEnded +- (void)draggingEnded:(NSDragOperation)operation { DNDLOG("draggingEnded"); @@ -1109,8 +1109,23 @@ - (void)draggingEnded [GlassDragSource setDelegate:nil]; + // At the end of dragging we're handed a single definitive + // drag operation (no Generic or Any). + jint mask = com_sun_glass_ui_Clipboard_ACTION_NONE; + if (operation == NSDragOperationNone) { + mask = com_sun_glass_ui_Clipboard_ACTION_NONE; + } else if (operation == NSDragOperationCopy) { + mask = com_sun_glass_ui_Clipboard_ACTION_COPY; + } else if (operation == NSDragOperationMove) { + mask = com_sun_glass_ui_Clipboard_ACTION_MOVE; + } else if (operation == NSDragOperationLink) { + mask = com_sun_glass_ui_Clipboard_ACTION_REFERENCE; + } else { + DNDLOG("Invalid drag operation"); + } + GET_MAIN_JENV; - (*env)->CallVoidMethod(env, self->jView, jViewNotifyDragEnd, [GlassDragSource getMask]); + (*env)->CallVoidMethod(env, self->jView, jViewNotifyDragEnd, mask); GLASS_CHECK_EXCEPTION(env); // RT-36038: OS X won't send mouseUp after DnD is complete, so we synthesize them