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_CDropTargetContextPeer.h"
27
28 #import <JavaNativeFoundation/JavaNativeFoundation.h>
29
30 #import "CDataTransferer.h"
31 #import "CDropTarget.h"
32 #import "DnDUtilities.h"
33 #import "ThreadUtilities.h"
34
35 JNF_CLASS_CACHE(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer");
36
37
38 static void TransferFailed(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jlong jformat) {
39 AWT_ASSERT_NOT_APPKIT_THREAD;
40 JNF_MEMBER_CACHE(transferFailedMethod, jc_CDropTargetContextPeer, "transferFailed", "(J)V");
41 JNFCallVoidMethod(env, jthis, transferFailedMethod, jformat); // AWT_THREADING Safe (!appKit)
42 }
43
44 static CDropTarget* GetCDropTarget(jlong jdroptarget) {
45 CDropTarget* dropTarget = (CDropTarget*) jlong_to_ptr(jdroptarget);
46
47 // Make sure the drop target is of the right kind:
48 if ([dropTarget isKindOfClass:[CDropTarget class]]) {
49 return dropTarget;
50 }
51
52 return nil;
53 }
54
55
56 /*
57 * Class: sun_lwawt_macosx_CDropTargetContextPeer
58 * Method: startTransfer
59 * Signature: (JJ)J
60 */
61 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_startTransfer
62 (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jformat)
63 {
64
65 jlong result = (jlong) 0L;
66
67 // Currently startTransfer and endTransfer are synchronous since [CDropTarget copyDraggingDataForFormat]
68 // works off a data copy and doesn't have to go to the native event thread to get the data.
69 // We can have endTransfer just call startTransfer.
70
71 JNF_COCOA_ENTER(env);
72 // Get the drop target native object:
73 CDropTarget* dropTarget = GetCDropTarget(jdroptarget);
74 if (dropTarget == nil) {
75 DLog2(@"[CDropTargetContextPeer startTransfer]: GetCDropTarget failed for %d.\n", (NSInteger) jdroptarget);
76 TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
77 return result;
78 }
79
80 JNF_MEMBER_CACHE(newDataMethod, jc_CDropTargetContextPeer, "newData", "(J[B)V");
81 if ((*env)->ExceptionOccurred(env) || !newDataMethod) {
82 DLog2(@"[CDropTargetContextPeer startTransfer]: couldn't get newData method for %d.\n", (NSInteger) jdroptarget);
83 TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
84 return result;
85 }
86
87 // Get data from drop target:
88 jobject jdropdata = [dropTarget copyDraggingDataForFormat:jformat];
89 if (!jdropdata) {
90 DLog2(@"[CDropTargetContextPeer startTransfer]: copyDraggingDataForFormat failed for %d.\n", (NSInteger) jdroptarget);
91 TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
92 return result;
93 }
94
95 // Pass the data to drop target:
96 @try {
97 JNFCallVoidMethod(env, jthis, newDataMethod, jformat, jdropdata); // AWT_THREADING Safe (!appKit)
98 } @catch (NSException *ex) {
99 DLog2(@"[CDropTargetContextPeer startTransfer]: exception in newData() for %d.\n", (NSInteger) jdroptarget);
100 JNFDeleteGlobalRef(env, jdropdata);
101 TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
102 return result;
103 }
104
105 // if no error return dropTarget's draggingSequence
106 result = [dropTarget getDraggingSequenceNumber];
107 JNF_COCOA_EXIT(env);
108
109 return result;
110 }
111
112 /*
113 * Class: sun_lwawt_macosx_CDropTargetContextPeer
114 * Method: addTransfer
115 * Signature: (JJJ)V
116 */
117 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_addTransfer
118 (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jlong jformat)
119 {
120 // Currently startTransfer and endTransfer are synchronous since [CDropTarget copyDraggingDataForFormat]
121 // works off a data copy and doesn't have to go to the native event thread to get the data.
122 // We can have endTransfer just call startTransfer.
123
124 Java_sun_lwawt_macosx_CDropTargetContextPeer_startTransfer(env, jthis, jdroptarget, jformat);
125
126 return;
127 }
128
129 /*
130 * Class: sun_lwawt_macosx_CDropTargetContextPeer
131 * Method: dropDone
132 * Signature: (JJZZI)V
133 */
134 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_dropDone
135 (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jboolean jislocal, jboolean jsuccess, jint jdropaction)
136 {
137 // Get the drop target native object:
138 JNF_COCOA_ENTER(env);
139 CDropTarget* dropTarget = GetCDropTarget(jdroptarget);
140 if (dropTarget == nil) {
141 DLog2(@"[CDropTargetContextPeer dropDone]: GetCDropTarget failed for %d.\n", (NSInteger) jdroptarget);
142 return;
143 }
144
145 // Notify drop target Java is all done with this dragging sequence:
146 [dropTarget javaDraggingEnded:(jlong)jdroptransfer success:jsuccess action:jdropaction];
147 JNF_COCOA_EXIT(env);
148
149 return;
150 }
|
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_CDropTargetContextPeer.h"
27
28 #import "CDataTransferer.h"
29 #import "CDropTarget.h"
30 #import "DnDUtilities.h"
31 #import "ThreadUtilities.h"
32 #import "JNIUtilities.h"
33
34 jclass jc_CDropTargetContextPeer = NULL;
35 #define GET_DTCP_CLASS() \
36 GET_CLASS(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer");
37
38 #define GET_DTCP_CLASS_RETURN(ret) \
39 GET_CLASS_RETURN(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer", ret);
40
41
42 static void TransferFailed(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jlong jformat) {
43 AWT_ASSERT_NOT_APPKIT_THREAD;
44 GET_DTCP_CLASS();
45 DECLARE_METHOD(transferFailedMethod, jc_CDropTargetContextPeer, "transferFailed", "(J)V");
46 (*env)->CallVoidMethod(env, jthis, transferFailedMethod, jformat); // AWT_THREADING Safe (!appKit)
47 CHECK_EXCEPTION();
48 }
49
50 static CDropTarget* GetCDropTarget(jlong jdroptarget) {
51 CDropTarget* dropTarget = (CDropTarget*) jlong_to_ptr(jdroptarget);
52
53 // Make sure the drop target is of the right kind:
54 if ([dropTarget isKindOfClass:[CDropTarget class]]) {
55 return dropTarget;
56 }
57
58 return nil;
59 }
60
61
62 /*
63 * Class: sun_lwawt_macosx_CDropTargetContextPeer
64 * Method: startTransfer
65 * Signature: (JJ)J
66 */
67 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_startTransfer
68 (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jformat)
69 {
70
71 jlong result = (jlong) 0L;
72
73 // Currently startTransfer and endTransfer are synchronous since [CDropTarget copyDraggingDataForFormat]
74 // works off a data copy and doesn't have to go to the native event thread to get the data.
75 // We can have endTransfer just call startTransfer.
76
77 JNI_COCOA_ENTER(env);
78 // Get the drop target native object:
79 CDropTarget* dropTarget = GetCDropTarget(jdroptarget);
80 if (dropTarget == nil) {
81 DLog2(@"[CDropTargetContextPeer startTransfer]: GetCDropTarget failed for %d.\n", (NSInteger) jdroptarget);
82 TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
83 return result;
84 }
85
86 GET_DTCP_CLASS_RETURN(result);
87 DECLARE_METHOD_RETURN(newDataMethod, jc_CDropTargetContextPeer, "newData", "(J[B)V", result);
88 if ((*env)->ExceptionOccurred(env) || !newDataMethod) {
89 DLog2(@"[CDropTargetContextPeer startTransfer]: couldn't get newData method for %d.\n", (NSInteger) jdroptarget);
90 TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
91 return result;
92 }
93
94 // Get data from drop target:
95 jobject jdropdata = [dropTarget copyDraggingDataForFormat:jformat];
96 if (!jdropdata) {
97 DLog2(@"[CDropTargetContextPeer startTransfer]: copyDraggingDataForFormat failed for %d.\n", (NSInteger) jdroptarget);
98 TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
99 return result;
100 }
101
102 // Pass the data to drop target:
103 @try {
104 (*env)->CallVoidMethod(env, jthis, newDataMethod, jformat, jdropdata); // AWT_THREADING Safe (!appKit)
105 } @catch (NSException *ex) {
106 DLog2(@"[CDropTargetContextPeer startTransfer]: exception in newData() for %d.\n", (NSInteger) jdroptarget);
107 (*env)->DeleteGlobalRef(env, jdropdata);
108 TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat);
109 return result;
110 }
111
112 // if no error return dropTarget's draggingSequence
113 result = [dropTarget getDraggingSequenceNumber];
114 JNI_COCOA_EXIT(env);
115
116 return result;
117 }
118
119 /*
120 * Class: sun_lwawt_macosx_CDropTargetContextPeer
121 * Method: addTransfer
122 * Signature: (JJJ)V
123 */
124 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_addTransfer
125 (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jlong jformat)
126 {
127 // Currently startTransfer and endTransfer are synchronous since [CDropTarget copyDraggingDataForFormat]
128 // works off a data copy and doesn't have to go to the native event thread to get the data.
129 // We can have endTransfer just call startTransfer.
130
131 Java_sun_lwawt_macosx_CDropTargetContextPeer_startTransfer(env, jthis, jdroptarget, jformat);
132
133 return;
134 }
135
136 /*
137 * Class: sun_lwawt_macosx_CDropTargetContextPeer
138 * Method: dropDone
139 * Signature: (JJZZI)V
140 */
141 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CDropTargetContextPeer_dropDone
142 (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jboolean jislocal, jboolean jsuccess, jint jdropaction)
143 {
144 // Get the drop target native object:
145 JNI_COCOA_ENTER(env);
146 CDropTarget* dropTarget = GetCDropTarget(jdroptarget);
147 if (dropTarget == nil) {
148 DLog2(@"[CDropTargetContextPeer dropDone]: GetCDropTarget failed for %d.\n", (NSInteger) jdroptarget);
149 return;
150 }
151
152 // Notify drop target Java is all done with this dragging sequence:
153 [dropTarget javaDraggingEnded:(jlong)jdroptransfer success:jsuccess action:jdropaction];
154 JNI_COCOA_EXIT(env);
155
156 return;
157 }
|