Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/native_NOTIOS/sun/awt/CDropTargetContextPeer.m
38829 views
/*1* Copyright (c) 2011, 2013, 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_CDropTargetContextPeer.h"2627#import <JavaNativeFoundation/JavaNativeFoundation.h>2829#import "CDataTransferer.h"30#import "CDropTarget.h"31#import "DnDUtilities.h"32#import "ThreadUtilities.h"3334JNF_CLASS_CACHE(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer");353637static void TransferFailed(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jlong jformat) {38AWT_ASSERT_NOT_APPKIT_THREAD;39JNF_MEMBER_CACHE(transferFailedMethod, jc_CDropTargetContextPeer, "transferFailed", "(J)V");40JNFCallVoidMethod(env, jthis, transferFailedMethod, jformat); // AWT_THREADING Safe (!appKit)41}4243static CDropTarget* GetCDropTarget(jlong jdroptarget) {44CDropTarget* dropTarget = (CDropTarget*) jlong_to_ptr(jdroptarget);4546// Make sure the drop target is of the right kind:47if ([dropTarget isKindOfClass:[CDropTarget class]]) {48return dropTarget;49}5051return nil;52}535455/*56* Class: sun_lwawt_macosx_CDropTargetContextPeer57* Method: startTransfer58* Signature: (JJ)J59*/60JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_startTransfer61(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jformat)62{6364jlong result = (jlong) 0L;6566// Currently startTransfer and endTransfer are synchronous since [CDropTarget copyDraggingDataForFormat]67// works off a data copy and doesn't have to go to the native event thread to get the data.68// We can have endTransfer just call startTransfer.6970JNF_COCOA_ENTER(env);71// Get the drop target native object:72CDropTarget* dropTarget = GetCDropTarget(jdroptarget);73if (dropTarget == nil) {74DLog2(@"[CDropTargetContextPeer startTransfer]: GetCDropTarget failed for %d.\n", (NSInteger) jdroptarget);75TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);76return result;77}7879JNF_MEMBER_CACHE(newDataMethod, jc_CDropTargetContextPeer, "newData", "(J[B)V");80if ((*env)->ExceptionOccurred(env) || !newDataMethod) {81DLog2(@"[CDropTargetContextPeer startTransfer]: couldn't get newData method for %d.\n", (NSInteger) jdroptarget);82TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);83return result;84}8586// Get data from drop target:87jobject jdropdata = [dropTarget copyDraggingDataForFormat:jformat];88if (!jdropdata) {89DLog2(@"[CDropTargetContextPeer startTransfer]: copyDraggingDataForFormat failed for %d.\n", (NSInteger) jdroptarget);90TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);91return result;92}9394// Pass the data to drop target:95@try {96JNFCallVoidMethod(env, jthis, newDataMethod, jformat, jdropdata); // AWT_THREADING Safe (!appKit)97} @catch (NSException *ex) {98DLog2(@"[CDropTargetContextPeer startTransfer]: exception in newData() for %d.\n", (NSInteger) jdroptarget);99JNFDeleteGlobalRef(env, jdropdata);100TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);101return result;102}103104// if no error return dropTarget's draggingSequence105result = [dropTarget getDraggingSequenceNumber];106JNF_COCOA_EXIT(env);107108return result;109}110111/*112* Class: sun_lwawt_macosx_CDropTargetContextPeer113* Method: addTransfer114* Signature: (JJJ)V115*/116JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_addTransfer117(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jlong jformat)118{119// Currently startTransfer and endTransfer are synchronous since [CDropTarget copyDraggingDataForFormat]120// works off a data copy and doesn't have to go to the native event thread to get the data.121// We can have endTransfer just call startTransfer.122123Java_sun_lwawt_macosx_CDropTargetContextPeer_startTransfer(env, jthis, jdroptarget, jformat);124125return;126}127128/*129* Class: sun_lwawt_macosx_CDropTargetContextPeer130* Method: dropDone131* Signature: (JJZZI)V132*/133JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_dropDone134(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jboolean jislocal, jboolean jsuccess, jint jdropaction)135{136// Get the drop target native object:137JNF_COCOA_ENTER(env);138CDropTarget* dropTarget = GetCDropTarget(jdroptarget);139if (dropTarget == nil) {140DLog2(@"[CDropTargetContextPeer dropDone]: GetCDropTarget failed for %d.\n", (NSInteger) jdroptarget);141return;142}143144// Notify drop target Java is all done with this dragging sequence:145[dropTarget javaDraggingEnded:(jlong)jdroptransfer success:jsuccess action:jdropaction];146JNF_COCOA_EXIT(env);147148return;149}150151152