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

Print this page




  64 
  65 #define G_TYPE_FUNDAMENTAL_SHIFT        (2)
  66 #define G_TYPE_MAKE_FUNDAMENTAL(x)      ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
  67 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
  68 
  69 #define CONV_BUFFER_SIZE 128
  70 
  71 #define NO_SYMBOL_EXCEPTION 1
  72 
  73 /* SynthConstants */
  74 const gint ENABLED    = 1 << 0;
  75 const gint MOUSE_OVER = 1 << 1;
  76 const gint PRESSED    = 1 << 2;
  77 const gint DISABLED   = 1 << 3;
  78 const gint FOCUSED    = 1 << 8;
  79 const gint SELECTED   = 1 << 9;
  80 const gint DEFAULT    = 1 << 10;
  81 
  82 static void *gtk2_libhandle = NULL;
  83 static void *gthread_libhandle = NULL;
  84 static gboolean flag_g_thread_get_initialized = FALSE;
  85 static jmp_buf j;
  86 
  87 /* Widgets */
  88 static GtkWidget *gtk2_widget = NULL;
  89 static GtkWidget *gtk2_window = NULL;
  90 static GtkFixed  *gtk2_fixed  = NULL;
  91 
  92 /* Paint system */
  93 static GdkPixmap *gtk2_white_pixmap = NULL;
  94 static GdkPixmap *gtk2_black_pixmap = NULL;
  95 static GdkPixbuf *gtk2_white_pixbuf = NULL;
  96 static GdkPixbuf *gtk2_black_pixbuf = NULL;
  97 static int gtk2_pixbuf_width = 0;
  98 static int gtk2_pixbuf_height = 0;
  99 
 100 /* Static buffer for conversion from java.lang.String to UTF-8 */
 101 static char convertionBuffer[CONV_BUFFER_SIZE];
 102 
 103 static gboolean new_combo = TRUE;
 104 const char ENV_PREFIX[] = "GTK_MODULES=";


 485             "gtk_file_chooser_set_filename");
 486     fp_gtk_file_chooser_set_current_name = dl_symbol(
 487             "gtk_file_chooser_set_current_name");
 488     fp_gtk_file_filter_add_custom = dl_symbol("gtk_file_filter_add_custom");
 489     fp_gtk_file_chooser_set_filter = dl_symbol("gtk_file_chooser_set_filter");
 490     fp_gtk_file_chooser_get_type = dl_symbol("gtk_file_chooser_get_type");
 491     fp_gtk_file_filter_new = dl_symbol("gtk_file_filter_new");
 492     if (fp_gtk_check_version(2, 8, 0) == NULL) {
 493         fp_gtk_file_chooser_set_do_overwrite_confirmation = dl_symbol(
 494                 "gtk_file_chooser_set_do_overwrite_confirmation");
 495     }
 496     fp_gtk_file_chooser_set_select_multiple = dl_symbol(
 497             "gtk_file_chooser_set_select_multiple");
 498     fp_gtk_file_chooser_get_current_folder = dl_symbol(
 499             "gtk_file_chooser_get_current_folder");
 500     fp_gtk_file_chooser_get_filenames = dl_symbol(
 501             "gtk_file_chooser_get_filenames");
 502     fp_gtk_g_slist_length = dl_symbol("g_slist_length");
 503 }
 504 
 505 gboolean gtk2_load()
 506 {
 507     gboolean result;
 508     int i;
 509     int (*handler)();
 510     int (*io_handler)();
 511     char *gtk_modules_env;
 512 
 513     gtk2_libhandle = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 514     if (gtk2_libhandle == NULL) {
 515         gtk2_libhandle = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
 516         if (gtk2_libhandle == NULL)
 517             return FALSE;
 518     }
 519 
 520     gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 521     if (gthread_libhandle == NULL) {
 522         gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL);
 523         if (gthread_libhandle == NULL)
 524             return FALSE;
 525     }


 793                 }
 794             }
 795             putenv (new_env);
 796             free (new_env);
 797             free (tmp_env);
 798         }
 799     }
 800 
 801     /*
 802      * GTK should be initialized with gtk_init_check() before use.
 803      *
 804      * gtk_init_check installs its own error handlers. It is critical that
 805      * we preserve error handler set from AWT. Otherwise we'll crash on
 806      * BadMatch errors which we would normally ignore. The IO error handler
 807      * is preserved here, too, just for consistency.
 808     */
 809     handler = XSetErrorHandler(NULL);
 810     io_handler = XSetIOErrorHandler(NULL);
 811 
 812     if (fp_gtk_check_version(2, 2, 0) == NULL) {
 813         // Init the thread system to use GLib in a thread-safe mode
 814         if (!flag_g_thread_get_initialized) {
 815             flag_g_thread_get_initialized = TRUE;


 816 



 817             fp_g_thread_init(NULL);
 818 
 819             //According the GTK documentation, gdk_threads_init() should be
 820             //called before gtk_init() or gtk_init_check()
 821             fp_gdk_threads_init();

 822         }

 823     }
 824     result = (*fp_gtk_init_check)(NULL, NULL);
 825 
 826     XSetErrorHandler(handler);
 827     XSetIOErrorHandler(io_handler);
 828 
 829     /* Initialize widget array. */
 830     for (i = 0; i < _GTK_WIDGET_TYPE_SIZE; i++)
 831     {
 832         gtk2_widgets[i] = NULL;
 833     }
 834 
 835     return result;
 836 }
 837 
 838 int gtk2_unload()
 839 {
 840     int i;
 841     char *gtk2_error;
 842 




  64 
  65 #define G_TYPE_FUNDAMENTAL_SHIFT        (2)
  66 #define G_TYPE_MAKE_FUNDAMENTAL(x)      ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
  67 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
  68 
  69 #define CONV_BUFFER_SIZE 128
  70 
  71 #define NO_SYMBOL_EXCEPTION 1
  72 
  73 /* SynthConstants */
  74 const gint ENABLED    = 1 << 0;
  75 const gint MOUSE_OVER = 1 << 1;
  76 const gint PRESSED    = 1 << 2;
  77 const gint DISABLED   = 1 << 3;
  78 const gint FOCUSED    = 1 << 8;
  79 const gint SELECTED   = 1 << 9;
  80 const gint DEFAULT    = 1 << 10;
  81 
  82 static void *gtk2_libhandle = NULL;
  83 static void *gthread_libhandle = NULL;
  84 
  85 static jmp_buf j;
  86 
  87 /* Widgets */
  88 static GtkWidget *gtk2_widget = NULL;
  89 static GtkWidget *gtk2_window = NULL;
  90 static GtkFixed  *gtk2_fixed  = NULL;
  91 
  92 /* Paint system */
  93 static GdkPixmap *gtk2_white_pixmap = NULL;
  94 static GdkPixmap *gtk2_black_pixmap = NULL;
  95 static GdkPixbuf *gtk2_white_pixbuf = NULL;
  96 static GdkPixbuf *gtk2_black_pixbuf = NULL;
  97 static int gtk2_pixbuf_width = 0;
  98 static int gtk2_pixbuf_height = 0;
  99 
 100 /* Static buffer for conversion from java.lang.String to UTF-8 */
 101 static char convertionBuffer[CONV_BUFFER_SIZE];
 102 
 103 static gboolean new_combo = TRUE;
 104 const char ENV_PREFIX[] = "GTK_MODULES=";


 485             "gtk_file_chooser_set_filename");
 486     fp_gtk_file_chooser_set_current_name = dl_symbol(
 487             "gtk_file_chooser_set_current_name");
 488     fp_gtk_file_filter_add_custom = dl_symbol("gtk_file_filter_add_custom");
 489     fp_gtk_file_chooser_set_filter = dl_symbol("gtk_file_chooser_set_filter");
 490     fp_gtk_file_chooser_get_type = dl_symbol("gtk_file_chooser_get_type");
 491     fp_gtk_file_filter_new = dl_symbol("gtk_file_filter_new");
 492     if (fp_gtk_check_version(2, 8, 0) == NULL) {
 493         fp_gtk_file_chooser_set_do_overwrite_confirmation = dl_symbol(
 494                 "gtk_file_chooser_set_do_overwrite_confirmation");
 495     }
 496     fp_gtk_file_chooser_set_select_multiple = dl_symbol(
 497             "gtk_file_chooser_set_select_multiple");
 498     fp_gtk_file_chooser_get_current_folder = dl_symbol(
 499             "gtk_file_chooser_get_current_folder");
 500     fp_gtk_file_chooser_get_filenames = dl_symbol(
 501             "gtk_file_chooser_get_filenames");
 502     fp_gtk_g_slist_length = dl_symbol("g_slist_length");
 503 }
 504 
 505 gboolean gtk2_load(JNIEnv *env)
 506 {
 507     gboolean result;
 508     int i;
 509     int (*handler)();
 510     int (*io_handler)();
 511     char *gtk_modules_env;
 512 
 513     gtk2_libhandle = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 514     if (gtk2_libhandle == NULL) {
 515         gtk2_libhandle = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
 516         if (gtk2_libhandle == NULL)
 517             return FALSE;
 518     }
 519 
 520     gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 521     if (gthread_libhandle == NULL) {
 522         gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL);
 523         if (gthread_libhandle == NULL)
 524             return FALSE;
 525     }


 793                 }
 794             }
 795             putenv (new_env);
 796             free (new_env);
 797             free (tmp_env);
 798         }
 799     }
 800 
 801     /*
 802      * GTK should be initialized with gtk_init_check() before use.
 803      *
 804      * gtk_init_check installs its own error handlers. It is critical that
 805      * we preserve error handler set from AWT. Otherwise we'll crash on
 806      * BadMatch errors which we would normally ignore. The IO error handler
 807      * is preserved here, too, just for consistency.
 808     */
 809     handler = XSetErrorHandler(NULL);
 810     io_handler = XSetIOErrorHandler(NULL);
 811 
 812     if (fp_gtk_check_version(2, 2, 0) == NULL) {
 813         jclass class = (*env)->FindClass(env, "sun/misc/GThreadHelper");
 814         jmethodID mid_isInitializationNeeded = (*env)->GetStaticMethodID(env, class, "isInitializationNeeded", "()Z");
 815         jmethodID mid_lock = (*env)->GetStaticMethodID(env, class, "lock", "()V");
 816         jmethodID mid_unlock = (*env)->GetStaticMethodID(env, class, "unlock", "()V");
 817         jmethodID mid_initFinished = (*env)->GetStaticMethodID(env, class, "initFinished", "()V");
 818 
 819         // Init the thread system to use GLib in a thread-safe mode
 820         (*env)->CallStaticVoidMethod(env, class, mid_lock);
 821         if ((*env)->CallStaticBooleanMethod(env, class, mid_isInitializationNeeded)) {
 822             fp_g_thread_init(NULL);
 823 
 824             //According the GTK documentation, gdk_threads_init() should be
 825             //called before gtk_init() or gtk_init_check()
 826             fp_gdk_threads_init();
 827             (*env)->CallStaticVoidMethod(env, class, mid_initFinished);
 828         }
 829         (*env)->CallStaticVoidMethod(env, class, mid_unlock);
 830     }
 831     result = (*fp_gtk_init_check)(NULL, NULL);
 832 
 833     XSetErrorHandler(handler);
 834     XSetIOErrorHandler(io_handler);
 835 
 836     /* Initialize widget array. */
 837     for (i = 0; i < _GTK_WIDGET_TYPE_SIZE; i++)
 838     {
 839         gtk2_widgets[i] = NULL;
 840     }
 841 
 842     return result;
 843 }
 844 
 845 int gtk2_unload()
 846 {
 847     int i;
 848     char *gtk2_error;
 849