1 /*
   2  * Copyright (c) 2011, 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    jobject jnsdragimage, 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     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
  51         dragSource = [[CDragSource alloc] init:jthis
  52                                      component:jcomponent
  53                                        control:controlObj
  54                                   transferable:jtransferable
  55                                   triggerEvent:jtrigger
  56                                       dragPosX:jdragposx
  57                                       dragPosY:jdragposy
  58                                      modifiers:jextmodifiers
  59                                     clickCount:jclickcount
  60                                      timeStamp:jtimestamp
  61                                      dragImage:jnsdragimage
  62                               dragImageOffsetX:jdragimageoffsetx
  63                               dragImageOffsetY:jdragimageoffsety
  64                                  sourceActions:jsourceactions
  65                                        formats:jformats
  66                                      formatMap:jformatmap];
  67     }];
  68 JNF_COCOA_EXIT(env);
  69 
  70     if (dragSource) {
  71         CFRetain(dragSource); // GC
  72         [dragSource release];
  73     }
  74     return ptr_to_jlong(dragSource);
  75 }
  76 
  77 /*
  78  * Class:     sun_lwawt_macosx_CDragSourceContextPeer
  79  * Method:    doDragging
  80  * Signature: (J)V
  81  */
  82 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_doDragging
  83   (JNIEnv *env, jobject jthis, jlong nativeDragSourceVal)
  84 {
  85     AWT_ASSERT_NOT_APPKIT_THREAD;
  86 
  87     CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal);
  88 
  89 JNF_COCOA_ENTER(env);
  90     [dragSource drag];
  91 JNF_COCOA_EXIT(env);
  92 }
  93 
  94 /*
  95  * Class:     sun_lwawt_macosx_CDragSourceContextPeer
  96  * Method:    releaseNativeDragSource
  97  * Signature: (J)V
  98  */
  99 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_releaseNativeDragSource
 100   (JNIEnv *env, jobject jthis, jlong nativeDragSourceVal)
 101 {
 102       CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal);
 103 
 104 JNF_COCOA_ENTER(env);
 105     [dragSource removeFromView:env];
 106 JNF_COCOA_EXIT(env);
 107 }