1 /*
   2  * Copyright (c) 1995, 2004, 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 #define WITH_XERROR_HANDLER(f) do {             \
  33     XSync(awt_display, False);                  \
  34     xerror_code = Success;                      \
  35     xerror_saved_handler = XSetErrorHandler(f); \
  36 } while (0)
  37 
  38 /* Convenience macro for handlers to use */
  39 #define XERROR_SAVE(err) do {                   \
  40     xerror_code = (err)->error_code;            \
  41 } while (0)
  42 
  43 #define RESTORE_XERROR_HANDLER do {             \
  44     XSync(awt_display, False);                  \
  45     XSetErrorHandler(xerror_saved_handler);     \
  46 } while (0)
  47 
  48 #define EXEC_WITH_XERROR_HANDLER(f, code) do {  \
  49     WITH_XERROR_HANDLER(f);                     \
  50     do {                                        \
  51         code;                                   \
  52     } while (0);                                \
  53     RESTORE_XERROR_HANDLER;                     \
  54 } while (0)
  55 
  56 /*
  57  * Since X reports protocol errors asynchronously, we often need to
  58  * install an error handler that acts like a callback.  While that
  59  * specialized handler is installed we save original handler here.
  60  */
  61 extern XErrorHandler xerror_saved_handler;
  62 
  63 /*
  64  * A place for error handler to report the error code.
  65  */
  66 extern unsigned char xerror_code;
  67 
  68 #endif /* !HEADLESS */
  69 
  70 #ifndef INTERSECTS
  71 #define INTERSECTS(r1_x1,r1_x2,r1_y1,r1_y2,r2_x1,r2_x2,r2_y1,r2_y2) \
  72 !((r2_x2 <= r1_x1) ||\
  73   (r2_y2 <= r1_y1) ||\
  74   (r2_x1 >= r1_x2) ||\
  75   (r2_y1 >= r1_y2))
  76 #endif
  77 
  78 #ifndef MIN
  79 #define MIN(a,b) ((a) < (b) ? (a) : (b))
  80 #endif
  81 #ifndef MAX
  82 #define MAX(a,b) ((a) > (b) ? (a) : (b))
  83 #endif
  84 
  85 struct DPos {
  86     int32_t x;
  87     int32_t y;
  88     int32_t mapped;
  89     void *data;
  90     void *peer;
  91     int32_t echoC;
  92 };
  93 
  94 extern void awtJNI_ThreadYield(JNIEnv *env);
  95 
  96 /*
  97  * Functions for accessing fields by name and signature
  98  */
  99 
 100 JNIEXPORT jobject JNICALL
 101 JNU_GetObjectField(JNIEnv *env, jobject self, const char *name,
 102                    const char *sig);
 103 
 104 JNIEXPORT jboolean JNICALL
 105 JNU_SetObjectField(JNIEnv *env, jobject self, const char *name,
 106                    const char *sig, jobject val);
 107 
 108 JNIEXPORT jlong JNICALL
 109 JNU_GetLongField(JNIEnv *env, jobject self, const char *name);
 110 
 111 JNIEXPORT jint JNICALL
 112 JNU_GetIntField(JNIEnv *env, jobject self, const char *name);
 113 
 114 JNIEXPORT jboolean JNICALL
 115 JNU_SetIntField(JNIEnv *env, jobject self, const char *name, jint val);
 116 
 117 JNIEXPORT jboolean JNICALL
 118 JNU_SetLongField(JNIEnv *env, jobject self, const char *name, jlong val);
 119 
 120 JNIEXPORT jboolean JNICALL
 121 JNU_GetBooleanField(JNIEnv *env, jobject self, const char *name);
 122 
 123 JNIEXPORT jboolean JNICALL
 124 JNU_SetBooleanField(JNIEnv *env, jobject self, const char *name, jboolean val);
 125 
 126 JNIEXPORT jint JNICALL
 127 JNU_GetCharField(JNIEnv *env, jobject self, const char *name);
 128 
 129 #endif           /* _AWT_UTIL_H_ */