src/solaris/native/sun/awt/awt_util.h

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -77,48 +77,66 @@
 
 void awt_util_addEmbeddedFrame(Widget embeddedFrame, jobject javaRef);
 void awt_util_delEmbeddedFrame(Widget embeddedFrame);
 Boolean awt_util_processEventForEmbeddedFrame(XEvent *ev);
 
-#define WITH_XERROR_HANDLER(f) do {             \
-    XSync(awt_display, False);                  \
-    xerror_code = Success;                      \
-    xerror_saved_handler = XSetErrorHandler(f); \
-} while (0)
-
-/* Convenience macro for handlers to use */
-#define XERROR_SAVE(err) do {                   \
-    xerror_code = (err)->error_code;            \
+/*
+ * Expected types of arguments of the macro.
+ * (JNIEnv*, const char*, const char*, jboolean, jobject)
+ */
+#define WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature,                          \
+                            handlerHasFlag, handlerRef) do {                                      \
+    handlerRef = JNU_CallStaticMethodByName(env, NULL, handlerClassName, "getInstance",           \
+        getInstanceSignature).l;                                                                  \
+    if (handlerHasFlag == JNI_TRUE) {                                                             \
+        JNU_CallMethodByName(env, NULL, handlerRef, "setErrorOccurredFlag", "(Z)V", JNI_FALSE);   \
+    }                                                                                             \
+    JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "WITH_XERROR_HANDLER", \
+        "(Lsun/awt/X11/XErrorHandler;)V", handlerRef);                                            \
 } while (0)
 
-#define RESTORE_XERROR_HANDLER do {             \
-    XSync(awt_display, False);                  \
-    XSetErrorHandler(xerror_saved_handler);     \
+/*
+ * Expected types of arguments of the macro.
+ * (JNIEnv*, jboolean)
+ */
+#define RESTORE_XERROR_HANDLER(env, doXSync) do {                                                 \
+    JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil",                        \
+        "RESTORE_XERROR_HANDLER", "(Z)V", doXSync);                                               \
 } while (0)
 
-#define EXEC_WITH_XERROR_HANDLER(f, code) do {  \
-    WITH_XERROR_HANDLER(f);                     \
+/*
+ * Expected types of arguments of the macro.
+ * (JNIEnv*, const char*, const char*, jboolean, jobject, jboolean, No type - C expression)
+ */
+#define EXEC_WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag,     \
+                                 handlerRef, errorOccurredFlag, code) do {                        \
+    handlerRef = NULL;                                                                            \
+    WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, handlerRef); \
     do {                                        \
         code;                                   \
     } while (0);                                \
-    RESTORE_XERROR_HANDLER;                     \
+    RESTORE_XERROR_HANDLER(env, JNI_TRUE);                                                        \
+    if (handlerHasFlag == JNI_TRUE) {                                                             \
+        errorOccurredFlag = GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef);                     \
+    }                                                                                             \
 } while (0)
 
 /*
- * Since X reports protocol errors asynchronously, we often need to
- * install an error handler that acts like a callback.  While that
- * specialized handler is installed we save original handler here.
+ * Expected types of arguments of the macro for jboolean expression.
+ * (JNIEnv*, jobject)
  */
-extern XErrorHandler xerror_saved_handler;
+#define GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef) (handlerRef != NULL ?                    \
+    JNU_CallMethodByName(env, NULL, handlerRef, "getErrorOccurredFlag", "()Z").z : JNI_FALSE)
 
 /*
- * A place for error handler to report the error code.
+ * Expected types of arguments of the macro for jbyte expression.
+ * (JNIEnv*, jobject)
  */
-extern unsigned char xerror_code;
-
-extern int xerror_ignore_bad_window(Display *dpy, XErrorEvent *err);
-
+#define GET_XERROR_CODE(env, savedError)                                                          \
+    ((savedError = JNU_GetStaticFieldByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil",           \
+        "saved_error", "Lsun/awt/X11/XErrorEvent;").l) != NULL ?                                  \
+        JNU_CallMethodByName(env, NULL, savedError, "get_error_code", "()B").b : Success)
 #endif /* !HEADLESS */
 
 #ifndef INTERSECTS
 #define INTERSECTS(r1_x1,r1_x2,r1_y1,r1_y2,r2_x1,r2_x2,r2_y1,r2_y2) \
 !((r2_x2 <= r1_x1) ||\