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 "JNIUtilities.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 */ 40JNIEXPORT 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 49JNI_COCOA_ENTER(env); 50 51 // Global references are disposed when the DragSource is removed 52 jobject gComponent = (*env)->NewGlobalRef(env, jcomponent); 53 jobject gDragSourceContextPeer = (*env)->NewGlobalRef(env, jthis); 54 jobject gTransferable = (*env)->NewGlobalRef(env, jtransferable); 55 jobject gTriggerEvent = (*env)->NewGlobalRef(env, jtrigger); 56 jlongArray gFormats = (*env)->NewGlobalRef(env, jformats); 57 jobject gFormatMap = (*env)->NewGlobalRef(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 }]; 77JNI_COCOA_EXIT(env); 78 79 return ptr_to_jlong(dragSource); 80} 81 82/* 83 * Class: sun_lwawt_macosx_CDragSourceContextPeer 84 * Method: doDragging 85 * Signature: (J)V 86 */ 87JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_doDragging 88 (JNIEnv *env, jobject jthis, jlong nativeDragSourceVal) 89{ 90 AWT_ASSERT_NOT_APPKIT_THREAD; 91 92 CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal); 93 94JNI_COCOA_ENTER(env); 95 [dragSource drag]; 96JNI_COCOA_EXIT(env); 97} 98 99/* 100 * Class: sun_lwawt_macosx_CDragSourceContextPeer 101 * Method: releaseNativeDragSource 102 * Signature: (J)V 103 */ 104JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_releaseNativeDragSource 105 (JNIEnv *env, jobject jthis, jlong nativeDragSourceVal) 106{ 107 CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal); 108 109JNI_COCOA_ENTER(env); 110 [dragSource removeFromView:env]; 111JNI_COCOA_EXIT(env); 112} 113