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
  23  * questions.
  24  */
  25 
  26 #ifndef _AWT_UTIL_H_
  27 #define _AWT_UTIL_H_
  28 
  29 #ifndef HEADLESS
  30 #include "gdefs.h"
  31 
  32 #define WITH_XERROR_HANDLER(f) do {             \
  33     XSync(awt_display, False);                  \
  34     xerror_code = Success;                      \
  35     xerror_saved_handler = XSetErrorHandler(f); \
  36 } while (0)
  37 
  38 /* Convenience macro for handlers to use */
  39 #define XERROR_SAVE(err) do {                   \
  40     xerror_code = (err)->error_code;            \




  41 } while (0)
  42 
  43 #define RESTORE_XERROR_HANDLER do {             \
  44     XSync(awt_display, False);                  \
  45     XSetErrorHandler(xerror_saved_handler);     \




  46 } while (0)
  47 
  48 #define EXEC_WITH_XERROR_HANDLER(f, code) do {  \
  49     WITH_XERROR_HANDLER(f);                     \






  50     do {                                        \
  51         code;                                   \
  52     } while (0);                                \
  53     RESTORE_XERROR_HANDLER;                     \




  54 } while (0)
  55 
  56 /*
  57  * Since X reports protocol errors asynchronously, we often need to
  58  * install an error handler that acts like a callback.  While that
  59  * specialized handler is installed we save original handler here.
  60  */
  61 extern XErrorHandler xerror_saved_handler;
  62 
  63 /*
  64  * A place for error handler to report the error code.
  65  */
  66 extern unsigned char xerror_code;
  67 
  68 #endif /* !HEADLESS */
  69 
  70 #ifndef INTERSECTS
  71 #define INTERSECTS(r1_x1,r1_x2,r1_y1,r1_y2,r2_x1,r2_x2,r2_y1,r2_y2) \
  72 !((r2_x2 <= r1_x1) ||\
  73   (r2_y2 <= r1_y1) ||\
  74   (r2_x1 >= r1_x2) ||\
  75   (r2_y1 >= r1_y2))
  76 #endif
  77 
  78 #ifndef MIN
  79 #define MIN(a,b) ((a) < (b) ? (a) : (b))
  80 #endif
  81 #ifndef MAX
  82 #define MAX(a,b) ((a) > (b) ? (a) : (b))
  83 #endif
  84 
  85 struct DPos {
  86     int32_t x;
  87     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
  23  * questions.
  24  */
  25 
  26 #ifndef _AWT_UTIL_H_
  27 #define _AWT_UTIL_H_
  28 
  29 #ifndef HEADLESS
  30 #include "gdefs.h"
  31 
  32 /*
  33  * Expected types of arguments of the macro.
  34  * (JNIEnv*, const char*, const char*, jboolean, jobject)
  35  */
  36 #define WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature,                          \
  37                             handlerHasFlag, handlerRef) do {                                      \
  38     handlerRef = JNU_CallStaticMethodByName(env, NULL, handlerClassName, "getInstance",           \
  39         getInstanceSignature).l;                                                                  \
  40     if (handlerHasFlag == JNI_TRUE) {                                                             \
  41         JNU_CallMethodByName(env, NULL, handlerRef, "setErrorOccurredFlag", "(Z)V", JNI_FALSE);   \
  42     }                                                                                             \
  43     JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "WITH_XERROR_HANDLER", \
  44         "(Lsun/awt/X11/XErrorHandler;)V", handlerRef);                                            \
  45 } while (0)
  46 
  47 /*
  48  * Expected types of arguments of the macro.
  49  * (JNIEnv*)
  50  */
  51 #define RESTORE_XERROR_HANDLER(env) do {                                                          \
  52     JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil",                        \
  53         "RESTORE_XERROR_HANDLER", "()V");                                                         \
  54 } while (0)
  55 
  56 /*
  57  * Expected types of arguments of the macro.
  58  * (JNIEnv*, const char*, const char*, jboolean, jboolean, No type - C expression)
  59  */
  60 #define EXEC_WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature,                     \
  61                                  handlerHasFlag, errorOccurredFlag, code) do {                    \
  62     jobject handlerRef = NULL;                                                                    \
  63     WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, handlerRef); \
  64     do {                                                                                          \
  65         code;                                                                                     \
  66     } while (0);                                                                                  \
  67     RESTORE_XERROR_HANDLER(env);                                                                  \
  68     if (handlerHasFlag == JNI_TRUE) {                                                             \
  69         errorOccurredFlag = JNU_CallMethodByName(env, NULL, handlerRef, "getErrorOccurredFlag",   \
  70             "()Z").z;                                                                             \
  71     }                                                                                             \
  72 } while (0)













  73 #endif /* !HEADLESS */
  74 
  75 #ifndef INTERSECTS
  76 #define INTERSECTS(r1_x1,r1_x2,r1_y1,r1_y2,r2_x1,r2_x2,r2_y1,r2_y2) \
  77 !((r2_x2 <= r1_x1) ||\
  78   (r2_y2 <= r1_y1) ||\
  79   (r2_x1 >= r1_x2) ||\
  80   (r2_y1 >= r1_y2))
  81 #endif
  82 
  83 #ifndef MIN
  84 #define MIN(a,b) ((a) < (b) ? (a) : (b))
  85 #endif
  86 #ifndef MAX
  87 #define MAX(a,b) ((a) > (b) ? (a) : (b))
  88 #endif
  89 
  90 struct DPos {
  91     int32_t x;
  92     int32_t y;