blob: e4be5800759026b6651a8213d3184b9611c32eaf [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2004 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26#ifndef AWT_DATATRANSFERER_H
27#define AWT_DATATRANSFERER_H
28
29#include <X11/Intrinsic.h>
30#include <inttypes.h>
31
32#define _XA_DELETE "DELETE"
33#define _XA_FILENAME "FILE_NAME"
34#define _XA_HOSTNAME "HOST_NAME"
35#define _XA_NULL "NULL"
36#define _DT_FILENAME "_DT_NETFILE"
37
38#define AWT_DND_POLL_INTERVAL ((unsigned long)250) /* milliseconds */
39
40typedef struct {
41 jobject source;
42 jobject transferable;
43 jobject formatMap;
44 jlongArray formats;
45} awt_convertDataCallbackStruct;
46
47extern XContext awt_convertDataContext; /* XContext is not 64 bits */
48
49extern Atom XA_TARGETS;
50
51/*
52 * Single routine to convert to target FILE_NAME or _DT_FILENAME
53 */
54Boolean
55convertFileType(jbyteArray data, Atom * type, XtPointer * value,
56 unsigned long *length, int32_t *format);
57
58Boolean
59awt_convertData(Widget w, Atom * selection, Atom * target, Atom * type,
60 XtPointer * value, unsigned long *length, int32_t *format);
61
62jlongArray
63get_selection_targets(JNIEnv *env, Atom selection, Time time_stamp);
64
65jlongArray
66getSelectionTargetsHelper(JNIEnv* env, XtPointer value, unsigned long length);
67
68jbyteArray
69get_selection_data(JNIEnv *env, Atom selection, Atom format, Time time_stamp);
70
71void
72awt_cleanupConvertDataContext(JNIEnv *env, Atom selectionAtom);
73
74/*
75 * NOTE: You need these macros only if you take care of performance, since they
76 * provide proper caching. Otherwise you can use JNU_CallMethodByName etc.
77 */
78
79/*
80 * This macro defines a function which returns the class for the specified
81 * class name with proper caching and error handling.
82 */
83#define DECLARE_JAVA_CLASS(javaclazz, name) \
84static jclass \
85get_ ## javaclazz(JNIEnv* env) { \
86 static jclass javaclazz = NULL; \
87 \
88 if (JNU_IsNull(env, javaclazz)) { \
89 jclass javaclazz ## Local = (*env)->FindClass(env, name); \
90 \
91 if (!JNU_IsNull(env, javaclazz ## Local)) { \
92 javaclazz = (jclass)(*env)->NewGlobalRef(env, javaclazz ## Local); \
93 (*env)->DeleteLocalRef(env, javaclazz ## Local); \
94 if (JNU_IsNull(env, javaclazz)) { \
95 JNU_ThrowOutOfMemoryError(env, ""); \
96 } \
97 } \
98 \
99 if (!JNU_IsNull(env, ((*env)->ExceptionOccurred(env)))) { \
100 (*env)->ExceptionDescribe(env); \
101 (*env)->ExceptionClear(env); \
102 } \
103 } \
104 \
105 DASSERT(!JNU_IsNull(env, javaclazz)); \
106 \
107 return javaclazz; \
108}
109
110/*
111 * The following macros defines blocks of code which retrieve a method of the
112 * specified class identified with the specified name and signature.
113 * The specified class should be previously declared with DECLARE_JAVA_CLASS.
114 * These macros should be placed at the beginning of a block, after definition
115 * of local variables, but before the code begins.
116 */
117#define DECLARE_VOID_JAVA_METHOD(method, javaclazz, name, signature) \
118 static jmethodID method = NULL; \
119 \
120 if (JNU_IsNull(env, method)) { \
121 jclass clazz = get_ ## javaclazz(env); \
122 \
123 if (JNU_IsNull(env, clazz)) { \
124 return; \
125 } \
126 \
127 method = (*env)->GetMethodID(env, clazz, name, signature); \
128 \
129 if ((*env)->ExceptionCheck(env) == JNI_TRUE) { \
130 (*env)->ExceptionDescribe(env); \
131 (*env)->ExceptionClear(env); \
132 } \
133 \
134 if (JNU_IsNull(env, method)) { \
135 DASSERT(False); \
136 return; \
137 } \
138 }
139
140#define DECLARE_BOOLEAN_JAVA_METHOD(method, javaclazz, name, signature) \
141 static jmethodID method = NULL; \
142 \
143 if (JNU_IsNull(env, method)) { \
144 jclass clazz = get_ ## javaclazz(env); \
145 \
146 if (JNU_IsNull(env, clazz)) { \
147 return False; \
148 } \
149 \
150 method = (*env)->GetMethodID(env, clazz, name, signature); \
151 \
152 if ((*env)->ExceptionCheck(env) == JNI_TRUE) { \
153 (*env)->ExceptionDescribe(env); \
154 (*env)->ExceptionClear(env); \
155 } \
156 \
157 if (JNU_IsNull(env, method)) { \
158 DASSERT(False); \
159 return False; \
160 } \
161 }
162
163#define DECLARE_JINT_JAVA_METHOD(method, javaclazz, name, signature) \
164 static jmethodID method = NULL; \
165 \
166 if (JNU_IsNull(env, method)) { \
167 jclass clazz = get_ ## javaclazz(env); \
168 \
169 if (JNU_IsNull(env, clazz)) { \
170 return java_awt_dnd_DnDConstants_ACTION_NONE; \
171 } \
172 \
173 method = (*env)->GetMethodID(env, clazz, name, signature); \
174 \
175 if ((*env)->ExceptionCheck(env) == JNI_TRUE) { \
176 (*env)->ExceptionDescribe(env); \
177 (*env)->ExceptionClear(env); \
178 } \
179 \
180 if (JNU_IsNull(env, method)) { \
181 DASSERT(False); \
182 return java_awt_dnd_DnDConstants_ACTION_NONE; \
183 } \
184 }
185
186#define DECLARE_OBJECT_JAVA_METHOD(method, javaclazz, name, signature) \
187 static jmethodID method = NULL; \
188 \
189 if (JNU_IsNull(env, method)) { \
190 jclass clazz = get_ ## javaclazz(env); \
191 \
192 if (JNU_IsNull(env, clazz)) { \
193 return NULL; \
194 } \
195 \
196 method = (*env)->GetMethodID(env, clazz, name, signature); \
197 \
198 if ((*env)->ExceptionCheck(env) == JNI_TRUE) { \
199 (*env)->ExceptionDescribe(env); \
200 (*env)->ExceptionClear(env); \
201 } \
202 \
203 if (JNU_IsNull(env, method)) { \
204 DASSERT(False); \
205 return NULL; \
206 } \
207 }
208
209#define DECLARE_STATIC_OBJECT_JAVA_METHOD(method, javaclazz, name, signature) \
210 static jmethodID method = NULL; \
211 jclass clazz = get_ ## javaclazz(env); \
212 \
213 if (JNU_IsNull(env, clazz)) { \
214 return NULL; \
215 } \
216 \
217 if (JNU_IsNull(env, method)) { \
218 method = (*env)->GetStaticMethodID(env, clazz, name, signature); \
219 \
220 if ((*env)->ExceptionCheck(env) == JNI_TRUE) { \
221 (*env)->ExceptionDescribe(env); \
222 (*env)->ExceptionClear(env); \
223 } \
224 \
225 if (JNU_IsNull(env, method)) { \
226 DASSERT(False); \
227 return NULL; \
228 } \
229 }
230
231#define DECLARE_STATIC_VOID_JAVA_METHOD(method, javaclazz, name, signature) \
232 static jmethodID method = NULL; \
233 jclass clazz = get_ ## javaclazz(env); \
234 \
235 if (JNU_IsNull(env, clazz)) { \
236 return; \
237 } \
238 \
239 if (JNU_IsNull(env, method)) { \
240 method = (*env)->GetStaticMethodID(env, clazz, name, signature); \
241 \
242 if ((*env)->ExceptionCheck(env) == JNI_TRUE) { \
243 (*env)->ExceptionDescribe(env); \
244 (*env)->ExceptionClear(env); \
245 } \
246 \
247 if (JNU_IsNull(env, method)) { \
248 DASSERT(False); \
249 return; \
250 } \
251 }
252
253#define DECLARE_STATIC_JINT_JAVA_METHOD(method, javaclazz, name, signature) \
254 static jmethodID method = NULL; \
255 jclass clazz = get_ ## javaclazz(env); \
256 \
257 if (JNU_IsNull(env, clazz)) { \
258 return java_awt_dnd_DnDConstants_ACTION_NONE; \
259 } \
260 \
261 if (JNU_IsNull(env, method)) { \
262 method = (*env)->GetStaticMethodID(env, clazz, name, signature); \
263 \
264 if ((*env)->ExceptionCheck(env) == JNI_TRUE) { \
265 (*env)->ExceptionDescribe(env); \
266 (*env)->ExceptionClear(env); \
267 } \
268 \
269 if (JNU_IsNull(env, method)) { \
270 DASSERT(False); \
271 return java_awt_dnd_DnDConstants_ACTION_NONE; \
272 } \
273 }
274
275#endif /* AWT_DATATRANSFERER_H */