Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m
41152 views
/*1* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#import "sun_lwawt_macosx_CDragSourceContextPeer.h"2627#import "JNIUtilities.h"2829#import "CDragSource.h"30#import "ThreadUtilities.h"313233/*34* Class: sun_lwawt_macosx_CDragSourceContextPeer35* Method: createNativeDragSource36* Signature: (Ljava/awt/Component;JLjava/awt/datatransfer/Transferable;37Ljava/awt/event/InputEvent;IIIIJIJIII[JLjava/util/Map;)J38*/39JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_createNativeDragSource40(JNIEnv *env, jobject jthis, jobject jcomponent, jlong jnativepeer, jobject jtransferable,41jobject jtrigger, jint jdragposx, jint jdragposy, jint jextmodifiers, jint jclickcount, jlong jtimestamp,42jlong nsdragimageptr, jint jdragimageoffsetx, jint jdragimageoffsety,43jint jsourceactions, jlongArray jformats, jobject jformatmap)44{45id controlObj = (id) jlong_to_ptr(jnativepeer);46__block CDragSource* dragSource = nil;4748JNI_COCOA_ENTER(env);4950// Global references are disposed when the DragSource is removed51jobject gComponent = (*env)->NewGlobalRef(env, jcomponent);52jobject gDragSourceContextPeer = (*env)->NewGlobalRef(env, jthis);53jobject gTransferable = (*env)->NewGlobalRef(env, jtransferable);54jobject gTriggerEvent = (*env)->NewGlobalRef(env, jtrigger);55jlongArray gFormats = (*env)->NewGlobalRef(env, jformats);56jobject gFormatMap = (*env)->NewGlobalRef(env, jformatmap);5758[ThreadUtilities performOnMainThreadWaiting:YES block:^(){59dragSource = [[CDragSource alloc] init:gDragSourceContextPeer60component:gComponent61control:controlObj62transferable:gTransferable63triggerEvent:gTriggerEvent64dragPosX:jdragposx65dragPosY:jdragposy66modifiers:jextmodifiers67clickCount:jclickcount68timeStamp:jtimestamp69dragImage:nsdragimageptr70dragImageOffsetX:jdragimageoffsetx71dragImageOffsetY:jdragimageoffsety72sourceActions:jsourceactions73formats:gFormats74formatMap:gFormatMap];75}];76JNI_COCOA_EXIT(env);7778return ptr_to_jlong(dragSource);79}8081/*82* Class: sun_lwawt_macosx_CDragSourceContextPeer83* Method: doDragging84* Signature: (J)V85*/86JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_doDragging87(JNIEnv *env, jobject jthis, jlong nativeDragSourceVal)88{89AWT_ASSERT_NOT_APPKIT_THREAD;9091CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal);9293JNI_COCOA_ENTER(env);94[dragSource drag];95JNI_COCOA_EXIT(env);96}9798/*99* Class: sun_lwawt_macosx_CDragSourceContextPeer100* Method: releaseNativeDragSource101* Signature: (J)V102*/103JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_releaseNativeDragSource104(JNIEnv *env, jobject jthis, jlong nativeDragSourceVal)105{106CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal);107108JNI_COCOA_ENTER(env);109[dragSource removeFromView:env];110JNI_COCOA_EXIT(env);111}112113114