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

Print this page


   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


  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;


   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


  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;