< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m

Print this page
rev 54094 : 8257853: Remove dependencies on JNF's JNI utility functions in AWT and 2D code
rev 54096 : 8259651: [macOS] Replace JNF_COCOA_ENTER/EXIT macros
rev 54097 : 8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion

*** 26,45 **** //#define DND_DEBUG TRUE #import "java_awt_dnd_DnDConstants.h" #import <Cocoa/Cocoa.h> - #import <JavaNativeFoundation/JavaNativeFoundation.h> #import "AWTEvent.h" #import "AWTView.h" #import "CDataTransferer.h" #import "CDropTarget.h" #import "CDragSource.h" #import "DnDUtilities.h" #import "ThreadUtilities.h" #import "LWCToolkit.h" // When sIsJavaDragging is true Java drag gesture has been recognized and a drag is/has been initialized. // We must stop posting MouseEvent.MOUSE_DRAGGED events for the duration of the drag or all hell will break // loose in shared code - tracking state going haywire. --- 26,45 ---- //#define DND_DEBUG TRUE #import "java_awt_dnd_DnDConstants.h" #import <Cocoa/Cocoa.h> #import "AWTEvent.h" #import "AWTView.h" #import "CDataTransferer.h" #import "CDropTarget.h" #import "CDragSource.h" #import "DnDUtilities.h" #import "ThreadUtilities.h" #import "LWCToolkit.h" + #import "JNIUtilities.h" // When sIsJavaDragging is true Java drag gesture has been recognized and a drag is/has been initialized. // We must stop posting MouseEvent.MOUSE_DRAGGED events for the duration of the drag or all hell will break // loose in shared code - tracking state going haywire.
*** 67,79 **** // sIsJavaDragging is reset on mouseDown as well. sIsJavaDragging = NO; } @end ! JNF_CLASS_CACHE(DataTransfererClass, "sun/awt/datatransfer/DataTransferer"); ! JNF_CLASS_CACHE(CDragSourceContextPeerClass, "sun/lwawt/macosx/CDragSourceContextPeer"); ! JNF_CLASS_CACHE(CImageClass, "sun/lwawt/macosx/CImage"); static NSDragOperation sDragOperation; static NSPoint sDraggingLocation; static BOOL sNeedsEnter; --- 67,87 ---- // sIsJavaDragging is reset on mouseDown as well. sIsJavaDragging = NO; } @end ! static jclass DataTransfererClass = NULL; ! static jclass CDragSourceContextPeerClass = NULL; ! ! #define GET_DT_CLASS() \ ! GET_CLASS(DataTransfererClass, "sun/awt/datatransfer/DataTransferer"); ! ! #define GET_DT_CLASS_RETURN(ret) \ ! GET_CLASS_RETURN(DataTransfererClass, "sun/awt/datatransfer/DataTransferer", ret); ! ! #define GET_DSCP_CLASS() \ ! GET_CLASS(CDragSourceContextPeerClass, "sun/lwawt/macosx/CDragSourceContextPeer"); static NSDragOperation sDragOperation; static NSPoint sDraggingLocation; static BOOL sNeedsEnter;
*** 158,193 **** // Remove this dragging source from the view: [((AWTView *) fView) setDragSource:nil]; // Clean up JNI refs if (fComponent != NULL) { ! JNFDeleteGlobalRef(env, fComponent); fComponent = NULL; } if (fDragSourceContextPeer != NULL) { ! JNFDeleteGlobalRef(env, fDragSourceContextPeer); fDragSourceContextPeer = NULL; } if (fTransferable != NULL) { ! JNFDeleteGlobalRef(env, fTransferable); fTransferable = NULL; } if (fTriggerEvent != NULL) { ! JNFDeleteGlobalRef(env, fTriggerEvent); fTriggerEvent = NULL; } if (fFormats != NULL) { ! JNFDeleteGlobalRef(env, fFormats); fFormats = NULL; } if (fFormatMap != NULL) { ! JNFDeleteGlobalRef(env, fFormatMap); fFormatMap = NULL; } [self release]; } --- 166,201 ---- // Remove this dragging source from the view: [((AWTView *) fView) setDragSource:nil]; // Clean up JNI refs if (fComponent != NULL) { ! (*env)->DeleteGlobalRef(env, fComponent); fComponent = NULL; } if (fDragSourceContextPeer != NULL) { ! (*env)->DeleteGlobalRef(env, fDragSourceContextPeer); fDragSourceContextPeer = NULL; } if (fTransferable != NULL) { ! (*env)->DeleteGlobalRef(env, fTransferable); fTransferable = NULL; } if (fTriggerEvent != NULL) { ! (*env)->DeleteGlobalRef(env, fTriggerEvent); fTriggerEvent = NULL; } if (fFormats != NULL) { ! (*env)->DeleteGlobalRef(env, fFormats); fFormats = NULL; } if (fFormatMap != NULL) { ! (*env)->DeleteGlobalRef(env, fFormatMap); fFormatMap = NULL; } [self release]; }
*** 210,221 **** // // * NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value. // - (jobject)dataTransferer:(JNIEnv*)env { ! JNF_STATIC_MEMBER_CACHE(getInstanceMethod, DataTransfererClass, "getInstance", "()Lsun/awt/datatransfer/DataTransferer;"); ! return JNFCallStaticObjectMethod(env, getInstanceMethod); } // Appropriated from Windows' awt_DataTransferer.cpp: // // * NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value. --- 218,232 ---- // // * NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value. // - (jobject)dataTransferer:(JNIEnv*)env { ! GET_DT_CLASS_RETURN(NULL); ! DECLARE_STATIC_METHOD_RETURN(getInstanceMethod, DataTransfererClass, "getInstance", "()Lsun/awt/datatransfer/DataTransferer;", NULL); ! jobject o = (*env)->CallStaticObjectMethod(env, DataTransfererClass, getInstanceMethod); ! CHECK_EXCEPTION(); ! return o; } // Appropriated from Windows' awt_DataTransferer.cpp: // // * NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value.
*** 225,237 **** JNIEnv* env = [ThreadUtilities getJNIEnv]; jobject transferer = [self dataTransferer:env]; jbyteArray data = nil; if (transferer != NULL) { ! JNF_MEMBER_CACHE(convertDataMethod, DataTransfererClass, "convertData", "(Ljava/lang/Object;Ljava/awt/datatransfer/Transferable;JLjava/util/Map;Z)[B"); ! data = JNFCallObjectMethod(env, transferer, convertDataMethod, fComponent, fTransferable, format, fFormatMap, (jboolean) TRUE); } return data; } --- 236,250 ---- JNIEnv* env = [ThreadUtilities getJNIEnv]; jobject transferer = [self dataTransferer:env]; jbyteArray data = nil; if (transferer != NULL) { ! GET_DT_CLASS_RETURN(NULL); ! DECLARE_METHOD_RETURN(convertDataMethod, DataTransfererClass, "convertData", "(Ljava/lang/Object;Ljava/awt/datatransfer/Transferable;JLjava/util/Map;Z)[B", NULL); ! data = (*env)->CallObjectMethod(env, transferer, convertDataMethod, fComponent, fTransferable, format, fFormatMap, (jboolean) TRUE); } + CHECK_EXCEPTION(); return data; }
*** 553,567 **** if (success && sNeedsEnter) { [self postDragEnter]; } // DragSourceContextPeer.dragDropFinished() should be called even if there was an error: ! JNF_MEMBER_CACHE(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V"); DLog3(@" -> posting dragDropFinished, point %f, %f", point.x, point.y); ! JNFCallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) ! JNF_MEMBER_CACHE(resetHoveringMethod, CDragSourceContextPeerClass, "resetHovering", "()V"); ! JNFCallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable } @finally { sNeedsEnter = NO; AWTToolkit.inDoDragDropLoop = NO; } --- 566,583 ---- if (success && sNeedsEnter) { [self postDragEnter]; } // DragSourceContextPeer.dragDropFinished() should be called even if there was an error: ! GET_DSCP_CLASS(); ! DECLARE_METHOD(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V"); DLog3(@" -> posting dragDropFinished, point %f, %f", point.x, point.y); ! (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); ! CHECK_EXCEPTION(); ! DECLARE_METHOD(resetHoveringMethod, CDragSourceContextPeerClass, "resetHovering", "()V"); ! (*env)->CallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable ! CHECK_EXCEPTION(); } @finally { sNeedsEnter = NO; AWTToolkit.inDoDragDropLoop = NO; }
*** 575,585 **** - (void)drag { AWT_ASSERT_NOT_APPKIT_THREAD; ! [self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES]; // AWT_THREADING Safe (called from unique asynchronous thread) } /******************************** BEGIN NSDraggingSource Interface ********************************/ - (void)draggingOperationChanged:(NSDragOperation)dragOp { --- 591,601 ---- - (void)drag { AWT_ASSERT_NOT_APPKIT_THREAD; ! [self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES]; } /******************************** BEGIN NSDraggingSource Interface ********************************/ - (void)draggingOperationChanged:(NSDragOperation)dragOp {
*** 592,603 **** NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation]; DLog3(@" -> posting operationChanged, point %f, %f", point.x, point.y); jint modifiedModifiers = fDragKeyModifiers | fDragMouseModifiers | [DnDUtilities javaKeyModifiersForNSDragOperation:dragOp]; ! JNF_MEMBER_CACHE(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V"); ! JNFCallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) } - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)localDrag { //DLog2(@"[CDragSource draggingSourceOperationMaskForLocal]: %@\n", self); return [DnDUtilities mapJavaDragOperationToNS:fSourceActions]; --- 608,621 ---- NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation]; DLog3(@" -> posting operationChanged, point %f, %f", point.x, point.y); jint modifiedModifiers = fDragKeyModifiers | fDragMouseModifiers | [DnDUtilities javaKeyModifiersForNSDragOperation:dragOp]; ! GET_DSCP_CLASS(); ! DECLARE_METHOD(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V"); ! (*env)->CallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); ! CHECK_EXCEPTION(); } - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)localDrag { //DLog2(@"[CDragSource draggingSourceOperationMaskForLocal]: %@\n", self); return [DnDUtilities mapJavaDragOperationToNS:fSourceActions];
*** 624,634 **** - (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint { //DLog4(@"[CDragSource draggedImage moved]: (%d, %d) %@\n", (int) screenPoint.x, (int) screenPoint.y, self); JNIEnv* env = [ThreadUtilities getJNIEnv]; ! JNF_COCOA_ENTER(env); [AWTToolkit eventCountPlusPlus]; // There are two things we would be interested in: // a) mouse pointer has moved // b) drag actions (key modifiers) have changed --- 642,652 ---- - (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint { //DLog4(@"[CDragSource draggedImage moved]: (%d, %d) %@\n", (int) screenPoint.x, (int) screenPoint.y, self); JNIEnv* env = [ThreadUtilities getJNIEnv]; ! JNI_COCOA_ENTER(env); [AWTToolkit eventCountPlusPlus]; // There are two things we would be interested in: // a) mouse pointer has moved // b) drag actions (key modifiers) have changed
*** 665,682 **** // Motion: dragMotion, dragMouseMoved DLog4(@"[CDragSource draggedImage moved]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self); DLog3(@" -> posting dragMotion, point %f, %f", point.x, point.y); ! JNF_MEMBER_CACHE(dragMotionMethod, CDragSourceContextPeerClass, "dragMotion", "(IIII)V"); ! JNFCallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) ! DLog3(@" -> posting dragMouseMoved, point %f, %f", point.x, point.y); ! JNF_MEMBER_CACHE(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V"); ! JNFCallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) } ! JNF_COCOA_EXIT(env); } - (BOOL)ignoreModifierKeysWhileDragging { //DLog2(@"[CDragSource ignoreModifierKeysWhileDragging]: %@\n", self); return NO; --- 683,702 ---- // Motion: dragMotion, dragMouseMoved DLog4(@"[CDragSource draggedImage moved]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self); DLog3(@" -> posting dragMotion, point %f, %f", point.x, point.y); ! GET_DSCP_CLASS(); ! DECLARE_METHOD(dragMotionMethod, CDragSourceContextPeerClass, "dragMotion", "(IIII)V"); ! (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); ! CHECK_EXCEPTION(); DLog3(@" -> posting dragMouseMoved, point %f, %f", point.x, point.y); ! DECLARE_METHOD(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V"); ! (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); ! CHECK_EXCEPTION(); } ! JNI_COCOA_EXIT(env); } - (BOOL)ignoreModifierKeysWhileDragging { //DLog2(@"[CDragSource ignoreModifierKeysWhileDragging]: %@\n", self); return NO;
*** 694,715 **** jint targetActions = fSourceActions; if ([CDropTarget currentDropTarget]) targetActions = [[CDropTarget currentDropTarget] currentJavaActions]; NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation]; DLog3(@" -> posting dragEnter, point %f, %f", point.x, point.y); ! JNF_MEMBER_CACHE(dragEnterMethod, CDragSourceContextPeerClass, "dragEnter", "(IIII)V"); ! JNFCallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) } - (void) postDragExit { JNIEnv *env = [ThreadUtilities getJNIEnv]; sNeedsEnter = YES; NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation]; DLog3(@" -> posting dragExit, point %f, %f", point.x, point.y); ! JNF_MEMBER_CACHE(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V"); ! JNFCallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) } // Java assumes that the origin is the top-left corner of the screen. // Cocoa assumes that the origin is the bottom-left corner of the screen. --- 714,740 ---- jint targetActions = fSourceActions; if ([CDropTarget currentDropTarget]) targetActions = [[CDropTarget currentDropTarget] currentJavaActions]; NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation]; DLog3(@" -> posting dragEnter, point %f, %f", point.x, point.y); ! GET_DSCP_CLASS(); ! DECLARE_METHOD(dragEnterMethod, CDragSourceContextPeerClass, "dragEnter", "(IIII)V"); ! (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); ! CHECK_EXCEPTION(); } - (void) postDragExit { JNIEnv *env = [ThreadUtilities getJNIEnv]; sNeedsEnter = YES; NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation]; DLog3(@" -> posting dragExit, point %f, %f", point.x, point.y); ! GET_DSCP_CLASS(); ! DECLARE_METHOD(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V"); ! (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); ! CHECK_EXCEPTION(); ! } // Java assumes that the origin is the top-left corner of the screen. // Cocoa assumes that the origin is the bottom-left corner of the screen.
< prev index next >