< 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,20 +26,20 @@
//#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"
+#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,13 +67,21 @@
// 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 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,36 +166,36 @@
// Remove this dragging source from the view:
[((AWTView *) fView) setDragSource:nil];
// Clean up JNI refs
if (fComponent != NULL) {
- JNFDeleteGlobalRef(env, fComponent);
+ (*env)->DeleteGlobalRef(env, fComponent);
fComponent = NULL;
}
if (fDragSourceContextPeer != NULL) {
- JNFDeleteGlobalRef(env, fDragSourceContextPeer);
+ (*env)->DeleteGlobalRef(env, fDragSourceContextPeer);
fDragSourceContextPeer = NULL;
}
if (fTransferable != NULL) {
- JNFDeleteGlobalRef(env, fTransferable);
+ (*env)->DeleteGlobalRef(env, fTransferable);
fTransferable = NULL;
}
if (fTriggerEvent != NULL) {
- JNFDeleteGlobalRef(env, fTriggerEvent);
+ (*env)->DeleteGlobalRef(env, fTriggerEvent);
fTriggerEvent = NULL;
}
if (fFormats != NULL) {
- JNFDeleteGlobalRef(env, fFormats);
+ (*env)->DeleteGlobalRef(env, fFormats);
fFormats = NULL;
}
if (fFormatMap != NULL) {
- JNFDeleteGlobalRef(env, fFormatMap);
+ (*env)->DeleteGlobalRef(env, fFormatMap);
fFormatMap = NULL;
}
[self release];
}
@@ -210,12 +218,15 @@
//
// * 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);
+ 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,13 +236,15 @@
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);
+ 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,15 +566,18 @@
if (success && sNeedsEnter) {
[self postDragEnter];
}
// DragSourceContextPeer.dragDropFinished() should be called even if there was an error:
- JNF_MEMBER_CACHE(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V");
+ GET_DSCP_CLASS();
+ DECLARE_METHOD(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
+ (*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,11 +591,11 @@
- (void)drag
{
AWT_ASSERT_NOT_APPKIT_THREAD;
- [self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES]; // AWT_THREADING Safe (called from unique asynchronous thread)
+ [self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES];
}
/******************************** BEGIN NSDraggingSource Interface ********************************/
- (void)draggingOperationChanged:(NSDragOperation)dragOp {
@@ -592,12 +608,14 @@
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)
+ 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,11 +642,11 @@
- (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);
+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,18 +683,20 @@
// 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)
-
+ 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);
- 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)
+ DECLARE_METHOD(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V");
+ (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y);
+ CHECK_EXCEPTION();
}
-JNF_COCOA_EXIT(env);
+JNI_COCOA_EXIT(env);
}
- (BOOL)ignoreModifierKeysWhileDragging {
//DLog2(@"[CDragSource ignoreModifierKeysWhileDragging]: %@\n", self);
return NO;
@@ -694,22 +714,27 @@
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)
+ 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);
- JNF_MEMBER_CACHE(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V");
- JNFCallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
+ 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 >