1 /* 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #import "sun_lwawt_macosx_CDragSourceContextPeer.h" 27 28 #import <JavaNativeFoundation/JavaNativeFoundation.h> 29 30 #import "CDragSource.h" 31 #import "ThreadUtilities.h" 32 33 34 /* 35 * Class: sun_lwawt_macosx_CDragSourceContextPeer 36 * Method: createNativeDragSource 37 * Signature: (Ljava/awt/Component;JLjava/awt/datatransfer/Transferable; 38 Ljava/awt/event/InputEvent;IIIIJIJIII[JLjava/util/Map;)J 39 */ 40 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_createNativeDragSource 41 (JNIEnv *env, jobject jthis, jobject jcomponent, jlong jnativepeer, jobject jtransferable, 42 jobject jtrigger, jint jdragposx, jint jdragposy, jint jextmodifiers, jint jclickcount, jlong jtimestamp, 43 jlong nsdragimageptr, jint jdragimageoffsetx, jint jdragimageoffsety, 44 jint jsourceactions, jlongArray jformats, jobject jformatmap) 45 { 46 id controlObj = (id) jlong_to_ptr(jnativepeer); 47 __block CDragSource* dragSource = nil; 48 49 JNF_COCOA_ENTER(env); 50 51 // Global references are disposed when the DragSource is removed 52 jobject gComponent = JNFNewGlobalRef(env, jcomponent); 53 jobject gDragSourceContextPeer = JNFNewGlobalRef(env, jthis); 54 jobject gTransferable = JNFNewGlobalRef(env, jtransferable); 55 jobject gTriggerEvent = JNFNewGlobalRef(env, jtrigger); 56 jlongArray gFormats = JNFNewGlobalRef(env, jformats); 57 jobject gFormatMap = JNFNewGlobalRef(env, jformatmap); 58 59 [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ 60 dragSource = [[CDragSource alloc] init:gDragSourceContextPeer 61 component:gComponent 62 control:controlObj 63 transferable:gTransferable 64 triggerEvent:gTriggerEvent 65 dragPosX:jdragposx 66 dragPosY:jdragposy 67 modifiers:jextmodifiers 68 clickCount:jclickcount 69 timeStamp:jtimestamp 70 dragImage:nsdragimageptr 71 dragImageOffsetX:jdragimageoffsetx 72 dragImageOffsetY:jdragimageoffsety 73 sourceActions:jsourceactions 74 formats:gFormats 75 formatMap:gFormatMap]; 76 }]; 77 JNF_COCOA_EXIT(env); 78 79 if (dragSource) { 80 CFRetain(dragSource); // GC 81 [dragSource release]; 82 } 83 return ptr_to_jlong(dragSource); 84 } 85 86 /* 87 * Class: sun_lwawt_macosx_CDragSourceContextPeer 88 * Method: doDragging 89 * Signature: (J)V 90 */ 91 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_doDragging 92 (JNIEnv *env, jobject jthis, jlong nativeDragSourceVal) 93 { 94 AWT_ASSERT_NOT_APPKIT_THREAD; 95 96 CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal); 97 98 JNF_COCOA_ENTER(env); 99 [dragSource drag]; 100 JNF_COCOA_EXIT(env); 101 } 102 103 /* 104 * Class: sun_lwawt_macosx_CDragSourceContextPeer 105 * Method: releaseNativeDragSource 106 * Signature: (J)V 107 */ 108 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_releaseNativeDragSource 109 (JNIEnv *env, jobject jthis, jlong nativeDragSourceVal) 110 { 111 CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal); 112 113 JNF_COCOA_ENTER(env); 114 [dragSource removeFromView:env]; 115 JNF_COCOA_EXIT(env); 116 }