1 /* 2 * Copyright (c) 1995, 2013, 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 /* 83 * Expected types of arguments of the macro. 84 * (JNIEnv*, const char*, const char*, jboolean, jobject) 85 */ 86 #define WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, \ 87 handlerHasFlag, handlerRef) do { \ 88 handlerRef = JNU_CallStaticMethodByName(env, NULL, handlerClassName, "getInstance", \ 89 getInstanceSignature).l; \ 90 if (handlerHasFlag == JNI_TRUE) { \ 91 JNU_CallMethodByName(env, NULL, handlerRef, "setErrorOccurredFlag", "(Z)V", JNI_FALSE); \ 92 } \ 93 JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "WITH_XERROR_HANDLER", \ 94 "(Lsun/awt/X11/XErrorHandler;)V", handlerRef); \ 95 } while (0) 96 97 /* 98 * Expected types of arguments of the macro. 99 * (JNIEnv*, jboolean) 100 */ 101 #define RESTORE_XERROR_HANDLER(env, doXSync) do { \ 102 JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", \ 103 "RESTORE_XERROR_HANDLER", "(Z)V", doXSync); \ 104 } while (0) 105 106 /* 107 * Expected types of arguments of the macro. 108 * (JNIEnv*, const char*, const char*, jboolean, jobject, jboolean, No type - C expression) 109 */ 110 #define EXEC_WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, \ 111 handlerRef, errorOccurredFlag, code) do { \ 112 handlerRef = NULL; \ 113 WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, handlerRef); \ 114 do { \ 115 code; \ 116 } while (0); \ 117 RESTORE_XERROR_HANDLER(env, JNI_TRUE); \ 118 if (handlerHasFlag == JNI_TRUE) { \ 119 errorOccurredFlag = GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef); \ 120 } \ 121 } while (0) 122 123 /* 124 * Expected types of arguments of the macro for jboolean expression. 125 * (JNIEnv*, jobject) 126 */ 127 #define GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef) (handlerRef != NULL ? \ 128 JNU_CallMethodByName(env, NULL, handlerRef, "getErrorOccurredFlag", "()Z").z : JNI_FALSE) 129 130 /* 131 * Expected types of arguments of the macro for jbyte expression. 132 * (JNIEnv*, jobject) 133 */ 134 #define GET_XERROR_CODE(env, savedError) \ 135 ((savedError = JNU_GetStaticFieldByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", \ 136 "saved_error", "Lsun/awt/X11/XErrorEvent;").l) != NULL ? \ 137 JNU_CallMethodByName(env, NULL, savedError, "get_error_code", "()B").b : Success) 138 #endif /* !HEADLESS */ 139 140 #ifndef INTERSECTS 141 #define INTERSECTS(r1_x1,r1_x2,r1_y1,r1_y2,r2_x1,r2_x2,r2_y1,r2_y2) \ 142 !((r2_x2 <= r1_x1) ||\ 143 (r2_y2 <= r1_y1) ||\ 144 (r2_x1 >= r1_x2) ||\ 145 (r2_y1 >= r1_y2)) 146 #endif 147 148 #ifndef MIN 149 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 150 #endif 151 #ifndef MAX 152 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 153 #endif 154 155 struct DPos { 156 int32_t x; 157 int32_t y; 158 int32_t mapped; 159 void *data; 160 void *peer; 161 int32_t echoC; 162 }; 163 164 extern jobject awtJNI_GetCurrentThread(JNIEnv *env); 165 extern void awtJNI_ThreadYield(JNIEnv *env); 166 167 #ifndef HEADLESS 168 extern Widget prevWidget; 169 #endif /* !HEADLESS */ 170 171 /* 172 * Functions for accessing fields by name and signature 173 */ 174 175 JNIEXPORT jobject JNICALL 176 JNU_GetObjectField(JNIEnv *env, jobject self, const char *name, 177 const char *sig); 178 179 JNIEXPORT jboolean JNICALL 180 JNU_SetObjectField(JNIEnv *env, jobject self, const char *name, 181 const char *sig, jobject val); 182 183 JNIEXPORT jlong JNICALL 184 JNU_GetLongField(JNIEnv *env, jobject self, const char *name); 185 186 JNIEXPORT jint JNICALL 187 JNU_GetIntField(JNIEnv *env, jobject self, const char *name); 188 189 JNIEXPORT jboolean JNICALL 190 JNU_SetIntField(JNIEnv *env, jobject self, const char *name, jint val); 191 192 JNIEXPORT jboolean JNICALL 193 JNU_SetLongField(JNIEnv *env, jobject self, const char *name, jlong val); 194 195 JNIEXPORT jboolean JNICALL 196 JNU_GetBooleanField(JNIEnv *env, jobject self, const char *name); 197 198 JNIEXPORT jboolean JNICALL 199 JNU_SetBooleanField(JNIEnv *env, jobject self, const char *name, jboolean val); 200 201 JNIEXPORT jint JNICALL 202 JNU_GetCharField(JNIEnv *env, jobject self, const char *name); 203 204 #ifndef HEADLESS 205 #ifdef __solaris__ 206 extern Widget awt_util_getXICStatusAreaWindow(Widget w); 207 #else 208 #if defined(MACOSX) 209 int32_t awt_util_getIMStatusHeight(Widget vw); 210 Widget awt_util_getXICStatusAreaWindow(Widget w); 211 #else 212 int32_t awt_util_getIMStatusHeight(Widget vw); 213 XVaNestedList awt_util_getXICStatusAreaList(Widget w); 214 Widget awt_util_getXICStatusAreaWindow(Widget w); 215 #endif 216 #endif 217 218 219 220 221 #if defined(__linux__) || defined(MACOSX) 222 typedef struct _XmImRefRec { 223 Cardinal num_refs; /* Number of referencing widgets. */ 224 Cardinal max_refs; /* Maximum length of refs array. */ 225 Widget* refs; /* Array of referencing widgets. */ 226 XtPointer **callbacks; 227 } XmImRefRec, *XmImRefInfo; 228 229 typedef struct _PreeditBufferRec { 230 unsigned short length; 231 wchar_t *text; 232 XIMFeedback *feedback; 233 int32_t caret; 234 XIMCaretStyle style; 235 } PreeditBufferRec, *PreeditBuffer; 236 237 typedef struct _XmImXICRec { 238 struct _XmImXICRec *next; /* Links all have the same XIM. */ 239 XIC xic; /* The XIC. */ 240 Window focus_window; /* Cached information about the XIC. */ 241 XIMStyle input_style; /* ...ditto... */ 242 int32_t status_width; /* ...ditto... */ 243 int32_t preedit_width; /* ...ditto... */ 244 int32_t sp_height; /* ...ditto... */ 245 Boolean has_focus; /* Does this XIC have keyboard focus. */ 246 Boolean anonymous; /* Do we have exclusive rights to this XIC. */ 247 XmImRefRec widget_refs; /* Widgets referencing this XIC. */ 248 struct _XmImXICRec **source; /* Original source of shared XICs. */ 249 PreeditBuffer preedit_buffer; 250 } XmImXICRec, *XmImXICInfo; 251 252 typedef struct _XmImShellRec { 253 /* per-Shell fields. */ 254 Widget im_widget; /* Dummy widget to make intrinsics behave. */ 255 Widget current_widget; /* Widget whose visual we're matching. */ 256 257 /* per <Shell,XIM> fields. */ 258 XmImXICInfo shell_xic; /* For PER_SHELL sharing policy. */ 259 XmImXICInfo iclist; /* All known XICs for this <XIM,Shell>. */ 260 } XmImShellRec, *XmImShellInfo; 261 262 typedef struct { 263 /* per-Display fields. */ 264 XContext current_xics; /* Map widget -> current XmImXICInfo. */ 265 266 /* per-XIM fields. */ 267 XIM xim; /* The XIM. */ 268 XIMStyles *styles; /* XNQueryInputStyle result. */ 269 XmImRefRec shell_refs; /* Shells referencing this XIM. */ 270 } XmImDisplayRec, *XmImDisplayInfo; 271 272 #endif 273 #endif /* !HEADLESS */ 274 #endif /* _AWT_UTIL_H_ */