< prev index next >

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

Print this page




  26 #include <stdlib.h>
  27 #include "jvm_md.h"
  28 #include "gtk_interface.h"
  29 
  30 GtkApi* gtk2_load(JNIEnv *env, const char* lib_name);
  31 GtkApi* gtk3_load(JNIEnv *env, const char* lib_name);
  32 
  33 gboolean gtk2_check(const char* lib_name, gboolean load);
  34 gboolean gtk3_check(const char* lib_name, gboolean load);
  35 
  36 GtkApi *gtk;
  37 
  38 typedef struct {
  39     GtkVersion version;
  40     const char* name;
  41     const char* vname;
  42     GtkApi* (*load)(JNIEnv *env, const char* lib_name);
  43     gboolean (*check)(const char* lib_name, gboolean load);
  44 } GtkLib;
  45 
  46 static GtkLib libs[] = {
  47     {
  48         GTK_2,
  49         JNI_LIB_NAME("gtk-x11-2.0"),
  50         VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0"),
  51         &gtk2_load,
  52         &gtk2_check
  53     },
  54     {
  55         GTK_3,
  56         JNI_LIB_NAME("gtk-3"),
  57         VERSIONED_JNI_LIB_NAME("gtk-3", "0"),
  58         &gtk3_load,
  59         &gtk3_check
  60     },
  61     {
  62         0,
  63         NULL,
  64         NULL,
  65         NULL,
  66         NULL
  67     }
  68 };
  69 























  70 static GtkLib* get_loaded() {
  71     GtkLib* lib = libs;
  72     while(!gtk && lib->version) {

  73         if (lib->check(lib->vname, /* load = */FALSE)) {
  74             return lib;
  75         }
  76         if (lib->check(lib->name, /* load = */FALSE)) {
  77             return lib;
  78         }
  79         lib++;
  80     }
  81     return NULL;
  82 }
  83 
  84 gboolean gtk_load(JNIEnv *env, GtkVersion version, gboolean verbose) {
  85     if (gtk == NULL) {
  86         GtkLib* lib = get_loaded();
  87         if (lib) {
  88             if (version != GTK_ANY && lib->version != version) {
  89                 if (verbose) {
  90                     fprintf(stderr, "WARNING: Cannot load GTK%d library: \
  91                          GTK%d has already been loaded\n", version, lib->version);
  92                 }
  93                 return FALSE;
  94             }
  95             if (verbose) {
  96                 fprintf(stderr, "Looking for GTK%d library...\n", version);
  97             }
  98             gtk = lib->load(env, lib->vname);
  99             if (!gtk) {
 100                 gtk = lib->load(env, lib->name);
 101             }
 102         } else {
 103             lib = libs;
 104             while (!gtk && lib->version) {

 105                 if (version == GTK_ANY || lib->version == version) {
 106                     if (verbose) {
 107                         fprintf(stderr, "Looking for GTK%d library...\n",
 108                                                                   lib->version);
 109                     }
 110                     gtk = lib->load(env, lib->vname);
 111                     if (!gtk) {
 112                         gtk = lib->load(env, lib->name);
 113                     }
 114                     if (verbose && !gtk) {
 115                         fprintf(stderr, "Not found.\n");
 116                     }
 117                 }
 118                 lib++;
 119             }
 120             lib--;
 121         }
 122         if (verbose) {
 123             if (gtk) {
 124                 fprintf(stderr, "GTK%d library loaded.\n", lib->version);
 125             } else {
 126                 fprintf(stderr, "Failed to load GTK library.\n");
 127             }
 128         }
 129     }
 130     return gtk != NULL;
 131 }
 132 
 133 static gboolean check_version(GtkVersion version) {
 134     GtkLib* lib = libs;
 135     while (lib->version) {
 136         if (version == GTK_ANY || lib->version == version) {
 137             if (lib->check(lib->vname, /* load = */TRUE)) {
 138                 return TRUE;
 139             }
 140             if (lib->check(lib->name, /* load = */TRUE)) {
 141                 return TRUE;
 142             }
 143         }
 144         lib++;
 145     }
 146     return FALSE;
 147 }
 148 
 149 gboolean gtk_check_version(GtkVersion version) {
 150     if (gtk) {
 151         return TRUE;
 152     }
 153     return check_version(version);
 154 }
 155 


  26 #include <stdlib.h>
  27 #include "jvm_md.h"
  28 #include "gtk_interface.h"
  29 
  30 GtkApi* gtk2_load(JNIEnv *env, const char* lib_name);
  31 GtkApi* gtk3_load(JNIEnv *env, const char* lib_name);
  32 
  33 gboolean gtk2_check(const char* lib_name, gboolean load);
  34 gboolean gtk3_check(const char* lib_name, gboolean load);
  35 
  36 GtkApi *gtk;
  37 
  38 typedef struct {
  39     GtkVersion version;
  40     const char* name;
  41     const char* vname;
  42     GtkApi* (*load)(JNIEnv *env, const char* lib_name);
  43     gboolean (*check)(const char* lib_name, gboolean load);
  44 } GtkLib;
  45 
  46 static GtkLib gtk_libs[] = {
  47     {
  48         GTK_2,
  49         JNI_LIB_NAME("gtk-x11-2.0"),
  50         VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0"),
  51         &gtk2_load,
  52         &gtk2_check
  53     },
  54     {
  55         GTK_3,
  56         JNI_LIB_NAME("gtk-3"),
  57         VERSIONED_JNI_LIB_NAME("gtk-3", "0"),
  58         &gtk3_load,
  59         &gtk3_check







  60     }
  61 };
  62 
  63 static GtkLib** get_libs_order(GtkVersion version) {
  64     static GtkLib** load_order;
  65     static int n_libs = 0;
  66     if (!n_libs) {
  67         n_libs = sizeof(gtk_libs) / sizeof(GtkLib);
  68         load_order = calloc(n_libs + 1, sizeof(GtkLib *));
  69     }
  70     int i, first = 0;
  71     for (i = 0; i < n_libs; i++) {
  72         load_order[i] = &gtk_libs[i];
  73         if (load_order[i]->version == version) {
  74             first = i;
  75         }
  76     }
  77     if (first) {
  78         for (i = first; i > 0; i--) {
  79             load_order[i] = load_order[i - 1];
  80         }
  81         load_order[0] = &gtk_libs[first];
  82     }
  83     return load_order;
  84 }
  85 
  86 static GtkLib* get_loaded() {
  87     GtkLib** libs = get_libs_order(GTK_ANY);
  88     while(!gtk && *libs) {
  89         GtkLib* lib = *libs++;
  90         if (lib->check(lib->vname, /* load = */FALSE)) {
  91             return lib;
  92         }
  93         if (lib->check(lib->name, /* load = */FALSE)) {
  94             return lib;
  95         }

  96     }
  97     return NULL;
  98 }
  99 
 100 gboolean gtk_load(JNIEnv *env, GtkVersion version, gboolean verbose) {
 101     if (gtk == NULL) {
 102         GtkLib* lib = get_loaded();
 103         if (lib) {

 104             if (verbose) {
 105                 fprintf(stderr, "Looking for GTK%d library...\n",
 106                                                                  lib->version);





 107             }
 108             gtk = lib->load(env, lib->vname);
 109             if (!gtk) {
 110                 gtk = lib->load(env, lib->name);
 111             }
 112         } else {
 113             GtkLib** libs = get_libs_order(version);
 114             while (!gtk && *libs) {
 115                 lib = *libs++;
 116                 if (version == GTK_ANY || lib->version == version) {
 117                     if (verbose) {
 118                         fprintf(stderr, "Looking for GTK%d library...\n",
 119                                                                   lib->version);
 120                     }
 121                     gtk = lib->load(env, lib->vname);
 122                     if (!gtk) {
 123                         gtk = lib->load(env, lib->name);
 124                     }
 125                     if (verbose && !gtk) {
 126                         fprintf(stderr, "Not found.\n");
 127                     }
 128                 }

 129             }

 130         }
 131         if (verbose) {
 132             if (gtk) {
 133                 fprintf(stderr, "GTK%d library loaded.\n", lib->version);
 134             } else {
 135                 fprintf(stderr, "Failed to load GTK library.\n");
 136             }
 137         }
 138     }
 139     return gtk != NULL;
 140 }
 141 
 142 static gboolean check_version(GtkVersion version) {
 143     GtkLib** libs = get_libs_order(version);
 144     while (*libs) {
 145         GtkLib* lib = *libs++;
 146         if (lib->check(lib->vname, /* load = */TRUE)) {
 147             return TRUE;
 148         }
 149         if (lib->check(lib->name, /* load = */TRUE)) {
 150             return TRUE;
 151         }
 152     }


 153     return FALSE;
 154 }
 155 
 156 gboolean gtk_check_version(GtkVersion version) {
 157     if (gtk || get_loaded()) {
 158         return TRUE;
 159     }
 160     return check_version(version);
 161 }
 162 
< prev index next >