< 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,19 +29,19 @@
#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"
+#import "JNIUtilities.h"
static NSInteger sDraggingSequenceNumber = -1;
static NSDragOperation sDragOperation;
static NSDragOperation sUpdateOperation;
@@ -55,11 +55,16 @@
static NSArray* sPasteboardData = nil;
static jlongArray sDraggingFormats = nil;
static CDropTarget* sCurrentDropTarget;
-extern JNFClassInfo jc_CDropTargetContextPeer;
+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,12 +81,12 @@
fDropTargetContextPeer = nil;
if (control != nil) {
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
- fComponent = JNFNewGlobalRef(env, jcomponent);
- fDropTarget = JNFNewGlobalRef(env, jdropTarget);
+ fComponent = (*env)->NewGlobalRef(env, jcomponent);
+ fDropTarget = (*env)->NewGlobalRef(env, jdropTarget);
fView = [((AWTView *) control) retain];
[fView setDropTarget:self];
@@ -140,11 +145,11 @@
[sPasteboardData release];
sPasteboardData = nil;
if (sDraggingFormats != NULL) {
JNIEnv *env = [ThreadUtilities getJNIEnv];
- JNFDeleteGlobalRef(env, sDraggingFormats);
+ (*env)->DeleteGlobalRef(env, sDraggingFormats);
sDraggingFormats = NULL;
}
sPasteboardItemsCount = 0;
sDraggingSequenceNumber = -1;
@@ -157,19 +162,19 @@
// Remove this dragging destination from the view:
[((AWTView *) fView) setDropTarget:nil];
// Clean up JNI refs
if (fComponent != NULL) {
- JNFDeleteGlobalRef(env, fComponent);
+ (*env)->DeleteGlobalRef(env, fComponent);
fComponent = NULL;
}
if (fDropTarget != NULL) {
- JNFDeleteGlobalRef(env, fDropTarget);
+ (*env)->DeleteGlobalRef(env, fDropTarget);
fDropTarget = NULL;
}
if (fDropTargetContextPeer != NULL) {
- JNFDeleteGlobalRef(env, fDropTargetContextPeer);
+ (*env)->DeleteGlobalRef(env, fDropTargetContextPeer);
fDropTargetContextPeer = NULL;
}
[self release];
}
@@ -231,11 +236,11 @@
jlongArray formats = (*env)->NewLongArray(env, sPasteboardItemsCount);
if (formats == nil)
return FALSE;
- sDraggingFormats = (jlongArray) JNFNewGlobalRef(env, formats);
+ sDraggingFormats = (jlongArray) (*env)->NewGlobalRef(env, formats);
(*env)->DeleteLocalRef(env, formats);
if (sDraggingFormats == nil)
return FALSE;
jboolean isCopy;
@@ -348,11 +353,11 @@
// Create a global byte array:
jbyteArray lbyteArray = (*env)->NewByteArray(env, dataLength);
if (lbyteArray == nil)
return nil;
- jbyteArray gbyteArray = (jbyteArray) JNFNewGlobalRef(env, lbyteArray);
+ jbyteArray gbyteArray = (jbyteArray) (*env)->NewGlobalRef(env, lbyteArray);
(*env)->DeleteLocalRef(env, lbyteArray);
if (gbyteArray == nil)
return nil;
// Get byte array elements:
@@ -451,22 +456,25 @@
sDraggingSequenceNumber = draggingSequenceNumber;
sDraggingError = FALSE;
// Delete any drop target context peer left over from a previous drag:
if (fDropTargetContextPeer != NULL) {
- JNFDeleteGlobalRef(env, fDropTargetContextPeer);
+ (*env)->DeleteGlobalRef(env, fDropTargetContextPeer);
fDropTargetContextPeer = NULL;
}
// Look up the CDropTargetContextPeer class:
- JNF_STATIC_MEMBER_CACHE(getDropTargetContextPeerMethod, jc_CDropTargetContextPeer, "getDropTargetContextPeer", "()Lsun/lwawt/macosx/CDropTargetContextPeer;");
+ 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 = JNFCallStaticObjectMethod(env, getDropTargetContextPeerMethod);
+ jobject dropTargetContextPeer = (*env)->CallStaticObjectMethod(env, jc_CDropTargetContextPeer, getDropTargetContextPeerMethod);
+ CHECK_EXCEPTION();
if (dropTargetContextPeer != nil) {
- fDropTargetContextPeer = JNFNewGlobalRef(env, dropTargetContextPeer);
+ fDropTargetContextPeer = (*env)->NewGlobalRef(env, dropTargetContextPeer);
(*env)->DeleteLocalRef(env, dropTargetContextPeer);
}
}
// Get dragging types (dragging data is only copied if dropped):
@@ -491,17 +499,20 @@
sJavaDropOperation = dropAction;
////////// END Calculate the current drag actions //////////
jlongArray formats = sDraggingFormats;
- JNF_MEMBER_CACHE(handleEnterMessageMethod, jc_CDropTargetContextPeer, "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I");
+ 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 = JNFCallIntMethod(env, fDropTargetContextPeer, handleEnterMessageMethod,
+ 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,14 +587,17 @@
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");
+ 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 = JNFCallIntMethod(env, fDropTargetContextPeer, handleMotionMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler)
+ 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,16 +620,18 @@
sCurrentDropTarget = nil;
JNIEnv* env = [ThreadUtilities getJNIEnv];
if (sDraggingExited == FALSE && sDraggingError == FALSE) {
- JNF_MEMBER_CACHE(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V");
+ 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)
- JNFCallVoidMethod(env, fDropTargetContextPeer,
+ (*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,14 +672,17 @@
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");
+ GET_DTCP_CLASS_RETURN(NO);
+ DECLARE_METHOD_RETURN(handleDropMessageMethod, jc_CDropTargetContextPeer, "handleDropMessage", "(Ljava/awt/Component;IIII[JJ)V", NO);
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)
+ (*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,14 +728,14 @@
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);
+JNI_COCOA_ENTER(env);
id controlObj = (id) jlong_to_ptr(jnativepeer);
dropTarget = [[CDropTarget alloc] init:jdroptarget component:jcomponent control:controlObj];
-JNF_COCOA_EXIT(env);
+JNI_COCOA_EXIT(env);
return ptr_to_jlong(dropTarget);
}
/*
@@ -727,9 +746,9 @@
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);
+JNI_COCOA_ENTER(env);
[dropTarget removeFromView:env];
-JNF_COCOA_EXIT(env);
+JNI_COCOA_EXIT(env);
}
< prev index next >