blob: 0090aa3822d34c26872963f4b4c5c24281220920 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1995-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_UTIL_H_
27#define _AWT_UTIL_H_
28
29#ifndef HEADLESS
30#ifndef XAWT
31#include <Xm/VendorSEP.h>
32#include <Xm/VendorSP.h>
33#endif
34#include "gdefs.h"
35
36typedef struct ConvertEventTimeAndModifiers {
37 jlong when;
38 jint modifiers;
39} ConvertEventTimeAndModifiers;
40
41Boolean awt_util_focusIsOnMenu(Display *display);
42int32_t awt_util_sendButtonClick(Display *display, Window window);
43
44Widget awt_util_createWarningWindow(Widget parent, char *warning);
45void awt_util_show(Widget w);
46void awt_util_hide(Widget w);
47void awt_util_enable(Widget w);
48void awt_util_disable(Widget w);
49void awt_util_reshape(Widget w, jint x, jint y, jint wd, jint ht);
50void awt_util_mapChildren(Widget w, void (*func)(Widget,void *),
51 int32_t applyToSelf, void *data);
52int32_t awt_util_setCursor(Widget w, Cursor c);
53void awt_util_convertEventTimeAndModifiers
54 (XEvent *event, ConvertEventTimeAndModifiers *output);
55Widget awt_WidgetAtXY(Widget root, Position x, Position y);
56char *awt_util_makeWMMenuItem(char *target, Atom protocol);
57Cardinal awt_util_insertCallback(Widget w);
58void awt_util_consumeAllXEvents(Widget widget);
59void awt_util_cleanupBeforeDestroyWidget(Widget widget);
60void awt_util_debug_init();
61Time awt_util_getCurrentServerTime();
62jlong awt_util_nowMillisUTC();
63jlong awt_util_nowMillisUTC_offset(Time server_offset);
64void awt_util_do_wheel_scroll(Widget scrolled_window, jint scrollType,
65 jint scrollAmt, jint wheelAmt);
66Widget awt_util_get_scrollbar_to_scroll(Widget window);
67
68
69typedef struct _EmbeddedFrame {
70 Widget embeddedFrame;
71 Window frameContainer;
72 jobject javaRef;
73 Boolean eventSelectedPreviously;
74 struct _EmbeddedFrame * next;
75 struct _EmbeddedFrame * prev;
76} EmbeddedFrame;
77
78void awt_util_addEmbeddedFrame(Widget embeddedFrame, jobject javaRef);
79void awt_util_delEmbeddedFrame(Widget embeddedFrame);
80Boolean awt_util_processEventForEmbeddedFrame(XEvent *ev);
81
82#define WITH_XERROR_HANDLER(f) do { \
83 XSync(awt_display, False); \
84 xerror_code = Success; \
85 xerror_saved_handler = XSetErrorHandler(f); \
86} while (0)
87
88/* Convenience macro for handlers to use */
89#define XERROR_SAVE(err) do { \
90 xerror_code = (err)->error_code; \
91} while (0)
92
93#define RESTORE_XERROR_HANDLER do { \
94 XSync(awt_display, False); \
95 XSetErrorHandler(xerror_saved_handler); \
96} while (0)
97
98#define EXEC_WITH_XERROR_HANDLER(f, code) do { \
99 WITH_XERROR_HANDLER(f); \
100 do { \
101 code; \
102 } while (0); \
103 RESTORE_XERROR_HANDLER; \
104} while (0)
105
106/*
107 * Since X reports protocol errors asynchronously, we often need to
108 * install an error handler that acts like a callback. While that
109 * specialized handler is installed we save original handler here.
110 */
111extern XErrorHandler xerror_saved_handler;
112
113/*
114 * A place for error handler to report the error code.
115 */
116extern unsigned char xerror_code;
117
118extern int xerror_ignore_bad_window(Display *dpy, XErrorEvent *err);
119
120#endif /* !HEADLESS */
121
122#ifndef INTERSECTS
123#define INTERSECTS(r1_x1,r1_x2,r1_y1,r1_y2,r2_x1,r2_x2,r2_y1,r2_y2) \
124!((r2_x2 <= r1_x1) ||\
125 (r2_y2 <= r1_y1) ||\
126 (r2_x1 >= r1_x2) ||\
127 (r2_y1 >= r1_y2))
128#endif
129
130#ifndef MIN
131#define MIN(a,b) ((a) < (b) ? (a) : (b))
132#endif
133#ifndef MAX
134#define MAX(a,b) ((a) > (b) ? (a) : (b))
135#endif
136
137struct DPos {
138 int32_t x;
139 int32_t y;
140 int32_t mapped;
141 void *data;
142 void *peer;
143 int32_t echoC;
144};
145
146extern jobject awtJNI_GetCurrentThread(JNIEnv *env);
147extern void awtJNI_ThreadYield(JNIEnv *env);
148
149#ifndef HEADLESS
150extern Widget prevWidget;
151#endif /* !HEADLESS */
152
153/*
154 * Functions for accessing fields by name and signature
155 */
156
157JNIEXPORT jobject JNICALL
158JNU_GetObjectField(JNIEnv *env, jobject self, const char *name,
159 const char *sig);
160
161JNIEXPORT jboolean JNICALL
162JNU_SetObjectField(JNIEnv *env, jobject self, const char *name,
163 const char *sig, jobject val);
164
165JNIEXPORT jlong JNICALL
166JNU_GetLongField(JNIEnv *env, jobject self, const char *name);
167
168JNIEXPORT jint JNICALL
169JNU_GetIntField(JNIEnv *env, jobject self, const char *name);
170
171JNIEXPORT jboolean JNICALL
172JNU_SetIntField(JNIEnv *env, jobject self, const char *name, jint val);
173
174JNIEXPORT jboolean JNICALL
175JNU_SetLongField(JNIEnv *env, jobject self, const char *name, jlong val);
176
177JNIEXPORT jboolean JNICALL
178JNU_GetBooleanField(JNIEnv *env, jobject self, const char *name);
179
180JNIEXPORT jboolean JNICALL
181JNU_SetBooleanField(JNIEnv *env, jobject self, const char *name, jboolean val);
182
183JNIEXPORT jint JNICALL
184JNU_GetCharField(JNIEnv *env, jobject self, const char *name);
185
186#ifndef HEADLESS
187#ifdef __solaris__
188extern Widget awt_util_getXICStatusAreaWindow(Widget w);
189#else
190int32_t awt_util_getIMStatusHeight(Widget vw);
191XVaNestedList awt_util_getXICStatusAreaList(Widget w);
192Widget awt_util_getXICStatusAreaWindow(Widget w);
193#endif
194
195
196
197
198#ifdef __linux__
199typedef struct _XmImRefRec {
200 Cardinal num_refs; /* Number of referencing widgets. */
201 Cardinal max_refs; /* Maximum length of refs array. */
202 Widget* refs; /* Array of referencing widgets. */
203 XtPointer **callbacks;
204} XmImRefRec, *XmImRefInfo;
205
206typedef struct _PreeditBufferRec {
207 unsigned short length;
208 wchar_t *text;
209 XIMFeedback *feedback;
210 int32_t caret;
211 XIMCaretStyle style;
212} PreeditBufferRec, *PreeditBuffer;
213
214typedef struct _XmImXICRec {
215 struct _XmImXICRec *next; /* Links all have the same XIM. */
216 XIC xic; /* The XIC. */
217 Window focus_window; /* Cached information about the XIC. */
218 XIMStyle input_style; /* ...ditto... */
219 int32_t status_width; /* ...ditto... */
220 int32_t preedit_width; /* ...ditto... */
221 int32_t sp_height; /* ...ditto... */
222 Boolean has_focus; /* Does this XIC have keyboard focus. */
223 Boolean anonymous; /* Do we have exclusive rights to this XIC. */
224 XmImRefRec widget_refs; /* Widgets referencing this XIC. */
225 struct _XmImXICRec **source; /* Original source of shared XICs. */
226 PreeditBuffer preedit_buffer;
227} XmImXICRec, *XmImXICInfo;
228
229typedef struct _XmImShellRec {
230 /* per-Shell fields. */
231 Widget im_widget; /* Dummy widget to make intrinsics behave. */
232 Widget current_widget; /* Widget whose visual we're matching. */
233
234 /* per <Shell,XIM> fields. */
235 XmImXICInfo shell_xic; /* For PER_SHELL sharing policy. */
236 XmImXICInfo iclist; /* All known XICs for this <XIM,Shell>. */
237} XmImShellRec, *XmImShellInfo;
238
239typedef struct {
240 /* per-Display fields. */
241 XContext current_xics; /* Map widget -> current XmImXICInfo. */
242
243 /* per-XIM fields. */
244 XIM xim; /* The XIM. */
245 XIMStyles *styles; /* XNQueryInputStyle result. */
246 XmImRefRec shell_refs; /* Shells referencing this XIM. */
247} XmImDisplayRec, *XmImDisplayInfo;
248
249#endif
250#endif /* !HEADLESS */
251#endif /* _AWT_UTIL_H_ */