annotate src/java.desktop/unix/native/libawt_xawt/awt/awt_UNIXToolkit.c @ 14339:6d60dfa5e3f8

8145547: [AWT/Swing] Conditional support for GTK 3 on Linux Reviewed-by: prr, alexsch
author ssadetsky
date Mon, 25 Apr 2016 15:37:31 +0300
parents e66f69113b89
children 251eb9ac75dd
rev   line source
duke@0 1 /*
ssadetsky@14339 2 * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
ohair@2362 7 * published by the Free Software Foundation. Oracle designates this
duke@0 8 * particular file as subject to the "Classpath" exception as provided
ohair@2362 9 * by Oracle in the LICENSE file that accompanied this code.
duke@0 10 *
duke@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 * accompanied this code).
duke@0 16 *
duke@0 17 * You should have received a copy of the GNU General Public License version
duke@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 *
ohair@2362 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@2362 22 * or visit www.oracle.com if you need additional information or have any
ohair@2362 23 * questions.
duke@0 24 */
duke@0 25
duke@0 26 #include <stdlib.h>
duke@0 27 #include <string.h>
duke@0 28 #include <unistd.h>
duke@0 29 #include <dlfcn.h>
duke@0 30
duke@0 31 #include <jni.h>
anthony@7441 32 #include <sizecalc.h>
duke@0 33 #include "sun_awt_UNIXToolkit.h"
duke@0 34
duke@0 35 #ifndef HEADLESS
duke@0 36 #include "awt.h"
ssadetsky@14339 37 #include "gtk_interface.h"
duke@0 38 #endif /* !HEADLESS */
duke@0 39
duke@0 40
duke@0 41 static jclass this_class = NULL;
duke@0 42 static jmethodID icon_upcall_method = NULL;
duke@0 43
duke@0 44
duke@0 45 /*
duke@0 46 * Class: sun_awt_UNIXToolkit
duke@0 47 * Method: check_gtk
ssadetsky@14339 48 * Signature: (I)Z
duke@0 49 */
duke@0 50 JNIEXPORT jboolean JNICALL
ssadetsky@14339 51 Java_sun_awt_UNIXToolkit_check_1gtk(JNIEnv *env, jclass klass, jint version) {
duke@0 52 #ifndef HEADLESS
ssadetsky@14339 53 return (jboolean)gtk_check_version(version);
duke@0 54 #else
duke@0 55 return JNI_FALSE;
duke@0 56 #endif /* !HEADLESS */
duke@0 57 }
duke@0 58
duke@0 59
duke@0 60 /*
duke@0 61 * Class: sun_awt_UNIXToolkit
duke@0 62 * Method: load_gtk
ssadetsky@14339 63 * Signature: (I)Z
duke@0 64 */
duke@0 65 JNIEXPORT jboolean JNICALL
ssadetsky@14339 66 Java_sun_awt_UNIXToolkit_load_1gtk(JNIEnv *env, jclass klass, jint version,
ssadetsky@14339 67 jboolean verbose) {
duke@0 68 #ifndef HEADLESS
ssadetsky@14339 69 return (jboolean)gtk_load(env, version, verbose);
duke@0 70 #else
duke@0 71 return JNI_FALSE;
duke@0 72 #endif /* !HEADLESS */
duke@0 73 }
duke@0 74
duke@0 75
duke@0 76 /*
duke@0 77 * Class: sun_awt_UNIXToolkit
duke@0 78 * Method: unload_gtk
duke@0 79 * Signature: ()Z
duke@0 80 */
duke@0 81 JNIEXPORT jboolean JNICALL
duke@0 82 Java_sun_awt_UNIXToolkit_unload_1gtk(JNIEnv *env, jclass klass)
duke@0 83 {
duke@0 84 #ifndef HEADLESS
ssadetsky@14339 85 return (jboolean)gtk->unload();
duke@0 86 #else
duke@0 87 return JNI_FALSE;
duke@0 88 #endif /* !HEADLESS */
duke@0 89 }
duke@0 90
ssadetsky@14339 91 jboolean init_method(JNIEnv *env, jobject this)
duke@0 92 {
duke@0 93 if (this_class == NULL) {
duke@0 94 this_class = (*env)->NewGlobalRef(env,
duke@0 95 (*env)->GetObjectClass(env, this));
duke@0 96 icon_upcall_method = (*env)->GetMethodID(env, this_class,
duke@0 97 "loadIconCallback", "([BIIIIIZ)V");
pchelko@9810 98 CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE);
duke@0 99 }
ssadetsky@14339 100 return JNI_TRUE;
duke@0 101 }
duke@0 102
duke@0 103 /*
duke@0 104 * Class: sun_awt_UNIXToolkit
duke@0 105 * Method: load_gtk_icon
duke@0 106 * Signature: (Ljava/lang/String)Z
duke@0 107 *
duke@0 108 * This method assumes that GTK libs are present.
duke@0 109 */
duke@0 110 JNIEXPORT jboolean JNICALL
duke@0 111 Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
duke@0 112 jstring filename)
duke@0 113 {
duke@0 114 #ifndef HEADLESS
duke@0 115 int len;
duke@0 116 char *filename_str = NULL;
duke@0 117 GError **error = NULL;
duke@0 118
duke@0 119 if (filename == NULL)
duke@0 120 {
duke@0 121 return JNI_FALSE;
duke@0 122 }
duke@0 123
duke@0 124 len = (*env)->GetStringUTFLength(env, filename);
anthony@7441 125 filename_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
anthony@7441 126 sizeof(char), len + 1);
duke@0 127 if (filename_str == NULL) {
duke@0 128 JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
duke@0 129 return JNI_FALSE;
duke@0 130 }
ssadetsky@14339 131 if (!init_method(env, this) ) {
ssadetsky@14339 132 return JNI_FALSE;
ssadetsky@14339 133 }
duke@0 134 (*env)->GetStringUTFRegion(env, filename, 0, len, filename_str);
ssadetsky@14339 135 jboolean result = gtk->get_file_icon_data(env, filename_str, error,
ssadetsky@14339 136 icon_upcall_method, this);
duke@0 137
duke@0 138 /* Release the strings we've allocated. */
duke@0 139 free(filename_str);
duke@0 140
ssadetsky@14339 141 return result;
duke@0 142 #else /* HEADLESS */
duke@0 143 return JNI_FALSE;
duke@0 144 #endif /* !HEADLESS */
duke@0 145 }
duke@0 146
duke@0 147 /*
duke@0 148 * Class: sun_awt_UNIXToolkit
duke@0 149 * Method: load_stock_icon
duke@0 150 * Signature: (ILjava/lang/String;IILjava/lang/String;)Z
duke@0 151 *
duke@0 152 * This method assumes that GTK libs are present.
duke@0 153 */
duke@0 154 JNIEXPORT jboolean JNICALL
duke@0 155 Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
duke@0 156 jint widget_type, jstring stock_id, jint icon_size,
duke@0 157 jint text_direction, jstring detail)
duke@0 158 {
duke@0 159 #ifndef HEADLESS
duke@0 160 int len;
duke@0 161 char *stock_id_str = NULL;
duke@0 162 char *detail_str = NULL;
duke@0 163
duke@0 164 if (stock_id == NULL)
duke@0 165 {
duke@0 166 return JNI_FALSE;
duke@0 167 }
duke@0 168
duke@0 169 len = (*env)->GetStringUTFLength(env, stock_id);
anthony@7441 170 stock_id_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
anthony@7441 171 sizeof(char), len + 1);
duke@0 172 if (stock_id_str == NULL) {
duke@0 173 JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
duke@0 174 return JNI_FALSE;
duke@0 175 }
duke@0 176 (*env)->GetStringUTFRegion(env, stock_id, 0, len, stock_id_str);
duke@0 177
duke@0 178 /* Detail isn't required so check for NULL. */
duke@0 179 if (detail != NULL)
duke@0 180 {
duke@0 181 len = (*env)->GetStringUTFLength(env, detail);
anthony@7441 182 detail_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
anthony@7441 183 sizeof(char), len + 1);
duke@0 184 if (detail_str == NULL) {
duke@0 185 JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
duke@0 186 return JNI_FALSE;
duke@0 187 }
duke@0 188 (*env)->GetStringUTFRegion(env, detail, 0, len, detail_str);
duke@0 189 }
duke@0 190
ssadetsky@14339 191 if (!init_method(env, this) ) {
ssadetsky@14339 192 return JNI_FALSE;
ssadetsky@14339 193 }
ssadetsky@14339 194 jboolean result = gtk->get_icon_data(env, widget_type, stock_id_str,
ssadetsky@14339 195 icon_size, text_direction, detail_str,
ssadetsky@14339 196 icon_upcall_method, this);
duke@0 197
duke@0 198 /* Release the strings we've allocated. */
duke@0 199 free(stock_id_str);
duke@0 200 if (detail_str != NULL)
duke@0 201 {
duke@0 202 free(detail_str);
duke@0 203 }
ssadetsky@14339 204 return result;
duke@0 205 #else /* HEADLESS */
duke@0 206 return JNI_FALSE;
duke@0 207 #endif /* !HEADLESS */
duke@0 208 }
duke@0 209
duke@0 210 /*
duke@0 211 * Class: sun_awt_UNIXToolkit
duke@0 212 * Method: nativeSync
duke@0 213 * Signature: ()V
duke@0 214 */
duke@0 215 JNIEXPORT void JNICALL
duke@0 216 Java_sun_awt_UNIXToolkit_nativeSync(JNIEnv *env, jobject this)
duke@0 217 {
duke@0 218 #ifndef HEADLESS
duke@0 219 AWT_LOCK();
duke@0 220 XSync(awt_display, False);
duke@0 221 AWT_UNLOCK();
duke@0 222 #endif /* !HEADLESS */
duke@0 223 }
duke@0 224
duke@0 225 /*
duke@0 226 * Class: sun_awt_SunToolkit
duke@0 227 * Method: closeSplashScreen
duke@0 228 * Signature: ()V
duke@0 229 */
duke@0 230 JNIEXPORT void JNICALL
duke@0 231 Java_sun_awt_SunToolkit_closeSplashScreen(JNIEnv *env, jclass cls)
duke@0 232 {
duke@0 233 typedef void (*SplashClose_t)();
duke@0 234 SplashClose_t splashClose;
duke@0 235 void* hSplashLib = dlopen(0, RTLD_LAZY);
duke@0 236 if (!hSplashLib) {
duke@0 237 return;
duke@0 238 }
duke@0 239 splashClose = (SplashClose_t)dlsym(hSplashLib,
duke@0 240 "SplashClose");
duke@0 241 if (splashClose) {
duke@0 242 splashClose();
duke@0 243 }
duke@0 244 dlclose(hSplashLib);
duke@0 245 }
anthony@2328 246
anthony@2328 247 /*
anthony@2328 248 * Class: sun_awt_UNIXToolkit
anthony@2328 249 * Method: gtkCheckVersionImpl
anthony@2328 250 * Signature: (III)Ljava/lang/String;
anthony@2328 251 */
anthony@2328 252 JNIEXPORT jboolean JNICALL
anthony@2328 253 Java_sun_awt_UNIXToolkit_gtkCheckVersionImpl(JNIEnv *env, jobject this,
anthony@2328 254 jint major, jint minor, jint micro)
anthony@2328 255 {
anthony@2328 256 char *ret;
anthony@2328 257
ssadetsky@14339 258 ret = gtk->gtk_check_version(major, minor, micro);
anthony@2328 259 if (ret == NULL) {
anthony@2328 260 return TRUE;
anthony@2328 261 }
anthony@2328 262
anthony@2328 263 return FALSE;
anthony@2328 264 }
ssadetsky@14339 265
ssadetsky@14339 266 /*
ssadetsky@14339 267 * Class: sun_awt_UNIXToolkit
ssadetsky@14339 268 * Method: get_gtk_version
ssadetsky@14339 269 * Signature: ()I
ssadetsky@14339 270 */
ssadetsky@14339 271 JNIEXPORT jint JNICALL
ssadetsky@14339 272 Java_sun_awt_UNIXToolkit_get_1gtk_1version(JNIEnv *env, jclass klass)
ssadetsky@14339 273 {
ssadetsky@14339 274 #ifndef HEADLESS
ssadetsky@14339 275 return gtk ? gtk->version : GTK_ANY;
ssadetsky@14339 276 #else
ssadetsky@14339 277 return GTK_ANY;
ssadetsky@14339 278 #endif /* !HEADLESS */
ssadetsky@14339 279 }