< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.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

*** 29,47 **** #import "AWTView.h" #import "sun_lwawt_macosx_CDropTarget.h" #import "java_awt_dnd_DnDConstants.h" - #import <JavaNativeFoundation/JavaNativeFoundation.h> #import <JavaRuntimeSupport/JavaRuntimeSupport.h> #include <objc/objc-runtime.h> #import "CDragSource.h" #import "CDataTransferer.h" #import "DnDUtilities.h" #import "ThreadUtilities.h" static NSInteger sDraggingSequenceNumber = -1; static NSDragOperation sDragOperation; static NSDragOperation sUpdateOperation; --- 29,47 ---- #import "AWTView.h" #import "sun_lwawt_macosx_CDropTarget.h" #import "java_awt_dnd_DnDConstants.h" #import <JavaRuntimeSupport/JavaRuntimeSupport.h> #include <objc/objc-runtime.h> #import "CDragSource.h" #import "CDataTransferer.h" #import "DnDUtilities.h" #import "ThreadUtilities.h" + #import "JNIUtilities.h" static NSInteger sDraggingSequenceNumber = -1; static NSDragOperation sDragOperation; static NSDragOperation sUpdateOperation;
*** 55,65 **** static NSArray* sPasteboardData = nil; static jlongArray sDraggingFormats = nil; static CDropTarget* sCurrentDropTarget; ! extern JNFClassInfo jc_CDropTargetContextPeer; @implementation CDropTarget + (CDropTarget *) currentDropTarget { return sCurrentDropTarget; --- 55,70 ---- static NSArray* sPasteboardData = nil; static jlongArray sDraggingFormats = nil; static CDropTarget* sCurrentDropTarget; ! extern jclass jc_CDropTargetContextPeer; ! #define GET_DTCP_CLASS() \ ! GET_CLASS(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer"); ! ! #define GET_DTCP_CLASS_RETURN(ret) \ ! GET_CLASS_RETURN(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer", ret); @implementation CDropTarget + (CDropTarget *) currentDropTarget { return sCurrentDropTarget;
*** 76,87 **** fDropTargetContextPeer = nil; if (control != nil) { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; ! fComponent = JNFNewGlobalRef(env, jcomponent); ! fDropTarget = JNFNewGlobalRef(env, jdropTarget); fView = [((AWTView *) control) retain]; [fView setDropTarget:self]; --- 81,92 ---- fDropTargetContextPeer = nil; if (control != nil) { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; ! fComponent = (*env)->NewGlobalRef(env, jcomponent); ! fDropTarget = (*env)->NewGlobalRef(env, jdropTarget); fView = [((AWTView *) control) retain]; [fView setDropTarget:self];
*** 140,150 **** [sPasteboardData release]; sPasteboardData = nil; if (sDraggingFormats != NULL) { JNIEnv *env = [ThreadUtilities getJNIEnv]; ! JNFDeleteGlobalRef(env, sDraggingFormats); sDraggingFormats = NULL; } sPasteboardItemsCount = 0; sDraggingSequenceNumber = -1; --- 145,155 ---- [sPasteboardData release]; sPasteboardData = nil; if (sDraggingFormats != NULL) { JNIEnv *env = [ThreadUtilities getJNIEnv]; ! (*env)->DeleteGlobalRef(env, sDraggingFormats); sDraggingFormats = NULL; } sPasteboardItemsCount = 0; sDraggingSequenceNumber = -1;
*** 157,175 **** // Remove this dragging destination from the view: [((AWTView *) fView) setDropTarget:nil]; // Clean up JNI refs if (fComponent != NULL) { ! JNFDeleteGlobalRef(env, fComponent); fComponent = NULL; } if (fDropTarget != NULL) { ! JNFDeleteGlobalRef(env, fDropTarget); fDropTarget = NULL; } if (fDropTargetContextPeer != NULL) { ! JNFDeleteGlobalRef(env, fDropTargetContextPeer); fDropTargetContextPeer = NULL; } [self release]; } --- 162,180 ---- // Remove this dragging destination from the view: [((AWTView *) fView) setDropTarget:nil]; // Clean up JNI refs if (fComponent != NULL) { ! (*env)->DeleteGlobalRef(env, fComponent); fComponent = NULL; } if (fDropTarget != NULL) { ! (*env)->DeleteGlobalRef(env, fDropTarget); fDropTarget = NULL; } if (fDropTargetContextPeer != NULL) { ! (*env)->DeleteGlobalRef(env, fDropTargetContextPeer); fDropTargetContextPeer = NULL; } [self release]; }
*** 231,241 **** jlongArray formats = (*env)->NewLongArray(env, sPasteboardItemsCount); if (formats == nil) return FALSE; ! sDraggingFormats = (jlongArray) JNFNewGlobalRef(env, formats); (*env)->DeleteLocalRef(env, formats); if (sDraggingFormats == nil) return FALSE; jboolean isCopy; --- 236,246 ---- jlongArray formats = (*env)->NewLongArray(env, sPasteboardItemsCount); if (formats == nil) return FALSE; ! sDraggingFormats = (jlongArray) (*env)->NewGlobalRef(env, formats); (*env)->DeleteLocalRef(env, formats); if (sDraggingFormats == nil) return FALSE; jboolean isCopy;
*** 348,358 **** // Create a global byte array: jbyteArray lbyteArray = (*env)->NewByteArray(env, dataLength); if (lbyteArray == nil) return nil; ! jbyteArray gbyteArray = (jbyteArray) JNFNewGlobalRef(env, lbyteArray); (*env)->DeleteLocalRef(env, lbyteArray); if (gbyteArray == nil) return nil; // Get byte array elements: --- 353,363 ---- // Create a global byte array: jbyteArray lbyteArray = (*env)->NewByteArray(env, dataLength); if (lbyteArray == nil) return nil; ! jbyteArray gbyteArray = (jbyteArray) (*env)->NewGlobalRef(env, lbyteArray); (*env)->DeleteLocalRef(env, lbyteArray); if (gbyteArray == nil) return nil; // Get byte array elements:
*** 451,472 **** sDraggingSequenceNumber = draggingSequenceNumber; sDraggingError = FALSE; // Delete any drop target context peer left over from a previous drag: if (fDropTargetContextPeer != NULL) { ! JNFDeleteGlobalRef(env, fDropTargetContextPeer); fDropTargetContextPeer = NULL; } // Look up the CDropTargetContextPeer class: ! JNF_STATIC_MEMBER_CACHE(getDropTargetContextPeerMethod, jc_CDropTargetContextPeer, "getDropTargetContextPeer", "()Lsun/lwawt/macosx/CDropTargetContextPeer;"); if (sDraggingError == FALSE) { // Create a new drop target context peer: ! jobject dropTargetContextPeer = JNFCallStaticObjectMethod(env, getDropTargetContextPeerMethod); if (dropTargetContextPeer != nil) { ! fDropTargetContextPeer = JNFNewGlobalRef(env, dropTargetContextPeer); (*env)->DeleteLocalRef(env, dropTargetContextPeer); } } // Get dragging types (dragging data is only copied if dropped): --- 456,480 ---- sDraggingSequenceNumber = draggingSequenceNumber; sDraggingError = FALSE; // Delete any drop target context peer left over from a previous drag: if (fDropTargetContextPeer != NULL) { ! (*env)->DeleteGlobalRef(env, fDropTargetContextPeer); fDropTargetContextPeer = NULL; } // Look up the CDropTargetContextPeer class: ! GET_DTCP_CLASS_RETURN(dragOp); ! DECLARE_STATIC_METHOD_RETURN(getDropTargetContextPeerMethod, jc_CDropTargetContextPeer, ! "getDropTargetContextPeer", "()Lsun/lwawt/macosx/CDropTargetContextPeer;", dragOp) if (sDraggingError == FALSE) { // Create a new drop target context peer: ! jobject dropTargetContextPeer = (*env)->CallStaticObjectMethod(env, jc_CDropTargetContextPeer, getDropTargetContextPeerMethod); ! CHECK_EXCEPTION(); if (dropTargetContextPeer != nil) { ! fDropTargetContextPeer = (*env)->NewGlobalRef(env, dropTargetContextPeer); (*env)->DeleteLocalRef(env, dropTargetContextPeer); } } // Get dragging types (dragging data is only copied if dropped):
*** 491,507 **** sJavaDropOperation = dropAction; ////////// END Calculate the current drag actions ////////// jlongArray formats = sDraggingFormats; ! JNF_MEMBER_CACHE(handleEnterMessageMethod, jc_CDropTargetContextPeer, "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I"); if (sDraggingError == FALSE) { // Double-casting self gets rid of 'different size' compiler warning: // AWT_THREADING Safe (CToolkitThreadBlockedHandler) ! actions = JNFCallIntMethod(env, fDropTargetContextPeer, handleEnterMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); } if (sDraggingError == FALSE) { // Initialize drag operation: sDragOperation = NSDragOperationNone; --- 499,518 ---- sJavaDropOperation = dropAction; ////////// END Calculate the current drag actions ////////// jlongArray formats = sDraggingFormats; ! GET_DTCP_CLASS_RETURN(dragOp); ! DECLARE_METHOD_RETURN(handleEnterMessageMethod, jc_CDropTargetContextPeer, ! "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I", dragOp); if (sDraggingError == FALSE) { // Double-casting self gets rid of 'different size' compiler warning: // AWT_THREADING Safe (CToolkitThreadBlockedHandler) ! actions = (*env)->CallIntMethod(env, fDropTargetContextPeer, handleEnterMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); + CHECK_EXCEPTION(); } if (sDraggingError == FALSE) { // Initialize drag operation: sDragOperation = NSDragOperationNone;
*** 576,589 **** javaLocation.y = fView.window.frame.size.height - javaLocation.y; //DLog5(@" : dragMoved: loc native %f, %f, java %f, %f\n", sDraggingLocation.x, sDraggingLocation.y, javaLocation.x, javaLocation.y); jlongArray formats = sDraggingFormats; ! JNF_MEMBER_CACHE(handleMotionMessageMethod, jc_CDropTargetContextPeer, "handleMotionMessage", "(Ljava/awt/Component;IIII[JJ)I"); if (sDraggingError == FALSE) { DLog3(@" >> posting handleMotionMessage, point %f, %f", javaLocation.x, javaLocation.y); ! userAction = JNFCallIntMethod(env, fDropTargetContextPeer, handleMotionMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler) } if (sDraggingError == FALSE) { dragOp = [DnDUtilities mapJavaDragOperationToNS:userAction]; --- 587,603 ---- javaLocation.y = fView.window.frame.size.height - javaLocation.y; //DLog5(@" : dragMoved: loc native %f, %f, java %f, %f\n", sDraggingLocation.x, sDraggingLocation.y, javaLocation.x, javaLocation.y); jlongArray formats = sDraggingFormats; ! GET_DTCP_CLASS_RETURN(dragOp); ! DECLARE_METHOD_RETURN(handleMotionMessageMethod, jc_CDropTargetContextPeer, "handleMotionMessage", "(Ljava/awt/Component;IIII[JJ)I", dragOp); if (sDraggingError == FALSE) { DLog3(@" >> posting handleMotionMessage, point %f, %f", javaLocation.x, javaLocation.y); ! userAction = (*env)->CallIntMethod(env, fDropTargetContextPeer, handleMotionMessageMethod, fComponent, ! (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler) ! CHECK_EXCEPTION(); } if (sDraggingError == FALSE) { dragOp = [DnDUtilities mapJavaDragOperationToNS:userAction];
*** 606,621 **** sCurrentDropTarget = nil; JNIEnv* env = [ThreadUtilities getJNIEnv]; if (sDraggingExited == FALSE && sDraggingError == FALSE) { ! JNF_MEMBER_CACHE(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V"); if (sDraggingError == FALSE) { DLog3(@" - dragExit: loc native %f, %f\n", sDraggingLocation.x, sDraggingLocation.y); // AWT_THREADING Safe (CToolkitThreadBlockedHandler) ! JNFCallVoidMethod(env, fDropTargetContextPeer, handleExitMessageMethod, fComponent, ptr_to_jlong(self)); } // 5-27-03 Note: [Radar 3270455] // -draggingExited: can be called both by the AppKit and by -performDragOperation: but shouldn't execute // twice per drop since cleanup code like that in swing/plaf/basic/BasicDropTargetListener would throw NPEs. --- 620,637 ---- sCurrentDropTarget = nil; JNIEnv* env = [ThreadUtilities getJNIEnv]; if (sDraggingExited == FALSE && sDraggingError == FALSE) { ! GET_DTCP_CLASS(); ! DECLARE_METHOD(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V"); if (sDraggingError == FALSE) { DLog3(@" - dragExit: loc native %f, %f\n", sDraggingLocation.x, sDraggingLocation.y); // AWT_THREADING Safe (CToolkitThreadBlockedHandler) ! (*env)->CallVoidMethod(env, fDropTargetContextPeer, handleExitMessageMethod, fComponent, ptr_to_jlong(self)); + CHECK_EXCEPTION(); } // 5-27-03 Note: [Radar 3270455] // -draggingExited: can be called both by the AppKit and by -performDragOperation: but shouldn't execute // twice per drop since cleanup code like that in swing/plaf/basic/BasicDropTargetListener would throw NPEs.
*** 656,669 **** jint actions = [DnDUtilities mapNSDragOperationMaskToJava:[sender draggingSourceOperationMask]]; jint dropAction = sJavaDropOperation; jlongArray formats = sDraggingFormats; ! JNF_MEMBER_CACHE(handleDropMessageMethod, jc_CDropTargetContextPeer, "handleDropMessage", "(Ljava/awt/Component;IIII[JJ)V"); if (sDraggingError == FALSE) { ! JNFCallVoidMethod(env, fDropTargetContextPeer, handleDropMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (event) } } else { // 8-19-03 Note: [Radar 3368754] // draggingExited: is not called after a drop - we must do that here ... but only in case // of an error, instead of drop(). Otherwise we get twice the cleanup in shared code. --- 672,688 ---- jint actions = [DnDUtilities mapNSDragOperationMaskToJava:[sender draggingSourceOperationMask]]; jint dropAction = sJavaDropOperation; jlongArray formats = sDraggingFormats; ! GET_DTCP_CLASS_RETURN(NO); ! DECLARE_METHOD_RETURN(handleDropMessageMethod, jc_CDropTargetContextPeer, "handleDropMessage", "(Ljava/awt/Component;IIII[JJ)V", NO); if (sDraggingError == FALSE) { ! (*env)->CallVoidMethod(env, fDropTargetContextPeer, handleDropMessageMethod, fComponent, ! (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (event) ! CHECK_EXCEPTION(); } } else { // 8-19-03 Note: [Radar 3368754] // draggingExited: is not called after a drop - we must do that here ... but only in case // of an error, instead of drop(). Otherwise we get twice the cleanup in shared code.
*** 709,722 **** JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDropTarget_createNativeDropTarget (JNIEnv *env, jobject jthis, jobject jdroptarget, jobject jcomponent, jlong jnativepeer) { CDropTarget* dropTarget = nil; ! JNF_COCOA_ENTER(env); id controlObj = (id) jlong_to_ptr(jnativepeer); dropTarget = [[CDropTarget alloc] init:jdroptarget component:jcomponent control:controlObj]; ! JNF_COCOA_EXIT(env); return ptr_to_jlong(dropTarget); } /* --- 728,741 ---- JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDropTarget_createNativeDropTarget (JNIEnv *env, jobject jthis, jobject jdroptarget, jobject jcomponent, jlong jnativepeer) { CDropTarget* dropTarget = nil; ! JNI_COCOA_ENTER(env); id controlObj = (id) jlong_to_ptr(jnativepeer); dropTarget = [[CDropTarget alloc] init:jdroptarget component:jcomponent control:controlObj]; ! JNI_COCOA_EXIT(env); return ptr_to_jlong(dropTarget); } /*
*** 727,735 **** JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTarget_releaseNativeDropTarget (JNIEnv *env, jobject jthis, jlong nativeDropTargetVal) { id dropTarget = (id)jlong_to_ptr(nativeDropTargetVal); ! JNF_COCOA_ENTER(env); [dropTarget removeFromView:env]; ! JNF_COCOA_EXIT(env); } --- 746,754 ---- JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTarget_releaseNativeDropTarget (JNIEnv *env, jobject jthis, jlong nativeDropTargetVal) { id dropTarget = (id)jlong_to_ptr(nativeDropTargetVal); ! JNI_COCOA_ENTER(env); [dropTarget removeFromView:env]; ! JNI_COCOA_EXIT(env); }
< prev index next >