< prev index next >

src/java.desktop/unix/native/libawt_xawt/awt/awt_UNIXToolkit.c

Print this page


   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


  96         icon_upcall_method = (*env)->GetMethodID(env, this_class,
  97                                  "loadIconCallback", "([BIIIIIZ)V");
  98         CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE);
  99     }
 100     return JNI_TRUE;
 101 }
 102 
 103 /*
 104  * Class:     sun_awt_UNIXToolkit
 105  * Method:    load_gtk_icon
 106  * Signature: (Ljava/lang/String)Z
 107  *
 108  * This method assumes that GTK libs are present.
 109  */
 110 JNIEXPORT jboolean JNICALL
 111 Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
 112         jstring filename)
 113 {
 114 #ifndef HEADLESS
 115     int len;

 116     char *filename_str = NULL;
 117     GError **error = NULL;
 118 
 119     if (filename == NULL)
 120     {
 121         return JNI_FALSE;
 122     }
 123 
 124     len = (*env)->GetStringUTFLength(env, filename);

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

 162     char *stock_id_str = NULL;
 163     char *detail_str = NULL;
 164     jboolean result = JNI_FALSE;
 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             free(stock_id_str);
 188             JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 189             return JNI_FALSE;
 190         }
 191         (*env)->GetStringUTFRegion(env, detail, 0, len, detail_str);
 192     }
 193 
 194     if (init_method(env, this)) {
 195         result = gtk->get_icon_data(env, widget_type, stock_id_str,
 196                                     icon_size, text_direction, detail_str,
 197                                     icon_upcall_method, this);
 198     }
 199     /* Release the strings we've allocated. */
 200     free(stock_id_str);
 201     free(detail_str);
 202 
 203     return result;
 204 #else /* HEADLESS */
 205     return JNI_FALSE;
 206 #endif /* !HEADLESS */
 207 }
 208 
 209 /*
 210  * Class:     sun_awt_UNIXToolkit
 211  * Method:    nativeSync


   1 /*
   2  * Copyright (c) 2004, 2019, 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


  96         icon_upcall_method = (*env)->GetMethodID(env, this_class,
  97                                  "loadIconCallback", "([BIIIIIZ)V");
  98         CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE);
  99     }
 100     return JNI_TRUE;
 101 }
 102 
 103 /*
 104  * Class:     sun_awt_UNIXToolkit
 105  * Method:    load_gtk_icon
 106  * Signature: (Ljava/lang/String)Z
 107  *
 108  * This method assumes that GTK libs are present.
 109  */
 110 JNIEXPORT jboolean JNICALL
 111 Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
 112         jstring filename)
 113 {
 114 #ifndef HEADLESS
 115     int len;
 116     jsize jlen;
 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     jlen = (*env)->GetStringLength(env, filename);
 127     filename_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
 128             sizeof(char), len + 1);
 129     if (filename_str == NULL) {
 130         JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 131         return JNI_FALSE;
 132     }
 133     if (!init_method(env, this) ) {
 134         free(filename_str);
 135         return JNI_FALSE;
 136     }
 137     (*env)->GetStringUTFRegion(env, filename, 0, jlen, filename_str);
 138     jboolean result = gtk->get_file_icon_data(env, filename_str, error,
 139                                             icon_upcall_method, this);
 140 
 141     /* Release the strings we've allocated. */
 142     free(filename_str);
 143 
 144     return result;
 145 #else /* HEADLESS */
 146     return JNI_FALSE;
 147 #endif /* !HEADLESS */
 148 }
 149 
 150 /*
 151  * Class:     sun_awt_UNIXToolkit
 152  * Method:    load_stock_icon
 153  * Signature: (ILjava/lang/String;IILjava/lang/String;)Z
 154  *
 155  * This method assumes that GTK libs are present.
 156  */
 157 JNIEXPORT jboolean JNICALL
 158 Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
 159         jint widget_type, jstring stock_id, jint icon_size,
 160         jint text_direction, jstring detail)
 161 {
 162 #ifndef HEADLESS
 163     int len;
 164     jsize jlen;
 165     char *stock_id_str = NULL;
 166     char *detail_str = NULL;
 167     jboolean result = JNI_FALSE;
 168 
 169     if (stock_id == NULL)
 170     {
 171         return JNI_FALSE;
 172     }
 173 
 174     len = (*env)->GetStringUTFLength(env, stock_id);
 175     jlen = (*env)->GetStringLength(env, stock_id);
 176     stock_id_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
 177             sizeof(char), len + 1);
 178     if (stock_id_str == NULL) {
 179         JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 180         return JNI_FALSE;
 181     }
 182     (*env)->GetStringUTFRegion(env, stock_id, 0, jlen, stock_id_str);
 183 
 184     /* Detail isn't required so check for NULL. */
 185     if (detail != NULL)
 186     {
 187         len = (*env)->GetStringUTFLength(env, detail);
 188         jlen = (*env)->GetStringLength(env, detail);
 189         detail_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
 190                 sizeof(char), len + 1);
 191         if (detail_str == NULL) {
 192             free(stock_id_str);
 193             JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
 194             return JNI_FALSE;
 195         }
 196         (*env)->GetStringUTFRegion(env, detail, 0, jlen, detail_str);
 197     }
 198 
 199     if (init_method(env, this)) {
 200         result = gtk->get_icon_data(env, widget_type, stock_id_str,
 201                                     icon_size, text_direction, detail_str,
 202                                     icon_upcall_method, this);
 203     }
 204     /* Release the strings we've allocated. */
 205     free(stock_id_str);
 206     free(detail_str);
 207 
 208     return result;
 209 #else /* HEADLESS */
 210     return JNI_FALSE;
 211 #endif /* !HEADLESS */
 212 }
 213 
 214 /*
 215  * Class:     sun_awt_UNIXToolkit
 216  * Method:    nativeSync


< prev index next >