awt_util.h revision 10731:e66f69113b89
1/*
2 * Copyright (c) 1995, 2014, 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    current_native_xerror_handler = (f);        \
35} while (0)
36
37#define RESTORE_XERROR_HANDLER do {             \
38    XSync(awt_display, False);                  \
39    current_native_xerror_handler = NULL;       \
40} while (0)
41
42#define EXEC_WITH_XERROR_HANDLER(f, code) do {  \
43    WITH_XERROR_HANDLER(f);                     \
44    do {                                        \
45        code;                                   \
46    } while (0);                                \
47    RESTORE_XERROR_HANDLER;                     \
48} while (0)
49
50/*
51 * Called by "ToolkitErrorHandler" function in "XlibWrapper.c" file.
52 */
53extern XErrorHandler current_native_xerror_handler;
54
55#endif /* !HEADLESS */
56
57#ifndef INTERSECTS
58#define INTERSECTS(r1_x1,r1_x2,r1_y1,r1_y2,r2_x1,r2_x2,r2_y1,r2_y2) \
59!((r2_x2 <= r1_x1) ||\
60  (r2_y2 <= r1_y1) ||\
61  (r2_x1 >= r1_x2) ||\
62  (r2_y1 >= r1_y2))
63#endif
64
65#ifndef MIN
66#define MIN(a,b) ((a) < (b) ? (a) : (b))
67#endif
68#ifndef MAX
69#define MAX(a,b) ((a) > (b) ? (a) : (b))
70#endif
71
72struct DPos {
73    int32_t x;
74    int32_t y;
75    int32_t mapped;
76    void *data;
77    void *peer;
78    int32_t echoC;
79};
80
81extern jboolean awtJNI_ThreadYield(JNIEnv *env);
82
83/*
84 * Functions for accessing fields by name and signature
85 */
86
87JNIEXPORT jobject JNICALL
88JNU_GetObjectField(JNIEnv *env, jobject self, const char *name,
89                   const char *sig);
90
91JNIEXPORT jboolean JNICALL
92JNU_SetObjectField(JNIEnv *env, jobject self, const char *name,
93                   const char *sig, jobject val);
94
95JNIEXPORT jlong JNICALL
96JNU_GetLongField(JNIEnv *env, jobject self, const char *name);
97
98JNIEXPORT jint JNICALL
99JNU_GetIntField(JNIEnv *env, jobject self, const char *name);
100
101JNIEXPORT jboolean JNICALL
102JNU_SetIntField(JNIEnv *env, jobject self, const char *name, jint val);
103
104JNIEXPORT jboolean JNICALL
105JNU_SetLongField(JNIEnv *env, jobject self, const char *name, jlong val);
106
107JNIEXPORT jboolean JNICALL
108JNU_GetBooleanField(JNIEnv *env, jobject self, const char *name);
109
110JNIEXPORT jboolean JNICALL
111JNU_SetBooleanField(JNIEnv *env, jobject self, const char *name, jboolean val);
112
113JNIEXPORT jint JNICALL
114JNU_GetCharField(JNIEnv *env, jobject self, const char *name);
115
116#endif           /* _AWT_UTIL_H_ */
117