< prev index next >

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

Print this page

        

*** 41,51 **** const char* vname; GtkApi* (*load)(JNIEnv *env, const char* lib_name); gboolean (*check)(const char* lib_name, gboolean load); } GtkLib; ! static GtkLib libs[] = { { GTK_2, JNI_LIB_NAME("gtk-x11-2.0"), VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0"), &gtk2_load, --- 41,51 ---- const char* vname; GtkApi* (*load)(JNIEnv *env, const char* lib_name); gboolean (*check)(const char* lib_name, gboolean load); } GtkLib; ! static GtkLib gtk_libs[] = { { GTK_2, JNI_LIB_NAME("gtk-x11-2.0"), VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0"), &gtk2_load,
*** 55,109 **** GTK_3, JNI_LIB_NAME("gtk-3"), VERSIONED_JNI_LIB_NAME("gtk-3", "0"), &gtk3_load, &gtk3_check - }, - { - 0, - NULL, - NULL, - NULL, - NULL } }; static GtkLib* get_loaded() { ! GtkLib* lib = libs; ! while(!gtk && lib->version) { if (lib->check(lib->vname, /* load = */FALSE)) { return lib; } if (lib->check(lib->name, /* load = */FALSE)) { return lib; } - lib++; } return NULL; } gboolean gtk_load(JNIEnv *env, GtkVersion version, gboolean verbose) { if (gtk == NULL) { GtkLib* lib = get_loaded(); if (lib) { - if (version != GTK_ANY && lib->version != version) { if (verbose) { ! fprintf(stderr, "WARNING: Cannot load GTK%d library: \ ! GTK%d has already been loaded\n", version, lib->version); ! } ! return FALSE; ! } ! if (verbose) { ! fprintf(stderr, "Looking for GTK%d library...\n", version); } gtk = lib->load(env, lib->vname); if (!gtk) { gtk = lib->load(env, lib->name); } } else { ! lib = libs; ! while (!gtk && lib->version) { if (version == GTK_ANY || lib->version == version) { if (verbose) { fprintf(stderr, "Looking for GTK%d library...\n", lib->version); } --- 55,120 ---- GTK_3, JNI_LIB_NAME("gtk-3"), VERSIONED_JNI_LIB_NAME("gtk-3", "0"), &gtk3_load, &gtk3_check } }; + static GtkLib** get_libs_order(GtkVersion version) { + static GtkLib** load_order; + static int n_libs = 0; + if (!n_libs) { + n_libs = sizeof(gtk_libs) / sizeof(GtkLib); + load_order = calloc(n_libs + 1, sizeof(GtkLib *)); + } + int i, first = 0; + for (i = 0; i < n_libs; i++) { + load_order[i] = &gtk_libs[i]; + if (load_order[i]->version == version) { + first = i; + } + } + if (first) { + for (i = first; i > 0; i--) { + load_order[i] = load_order[i - 1]; + } + load_order[0] = &gtk_libs[first]; + } + return load_order; + } + static GtkLib* get_loaded() { ! GtkLib** libs = get_libs_order(GTK_ANY); ! while(!gtk && *libs) { ! GtkLib* lib = *libs++; if (lib->check(lib->vname, /* load = */FALSE)) { return lib; } if (lib->check(lib->name, /* load = */FALSE)) { return lib; } } return NULL; } gboolean gtk_load(JNIEnv *env, GtkVersion version, gboolean verbose) { if (gtk == NULL) { GtkLib* lib = get_loaded(); if (lib) { if (verbose) { ! fprintf(stderr, "Looking for GTK%d library...\n", ! lib->version); } gtk = lib->load(env, lib->vname); if (!gtk) { gtk = lib->load(env, lib->name); } } else { ! GtkLib** libs = get_libs_order(version); ! while (!gtk && *libs) { ! lib = *libs++; if (version == GTK_ANY || lib->version == version) { if (verbose) { fprintf(stderr, "Looking for GTK%d library...\n", lib->version); }
*** 113,125 **** } if (verbose && !gtk) { fprintf(stderr, "Not found.\n"); } } - lib++; } - lib--; } if (verbose) { if (gtk) { fprintf(stderr, "GTK%d library loaded.\n", lib->version); } else { --- 124,134 ----
*** 129,155 **** } return gtk != NULL; } static gboolean check_version(GtkVersion version) { ! GtkLib* lib = libs; ! while (lib->version) { ! if (version == GTK_ANY || lib->version == version) { if (lib->check(lib->vname, /* load = */TRUE)) { return TRUE; } if (lib->check(lib->name, /* load = */TRUE)) { return TRUE; } } - lib++; - } return FALSE; } gboolean gtk_check_version(GtkVersion version) { ! if (gtk) { return TRUE; } return check_version(version); } --- 138,162 ---- } return gtk != NULL; } static gboolean check_version(GtkVersion version) { ! GtkLib** libs = get_libs_order(version); ! while (*libs) { ! GtkLib* lib = *libs++; if (lib->check(lib->vname, /* load = */TRUE)) { return TRUE; } if (lib->check(lib->name, /* load = */TRUE)) { return TRUE; } } return FALSE; } gboolean gtk_check_version(GtkVersion version) { ! if (gtk || get_loaded()) { return TRUE; } return check_version(version); }
< prev index next >