1 /* 2 * Copyright (c) 1995, 2013, 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 #ifndef _AWT_UTIL_H_ 27 #define _AWT_UTIL_H_ 28 29 #ifndef HEADLESS 30 #include "gdefs.h" 31 32 /* 33 * Expected types of arguments of the macro. 34 * (JNIEnv*, const char*, const char*, jboolean, jobject) 35 */ 36 #define WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, \ 37 handlerHasFlag, handlerRef) do { \ 38 handlerRef = JNU_CallStaticMethodByName(env, NULL, handlerClassName, "getInstance", \ 39 getInstanceSignature).l; \ 40 if (handlerHasFlag == JNI_TRUE) { \ 41 JNU_CallMethodByName(env, NULL, handlerRef, "setErrorOccurredFlag", "(Z)V", JNI_FALSE); \ 42 } \ 43 JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "WITH_XERROR_HANDLER", \ 44 "(Lsun/awt/X11/XErrorHandler;)V", handlerRef); \ 45 } while (0) 46 47 /* 48 * Expected types of arguments of the macro. 49 * (JNIEnv*) 50 */ 51 #define RESTORE_XERROR_HANDLER(env) do { \ 52 JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", \ 53 "RESTORE_XERROR_HANDLER", "()V"); \ 54 } while (0) 55 56 /* 57 * Expected types of arguments of the macro. 58 * (JNIEnv*, const char*, const char*, jboolean, jobject, jboolean, No type - C expression) 59 */ 60 #define EXEC_WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, \ 61 handlerRef, errorOccurredFlag, code) do { \ 62 handlerRef = NULL; \ 63 WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, handlerRef); \ 64 do { \ 65 code; \ 66 } while (0); \ 67 RESTORE_XERROR_HANDLER(env); \ 68 if (handlerHasFlag == JNI_TRUE) { \ 69 errorOccurredFlag = JNU_CallMethodByName(env, NULL, handlerRef, "getErrorOccurredFlag", \ 70 "()Z").z; \ 71 } \ 72 } while (0) 73 #endif /* !HEADLESS */ 74 75 #ifndef INTERSECTS 76 #define INTERSECTS(r1_x1,r1_x2,r1_y1,r1_y2,r2_x1,r2_x2,r2_y1,r2_y2) \ 77 !((r2_x2 <= r1_x1) ||\ 78 (r2_y2 <= r1_y1) ||\ 79 (r2_x1 >= r1_x2) ||\ 80 (r2_y1 >= r1_y2)) 81 #endif 82 83 #ifndef MIN 84 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 85 #endif 86 #ifndef MAX 87 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 88 #endif 89 90 struct DPos { 91 int32_t x; 92 int32_t y; 93 int32_t mapped; 94 void *data; 95 void *peer; 96 int32_t echoC; 97 }; 98 99 extern void awtJNI_ThreadYield(JNIEnv *env); 100 101 /* 102 * Functions for accessing fields by name and signature 103 */ 104 105 JNIEXPORT jobject JNICALL 106 JNU_GetObjectField(JNIEnv *env, jobject self, const char *name, 107 const char *sig); 108 109 JNIEXPORT jboolean JNICALL 110 JNU_SetObjectField(JNIEnv *env, jobject self, const char *name, 111 const char *sig, jobject val); 112 113 JNIEXPORT jlong JNICALL 114 JNU_GetLongField(JNIEnv *env, jobject self, const char *name); 115 116 JNIEXPORT jint JNICALL 117 JNU_GetIntField(JNIEnv *env, jobject self, const char *name); 118 119 JNIEXPORT jboolean JNICALL 120 JNU_SetIntField(JNIEnv *env, jobject self, const char *name, jint val); 121 122 JNIEXPORT jboolean JNICALL 123 JNU_SetLongField(JNIEnv *env, jobject self, const char *name, jlong val); 124 125 JNIEXPORT jboolean JNICALL 126 JNU_GetBooleanField(JNIEnv *env, jobject self, const char *name); 127 128 JNIEXPORT jboolean JNICALL 129 JNU_SetBooleanField(JNIEnv *env, jobject self, const char *name, jboolean val); 130 131 JNIEXPORT jint JNICALL 132 JNU_GetCharField(JNIEnv *env, jobject self, const char *name); 133 134 #endif /* _AWT_UTIL_H_ */