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 #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 #if defined(MACOSX) 191 int32_t awt_util_getIMStatusHeight(Widget vw); 192 Widget awt_util_getXICStatusAreaWindow(Widget w); 193 #else 194 int32_t awt_util_getIMStatusHeight(Widget vw); 195 XVaNestedList awt_util_getXICStatusAreaList(Widget w); 196 Widget awt_util_getXICStatusAreaWindow(Widget w); 197 #endif 198 #endif 199 200 201 202 203 #if defined(__linux__) || defined(MACOSX) 204 typedef struct _XmImRefRec { 205 Cardinal num_refs; /* Number of referencing widgets. */ 206 Cardinal max_refs; /* Maximum length of refs array. */ 207 Widget* refs; /* Array of referencing widgets. */ 208 XtPointer **callbacks; 209 } XmImRefRec, *XmImRefInfo; 210 211 typedef struct _PreeditBufferRec { 212 unsigned short length; 213 wchar_t *text; 214 XIMFeedback *feedback; 215 int32_t caret; 216 XIMCaretStyle style; 217 } PreeditBufferRec, *PreeditBuffer; 218 219 typedef struct _XmImXICRec { 220 struct _XmImXICRec *next; /* Links all have the same XIM. */ 221 XIC xic; /* The XIC. */ 222 Window focus_window; /* Cached information about the XIC. */ 223 XIMStyle input_style; /* ...ditto... */ 224 int32_t status_width; /* ...ditto... */ 225 int32_t preedit_width; /* ...ditto... */ 226 int32_t sp_height; /* ...ditto... */ 227 Boolean has_focus; /* Does this XIC have keyboard focus. */ 228 Boolean anonymous; /* Do we have exclusive rights to this XIC. */ 229 XmImRefRec widget_refs; /* Widgets referencing this XIC. */ 230 struct _XmImXICRec **source; /* Original source of shared XICs. */ 231 PreeditBuffer preedit_buffer; 232 } XmImXICRec, *XmImXICInfo; 233 234 typedef struct _XmImShellRec { 235 /* per-Shell fields. */ 236 Widget im_widget; /* Dummy widget to make intrinsics behave. */ 237 Widget current_widget; /* Widget whose visual we're matching. */ 238 239 /* per <Shell,XIM> fields. */ 240 XmImXICInfo shell_xic; /* For PER_SHELL sharing policy. */ 241 XmImXICInfo iclist; /* All known XICs for this <XIM,Shell>. */ 242 } XmImShellRec, *XmImShellInfo; 243 244 typedef struct { 245 /* per-Display fields. */ 246 XContext current_xics; /* Map widget -> current XmImXICInfo. */ 247 248 /* per-XIM fields. */ 249 XIM xim; /* The XIM. */ 250 XIMStyles *styles; /* XNQueryInputStyle result. */ 251 XmImRefRec shell_refs; /* Shells referencing this XIM. */ 252 } XmImDisplayRec, *XmImDisplayInfo; 253 254 #endif 255 #endif /* !HEADLESS */ 256 #endif /* _AWT_UTIL_H_ */