< prev index next >

src/solaris/native/sun/awt/awt_UNIXToolkit.c

Print this page


   1 /*
   2  * Copyright (c) 2004, 2014, 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 #include <stdlib.h>
  27 #include <string.h>
  28 #include <unistd.h>
  29 #include <dlfcn.h>
  30 
  31 #include <jni.h>
  32 #include <sizecalc.h>
  33 #include "sun_awt_UNIXToolkit.h"
  34 
  35 #ifndef HEADLESS
  36 #include "awt.h"
  37 #include "gtk2_interface.h"
  38 #endif /* !HEADLESS */
  39 
  40 
  41 static jclass this_class = NULL;
  42 static jmethodID icon_upcall_method = NULL;
  43 
  44 
  45 /*
  46  * Class:     sun_awt_UNIXToolkit
  47  * Method:    check_gtk
  48  * Signature: ()Z
  49  */
  50 JNIEXPORT jboolean JNICALL
  51 Java_sun_awt_UNIXToolkit_check_1gtk(JNIEnv *env, jclass klass)
  52 {
  53 #ifndef HEADLESS
  54     return (jboolean)gtk2_check_version();
  55 #else
  56     return JNI_FALSE;
  57 #endif /* !HEADLESS */
  58 }
  59 
  60 
  61 /*
  62  * Class:     sun_awt_UNIXToolkit
  63  * Method:    load_gtk
  64  * Signature: ()Z
  65  */
  66 JNIEXPORT jboolean JNICALL
  67 Java_sun_awt_UNIXToolkit_load_1gtk(JNIEnv *env, jclass klass)
  68 {
  69 #ifndef HEADLESS
  70     return (jboolean)gtk2_load(env);
  71 #else
  72     return JNI_FALSE;
  73 #endif /* !HEADLESS */
  74 }
  75 
  76 
  77 /*
  78  * Class:     sun_awt_UNIXToolkit
  79  * Method:    unload_gtk
  80  * Signature: ()Z
  81  */
  82 JNIEXPORT jboolean JNICALL
  83 Java_sun_awt_UNIXToolkit_unload_1gtk(JNIEnv *env, jclass klass)
  84 {
  85 #ifndef HEADLESS
  86     return (jboolean)gtk2_unload();
  87 #else
  88     return JNI_FALSE;
  89 #endif /* !HEADLESS */
  90 }
  91 
  92 jboolean _icon_upcall(JNIEnv *env, jobject this, GdkPixbuf *pixbuf)
  93 {
  94     jboolean result = JNI_FALSE;
  95 
  96     if (this_class == NULL) {
  97         this_class = (*env)->NewGlobalRef(env,
  98                                           (*env)->GetObjectClass(env, this));
  99         icon_upcall_method = (*env)->GetMethodID(env, this_class,
 100                                  "loadIconCallback", "([BIIIIIZ)V");
 101         CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE);
 102     }
 103 
 104     if (pixbuf != NULL)
 105     {
 106         guchar *pixbuf_data = (*fp_gdk_pixbuf_get_pixels)(pixbuf);
 107         int row_stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
 108         int width = (*fp_gdk_pixbuf_get_width)(pixbuf);
 109         int height = (*fp_gdk_pixbuf_get_height)(pixbuf);
 110         int bps = (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf);
 111         int channels = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
 112         gboolean alpha = (*fp_gdk_pixbuf_get_has_alpha)(pixbuf);
 113 
 114         /* Copy the data array into a Java structure so we can pass it back. */
 115         jbyteArray data = (*env)->NewByteArray(env, (row_stride * height));
 116         JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
 117 
 118         (*env)->SetByteArrayRegion(env, data, 0, (row_stride * height),
 119                                    (jbyte *)pixbuf_data);
 120 
 121         /* Release the pixbuf. */
 122         (*fp_g_object_unref)(pixbuf);
 123 
 124         /* Call the callback method to create the image on the Java side. */
 125         (*env)->CallVoidMethod(env, this, icon_upcall_method, data,
 126                 width, height, row_stride, bps, channels, alpha);
 127         result = JNI_TRUE;
 128     }
 129     return result;
 130 }
 131 
 132 /*
 133  * Class:     sun_awt_UNIXToolkit
 134  * Method:    load_gtk_icon
 135  * Signature: (Ljava/lang/String)Z
 136  *
 137  * This method assumes that GTK libs are present.
 138  */
 139 JNIEXPORT jboolean JNICALL
 140 Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
 141         jstring filename)
 142 {
 143 #ifndef HEADLESS
 144     int len;
 145     char *filename_str = NULL;
 146     GError **error = NULL;
 147     GdkPixbuf *pixbuf;
 148 
 149     if (filename == NULL)
 150     {
 151         return JNI_FALSE;
 152     }
 153 
 154     len = (*env)->GetStringUTFLength(env, filename);
 155     filename_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
 156             sizeof(char), len + 1);
 157     if (filename_str == NULL) {
 158         JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 159         return JNI_FALSE;
 160     }




 161     (*env)->GetStringUTFRegion(env, filename, 0, len, filename_str);
 162     pixbuf = (*fp_gdk_pixbuf_new_from_file)(filename_str, error);

 163 
 164     /* Release the strings we've allocated. */
 165     free(filename_str);
 166 
 167     return _icon_upcall(env, this, pixbuf);
 168 #else /* HEADLESS */
 169     return JNI_FALSE;
 170 #endif /* !HEADLESS */
 171 }
 172 
 173 /*
 174  * Class:     sun_awt_UNIXToolkit
 175  * Method:    load_stock_icon
 176  * Signature: (ILjava/lang/String;IILjava/lang/String;)Z
 177  *
 178  * This method assumes that GTK libs are present.
 179  */
 180 JNIEXPORT jboolean JNICALL
 181 Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
 182         jint widget_type, jstring stock_id, jint icon_size,
 183         jint text_direction, jstring detail)
 184 {
 185 #ifndef HEADLESS
 186     int len;
 187     char *stock_id_str = NULL;
 188     char *detail_str = NULL;
 189     GdkPixbuf *pixbuf;
 190 
 191     if (stock_id == NULL)
 192     {
 193         return JNI_FALSE;
 194     }
 195 
 196     len = (*env)->GetStringUTFLength(env, stock_id);
 197     stock_id_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
 198             sizeof(char), len + 1);
 199     if (stock_id_str == NULL) {
 200         JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 201         return JNI_FALSE;
 202     }
 203     (*env)->GetStringUTFRegion(env, stock_id, 0, len, stock_id_str);
 204 
 205     /* Detail isn't required so check for NULL. */
 206     if (detail != NULL)
 207     {
 208         len = (*env)->GetStringUTFLength(env, detail);
 209         detail_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
 210                 sizeof(char), len + 1);
 211         if (detail_str == NULL) {
 212             JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 213             return JNI_FALSE;
 214         }
 215         (*env)->GetStringUTFRegion(env, detail, 0, len, detail_str);
 216     }
 217 
 218     pixbuf = gtk2_get_stock_icon(widget_type, stock_id_str, icon_size,
 219                                  text_direction, detail_str);




 220 
 221     /* Release the strings we've allocated. */
 222     free(stock_id_str);
 223     if (detail_str != NULL)
 224     {
 225         free(detail_str);
 226     }
 227 
 228     return _icon_upcall(env, this, pixbuf);
 229 #else /* HEADLESS */
 230     return JNI_FALSE;
 231 #endif /* !HEADLESS */
 232 }
 233 
 234 /*
 235  * Class:     sun_awt_UNIXToolkit
 236  * Method:    nativeSync
 237  * Signature: ()V
 238  */
 239 JNIEXPORT void JNICALL
 240 Java_sun_awt_UNIXToolkit_nativeSync(JNIEnv *env, jobject this)
 241 {
 242 #ifndef HEADLESS
 243     AWT_LOCK();
 244     XSync(awt_display, False);
 245     AWT_UNLOCK();
 246 #endif /* !HEADLESS */
 247 }
 248 


 262     }
 263     splashClose = (SplashClose_t)dlsym(hSplashLib,
 264         "SplashClose");
 265     if (splashClose) {
 266         splashClose();
 267     }
 268     dlclose(hSplashLib);
 269 }
 270 
 271 /*
 272  * Class:     sun_awt_UNIXToolkit
 273  * Method:    gtkCheckVersionImpl
 274  * Signature: (III)Ljava/lang/String;
 275  */
 276 JNIEXPORT jboolean JNICALL
 277 Java_sun_awt_UNIXToolkit_gtkCheckVersionImpl(JNIEnv *env, jobject this,
 278         jint major, jint minor, jint micro)
 279 {
 280     char *ret;
 281 
 282     ret = fp_gtk_check_version(major, minor, micro);
 283     if (ret == NULL) {
 284         return TRUE;
 285     }
 286 
 287     free(ret);
 288     return FALSE;















 289 }
   1 /*
   2  * Copyright (c) 2004, 2018, 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 #include <stdlib.h>
  27 #include <string.h>
  28 #include <unistd.h>
  29 #include <dlfcn.h>
  30 
  31 #include <jni.h>
  32 #include <sizecalc.h>
  33 #include "sun_awt_UNIXToolkit.h"
  34 
  35 #ifndef HEADLESS
  36 #include "awt.h"
  37 #include "gtk_interface.h"
  38 #endif /* !HEADLESS */
  39 
  40 
  41 static jclass this_class = NULL;
  42 static jmethodID icon_upcall_method = NULL;
  43 
  44 
  45 /*
  46  * Class:     sun_awt_UNIXToolkit
  47  * Method:    check_gtk
  48  * Signature: (I)Z
  49  */
  50 JNIEXPORT jboolean JNICALL
  51 Java_sun_awt_UNIXToolkit_check_1gtk(JNIEnv *env, jclass klass, jint version) {

  52 #ifndef HEADLESS
  53     return (jboolean)gtk_check_version(version);
  54 #else
  55     return JNI_FALSE;
  56 #endif /* !HEADLESS */
  57 }
  58 
  59 
  60 /*
  61  * Class:     sun_awt_UNIXToolkit
  62  * Method:    load_gtk
  63  * Signature: (I)Z
  64  */
  65 JNIEXPORT jboolean JNICALL
  66 Java_sun_awt_UNIXToolkit_load_1gtk(JNIEnv *env, jclass klass, jint version,
  67                                                              jboolean verbose) {
  68 #ifndef HEADLESS
  69     return (jboolean)gtk_load(env, version, verbose);
  70 #else
  71     return JNI_FALSE;
  72 #endif /* !HEADLESS */
  73 }
  74 
  75 
  76 /*
  77  * Class:     sun_awt_UNIXToolkit
  78  * Method:    unload_gtk
  79  * Signature: ()Z
  80  */
  81 JNIEXPORT jboolean JNICALL
  82 Java_sun_awt_UNIXToolkit_unload_1gtk(JNIEnv *env, jclass klass)
  83 {
  84 #ifndef HEADLESS
  85     return (jboolean)gtk->unload();
  86 #else
  87     return JNI_FALSE;
  88 #endif /* !HEADLESS */
  89 }
  90 
  91 jboolean init_method(JNIEnv *env, jobject this)
  92 {


  93     if (this_class == NULL) {
  94         this_class = (*env)->NewGlobalRef(env,
  95                                           (*env)->GetObjectClass(env, this));
  96         icon_upcall_method = (*env)->GetMethodID(env, this_class,
  97                                  "loadIconCallback", "([BIIIIIZ)V");
  98         CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE);
  99     }
 100 
 101     return JNI_TRUE;

























 102 }
 103 
 104 /*
 105  * Class:     sun_awt_UNIXToolkit
 106  * Method:    load_gtk_icon
 107  * Signature: (Ljava/lang/String)Z
 108  *
 109  * This method assumes that GTK libs are present.
 110  */
 111 JNIEXPORT jboolean JNICALL
 112 Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
 113         jstring filename)
 114 {
 115 #ifndef HEADLESS
 116     int len;
 117     char *filename_str = NULL;
 118     GError **error = NULL;

 119 
 120     if (filename == NULL)
 121     {
 122         return JNI_FALSE;
 123     }
 124 
 125     len = (*env)->GetStringUTFLength(env, filename);
 126     filename_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
 127             sizeof(char), len + 1);
 128     if (filename_str == NULL) {
 129         JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 130         return JNI_FALSE;
 131     }
 132     if (!init_method(env, this) ) {
 133         free(filename_str);
 134         return JNI_FALSE;
 135     }
 136     (*env)->GetStringUTFRegion(env, filename, 0, len, filename_str);
 137     jboolean result = gtk->get_file_icon_data(env, filename_str, error,
 138                                             icon_upcall_method, this);
 139 
 140     /* Release the strings we've allocated. */
 141     free(filename_str);
 142 
 143     return result;
 144 #else /* HEADLESS */
 145     return JNI_FALSE;
 146 #endif /* !HEADLESS */
 147 }
 148 
 149 /*
 150  * Class:     sun_awt_UNIXToolkit
 151  * Method:    load_stock_icon
 152  * Signature: (ILjava/lang/String;IILjava/lang/String;)Z
 153  *
 154  * This method assumes that GTK libs are present.
 155  */
 156 JNIEXPORT jboolean JNICALL
 157 Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
 158         jint widget_type, jstring stock_id, jint icon_size,
 159         jint text_direction, jstring detail)
 160 {
 161 #ifndef HEADLESS
 162     int len;
 163     char *stock_id_str = NULL;
 164     char *detail_str = NULL;

 165 
 166     if (stock_id == NULL)
 167     {
 168         return JNI_FALSE;
 169     }
 170 
 171     len = (*env)->GetStringUTFLength(env, stock_id);
 172     stock_id_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
 173             sizeof(char), len + 1);
 174     if (stock_id_str == NULL) {
 175         JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 176         return JNI_FALSE;
 177     }
 178     (*env)->GetStringUTFRegion(env, stock_id, 0, len, stock_id_str);
 179 
 180     /* Detail isn't required so check for NULL. */
 181     if (detail != NULL)
 182     {
 183         len = (*env)->GetStringUTFLength(env, detail);
 184         detail_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
 185                 sizeof(char), len + 1);
 186         if (detail_str == NULL) {
 187             JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 188             return JNI_FALSE;
 189         }
 190         (*env)->GetStringUTFRegion(env, detail, 0, len, detail_str);
 191     }
 192 
 193     if (!init_method(env, this) ) {
 194         return JNI_FALSE;
 195     }
 196     jboolean result = gtk->get_icon_data(env, widget_type, stock_id_str,
 197                   icon_size, text_direction, detail_str,
 198                   icon_upcall_method, this);
 199 
 200     /* Release the strings we've allocated. */
 201     free(stock_id_str);
 202     if (detail_str != NULL)
 203     {
 204         free(detail_str);
 205     }
 206 
 207     return result;
 208 #else /* HEADLESS */
 209     return JNI_FALSE;
 210 #endif /* !HEADLESS */
 211 }
 212 
 213 /*
 214  * Class:     sun_awt_UNIXToolkit
 215  * Method:    nativeSync
 216  * Signature: ()V
 217  */
 218 JNIEXPORT void JNICALL
 219 Java_sun_awt_UNIXToolkit_nativeSync(JNIEnv *env, jobject this)
 220 {
 221 #ifndef HEADLESS
 222     AWT_LOCK();
 223     XSync(awt_display, False);
 224     AWT_UNLOCK();
 225 #endif /* !HEADLESS */
 226 }
 227 


 241     }
 242     splashClose = (SplashClose_t)dlsym(hSplashLib,
 243         "SplashClose");
 244     if (splashClose) {
 245         splashClose();
 246     }
 247     dlclose(hSplashLib);
 248 }
 249 
 250 /*
 251  * Class:     sun_awt_UNIXToolkit
 252  * Method:    gtkCheckVersionImpl
 253  * Signature: (III)Ljava/lang/String;
 254  */
 255 JNIEXPORT jboolean JNICALL
 256 Java_sun_awt_UNIXToolkit_gtkCheckVersionImpl(JNIEnv *env, jobject this,
 257         jint major, jint minor, jint micro)
 258 {
 259     char *ret;
 260 
 261     ret = gtk->gtk_check_version(major, minor, micro);
 262     if (ret == NULL) {
 263         return TRUE;
 264     }
 265 

 266     return FALSE;
 267 }
 268 
 269 /*
 270  * Class:     sun_awt_UNIXToolkit
 271  * Method:    get_gtk_version
 272  * Signature: ()I
 273  */
 274 JNIEXPORT jint JNICALL
 275 Java_sun_awt_UNIXToolkit_get_1gtk_1version(JNIEnv *env, jclass klass)
 276 {
 277 #ifndef HEADLESS
 278     return gtk ? gtk->version : GTK_ANY;
 279 #else
 280     return GTK_ANY;
 281 #endif /* !HEADLESS */
 282 }
< prev index next >