|
1 /* |
|
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 |
|
36 typedef struct ConvertEventTimeAndModifiers { |
|
37 jlong when; |
|
38 jint modifiers; |
|
39 } ConvertEventTimeAndModifiers; |
|
40 |
|
41 Boolean awt_util_focusIsOnMenu(Display *display); |
|
42 int32_t awt_util_sendButtonClick(Display *display, Window window); |
|
43 |
|
44 Widget awt_util_createWarningWindow(Widget parent, char *warning); |
|
45 void awt_util_show(Widget w); |
|
46 void awt_util_hide(Widget w); |
|
47 void awt_util_enable(Widget w); |
|
48 void awt_util_disable(Widget w); |
|
49 void awt_util_reshape(Widget w, jint x, jint y, jint wd, jint ht); |
|
50 void awt_util_mapChildren(Widget w, void (*func)(Widget,void *), |
|
51 int32_t applyToSelf, void *data); |
|
52 int32_t awt_util_setCursor(Widget w, Cursor c); |
|
53 void awt_util_convertEventTimeAndModifiers |
|
54 (XEvent *event, ConvertEventTimeAndModifiers *output); |
|
55 Widget awt_WidgetAtXY(Widget root, Position x, Position y); |
|
56 char *awt_util_makeWMMenuItem(char *target, Atom protocol); |
|
57 Cardinal awt_util_insertCallback(Widget w); |
|
58 void awt_util_consumeAllXEvents(Widget widget); |
|
59 void awt_util_cleanupBeforeDestroyWidget(Widget widget); |
|
60 void awt_util_debug_init(); |
|
61 Time awt_util_getCurrentServerTime(); |
|
62 jlong awt_util_nowMillisUTC(); |
|
63 jlong awt_util_nowMillisUTC_offset(Time server_offset); |
|
64 void awt_util_do_wheel_scroll(Widget scrolled_window, jint scrollType, |
|
65 jint scrollAmt, jint wheelAmt); |
|
66 Widget awt_util_get_scrollbar_to_scroll(Widget window); |
|
67 |
|
68 |
|
69 typedef 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 |
|
78 void awt_util_addEmbeddedFrame(Widget embeddedFrame, jobject javaRef); |
|
79 void awt_util_delEmbeddedFrame(Widget embeddedFrame); |
|
80 Boolean 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 */ |
|
111 extern XErrorHandler xerror_saved_handler; |
|
112 |
|
113 /* |
|
114 * A place for error handler to report the error code. |
|
115 */ |
|
116 extern unsigned char xerror_code; |
|
117 |
|
118 extern 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 |
|
137 struct 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 |
|
146 extern jobject awtJNI_GetCurrentThread(JNIEnv *env); |
|
147 extern void awtJNI_ThreadYield(JNIEnv *env); |
|
148 |
|
149 #ifndef HEADLESS |
|
150 extern Widget prevWidget; |
|
151 #endif /* !HEADLESS */ |
|
152 |
|
153 /* |
|
154 * Functions for accessing fields by name and signature |
|
155 */ |
|
156 |
|
157 JNIEXPORT jobject JNICALL |
|
158 JNU_GetObjectField(JNIEnv *env, jobject self, const char *name, |
|
159 const char *sig); |
|
160 |
|
161 JNIEXPORT jboolean JNICALL |
|
162 JNU_SetObjectField(JNIEnv *env, jobject self, const char *name, |
|
163 const char *sig, jobject val); |
|
164 |
|
165 JNIEXPORT jlong JNICALL |
|
166 JNU_GetLongField(JNIEnv *env, jobject self, const char *name); |
|
167 |
|
168 JNIEXPORT jint JNICALL |
|
169 JNU_GetIntField(JNIEnv *env, jobject self, const char *name); |
|
170 |
|
171 JNIEXPORT jboolean JNICALL |
|
172 JNU_SetIntField(JNIEnv *env, jobject self, const char *name, jint val); |
|
173 |
|
174 JNIEXPORT jboolean JNICALL |
|
175 JNU_SetLongField(JNIEnv *env, jobject self, const char *name, jlong val); |
|
176 |
|
177 JNIEXPORT jboolean JNICALL |
|
178 JNU_GetBooleanField(JNIEnv *env, jobject self, const char *name); |
|
179 |
|
180 JNIEXPORT jboolean JNICALL |
|
181 JNU_SetBooleanField(JNIEnv *env, jobject self, const char *name, jboolean val); |
|
182 |
|
183 JNIEXPORT jint JNICALL |
|
184 JNU_GetCharField(JNIEnv *env, jobject self, const char *name); |
|
185 |
|
186 #ifndef HEADLESS |
|
187 #ifdef __solaris__ |
|
188 extern Widget awt_util_getXICStatusAreaWindow(Widget w); |
|
189 #else |
|
190 int32_t awt_util_getIMStatusHeight(Widget vw); |
|
191 XVaNestedList awt_util_getXICStatusAreaList(Widget w); |
|
192 Widget awt_util_getXICStatusAreaWindow(Widget w); |
|
193 #endif |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 #ifdef __linux__ |
|
199 typedef 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 |
|
206 typedef struct _PreeditBufferRec { |
|
207 unsigned short length; |
|
208 wchar_t *text; |
|
209 XIMFeedback *feedback; |
|
210 int32_t caret; |
|
211 XIMCaretStyle style; |
|
212 } PreeditBufferRec, *PreeditBuffer; |
|
213 |
|
214 typedef 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 |
|
229 typedef 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 |
|
239 typedef 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_ */ |