< prev index next >

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

Print this page




  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
  23  * questions.
  24  */
  25 #include <dlfcn.h>
  26 #include <setjmp.h>
  27 #include <X11/Xlib.h>
  28 #include <limits.h>
  29 #include <stdio.h>
  30 #include <string.h>
  31 #include "gtk2_interface.h"
  32 #include "java_awt_Transparency.h"
  33 #include "jvm_md.h"
  34 #include "sizecalc.h"
  35 #include <jni_util.h>
  36 #include "awt.h"
  37 
  38 #define GTK2_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0")
  39 #define GTK2_LIB JNI_LIB_NAME("gtk-x11-2.0")
  40 #define GTHREAD_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("gthread-2.0", "0")
  41 #define GTHREAD_LIB JNI_LIB_NAME("gthread-2.0")
  42 
  43 #define G_TYPE_INVALID                  G_TYPE_MAKE_FUNDAMENTAL (0)
  44 #define G_TYPE_NONE                     G_TYPE_MAKE_FUNDAMENTAL (1)
  45 #define G_TYPE_INTERFACE                G_TYPE_MAKE_FUNDAMENTAL (2)
  46 #define G_TYPE_CHAR                     G_TYPE_MAKE_FUNDAMENTAL (3)
  47 #define G_TYPE_UCHAR                    G_TYPE_MAKE_FUNDAMENTAL (4)
  48 #define G_TYPE_BOOLEAN                  G_TYPE_MAKE_FUNDAMENTAL (5)
  49 #define G_TYPE_INT                      G_TYPE_MAKE_FUNDAMENTAL (6)
  50 #define G_TYPE_UINT                     G_TYPE_MAKE_FUNDAMENTAL (7)
  51 #define G_TYPE_LONG                     G_TYPE_MAKE_FUNDAMENTAL (8)
  52 #define G_TYPE_ULONG                    G_TYPE_MAKE_FUNDAMENTAL (9)
  53 #define G_TYPE_INT64                    G_TYPE_MAKE_FUNDAMENTAL (10)
  54 #define G_TYPE_UINT64                   G_TYPE_MAKE_FUNDAMENTAL (11)
  55 #define G_TYPE_ENUM                     G_TYPE_MAKE_FUNDAMENTAL (12)
  56 #define G_TYPE_FLAGS                    G_TYPE_MAKE_FUNDAMENTAL (13)
  57 #define G_TYPE_FLOAT                    G_TYPE_MAKE_FUNDAMENTAL (14)
  58 #define G_TYPE_DOUBLE                   G_TYPE_MAKE_FUNDAMENTAL (15)
  59 #define G_TYPE_STRING                   G_TYPE_MAKE_FUNDAMENTAL (16)
  60 #define G_TYPE_POINTER                  G_TYPE_MAKE_FUNDAMENTAL (17)
  61 #define G_TYPE_BOXED                    G_TYPE_MAKE_FUNDAMENTAL (18)
  62 #define G_TYPE_PARAM                    G_TYPE_MAKE_FUNDAMENTAL (19)
  63 #define G_TYPE_OBJECT                   G_TYPE_MAKE_FUNDAMENTAL (20)
  64 
  65 #define GTK_TYPE_BORDER                 ((*fp_gtk_border_get_type)())
  66 
  67 #define G_TYPE_FUNDAMENTAL_SHIFT        (2)
  68 #define G_TYPE_MAKE_FUNDAMENTAL(x)      ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
  69 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
  70 
  71 #define CONV_BUFFER_SIZE 128
  72 
  73 #define NO_SYMBOL_EXCEPTION 1
  74 
  75 /* SynthConstants */
  76 const gint ENABLED    = 1 << 0;
  77 const gint MOUSE_OVER = 1 << 1;
  78 const gint PRESSED    = 1 << 2;
  79 const gint DISABLED   = 1 << 3;
  80 const gint FOCUSED    = 1 << 8;
  81 const gint SELECTED   = 1 << 9;
  82 const gint DEFAULT    = 1 << 10;
  83 
  84 static void *gtk2_libhandle = NULL;
  85 static void *gthread_libhandle = NULL;
  86 
  87 static jmp_buf j;
  88 
  89 /* Widgets */
  90 static GtkWidget *gtk2_widget = NULL;
  91 static GtkWidget *gtk2_window = NULL;
  92 static GtkFixed  *gtk2_fixed  = NULL;
  93 
  94 /* Paint system */
  95 static GdkPixmap *gtk2_white_pixmap = NULL;
  96 static GdkPixmap *gtk2_black_pixmap = NULL;
  97 static GdkPixbuf *gtk2_white_pixbuf = NULL;
  98 static GdkPixbuf *gtk2_black_pixbuf = NULL;
  99 static int gtk2_pixbuf_width = 0;
 100 static int gtk2_pixbuf_height = 0;
 101 
 102 /* Static buffer for conversion from java.lang.String to UTF-8 */
 103 static char convertionBuffer[CONV_BUFFER_SIZE];
 104 
 105 static gboolean new_combo = TRUE;
 106 const char ENV_PREFIX[] = "GTK_MODULES=";
 107 
 108 /*******************/
 109 enum GtkWidgetType
 110 {
 111     _GTK_ARROW_TYPE,
 112     _GTK_BUTTON_TYPE,
 113     _GTK_CHECK_BUTTON_TYPE,
 114     _GTK_CHECK_MENU_ITEM_TYPE,
 115     _GTK_COLOR_SELECTION_DIALOG_TYPE,
 116     _GTK_COMBO_BOX_TYPE,
 117     _GTK_COMBO_BOX_ARROW_BUTTON_TYPE,
 118     _GTK_COMBO_BOX_TEXT_FIELD_TYPE,
 119     _GTK_CONTAINER_TYPE,
 120     _GTK_ENTRY_TYPE,
 121     _GTK_FRAME_TYPE,
 122     _GTK_HANDLE_BOX_TYPE,
 123     _GTK_HPANED_TYPE,
 124     _GTK_HPROGRESS_BAR_TYPE,
 125     _GTK_HSCALE_TYPE,
 126     _GTK_HSCROLLBAR_TYPE,
 127     _GTK_HSEPARATOR_TYPE,
 128     _GTK_IMAGE_TYPE,
 129     _GTK_MENU_TYPE,
 130     _GTK_MENU_BAR_TYPE,
 131     _GTK_MENU_ITEM_TYPE,
 132     _GTK_NOTEBOOK_TYPE,
 133     _GTK_LABEL_TYPE,
 134     _GTK_RADIO_BUTTON_TYPE,
 135     _GTK_RADIO_MENU_ITEM_TYPE,
 136     _GTK_SCROLLED_WINDOW_TYPE,
 137     _GTK_SEPARATOR_MENU_ITEM_TYPE,
 138     _GTK_SEPARATOR_TOOL_ITEM_TYPE,
 139     _GTK_SPIN_BUTTON_TYPE,
 140     _GTK_TEXT_VIEW_TYPE,
 141     _GTK_TOGGLE_BUTTON_TYPE,
 142     _GTK_TOOLBAR_TYPE,
 143     _GTK_TOOLTIP_TYPE,
 144     _GTK_TREE_VIEW_TYPE,
 145     _GTK_VIEWPORT_TYPE,
 146     _GTK_VPANED_TYPE,
 147     _GTK_VPROGRESS_BAR_TYPE,
 148     _GTK_VSCALE_TYPE,
 149     _GTK_VSCROLLBAR_TYPE,
 150     _GTK_VSEPARATOR_TYPE,
 151     _GTK_WINDOW_TYPE,
 152     _GTK_DIALOG_TYPE,
 153     _GTK_WIDGET_TYPE_SIZE
 154 };
 155 
 156 
 157 static GtkWidget *gtk2_widgets[_GTK_WIDGET_TYPE_SIZE];
 158 
 159 /*************************
 160  * Glib function pointers
 161  *************************/
 162 
 163 static gboolean (*fp_g_main_context_iteration)(GMainContext *context,
 164                                              gboolean may_block);
 165 
 166 static GValue*      (*fp_g_value_init)(GValue *value, GType g_type);
 167 static gboolean     (*fp_g_type_is_a)(GType type, GType is_a_type);
 168 static gboolean     (*fp_g_value_get_boolean)(const GValue *value);
 169 static gchar        (*fp_g_value_get_char)(const GValue *value);
 170 static guchar       (*fp_g_value_get_uchar)(const GValue *value);
 171 static gint         (*fp_g_value_get_int)(const GValue *value);
 172 static guint        (*fp_g_value_get_uint)(const GValue *value);
 173 static glong        (*fp_g_value_get_long)(const GValue *value);
 174 static gulong       (*fp_g_value_get_ulong)(const GValue *value);
 175 static gint64       (*fp_g_value_get_int64)(const GValue *value);
 176 static guint64      (*fp_g_value_get_uint64)(const GValue *value);


 345         const gchar *first_property_name, ...);
 346 static void (*fp_gtk_widget_class_install_style_property)(
 347         GtkWidgetClass* class, GParamSpec *pspec);
 348 static GParamSpec* (*fp_gtk_widget_class_find_style_property)(
 349         GtkWidgetClass* class, const gchar* property_name);
 350 static void (*fp_gtk_widget_style_get_property)(GtkWidget* widget,
 351         const gchar* property_name, GValue* value);
 352 static char* (*fp_pango_font_description_to_string)(
 353         const PangoFontDescription* fd);
 354 static GtkSettings* (*fp_gtk_settings_get_default)();
 355 static GtkSettings* (*fp_gtk_widget_get_settings)(GtkWidget *widget);
 356 static GType        (*fp_gtk_border_get_type)();
 357 static void (*fp_gtk_arrow_set)(GtkWidget* arrow,
 358                                 GtkArrowType arrow_type,
 359                                 GtkShadowType shadow_type);
 360 static void (*fp_gtk_widget_size_request)(GtkWidget *widget,
 361                                           GtkRequisition *requisition);
 362 static GtkAdjustment* (*fp_gtk_range_get_adjustment)(GtkRange* range);
 363 
 364 /* Method bodies */
 365 const char *getStrFor(JNIEnv *env, jstring val)
 366 {
 367     int length = (*env)->GetStringLength(env, val);
 368     if (length > CONV_BUFFER_SIZE-1)
 369     {
 370         length = CONV_BUFFER_SIZE-1;
 371 #ifdef INTERNAL_BUILD
 372         fprintf(stderr, "Note: Detail is too long: %d chars\n", length);
 373 #endif /* INTERNAL_BUILD */
 374     }
 375 
 376     (*env)->GetStringUTFRegion(env, val, 0, length, convertionBuffer);
 377     return convertionBuffer;
 378 }
 379 
 380 static void throw_exception(JNIEnv *env, const char* name, const char* message)
 381 {
 382     jclass class = (*env)->FindClass(env, name);
 383 
 384     if (class != NULL)
 385         (*env)->ThrowNew(env, class, message);
 386 
 387     (*env)->DeleteLocalRef(env, class);
 388 }
 389 
 390 /* This is a workaround for the bug:
 391  * http://sourceware.org/bugzilla/show_bug.cgi?id=1814
 392  * (dlsym/dlopen clears dlerror state)
 393  * This bug is specific to Linux, but there is no harm in
 394  * applying this workaround on Solaris as well.
 395  */
 396 static void* dl_symbol(const char* name)
 397 {
 398     void* result = dlsym(gtk2_libhandle, name);
 399     if (!result)
 400         longjmp(j, NO_SYMBOL_EXCEPTION);
 401 
 402     return result;
 403 }
 404 
 405 static void* dl_symbol_gthread(const char* name)
 406 {
 407     void* result = dlsym(gthread_libhandle, name);
 408     if (!result)
 409         longjmp(j, NO_SYMBOL_EXCEPTION);
 410 
 411     return result;
 412 }
 413 
 414 gboolean gtk2_check_version()
 415 {
 416     if (gtk2_libhandle != NULL) {
 417         /* We've already successfully opened the GTK libs, so return true. */
 418         return TRUE;
 419     } else {
 420         void *lib = NULL;
 421         gboolean result = FALSE;














 422 
 423         lib = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 424         if (lib == NULL) {
 425             lib = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
 426             if (lib == NULL) {
 427                 return FALSE;
 428             }
 429         }
 430 
 431         fp_gtk_check_version = dlsym(lib, "gtk_check_version");
 432         /* Check for GTK 2.2+ */
 433         if (!fp_gtk_check_version(2, 2, 0)) {
 434             result = TRUE;
 435         }
 436 
 437         // 8048289: workaround for https://bugzilla.gnome.org/show_bug.cgi?id=733065
 438         // dlclose(lib);
 439 
 440         return result;
 441     }
 442 }
 443 
 444 #define ADD_SUPPORTED_ACTION(actionStr) \
 445 do { \
 446     jfieldID fld_action = (*env)->GetStaticFieldID(env, cls_action, actionStr, "Ljava/awt/Desktop$Action;"); \
 447     if (!(*env)->ExceptionCheck(env)) { \
 448         jobject action = (*env)->GetStaticObjectField(env, cls_action, fld_action); \
 449         (*env)->CallBooleanMethod(env, supportedActions, mid_arrayListAdd, action); \
 450     } else { \
 451         (*env)->ExceptionClear(env); \
 452     } \
 453 } while(0);
 454 
 455 
 456 void update_supported_actions(JNIEnv *env) {
 457     GVfs * (*fp_g_vfs_get_default) (void);
 458     const gchar * const * (*fp_g_vfs_get_supported_uri_schemes) (GVfs * vfs);
 459     const gchar * const * schemes = NULL;
 460 
 461     jclass cls_action = (*env)->FindClass(env, "java/awt/Desktop$Action");
 462     CHECK_NULL(cls_action);
 463     jclass cls_xDesktopPeer = (*env)->FindClass(env, "sun/awt/X11/XDesktopPeer");
 464     CHECK_NULL(cls_xDesktopPeer);
 465     jfieldID fld_supportedActions = (*env)->GetStaticFieldID(env, cls_xDesktopPeer, "supportedActions", "Ljava/util/List;");
 466     CHECK_NULL(fld_supportedActions);
 467     jobject supportedActions = (*env)->GetStaticObjectField(env, cls_xDesktopPeer, fld_supportedActions);
 468 
 469     jclass cls_arrayList = (*env)->FindClass(env, "java/util/ArrayList");
 470     CHECK_NULL(cls_arrayList);
 471     jmethodID mid_arrayListAdd = (*env)->GetMethodID(env, cls_arrayList, "add", "(Ljava/lang/Object;)Z");
 472     CHECK_NULL(mid_arrayListAdd);
 473     jmethodID mid_arrayListClear = (*env)->GetMethodID(env, cls_arrayList, "clear", "()V");
 474     CHECK_NULL(mid_arrayListClear);
 475 
 476     (*env)->CallVoidMethod(env, supportedActions, mid_arrayListClear);


 499             int i = 0;
 500             while (schemes[i]) {
 501                 if (strcmp(schemes[i], "http") == 0) {
 502                     ADD_SUPPORTED_ACTION("BROWSE");
 503                     ADD_SUPPORTED_ACTION("MAIL");
 504                     break;
 505                 }
 506                 i++;
 507             }
 508         }
 509     } else {
 510 #ifdef INTERNAL_BUILD
 511         fprintf(stderr, "Cannot load g_vfs_get_supported_uri_schemes\n");
 512 #endif /* INTERNAL_BUILD */
 513     }
 514 
 515 }
 516 /**
 517  * Functions for awt_Desktop.c
 518  */
 519 gboolean gtk2_show_uri_load(JNIEnv *env) {
 520      gboolean success = FALSE;
 521      dlerror();
 522      const char *gtk_version = fp_gtk_check_version(2, 14, 0);
 523      if (gtk_version != NULL) {
 524          // The gtk_show_uri is available from GTK+ 2.14
 525 #ifdef INTERNAL_BUILD
 526          fprintf (stderr, "The version of GTK is %s. "
 527              "The gtk_show_uri function is supported "
 528              "since GTK+ 2.14.\n", gtk_version);
 529 #endif /* INTERNAL_BUILD */
 530      } else {
 531          // Loading symbols only if the GTK version is 2.14 and higher
 532          fp_gtk_show_uri = dl_symbol("gtk_show_uri");
 533          const char *dlsym_error = dlerror();
 534          if (dlsym_error) {
 535 #ifdef INTERNAL_BUILD
 536              fprintf (stderr, "Cannot load symbol: %s \n", dlsym_error);
 537 #endif /* INTERNAL_BUILD */
 538          } else if (fp_gtk_show_uri == NULL) {
 539 #ifdef INTERNAL_BUILD
 540              fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n");
 541 #endif /* INTERNAL_BUILD */
 542         } else {

 543             update_supported_actions(env);
 544             success = TRUE;
 545         }
 546      }
 547      return success;
 548 }
 549 
 550 /**
 551  * Functions for sun_awt_X11_GtkFileDialogPeer.c
 552  */
 553 void gtk2_file_chooser_load()
 554 {
 555     fp_gtk_file_chooser_get_filename = dl_symbol(
 556             "gtk_file_chooser_get_filename");
 557     fp_gtk_file_chooser_dialog_new = dl_symbol("gtk_file_chooser_dialog_new");
 558     fp_gtk_file_chooser_set_current_folder = dl_symbol(
 559             "gtk_file_chooser_set_current_folder");
 560     fp_gtk_file_chooser_set_filename = dl_symbol(
 561             "gtk_file_chooser_set_filename");
 562     fp_gtk_file_chooser_set_current_name = dl_symbol(
 563             "gtk_file_chooser_set_current_name");
 564     fp_gtk_file_filter_add_custom = dl_symbol("gtk_file_filter_add_custom");
 565     fp_gtk_file_chooser_set_filter = dl_symbol("gtk_file_chooser_set_filter");
 566     fp_gtk_file_chooser_get_type = dl_symbol("gtk_file_chooser_get_type");
 567     fp_gtk_file_filter_new = dl_symbol("gtk_file_filter_new");
 568     if (fp_gtk_check_version(2, 8, 0) == NULL) {
 569         fp_gtk_file_chooser_set_do_overwrite_confirmation = dl_symbol(
 570                 "gtk_file_chooser_set_do_overwrite_confirmation");
 571     }
 572     fp_gtk_file_chooser_set_select_multiple = dl_symbol(
 573             "gtk_file_chooser_set_select_multiple");
 574     fp_gtk_file_chooser_get_current_folder = dl_symbol(
 575             "gtk_file_chooser_get_current_folder");
 576     fp_gtk_file_chooser_get_filenames = dl_symbol(
 577             "gtk_file_chooser_get_filenames");
 578     fp_gtk_g_slist_length = dl_symbol("g_slist_length");
 579 }
 580 
 581 gboolean gtk2_load(JNIEnv *env)
 582 {
 583     gboolean result;
 584     int i;
 585     int (*handler)();
 586     int (*io_handler)();
 587     char *gtk_modules_env;
 588 
 589     gtk2_libhandle = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 590     if (gtk2_libhandle == NULL) {
 591         gtk2_libhandle = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
 592         if (gtk2_libhandle == NULL)
 593             return FALSE;
 594     }
 595 
 596     gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 597     if (gthread_libhandle == NULL) {
 598         gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL);
 599         if (gthread_libhandle == NULL)
 600             return FALSE;
 601     }
 602 
 603     if (setjmp(j) == 0)
 604     {
 605         fp_gtk_check_version = dl_symbol("gtk_check_version");
 606         /* Check for GTK 2.2+ */
 607         if (fp_gtk_check_version(2, 2, 0)) {
 608             longjmp(j, NO_SYMBOL_EXCEPTION);
 609         }
 610 
 611         /* GLib */
 612         fp_glib_check_version = dlsym(gtk2_libhandle, "glib_check_version");


 914             }
 915 
 916             //According the GTK documentation, gdk_threads_init() should be
 917             //called before gtk_init() or gtk_init_check()
 918             fp_gdk_threads_init();
 919         }
 920         (*env)->CallStaticVoidMethod(env, clazz, mid_unlock);
 921     }
 922     result = (*fp_gtk_init_check)(NULL, NULL);
 923 
 924     XSetErrorHandler(handler);
 925     XSetIOErrorHandler(io_handler);
 926     AWT_UNLOCK();
 927 
 928     /* Initialize widget array. */
 929     for (i = 0; i < _GTK_WIDGET_TYPE_SIZE; i++)
 930     {
 931         gtk2_widgets[i] = NULL;
 932     }
 933 
 934     return result;






 935 }
 936 
 937 int gtk2_unload()
 938 {
 939     int i;
 940     char *gtk2_error;
 941 
 942     if (!gtk2_libhandle)
 943         return TRUE;
 944 
 945     /* Release painting objects */
 946     if (gtk2_white_pixmap != NULL) {
 947         (*fp_g_object_unref)(gtk2_white_pixmap);
 948         (*fp_g_object_unref)(gtk2_black_pixmap);
 949         (*fp_g_object_unref)(gtk2_white_pixbuf);
 950         (*fp_g_object_unref)(gtk2_black_pixbuf);
 951         gtk2_white_pixmap = gtk2_black_pixmap =
 952             gtk2_white_pixbuf = gtk2_black_pixbuf = NULL;
 953     }
 954     gtk2_pixbuf_width = 0;


 958         /* Destroying toplevel widget will destroy all contained widgets */
 959         (*fp_gtk_widget_destroy)(gtk2_window);
 960 
 961         /* Unset some static data so they get reinitialized on next load */
 962         gtk2_window = NULL;
 963     }
 964 
 965     dlerror();
 966     dlclose(gtk2_libhandle);
 967     dlclose(gthread_libhandle);
 968     if ((gtk2_error = dlerror()) != NULL)
 969     {
 970         return FALSE;
 971     }
 972     return TRUE;
 973 }
 974 
 975 /* Dispatch all pending events from the GTK event loop.
 976  * This is needed to catch theme change and update widgets' style.
 977  */
 978 void flush_gtk_event_loop()
 979 {
 980     while( (*fp_g_main_context_iteration)(NULL, FALSE));
 981 }
 982 
 983 /*
 984  * Initialize components of containment hierarchy. This creates a GtkFixed
 985  * inside a GtkWindow. All widgets get realized.
 986  */
 987 static void init_containers()
 988 {
 989     if (gtk2_window == NULL)
 990     {
 991         gtk2_window = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
 992         gtk2_fixed = (GtkFixed *)(*fp_gtk_fixed_new)();
 993         (*fp_gtk_container_add)((GtkContainer*)gtk2_window,
 994                                 (GtkWidget *)gtk2_fixed);
 995         (*fp_gtk_widget_realize)(gtk2_window);
 996         (*fp_gtk_widget_realize)((GtkWidget *)gtk2_fixed);
 997     }
 998 }


1007  * work around this:
1008  * 1) Subclass GdkPixmap and cache translucent objects on client side. This
1009  * requires us to implement parts of X server drawing logic on client side.
1010  * Many X requests can potentially be "translucent"; e.g. XDrawLine with
1011  * fill=tile and a translucent tile is a "translucent" operation, whereas
1012  * XDrawLine with fill=solid is an "opaque" one. Moreover themes can (and some
1013  * do) intermix transparent and opaque operations which makes caching even
1014  * more problematic.
1015  * 2) Use Xorg 32bit ARGB visual when available. GDK has no native support
1016  * for it (as of version 2.6). Also even in JDS 3 Xorg does not support
1017  * these visuals by default, which makes optimizing for them pointless.
1018  * We can consider doing this at a later point when ARGB visuals become more
1019  * popular.
1020  * 3') GTK has plans to use Cairo as its graphical backend (presumably in
1021  * 2.8), and Cairo supports alpha. With it we could also get rid of the
1022  * unnecessary round trip to server and do all the drawing on client side.
1023  * 4) For now we draw to two different pixmaps and restore alpha channel by
1024  * comparing results. This can be optimized by using subclassed pixmap and
1025  * doing the second drawing only if necessary.
1026 */
1027 void gtk2_init_painting(JNIEnv *env, gint width, gint height)
1028 {
1029     GdkGC *gc;
1030     GdkPixbuf *white, *black;
1031 
1032     init_containers();
1033 
1034     if (gtk2_pixbuf_width < width || gtk2_pixbuf_height < height)
1035     {
1036         white = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
1037         black = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
1038 
1039         if (white == NULL || black == NULL)
1040         {
1041             snprintf(convertionBuffer, CONV_BUFFER_SIZE, "Couldn't create pixbuf of size %dx%d", width, height);
1042             throw_exception(env, "java/lang/RuntimeException", convertionBuffer);
1043             fp_gdk_threads_leave();
1044             return;
1045         }
1046 
1047         if (gtk2_white_pixmap != NULL) {


1067     (*fp_gdk_rgb_gc_set_foreground)(gc, 0xffffff);
1068     (*fp_gdk_draw_rectangle)(gtk2_white_pixmap, gc, TRUE, 0, 0, width, height);
1069     (*fp_g_object_unref)(gc);
1070 
1071     gc = (*fp_gdk_gc_new)(gtk2_black_pixmap);
1072     (*fp_gdk_rgb_gc_set_foreground)(gc, 0x000000);
1073     (*fp_gdk_draw_rectangle)(gtk2_black_pixmap, gc, TRUE, 0, 0, width, height);
1074     (*fp_g_object_unref)(gc);
1075 }
1076 
1077 /*
1078  * Restore image from white and black pixmaps and copy it into destination
1079  * buffer. This method compares two pixbufs taken from white and black
1080  * pixmaps and decodes color and alpha components. Pixbufs are RGB without
1081  * alpha, destination buffer is ABGR.
1082  *
1083  * The return value is the transparency type of the resulting image, either
1084  * one of java_awt_Transparency_OPAQUE, java_awt_Transparency_BITMASK, and
1085  * java_awt_Transparency_TRANSLUCENT.
1086  */
1087 gint gtk2_copy_image(gint *dst, gint width, gint height)
1088 {
1089     gint i, j, r, g, b;
1090     guchar *white, *black;
1091     gint stride, padding;
1092     gboolean is_opaque = TRUE;
1093     gboolean is_bitmask = TRUE;
1094 
1095     (*fp_gdk_pixbuf_get_from_drawable)(gtk2_white_pixbuf, gtk2_white_pixmap,
1096             NULL, 0, 0, 0, 0, width, height);
1097     (*fp_gdk_pixbuf_get_from_drawable)(gtk2_black_pixbuf, gtk2_black_pixmap,
1098             NULL, 0, 0, 0, 0, width, height);
1099 
1100     white = (*fp_gdk_pixbuf_get_pixels)(gtk2_white_pixbuf);
1101     black = (*fp_gdk_pixbuf_get_pixels)(gtk2_black_pixbuf);
1102     stride = (*fp_gdk_pixbuf_get_rowstride)(gtk2_black_pixbuf);
1103     padding = stride - width * 4;
1104 
1105     for (i = 0; i < height; i++) {
1106         for (j = 0; j < width; j++) {
1107             int r1 = *white++;


1729             h = size.height - ((GtkMisc*)gtk2_widget)->ypad * 2;
1730             w = h = MIN(MIN(w, h), MIN(width,height)) * 0.7;
1731             break;
1732 
1733         default:
1734             w = width;
1735             h = height;
1736             break;
1737     }
1738     x += (width - w) / 2;
1739     y += (height - h) / 2;
1740 
1741     (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1742             shadow_type, NULL, gtk2_widget, detail, arrow_type, fill,
1743             x, y, w, h);
1744     (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1745             shadow_type, NULL, gtk2_widget, detail, arrow_type, fill,
1746             x, y, w, h);
1747 }
1748 
1749 void gtk2_paint_box(WidgetType widget_type, GtkStateType state_type,
1750                     GtkShadowType shadow_type, const gchar *detail,
1751                     gint x, gint y, gint width, gint height,
1752                     gint synth_state, GtkTextDirection dir)
1753 {
1754     gtk2_widget = gtk2_get_widget(widget_type);
1755 
1756     /*
1757      * The clearlooks engine sometimes looks at the widget's state field
1758      * instead of just the state_type variable that we pass in, so to account
1759      * for those cases we set the widget's state field accordingly.  The
1760      * flags field is similarly important for things like focus/default state.
1761      */
1762     gtk2_widget->state = state_type;
1763 
1764     if (widget_type == HSLIDER_TRACK) {
1765         /*
1766          * For horizontal JSliders with right-to-left orientation, we need
1767          * to set the "inverted" flag to match the native GTK behavior where
1768          * the foreground highlight is on the right side of the slider thumb.
1769          * This is needed especially for the ubuntulooks engine, which looks


1899     gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR);
1900 }
1901 
1902 void gtk2_paint_box_gap(WidgetType widget_type, GtkStateType state_type,
1903         GtkShadowType shadow_type, const gchar *detail,
1904         gint x, gint y, gint width, gint height,
1905         GtkPositionType gap_side, gint gap_x, gint gap_width)
1906 {
1907     /* Clearlooks needs a real clip area to paint the gap properly */
1908     GdkRectangle area = { x, y, width, height };
1909 
1910     gtk2_widget = gtk2_get_widget(widget_type);
1911     (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1912             shadow_type, &area, gtk2_widget, detail,
1913             x, y, width, height, gap_side, gap_x, gap_width);
1914     (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1915             shadow_type, &area, gtk2_widget, detail,
1916             x, y, width, height, gap_side, gap_x, gap_width);
1917 }
1918 
1919 void gtk2_paint_check(WidgetType widget_type, gint synth_state,
1920         const gchar *detail, gint x, gint y, gint width, gint height)
1921 {
1922     GtkStateType state_type = get_gtk_state_type(widget_type, synth_state);
1923     GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state);
1924 
1925     gtk2_widget = gtk2_get_widget(widget_type);
1926     init_toggle_widget(widget_type, synth_state);
1927 
1928     (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1929             shadow_type, NULL, gtk2_widget, detail,
1930             x, y, width, height);
1931     (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1932             shadow_type, NULL, gtk2_widget, detail,
1933             x, y, width, height);
1934 }
1935 
1936 void gtk2_paint_diamond(WidgetType widget_type, GtkStateType state_type,
1937         GtkShadowType shadow_type, const gchar *detail,
1938         gint x, gint y, gint width, gint height)
1939 {
1940     gtk2_widget = gtk2_get_widget(widget_type);
1941     (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1942             shadow_type, NULL, gtk2_widget, detail,
1943             x, y, width, height);
1944     (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1945             shadow_type, NULL, gtk2_widget, detail,
1946             x, y, width, height);
1947 }
1948 
1949 void gtk2_paint_expander(WidgetType widget_type, GtkStateType state_type,
1950         const gchar *detail, gint x, gint y, gint width, gint height,
1951         GtkExpanderStyle expander_style)
1952 {
1953     gtk2_widget = gtk2_get_widget(widget_type);
1954     (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_white_pixmap,
1955             state_type, NULL, gtk2_widget, detail,
1956             x + width / 2, y + height / 2, expander_style);
1957     (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_black_pixmap,
1958             state_type, NULL, gtk2_widget, detail,
1959             x + width / 2, y + height / 2, expander_style);
1960 }
1961 
1962 void gtk2_paint_extension(WidgetType widget_type, GtkStateType state_type,
1963         GtkShadowType shadow_type, const gchar *detail,
1964         gint x, gint y, gint width, gint height, GtkPositionType gap_side)
1965 {
1966     gtk2_widget = gtk2_get_widget(widget_type);
1967     (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_white_pixmap,
1968             state_type, shadow_type, NULL, gtk2_widget, detail,
1969             x, y, width, height, gap_side);
1970     (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_black_pixmap,
1971             state_type, shadow_type, NULL, gtk2_widget, detail,
1972             x, y, width, height, gap_side);
1973 }
1974 
1975 void gtk2_paint_flat_box(WidgetType widget_type, GtkStateType state_type,
1976         GtkShadowType shadow_type, const gchar *detail,
1977         gint x, gint y, gint width, gint height, gboolean has_focus)
1978 {
1979     gtk2_widget = gtk2_get_widget(widget_type);
1980 
1981     if (has_focus)
1982         ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS;
1983     else
1984         ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
1985 
1986     (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_white_pixmap,
1987             state_type, shadow_type, NULL, gtk2_widget, detail,
1988             x, y, width, height);
1989     (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_black_pixmap,
1990             state_type, shadow_type, NULL, gtk2_widget, detail,
1991             x, y, width, height);
1992 }
1993 
1994 void gtk2_paint_focus(WidgetType widget_type, GtkStateType state_type,
1995         const char *detail, gint x, gint y, gint width, gint height)
1996 {
1997     gtk2_widget = gtk2_get_widget(widget_type);
1998     (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1999             NULL, gtk2_widget, detail, x, y, width, height);
2000     (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2001             NULL, gtk2_widget, detail, x, y, width, height);
2002 }
2003 
2004 void gtk2_paint_handle(WidgetType widget_type, GtkStateType state_type,
2005         GtkShadowType shadow_type, const gchar *detail,
2006         gint x, gint y, gint width, gint height, GtkOrientation orientation)
2007 {
2008     gtk2_widget = gtk2_get_widget(widget_type);
2009     (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2010             shadow_type, NULL, gtk2_widget, detail,
2011             x, y, width, height, orientation);
2012     (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2013             shadow_type, NULL, gtk2_widget, detail,
2014             x, y, width, height, orientation);
2015 }
2016 
2017 void gtk2_paint_hline(WidgetType widget_type, GtkStateType state_type,
2018         const gchar *detail, gint x, gint y, gint width, gint height)
2019 {
2020     gtk2_widget = gtk2_get_widget(widget_type);
2021     (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2022             NULL, gtk2_widget, detail, x, x + width, y);
2023     (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2024             NULL, gtk2_widget, detail, x, x + width, y);
2025 }
2026 
2027 void gtk2_paint_option(WidgetType widget_type, gint synth_state,
2028         const gchar *detail, gint x, gint y, gint width, gint height)
2029 {
2030     GtkStateType state_type = get_gtk_state_type(widget_type, synth_state);
2031     GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state);
2032 
2033     gtk2_widget = gtk2_get_widget(widget_type);
2034     init_toggle_widget(widget_type, synth_state);
2035 
2036     (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2037             shadow_type, NULL, gtk2_widget, detail,
2038             x, y, width, height);
2039     (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2040             shadow_type, NULL, gtk2_widget, detail,
2041             x, y, width, height);
2042 }
2043 
2044 void gtk2_paint_shadow(WidgetType widget_type, GtkStateType state_type,
2045                        GtkShadowType shadow_type, const gchar *detail,
2046                        gint x, gint y, gint width, gint height,
2047                        gint synth_state, GtkTextDirection dir)
2048 {
2049     gtk2_widget = gtk2_get_widget(widget_type);
2050 
2051     /*
2052      * The clearlooks engine sometimes looks at the widget's state field
2053      * instead of just the state_type variable that we pass in, so to account
2054      * for those cases we set the widget's state field accordingly.  The
2055      * flags field is similarly important for things like focus state.
2056      */
2057     gtk2_widget->state = state_type;
2058 
2059     /*
2060      * Some engines (e.g. clearlooks) will paint the shadow of certain
2061      * widgets (e.g. COMBO_BOX_TEXT_FIELD) differently depending on the
2062      * the text direction.
2063      */
2064     gtk2_set_direction(gtk2_widget, dir);


2074         } else {
2075             ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
2076         }
2077         break;
2078     default:
2079         break;
2080     }
2081 
2082     (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2083             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
2084     (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2085             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
2086 
2087     /*
2088      * Reset the text direction to the default value so that we don't
2089      * accidentally affect other operations and widgets.
2090      */
2091     gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR);
2092 }
2093 
2094 void gtk2_paint_slider(WidgetType widget_type, GtkStateType state_type,
2095         GtkShadowType shadow_type, const gchar *detail,
2096         gint x, gint y, gint width, gint height, GtkOrientation orientation)

2097 {
2098     gtk2_widget = gtk2_get_widget(widget_type);
2099     (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2100             shadow_type, NULL, gtk2_widget, detail,
2101             x, y, width, height, orientation);
2102     (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2103             shadow_type, NULL, gtk2_widget, detail,
2104             x, y, width, height, orientation);
2105 }
2106 
2107 void gtk2_paint_vline(WidgetType widget_type, GtkStateType state_type,
2108         const gchar *detail, gint x, gint y, gint width, gint height)
2109 {
2110     gtk2_widget = gtk2_get_widget(widget_type);
2111     (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2112             NULL, gtk2_widget, detail, y, y + height, x);
2113     (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2114             NULL, gtk2_widget, detail, y, y + height, x);
2115 }
2116 
2117 void gtk_paint_background(WidgetType widget_type, GtkStateType state_type,
2118         gint x, gint y, gint width, gint height)
2119 {
2120     gtk2_widget = gtk2_get_widget(widget_type);
2121     (*fp_gtk_style_apply_default_background)(gtk2_widget->style,
2122             gtk2_white_pixmap, TRUE, state_type, NULL, x, y, width, height);
2123     (*fp_gtk_style_apply_default_background)(gtk2_widget->style,
2124             gtk2_black_pixmap, TRUE, state_type, NULL, x, y, width, height);
2125 }
2126 
2127 GdkPixbuf *gtk2_get_stock_icon(gint widget_type, const gchar *stock_id,
2128         GtkIconSize size, GtkTextDirection direction, const char *detail)
2129 {
2130     init_containers();
2131     gtk2_widget = gtk2_get_widget((widget_type < 0) ? IMAGE : widget_type);
2132     gtk2_widget->state = GTK_STATE_NORMAL;
2133     (*fp_gtk_widget_set_direction)(gtk2_widget, direction);
2134     return (*fp_gtk_widget_render_icon)(gtk2_widget, stock_id, size, detail);
2135 }
2136 












































2137 /*************************************************/
2138 gint gtk2_get_xthickness(JNIEnv *env, WidgetType widget_type)
2139 {
2140     init_containers();
2141 
2142     gtk2_widget = gtk2_get_widget(widget_type);
2143     GtkStyle* style = gtk2_widget->style;
2144     return style->xthickness;
2145 }
2146 
2147 gint gtk2_get_ythickness(JNIEnv *env, WidgetType widget_type)
2148 {
2149     init_containers();
2150 
2151     gtk2_widget = gtk2_get_widget(widget_type);
2152     GtkStyle* style = gtk2_widget->style;
2153     return style->ythickness;
2154 }
2155 
2156 /*************************************************/
2157 guint8 recode_color(guint16 channel)
2158 {
2159     return (guint8)(channel>>8);
2160 }
2161 
2162 gint gtk2_get_color_for_state(JNIEnv *env, WidgetType widget_type,
2163                               GtkStateType state_type, ColorType color_type)
2164 {
2165     gint result = 0;
2166     GdkColor *color = NULL;
2167 
2168     init_containers();
2169 
2170     gtk2_widget = gtk2_get_widget(widget_type);
2171     GtkStyle* style = gtk2_widget->style;
2172 
2173     switch (color_type)
2174     {
2175         case FOREGROUND:
2176             color = &(style->fg[state_type]);
2177             break;
2178         case BACKGROUND:
2179             color = &(style->bg[state_type]);
2180             break;
2181         case TEXT_FOREGROUND:
2182             color = &(style->text[state_type]);


2194             color = &(style->mid[state_type]);
2195             break;
2196         case FOCUS:
2197         case BLACK:
2198             color = &(style->black);
2199             break;
2200         case WHITE:
2201             color = &(style->white);
2202             break;
2203     }
2204 
2205     if (color)
2206         result = recode_color(color->red)   << 16 |
2207                  recode_color(color->green) << 8  |
2208                  recode_color(color->blue);
2209 
2210     return result;
2211 }
2212 
2213 /*************************************************/
2214 jobject create_Boolean(JNIEnv *env, jboolean boolean_value);
2215 jobject create_Integer(JNIEnv *env, jint int_value);
2216 jobject create_Long(JNIEnv *env, jlong long_value);
2217 jobject create_Float(JNIEnv *env, jfloat float_value);
2218 jobject create_Double(JNIEnv *env, jdouble double_value);
2219 jobject create_Character(JNIEnv *env, jchar char_value);
2220 jobject create_Insets(JNIEnv *env, GtkBorder *border);
2221 
2222 jobject gtk2_get_class_value(JNIEnv *env, WidgetType widget_type, jstring jkey)

2223 {
2224     init_containers();
2225 
2226     const char* key = getStrFor(env, jkey);
2227     gtk2_widget = gtk2_get_widget(widget_type);
2228 
2229     GValue value;
2230     value.g_type = 0;
2231 
2232     GParamSpec* param = (*fp_gtk_widget_class_find_style_property)(
2233                                     ((GTypeInstance*)gtk2_widget)->g_class, key);
2234     if( param )
2235     {
2236         (*fp_g_value_init)( &value, param->value_type );
2237         (*fp_gtk_widget_style_get_property)(gtk2_widget, key, &value);
2238 
2239         if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOOLEAN ))
2240         {
2241             gboolean val = (*fp_g_value_get_boolean)(&value);
2242             return create_Boolean(env, (jboolean)val);
2243         }
2244         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_CHAR ))
2245         {
2246             gchar val = (*fp_g_value_get_char)(&value);


2327         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOXED ))
2328         {
2329             gpointer* val = (*fp_g_value_get_boxed)(&value);
2330             printf( "Boxed: %p\n", val );
2331         }
2332         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_POINTER ))
2333         {
2334             gpointer* val = (*fp_g_value_get_pointer)(&value);
2335             printf( "Pointer: %p\n", val );
2336         }
2337         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_OBJECT ))
2338         {
2339             GObject* val = (GObject*)(*fp_g_value_get_object)(&value);
2340             printf( "Object: %p\n", val );
2341         }*/
2342     }
2343 
2344     return NULL;
2345 }
2346 
2347 void gtk2_set_range_value(WidgetType widget_type, jdouble value,
2348                           jdouble min, jdouble max, jdouble visible)
2349 {
2350     GtkAdjustment *adj;
2351 
2352     gtk2_widget = gtk2_get_widget(widget_type);
2353 
2354     adj = (*fp_gtk_range_get_adjustment)((GtkRange *)gtk2_widget);
2355     adj->value = (gdouble)value;
2356     adj->lower = (gdouble)min;
2357     adj->upper = (gdouble)max;
2358     adj->page_size = (gdouble)visible;
2359 }
2360 
2361 /*************************************************/
2362 jobject create_Object(JNIEnv *env, jmethodID *cid,
2363                              const char* class_name,
2364                              const char* signature,
2365                              jvalue* value)
2366 {
2367     jclass  class;
2368     jobject result;
2369 
2370     class = (*env)->FindClass(env, class_name);
2371     if( class == NULL )
2372         return NULL; /* can't find/load the class, exception thrown */
2373 
2374     if( *cid == NULL)
2375     {
2376         *cid = (*env)->GetMethodID(env, class, "<init>", signature);
2377         if( *cid == NULL )
2378         {
2379             (*env)->DeleteLocalRef(env, class);
2380             return NULL; /* can't find/get the method, exception thrown */
2381         }
2382     }


2445     value.c = char_value;
2446 
2447     return create_Object(env, &cid, "java/lang/Character", "(C)V", &value);
2448 }
2449 
2450 
2451 jobject create_Insets(JNIEnv *env, GtkBorder *border)
2452 {
2453     static jmethodID cid = NULL;
2454     jvalue values[4];
2455 
2456     values[0].i = border->top;
2457     values[1].i = border->left;
2458     values[2].i = border->bottom;
2459     values[3].i = border->right;
2460 
2461     return create_Object(env, &cid, "java/awt/Insets", "(IIII)V", values);
2462 }
2463 
2464 /*********************************************/
2465 jstring gtk2_get_pango_font_name(JNIEnv *env, WidgetType widget_type)
2466 {
2467     init_containers();
2468 
2469     gtk2_widget = gtk2_get_widget(widget_type);
2470     jstring  result = NULL;
2471     GtkStyle* style = gtk2_widget->style;
2472 
2473     if (style && style->font_desc)
2474     {
2475         gchar* val = (*fp_pango_font_description_to_string)(style->font_desc);
2476         result = (*env)->NewStringUTF(env, val);
2477         (*fp_g_free)( val );
2478     }
2479 
2480     return result;
2481 }
2482 
2483 /***********************************************/
2484 jobject get_string_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2485 {
2486     jobject result = NULL;
2487     gchar*  strval = NULL;
2488 
2489     (*fp_g_object_get)(settings, key, &strval, NULL);
2490     result = (*env)->NewStringUTF(env, strval);
2491     (*fp_g_free)(strval);
2492 
2493     return result;
2494 }
2495 
2496 jobject get_integer_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2497 {
2498     gint intval = NULL;
2499     (*fp_g_object_get)(settings, key, &intval, NULL);
2500     return create_Integer(env, intval);
2501 }
2502 
2503 jobject get_boolean_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2504 {
2505     gint intval = NULL;
2506     (*fp_g_object_get)(settings, key, &intval, NULL);
2507     return create_Boolean(env, intval);
2508 }
2509 
2510 jobject gtk2_get_setting(JNIEnv *env, Setting property)
2511 {
2512     GtkSettings* settings = (*fp_gtk_settings_get_default)();
2513 
2514     switch (property)
2515     {
2516         case GTK_FONT_NAME:
2517             return get_string_property(env, settings, "gtk-font-name");
2518         case GTK_ICON_SIZES:
2519             return get_string_property(env, settings, "gtk-icon-sizes");
2520         case GTK_CURSOR_BLINK:
2521             return get_boolean_property(env, settings, "gtk-cursor-blink");
2522         case GTK_CURSOR_BLINK_TIME:
2523             return get_integer_property(env, settings, "gtk-cursor-blink-time");
2524     }
2525 
2526     return NULL;




















































































2527 }


  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
  23  * questions.
  24  */
  25 #include <dlfcn.h>
  26 #include <setjmp.h>
  27 #include <X11/Xlib.h>
  28 #include <limits.h>
  29 #include <stdio.h>
  30 #include <string.h>
  31 #include "gtk2_interface.h"
  32 #include "java_awt_Transparency.h"
  33 #include "jvm_md.h"
  34 #include "sizecalc.h"
  35 #include <jni_util.h>
  36 #include "awt.h"
  37 



























  38 #define GTK_TYPE_BORDER                 ((*fp_gtk_border_get_type)())
  39 
  40 #define G_TYPE_FUNDAMENTAL_SHIFT        (2)
  41 #define G_TYPE_MAKE_FUNDAMENTAL(x)      ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))

  42 
  43 #define CONV_BUFFER_SIZE 128
  44 
  45 #define NO_SYMBOL_EXCEPTION 1
  46 









  47 static void *gtk2_libhandle = NULL;
  48 static void *gthread_libhandle = NULL;
  49 
  50 static jmp_buf j;
  51 
  52 /* Widgets */
  53 static GtkWidget *gtk2_widget = NULL;
  54 static GtkWidget *gtk2_window = NULL;
  55 static GtkFixed  *gtk2_fixed  = NULL;
  56 
  57 /* Paint system */
  58 static GdkPixmap *gtk2_white_pixmap = NULL;
  59 static GdkPixmap *gtk2_black_pixmap = NULL;
  60 static GdkPixbuf *gtk2_white_pixbuf = NULL;
  61 static GdkPixbuf *gtk2_black_pixbuf = NULL;
  62 static int gtk2_pixbuf_width = 0;
  63 static int gtk2_pixbuf_height = 0;
  64 
  65 /* Static buffer for conversion from java.lang.String to UTF-8 */
  66 static char convertionBuffer[CONV_BUFFER_SIZE];
  67 
  68 static gboolean new_combo = TRUE;
  69 const char ENV_PREFIX[] = "GTK_MODULES=";
  70 

















































  71 static GtkWidget *gtk2_widgets[_GTK_WIDGET_TYPE_SIZE];
  72 
  73 /*************************
  74  * Glib function pointers
  75  *************************/
  76 
  77 static gboolean (*fp_g_main_context_iteration)(GMainContext *context,
  78                                              gboolean may_block);
  79 
  80 static GValue*      (*fp_g_value_init)(GValue *value, GType g_type);
  81 static gboolean     (*fp_g_type_is_a)(GType type, GType is_a_type);
  82 static gboolean     (*fp_g_value_get_boolean)(const GValue *value);
  83 static gchar        (*fp_g_value_get_char)(const GValue *value);
  84 static guchar       (*fp_g_value_get_uchar)(const GValue *value);
  85 static gint         (*fp_g_value_get_int)(const GValue *value);
  86 static guint        (*fp_g_value_get_uint)(const GValue *value);
  87 static glong        (*fp_g_value_get_long)(const GValue *value);
  88 static gulong       (*fp_g_value_get_ulong)(const GValue *value);
  89 static gint64       (*fp_g_value_get_int64)(const GValue *value);
  90 static guint64      (*fp_g_value_get_uint64)(const GValue *value);


 259         const gchar *first_property_name, ...);
 260 static void (*fp_gtk_widget_class_install_style_property)(
 261         GtkWidgetClass* class, GParamSpec *pspec);
 262 static GParamSpec* (*fp_gtk_widget_class_find_style_property)(
 263         GtkWidgetClass* class, const gchar* property_name);
 264 static void (*fp_gtk_widget_style_get_property)(GtkWidget* widget,
 265         const gchar* property_name, GValue* value);
 266 static char* (*fp_pango_font_description_to_string)(
 267         const PangoFontDescription* fd);
 268 static GtkSettings* (*fp_gtk_settings_get_default)();
 269 static GtkSettings* (*fp_gtk_widget_get_settings)(GtkWidget *widget);
 270 static GType        (*fp_gtk_border_get_type)();
 271 static void (*fp_gtk_arrow_set)(GtkWidget* arrow,
 272                                 GtkArrowType arrow_type,
 273                                 GtkShadowType shadow_type);
 274 static void (*fp_gtk_widget_size_request)(GtkWidget *widget,
 275                                           GtkRequisition *requisition);
 276 static GtkAdjustment* (*fp_gtk_range_get_adjustment)(GtkRange* range);
 277 
 278 /* Method bodies */














 279 
 280 static void throw_exception(JNIEnv *env, const char* name, const char* message)
 281 {
 282     jclass class = (*env)->FindClass(env, name);
 283 
 284     if (class != NULL)
 285         (*env)->ThrowNew(env, class, message);
 286 
 287     (*env)->DeleteLocalRef(env, class);
 288 }
 289 
 290 /* This is a workaround for the bug:
 291  * http://sourceware.org/bugzilla/show_bug.cgi?id=1814
 292  * (dlsym/dlopen clears dlerror state)
 293  * This bug is specific to Linux, but there is no harm in
 294  * applying this workaround on Solaris as well.
 295  */
 296 static void* dl_symbol(const char* name)
 297 {
 298     void* result = dlsym(gtk2_libhandle, name);
 299     if (!result)
 300         longjmp(j, NO_SYMBOL_EXCEPTION);
 301 
 302     return result;
 303 }
 304 
 305 static void* dl_symbol_gthread(const char* name)
 306 {
 307     void* result = dlsym(gthread_libhandle, name);
 308     if (!result)
 309         longjmp(j, NO_SYMBOL_EXCEPTION);
 310 
 311     return result;
 312 }
 313 
 314 gboolean gtk2_check(const char* lib_name, gboolean load)
 315 {
 316     if (gtk2_libhandle != NULL) {
 317         /* We've already successfully opened the GTK libs, so return true. */
 318         return TRUE;
 319     } else {
 320         void *lib = NULL;
 321         #ifdef RTLD_NOLOAD
 322         /* Just check if gtk libs are already in the process space */
 323         lib = dlopen(lib_name, RTLD_LAZY | RTLD_NOLOAD);
 324         if (!load || lib != NULL) {
 325             return lib != NULL;
 326         }
 327 #else
 328 #ifdef _AIX
 329         /* On AIX we could implement this with the help of loadquery(L_GETINFO, ..)  */
 330         /* (see reload_table() in hotspot/src/os/aix/vm/loadlib_aix.cpp) but it is   */
 331         /* probably not worth it because most AIX servers don't have GTK libs anyway */
 332 #endif
 333 #endif
 334 
 335         lib = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL);
 336 



 337         if (lib == NULL) {
 338             return FALSE;
 339         }

 340 
 341         fp_gtk_check_version = dlsym(lib, "gtk_check_version");
 342         /* Check for GTK 2.2+ */
 343         if (!fp_gtk_check_version(2, 2, 0)) {
 344             return  TRUE;
 345         }
 346 
 347         // 8048289: workaround for https://bugzilla.gnome.org/show_bug.cgi?id=733065
 348         // dlclose(lib);
 349 
 350         return FALSE;
 351     }
 352 }
 353 
 354 #define ADD_SUPPORTED_ACTION(actionStr) \
 355 do { \
 356     jfieldID fld_action = (*env)->GetStaticFieldID(env, cls_action, actionStr, "Ljava/awt/Desktop$Action;"); \
 357     if (!(*env)->ExceptionCheck(env)) { \
 358         jobject action = (*env)->GetStaticObjectField(env, cls_action, fld_action); \
 359         (*env)->CallBooleanMethod(env, supportedActions, mid_arrayListAdd, action); \
 360     } else { \
 361         (*env)->ExceptionClear(env); \
 362     } \
 363 } while(0);
 364 
 365 
 366 static void update_supported_actions(JNIEnv *env) {
 367     GVfs * (*fp_g_vfs_get_default) (void);
 368     const gchar * const * (*fp_g_vfs_get_supported_uri_schemes) (GVfs * vfs);
 369     const gchar * const * schemes = NULL;
 370 
 371     jclass cls_action = (*env)->FindClass(env, "java/awt/Desktop$Action");
 372     CHECK_NULL(cls_action);
 373     jclass cls_xDesktopPeer = (*env)->FindClass(env, "sun/awt/X11/XDesktopPeer");
 374     CHECK_NULL(cls_xDesktopPeer);
 375     jfieldID fld_supportedActions = (*env)->GetStaticFieldID(env, cls_xDesktopPeer, "supportedActions", "Ljava/util/List;");
 376     CHECK_NULL(fld_supportedActions);
 377     jobject supportedActions = (*env)->GetStaticObjectField(env, cls_xDesktopPeer, fld_supportedActions);
 378 
 379     jclass cls_arrayList = (*env)->FindClass(env, "java/util/ArrayList");
 380     CHECK_NULL(cls_arrayList);
 381     jmethodID mid_arrayListAdd = (*env)->GetMethodID(env, cls_arrayList, "add", "(Ljava/lang/Object;)Z");
 382     CHECK_NULL(mid_arrayListAdd);
 383     jmethodID mid_arrayListClear = (*env)->GetMethodID(env, cls_arrayList, "clear", "()V");
 384     CHECK_NULL(mid_arrayListClear);
 385 
 386     (*env)->CallVoidMethod(env, supportedActions, mid_arrayListClear);


 409             int i = 0;
 410             while (schemes[i]) {
 411                 if (strcmp(schemes[i], "http") == 0) {
 412                     ADD_SUPPORTED_ACTION("BROWSE");
 413                     ADD_SUPPORTED_ACTION("MAIL");
 414                     break;
 415                 }
 416                 i++;
 417             }
 418         }
 419     } else {
 420 #ifdef INTERNAL_BUILD
 421         fprintf(stderr, "Cannot load g_vfs_get_supported_uri_schemes\n");
 422 #endif /* INTERNAL_BUILD */
 423     }
 424 
 425 }
 426 /**
 427  * Functions for awt_Desktop.c
 428  */
 429 static gboolean gtk2_show_uri_load(JNIEnv *env) {
 430      gboolean success = FALSE;
 431      dlerror();
 432      const char *gtk_version = fp_gtk_check_version(2, 14, 0);
 433      if (gtk_version != NULL) {
 434          // The gtk_show_uri is available from GTK+ 2.14
 435 #ifdef INTERNAL_BUILD
 436          fprintf (stderr, "The version of GTK is %s. "
 437              "The gtk_show_uri function is supported "
 438              "since GTK+ 2.14.\n", gtk_version);
 439 #endif /* INTERNAL_BUILD */
 440      } else {
 441          // Loading symbols only if the GTK version is 2.14 and higher
 442          fp_gtk_show_uri = dl_symbol("gtk_show_uri");
 443          const char *dlsym_error = dlerror();
 444          if (dlsym_error) {
 445 #ifdef INTERNAL_BUILD
 446              fprintf (stderr, "Cannot load symbol: %s \n", dlsym_error);
 447 #endif /* INTERNAL_BUILD */
 448          } else if (fp_gtk_show_uri == NULL) {
 449 #ifdef INTERNAL_BUILD
 450              fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n");
 451 #endif /* INTERNAL_BUILD */
 452         } else {
 453             gtk->gtk_show_uri = fp_gtk_show_uri;
 454             update_supported_actions(env);
 455             success = TRUE;
 456         }
 457      }
 458      return success;
 459 }
 460 
 461 /**
 462  * Functions for sun_awt_X11_GtkFileDialogPeer.c
 463  */
 464 static void gtk2_file_chooser_load()
 465 {
 466     fp_gtk_file_chooser_get_filename = dl_symbol(
 467             "gtk_file_chooser_get_filename");
 468     fp_gtk_file_chooser_dialog_new = dl_symbol("gtk_file_chooser_dialog_new");
 469     fp_gtk_file_chooser_set_current_folder = dl_symbol(
 470             "gtk_file_chooser_set_current_folder");
 471     fp_gtk_file_chooser_set_filename = dl_symbol(
 472             "gtk_file_chooser_set_filename");
 473     fp_gtk_file_chooser_set_current_name = dl_symbol(
 474             "gtk_file_chooser_set_current_name");
 475     fp_gtk_file_filter_add_custom = dl_symbol("gtk_file_filter_add_custom");
 476     fp_gtk_file_chooser_set_filter = dl_symbol("gtk_file_chooser_set_filter");
 477     fp_gtk_file_chooser_get_type = dl_symbol("gtk_file_chooser_get_type");
 478     fp_gtk_file_filter_new = dl_symbol("gtk_file_filter_new");
 479     if (fp_gtk_check_version(2, 8, 0) == NULL) {
 480         fp_gtk_file_chooser_set_do_overwrite_confirmation = dl_symbol(
 481                 "gtk_file_chooser_set_do_overwrite_confirmation");
 482     }
 483     fp_gtk_file_chooser_set_select_multiple = dl_symbol(
 484             "gtk_file_chooser_set_select_multiple");
 485     fp_gtk_file_chooser_get_current_folder = dl_symbol(
 486             "gtk_file_chooser_get_current_folder");
 487     fp_gtk_file_chooser_get_filenames = dl_symbol(
 488             "gtk_file_chooser_get_filenames");
 489     fp_gtk_g_slist_length = dl_symbol("g_slist_length");
 490 }
 491 
 492 GtkApi* gtk2_load(JNIEnv *env, const char* lib_name)
 493 {
 494     gboolean result;
 495     int i;
 496     int (*handler)();
 497     int (*io_handler)();
 498     char *gtk_modules_env;
 499 
 500     gtk2_libhandle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL);
 501     if (gtk2_libhandle == NULL) {


 502         return FALSE;
 503     }
 504 
 505     gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 506     if (gthread_libhandle == NULL) {
 507         gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL);
 508         if (gthread_libhandle == NULL)
 509             return FALSE;
 510     }
 511 
 512     if (setjmp(j) == 0)
 513     {
 514         fp_gtk_check_version = dl_symbol("gtk_check_version");
 515         /* Check for GTK 2.2+ */
 516         if (fp_gtk_check_version(2, 2, 0)) {
 517             longjmp(j, NO_SYMBOL_EXCEPTION);
 518         }
 519 
 520         /* GLib */
 521         fp_glib_check_version = dlsym(gtk2_libhandle, "glib_check_version");


 823             }
 824 
 825             //According the GTK documentation, gdk_threads_init() should be
 826             //called before gtk_init() or gtk_init_check()
 827             fp_gdk_threads_init();
 828         }
 829         (*env)->CallStaticVoidMethod(env, clazz, mid_unlock);
 830     }
 831     result = (*fp_gtk_init_check)(NULL, NULL);
 832 
 833     XSetErrorHandler(handler);
 834     XSetIOErrorHandler(io_handler);
 835     AWT_UNLOCK();
 836 
 837     /* Initialize widget array. */
 838     for (i = 0; i < _GTK_WIDGET_TYPE_SIZE; i++)
 839     {
 840         gtk2_widgets[i] = NULL;
 841     }
 842 
 843     
 844     if (result) {
 845         GtkApi* gtk = (GtkApi*)malloc(sizeof(GtkApi));
 846         gtk2_init(gtk);
 847         return gtk;
 848     }
 849     return NULL;
 850 }
 851 
 852 int gtk2_unload()
 853 {
 854     int i;
 855     char *gtk2_error;
 856 
 857     if (!gtk2_libhandle)
 858         return TRUE;
 859 
 860     /* Release painting objects */
 861     if (gtk2_white_pixmap != NULL) {
 862         (*fp_g_object_unref)(gtk2_white_pixmap);
 863         (*fp_g_object_unref)(gtk2_black_pixmap);
 864         (*fp_g_object_unref)(gtk2_white_pixbuf);
 865         (*fp_g_object_unref)(gtk2_black_pixbuf);
 866         gtk2_white_pixmap = gtk2_black_pixmap =
 867             gtk2_white_pixbuf = gtk2_black_pixbuf = NULL;
 868     }
 869     gtk2_pixbuf_width = 0;


 873         /* Destroying toplevel widget will destroy all contained widgets */
 874         (*fp_gtk_widget_destroy)(gtk2_window);
 875 
 876         /* Unset some static data so they get reinitialized on next load */
 877         gtk2_window = NULL;
 878     }
 879 
 880     dlerror();
 881     dlclose(gtk2_libhandle);
 882     dlclose(gthread_libhandle);
 883     if ((gtk2_error = dlerror()) != NULL)
 884     {
 885         return FALSE;
 886     }
 887     return TRUE;
 888 }
 889 
 890 /* Dispatch all pending events from the GTK event loop.
 891  * This is needed to catch theme change and update widgets' style.
 892  */
 893 static void flush_gtk_event_loop()
 894 {
 895     while( (*fp_g_main_context_iteration)(NULL, FALSE));
 896 }
 897 
 898 /*
 899  * Initialize components of containment hierarchy. This creates a GtkFixed
 900  * inside a GtkWindow. All widgets get realized.
 901  */
 902 static void init_containers()
 903 {
 904     if (gtk2_window == NULL)
 905     {
 906         gtk2_window = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
 907         gtk2_fixed = (GtkFixed *)(*fp_gtk_fixed_new)();
 908         (*fp_gtk_container_add)((GtkContainer*)gtk2_window,
 909                                 (GtkWidget *)gtk2_fixed);
 910         (*fp_gtk_widget_realize)(gtk2_window);
 911         (*fp_gtk_widget_realize)((GtkWidget *)gtk2_fixed);
 912     }
 913 }


 922  * work around this:
 923  * 1) Subclass GdkPixmap and cache translucent objects on client side. This
 924  * requires us to implement parts of X server drawing logic on client side.
 925  * Many X requests can potentially be "translucent"; e.g. XDrawLine with
 926  * fill=tile and a translucent tile is a "translucent" operation, whereas
 927  * XDrawLine with fill=solid is an "opaque" one. Moreover themes can (and some
 928  * do) intermix transparent and opaque operations which makes caching even
 929  * more problematic.
 930  * 2) Use Xorg 32bit ARGB visual when available. GDK has no native support
 931  * for it (as of version 2.6). Also even in JDS 3 Xorg does not support
 932  * these visuals by default, which makes optimizing for them pointless.
 933  * We can consider doing this at a later point when ARGB visuals become more
 934  * popular.
 935  * 3') GTK has plans to use Cairo as its graphical backend (presumably in
 936  * 2.8), and Cairo supports alpha. With it we could also get rid of the
 937  * unnecessary round trip to server and do all the drawing on client side.
 938  * 4) For now we draw to two different pixmaps and restore alpha channel by
 939  * comparing results. This can be optimized by using subclassed pixmap and
 940  * doing the second drawing only if necessary.
 941 */
 942 static void gtk2_init_painting(JNIEnv *env, gint width, gint height)
 943 {
 944     GdkGC *gc;
 945     GdkPixbuf *white, *black;
 946 
 947     init_containers();
 948 
 949     if (gtk2_pixbuf_width < width || gtk2_pixbuf_height < height)
 950     {
 951         white = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
 952         black = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
 953 
 954         if (white == NULL || black == NULL)
 955         {
 956             snprintf(convertionBuffer, CONV_BUFFER_SIZE, "Couldn't create pixbuf of size %dx%d", width, height);
 957             throw_exception(env, "java/lang/RuntimeException", convertionBuffer);
 958             fp_gdk_threads_leave();
 959             return;
 960         }
 961 
 962         if (gtk2_white_pixmap != NULL) {


 982     (*fp_gdk_rgb_gc_set_foreground)(gc, 0xffffff);
 983     (*fp_gdk_draw_rectangle)(gtk2_white_pixmap, gc, TRUE, 0, 0, width, height);
 984     (*fp_g_object_unref)(gc);
 985 
 986     gc = (*fp_gdk_gc_new)(gtk2_black_pixmap);
 987     (*fp_gdk_rgb_gc_set_foreground)(gc, 0x000000);
 988     (*fp_gdk_draw_rectangle)(gtk2_black_pixmap, gc, TRUE, 0, 0, width, height);
 989     (*fp_g_object_unref)(gc);
 990 }
 991 
 992 /*
 993  * Restore image from white and black pixmaps and copy it into destination
 994  * buffer. This method compares two pixbufs taken from white and black
 995  * pixmaps and decodes color and alpha components. Pixbufs are RGB without
 996  * alpha, destination buffer is ABGR.
 997  *
 998  * The return value is the transparency type of the resulting image, either
 999  * one of java_awt_Transparency_OPAQUE, java_awt_Transparency_BITMASK, and
1000  * java_awt_Transparency_TRANSLUCENT.
1001  */
1002 static gint gtk2_copy_image(gint *dst, gint width, gint height)
1003 {
1004     gint i, j, r, g, b;
1005     guchar *white, *black;
1006     gint stride, padding;
1007     gboolean is_opaque = TRUE;
1008     gboolean is_bitmask = TRUE;
1009 
1010     (*fp_gdk_pixbuf_get_from_drawable)(gtk2_white_pixbuf, gtk2_white_pixmap,
1011             NULL, 0, 0, 0, 0, width, height);
1012     (*fp_gdk_pixbuf_get_from_drawable)(gtk2_black_pixbuf, gtk2_black_pixmap,
1013             NULL, 0, 0, 0, 0, width, height);
1014 
1015     white = (*fp_gdk_pixbuf_get_pixels)(gtk2_white_pixbuf);
1016     black = (*fp_gdk_pixbuf_get_pixels)(gtk2_black_pixbuf);
1017     stride = (*fp_gdk_pixbuf_get_rowstride)(gtk2_black_pixbuf);
1018     padding = stride - width * 4;
1019 
1020     for (i = 0; i < height; i++) {
1021         for (j = 0; j < width; j++) {
1022             int r1 = *white++;


1644             h = size.height - ((GtkMisc*)gtk2_widget)->ypad * 2;
1645             w = h = MIN(MIN(w, h), MIN(width,height)) * 0.7;
1646             break;
1647 
1648         default:
1649             w = width;
1650             h = height;
1651             break;
1652     }
1653     x += (width - w) / 2;
1654     y += (height - h) / 2;
1655 
1656     (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1657             shadow_type, NULL, gtk2_widget, detail, arrow_type, fill,
1658             x, y, w, h);
1659     (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1660             shadow_type, NULL, gtk2_widget, detail, arrow_type, fill,
1661             x, y, w, h);
1662 }
1663 
1664 static void gtk2_paint_box(WidgetType widget_type, GtkStateType state_type,
1665                     GtkShadowType shadow_type, const gchar *detail,
1666                     gint x, gint y, gint width, gint height,
1667                     gint synth_state, GtkTextDirection dir)
1668 {
1669     gtk2_widget = gtk2_get_widget(widget_type);
1670 
1671     /*
1672      * The clearlooks engine sometimes looks at the widget's state field
1673      * instead of just the state_type variable that we pass in, so to account
1674      * for those cases we set the widget's state field accordingly.  The
1675      * flags field is similarly important for things like focus/default state.
1676      */
1677     gtk2_widget->state = state_type;
1678 
1679     if (widget_type == HSLIDER_TRACK) {
1680         /*
1681          * For horizontal JSliders with right-to-left orientation, we need
1682          * to set the "inverted" flag to match the native GTK behavior where
1683          * the foreground highlight is on the right side of the slider thumb.
1684          * This is needed especially for the ubuntulooks engine, which looks


1814     gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR);
1815 }
1816 
1817 void gtk2_paint_box_gap(WidgetType widget_type, GtkStateType state_type,
1818         GtkShadowType shadow_type, const gchar *detail,
1819         gint x, gint y, gint width, gint height,
1820         GtkPositionType gap_side, gint gap_x, gint gap_width)
1821 {
1822     /* Clearlooks needs a real clip area to paint the gap properly */
1823     GdkRectangle area = { x, y, width, height };
1824 
1825     gtk2_widget = gtk2_get_widget(widget_type);
1826     (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1827             shadow_type, &area, gtk2_widget, detail,
1828             x, y, width, height, gap_side, gap_x, gap_width);
1829     (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1830             shadow_type, &area, gtk2_widget, detail,
1831             x, y, width, height, gap_side, gap_x, gap_width);
1832 }
1833 
1834 static void gtk2_paint_check(WidgetType widget_type, gint synth_state,
1835         const gchar *detail, gint x, gint y, gint width, gint height)
1836 {
1837     GtkStateType state_type = get_gtk_state_type(widget_type, synth_state);
1838     GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state);
1839 
1840     gtk2_widget = gtk2_get_widget(widget_type);
1841     init_toggle_widget(widget_type, synth_state);
1842 
1843     (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1844             shadow_type, NULL, gtk2_widget, detail,
1845             x, y, width, height);
1846     (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1847             shadow_type, NULL, gtk2_widget, detail,
1848             x, y, width, height);
1849 }
1850 
1851 static void gtk2_paint_diamond(WidgetType widget_type, GtkStateType state_type,
1852         GtkShadowType shadow_type, const gchar *detail,
1853         gint x, gint y, gint width, gint height)
1854 {
1855     gtk2_widget = gtk2_get_widget(widget_type);
1856     (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1857             shadow_type, NULL, gtk2_widget, detail,
1858             x, y, width, height);
1859     (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1860             shadow_type, NULL, gtk2_widget, detail,
1861             x, y, width, height);
1862 }
1863 
1864 static void gtk2_paint_expander(WidgetType widget_type, GtkStateType state_type,
1865         const gchar *detail, gint x, gint y, gint width, gint height,
1866         GtkExpanderStyle expander_style)
1867 {
1868     gtk2_widget = gtk2_get_widget(widget_type);
1869     (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_white_pixmap,
1870             state_type, NULL, gtk2_widget, detail,
1871             x + width / 2, y + height / 2, expander_style);
1872     (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_black_pixmap,
1873             state_type, NULL, gtk2_widget, detail,
1874             x + width / 2, y + height / 2, expander_style);
1875 }
1876 
1877 static void gtk2_paint_extension(WidgetType widget_type, GtkStateType state_type,
1878         GtkShadowType shadow_type, const gchar *detail,
1879         gint x, gint y, gint width, gint height, GtkPositionType gap_side)
1880 {
1881     gtk2_widget = gtk2_get_widget(widget_type);
1882     (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_white_pixmap,
1883             state_type, shadow_type, NULL, gtk2_widget, detail,
1884             x, y, width, height, gap_side);
1885     (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_black_pixmap,
1886             state_type, shadow_type, NULL, gtk2_widget, detail,
1887             x, y, width, height, gap_side);
1888 }
1889 
1890 static void gtk2_paint_flat_box(WidgetType widget_type, GtkStateType state_type,
1891         GtkShadowType shadow_type, const gchar *detail,
1892         gint x, gint y, gint width, gint height, gboolean has_focus)
1893 {
1894     gtk2_widget = gtk2_get_widget(widget_type);
1895 
1896     if (has_focus)
1897         ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS;
1898     else
1899         ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
1900 
1901     (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_white_pixmap,
1902             state_type, shadow_type, NULL, gtk2_widget, detail,
1903             x, y, width, height);
1904     (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_black_pixmap,
1905             state_type, shadow_type, NULL, gtk2_widget, detail,
1906             x, y, width, height);
1907 }
1908 
1909 static void gtk2_paint_focus(WidgetType widget_type, GtkStateType state_type,
1910         const char *detail, gint x, gint y, gint width, gint height)
1911 {
1912     gtk2_widget = gtk2_get_widget(widget_type);
1913     (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1914             NULL, gtk2_widget, detail, x, y, width, height);
1915     (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1916             NULL, gtk2_widget, detail, x, y, width, height);
1917 }
1918 
1919 static void gtk2_paint_handle(WidgetType widget_type, GtkStateType state_type,
1920         GtkShadowType shadow_type, const gchar *detail,
1921         gint x, gint y, gint width, gint height, GtkOrientation orientation)
1922 {
1923     gtk2_widget = gtk2_get_widget(widget_type);
1924     (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1925             shadow_type, NULL, gtk2_widget, detail,
1926             x, y, width, height, orientation);
1927     (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1928             shadow_type, NULL, gtk2_widget, detail,
1929             x, y, width, height, orientation);
1930 }
1931 
1932 static void gtk2_paint_hline(WidgetType widget_type, GtkStateType state_type,
1933         const gchar *detail, gint x, gint y, gint width, gint height)
1934 {
1935     gtk2_widget = gtk2_get_widget(widget_type);
1936     (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1937             NULL, gtk2_widget, detail, x, x + width, y);
1938     (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1939             NULL, gtk2_widget, detail, x, x + width, y);
1940 }
1941 
1942 static void gtk2_paint_option(WidgetType widget_type, gint synth_state,
1943         const gchar *detail, gint x, gint y, gint width, gint height)
1944 {
1945     GtkStateType state_type = get_gtk_state_type(widget_type, synth_state);
1946     GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state);
1947 
1948     gtk2_widget = gtk2_get_widget(widget_type);
1949     init_toggle_widget(widget_type, synth_state);
1950 
1951     (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1952             shadow_type, NULL, gtk2_widget, detail,
1953             x, y, width, height);
1954     (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1955             shadow_type, NULL, gtk2_widget, detail,
1956             x, y, width, height);
1957 }
1958 
1959 static void gtk2_paint_shadow(WidgetType widget_type, GtkStateType state_type,
1960                        GtkShadowType shadow_type, const gchar *detail,
1961                        gint x, gint y, gint width, gint height,
1962                        gint synth_state, GtkTextDirection dir)
1963 {
1964     gtk2_widget = gtk2_get_widget(widget_type);
1965 
1966     /*
1967      * The clearlooks engine sometimes looks at the widget's state field
1968      * instead of just the state_type variable that we pass in, so to account
1969      * for those cases we set the widget's state field accordingly.  The
1970      * flags field is similarly important for things like focus state.
1971      */
1972     gtk2_widget->state = state_type;
1973 
1974     /*
1975      * Some engines (e.g. clearlooks) will paint the shadow of certain
1976      * widgets (e.g. COMBO_BOX_TEXT_FIELD) differently depending on the
1977      * the text direction.
1978      */
1979     gtk2_set_direction(gtk2_widget, dir);


1989         } else {
1990             ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
1991         }
1992         break;
1993     default:
1994         break;
1995     }
1996 
1997     (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1998             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
1999     (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2000             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
2001 
2002     /*
2003      * Reset the text direction to the default value so that we don't
2004      * accidentally affect other operations and widgets.
2005      */
2006     gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR);
2007 }
2008 
2009 static void gtk2_paint_slider(WidgetType widget_type, GtkStateType state_type,
2010         GtkShadowType shadow_type, const gchar *detail,
2011         gint x, gint y, gint width, gint height, GtkOrientation orientation,
2012         gboolean has_focus)
2013 {
2014     gtk2_widget = gtk2_get_widget(widget_type);
2015     (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2016             shadow_type, NULL, gtk2_widget, detail,
2017             x, y, width, height, orientation);
2018     (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2019             shadow_type, NULL, gtk2_widget, detail,
2020             x, y, width, height, orientation);
2021 }
2022 
2023 static void gtk2_paint_vline(WidgetType widget_type, GtkStateType state_type,
2024         const gchar *detail, gint x, gint y, gint width, gint height)
2025 {
2026     gtk2_widget = gtk2_get_widget(widget_type);
2027     (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2028             NULL, gtk2_widget, detail, y, y + height, x);
2029     (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2030             NULL, gtk2_widget, detail, y, y + height, x);
2031 }
2032 
2033 static void gtk_paint_background(WidgetType widget_type, GtkStateType state_type,
2034         gint x, gint y, gint width, gint height)
2035 {
2036     gtk2_widget = gtk2_get_widget(widget_type);
2037     (*fp_gtk_style_apply_default_background)(gtk2_widget->style,
2038             gtk2_white_pixmap, TRUE, state_type, NULL, x, y, width, height);
2039     (*fp_gtk_style_apply_default_background)(gtk2_widget->style,
2040             gtk2_black_pixmap, TRUE, state_type, NULL, x, y, width, height);
2041 }
2042 
2043 static GdkPixbuf *gtk2_get_stock_icon(gint widget_type, const gchar *stock_id,
2044         GtkIconSize size, GtkTextDirection direction, const char *detail)
2045 {
2046     init_containers();
2047     gtk2_widget = gtk2_get_widget((widget_type < 0) ? IMAGE : widget_type);
2048     gtk2_widget->state = GTK_STATE_NORMAL;
2049     (*fp_gtk_widget_set_direction)(gtk2_widget, direction);
2050     return (*fp_gtk_widget_render_icon)(gtk2_widget, stock_id, size, detail);
2051 }
2052 
2053 static jboolean gtk2_get_pixbuf_data(JNIEnv *env, GdkPixbuf* pixbuf,
2054                               jmethodID icon_upcall_method, jobject this) {
2055     if (!pixbuf) {
2056         return JNI_FALSE;
2057     }
2058     guchar *pixbuf_data = (*fp_gdk_pixbuf_get_pixels)(pixbuf);
2059     if (pixbuf_data) {
2060         int row_stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
2061         int width = (*fp_gdk_pixbuf_get_width)(pixbuf);
2062         int height = (*fp_gdk_pixbuf_get_height)(pixbuf);
2063         int bps = (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf);
2064         int channels = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
2065         gboolean alpha = (*fp_gdk_pixbuf_get_has_alpha)(pixbuf);
2066 
2067         jbyteArray data = (*env)->NewByteArray(env, (row_stride * height));
2068         JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
2069 
2070         (*env)->SetByteArrayRegion(env, data, 0, (row_stride * height),
2071                                    (jbyte *)pixbuf_data);
2072         (*fp_g_object_unref)(pixbuf);
2073 
2074         /* Call the callback method to create the image on the Java side. */
2075         (*env)->CallVoidMethod(env, this, icon_upcall_method, data,
2076                 width, height, row_stride, bps, channels, alpha);
2077         return JNI_TRUE;
2078     }
2079     return JNI_FALSE;
2080 }
2081 
2082 static jboolean gtk2_get_file_icon_data(JNIEnv *env, const char *filename,
2083                  GError **error, jmethodID icon_upcall_method, jobject this) {
2084     GdkPixbuf* pixbuf = fp_gdk_pixbuf_new_from_file(filename, error);
2085     return gtk2_get_pixbuf_data(env, pixbuf, icon_upcall_method, this);
2086 }
2087 
2088 static jboolean gtk2_get_icon_data(JNIEnv *env, gint widget_type,
2089                               const gchar *stock_id, GtkIconSize size,
2090                               GtkTextDirection direction, const char *detail,
2091                               jmethodID icon_upcall_method, jobject this) {
2092     GdkPixbuf* pixbuf = gtk2_get_stock_icon(widget_type, stock_id, size,
2093                                        direction, detail);
2094     return gtk2_get_pixbuf_data(env, pixbuf, icon_upcall_method, this);
2095 }
2096 
2097 /*************************************************/
2098 static gint gtk2_get_xthickness(JNIEnv *env, WidgetType widget_type)
2099 {
2100     init_containers();
2101 
2102     gtk2_widget = gtk2_get_widget(widget_type);
2103     GtkStyle* style = gtk2_widget->style;
2104     return style->xthickness;
2105 }
2106 
2107 static gint gtk2_get_ythickness(JNIEnv *env, WidgetType widget_type)
2108 {
2109     init_containers();
2110 
2111     gtk2_widget = gtk2_get_widget(widget_type);
2112     GtkStyle* style = gtk2_widget->style;
2113     return style->ythickness;
2114 }
2115 
2116 /*************************************************/
2117 static guint8 recode_color(guint16 channel)
2118 {
2119     return (guint8)(channel>>8);
2120 }
2121 
2122 static gint gtk2_get_color_for_state(JNIEnv *env, WidgetType widget_type,
2123                               GtkStateType state_type, ColorType color_type)
2124 {
2125     gint result = 0;
2126     GdkColor *color = NULL;
2127 
2128     init_containers();
2129 
2130     gtk2_widget = gtk2_get_widget(widget_type);
2131     GtkStyle* style = gtk2_widget->style;
2132 
2133     switch (color_type)
2134     {
2135         case FOREGROUND:
2136             color = &(style->fg[state_type]);
2137             break;
2138         case BACKGROUND:
2139             color = &(style->bg[state_type]);
2140             break;
2141         case TEXT_FOREGROUND:
2142             color = &(style->text[state_type]);


2154             color = &(style->mid[state_type]);
2155             break;
2156         case FOCUS:
2157         case BLACK:
2158             color = &(style->black);
2159             break;
2160         case WHITE:
2161             color = &(style->white);
2162             break;
2163     }
2164 
2165     if (color)
2166         result = recode_color(color->red)   << 16 |
2167                  recode_color(color->green) << 8  |
2168                  recode_color(color->blue);
2169 
2170     return result;
2171 }
2172 
2173 /*************************************************/
2174 static jobject create_Boolean(JNIEnv *env, jboolean boolean_value);
2175 static jobject create_Integer(JNIEnv *env, jint int_value);
2176 static jobject create_Long(JNIEnv *env, jlong long_value);
2177 static jobject create_Float(JNIEnv *env, jfloat float_value);
2178 static jobject create_Double(JNIEnv *env, jdouble double_value);
2179 static jobject create_Character(JNIEnv *env, jchar char_value);
2180 static jobject create_Insets(JNIEnv *env, GtkBorder *border);
2181 
2182 static jobject gtk2_get_class_value(JNIEnv *env, WidgetType widget_type,
2183                               const char* key)
2184 {
2185     init_containers();
2186 

2187     gtk2_widget = gtk2_get_widget(widget_type);
2188 
2189     GValue value;
2190     value.g_type = 0;
2191 
2192     GParamSpec* param = (*fp_gtk_widget_class_find_style_property)(
2193                                     ((GTypeInstance*)gtk2_widget)->g_class, key);
2194     if( param )
2195     {
2196         (*fp_g_value_init)( &value, param->value_type );
2197         (*fp_gtk_widget_style_get_property)(gtk2_widget, key, &value);
2198 
2199         if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOOLEAN ))
2200         {
2201             gboolean val = (*fp_g_value_get_boolean)(&value);
2202             return create_Boolean(env, (jboolean)val);
2203         }
2204         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_CHAR ))
2205         {
2206             gchar val = (*fp_g_value_get_char)(&value);


2287         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOXED ))
2288         {
2289             gpointer* val = (*fp_g_value_get_boxed)(&value);
2290             printf( "Boxed: %p\n", val );
2291         }
2292         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_POINTER ))
2293         {
2294             gpointer* val = (*fp_g_value_get_pointer)(&value);
2295             printf( "Pointer: %p\n", val );
2296         }
2297         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_OBJECT ))
2298         {
2299             GObject* val = (GObject*)(*fp_g_value_get_object)(&value);
2300             printf( "Object: %p\n", val );
2301         }*/
2302     }
2303 
2304     return NULL;
2305 }
2306 
2307 static void gtk2_set_range_value(WidgetType widget_type, jdouble value,
2308                           jdouble min, jdouble max, jdouble visible)
2309 {
2310     GtkAdjustment *adj;
2311 
2312     gtk2_widget = gtk2_get_widget(widget_type);
2313 
2314     adj = (*fp_gtk_range_get_adjustment)((GtkRange *)gtk2_widget);
2315     adj->value = (gdouble)value;
2316     adj->lower = (gdouble)min;
2317     adj->upper = (gdouble)max;
2318     adj->page_size = (gdouble)visible;
2319 }
2320 
2321 /*************************************************/
2322 static jobject create_Object(JNIEnv *env, jmethodID *cid,
2323                              const char* class_name,
2324                              const char* signature,
2325                              jvalue* value)
2326 {
2327     jclass  class;
2328     jobject result;
2329 
2330     class = (*env)->FindClass(env, class_name);
2331     if( class == NULL )
2332         return NULL; /* can't find/load the class, exception thrown */
2333 
2334     if( *cid == NULL)
2335     {
2336         *cid = (*env)->GetMethodID(env, class, "<init>", signature);
2337         if( *cid == NULL )
2338         {
2339             (*env)->DeleteLocalRef(env, class);
2340             return NULL; /* can't find/get the method, exception thrown */
2341         }
2342     }


2405     value.c = char_value;
2406 
2407     return create_Object(env, &cid, "java/lang/Character", "(C)V", &value);
2408 }
2409 
2410 
2411 jobject create_Insets(JNIEnv *env, GtkBorder *border)
2412 {
2413     static jmethodID cid = NULL;
2414     jvalue values[4];
2415 
2416     values[0].i = border->top;
2417     values[1].i = border->left;
2418     values[2].i = border->bottom;
2419     values[3].i = border->right;
2420 
2421     return create_Object(env, &cid, "java/awt/Insets", "(IIII)V", values);
2422 }
2423 
2424 /*********************************************/
2425 static jstring gtk2_get_pango_font_name(JNIEnv *env, WidgetType widget_type)
2426 {
2427     init_containers();
2428 
2429     gtk2_widget = gtk2_get_widget(widget_type);
2430     jstring  result = NULL;
2431     GtkStyle* style = gtk2_widget->style;
2432 
2433     if (style && style->font_desc)
2434     {
2435         gchar* val = (*fp_pango_font_description_to_string)(style->font_desc);
2436         result = (*env)->NewStringUTF(env, val);
2437         (*fp_g_free)( val );
2438     }
2439 
2440     return result;
2441 }
2442 
2443 /***********************************************/
2444 static jobject get_string_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2445 {
2446     jobject result = NULL;
2447     gchar*  strval = NULL;
2448 
2449     (*fp_g_object_get)(settings, key, &strval, NULL);
2450     result = (*env)->NewStringUTF(env, strval);
2451     (*fp_g_free)(strval);
2452 
2453     return result;
2454 }
2455 
2456 static jobject get_integer_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2457 {
2458     gint intval = 0;
2459     (*fp_g_object_get)(settings, key, &intval, NULL);
2460     return create_Integer(env, intval);
2461 }
2462 
2463 static jobject get_boolean_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2464 {
2465     gint intval = 0;
2466     (*fp_g_object_get)(settings, key, &intval, NULL);
2467     return create_Boolean(env, intval);
2468 }
2469 
2470 static jobject gtk2_get_setting(JNIEnv *env, Setting property)
2471 {
2472     GtkSettings* settings = (*fp_gtk_settings_get_default)();
2473 
2474     switch (property)
2475     {
2476         case GTK_FONT_NAME:
2477             return get_string_property(env, settings, "gtk-font-name");
2478         case GTK_ICON_SIZES:
2479             return get_string_property(env, settings, "gtk-icon-sizes");
2480         case GTK_CURSOR_BLINK:
2481             return get_boolean_property(env, settings, "gtk-cursor-blink");
2482         case GTK_CURSOR_BLINK_TIME:
2483             return get_integer_property(env, settings, "gtk-cursor-blink-time");
2484     }
2485 
2486     return NULL;
2487 }
2488 
2489 static GdkWindow* gtk2_get_window(void *widget) {
2490     return ((GtkWidget*)widget)->window;
2491 }
2492 
2493 void gtk2_init(GtkApi* gtk) {
2494     gtk->version = GTK_2;
2495 
2496     gtk->show_uri_load = &gtk2_show_uri_load;
2497     gtk->unload = &gtk2_unload;
2498     gtk->flush_event_loop = &flush_gtk_event_loop;
2499     gtk->gtk_check_version = fp_gtk_check_version;
2500     gtk->get_setting = &gtk2_get_setting;
2501 
2502     gtk->paint_arrow = &gtk2_paint_arrow;
2503     gtk->paint_box = &gtk2_paint_box;
2504     gtk->paint_box_gap = &gtk2_paint_box_gap;
2505     gtk->paint_expander = &gtk2_paint_expander;
2506     gtk->paint_extension = &gtk2_paint_extension;
2507     gtk->paint_flat_box = &gtk2_paint_flat_box;
2508     gtk->paint_focus = &gtk2_paint_focus;
2509     gtk->paint_handle = &gtk2_paint_handle;
2510     gtk->paint_hline = &gtk2_paint_hline;
2511     gtk->paint_vline = &gtk2_paint_vline;
2512     gtk->paint_option = &gtk2_paint_option;
2513     gtk->paint_shadow = &gtk2_paint_shadow;
2514     gtk->paint_slider = &gtk2_paint_slider;
2515     gtk->paint_background = &gtk_paint_background;
2516     gtk->paint_check = &gtk2_paint_check;
2517     gtk->set_range_value = &gtk2_set_range_value;
2518 
2519     gtk->init_painting = &gtk2_init_painting;
2520     gtk->copy_image = &gtk2_copy_image;
2521 
2522     gtk->get_xthickness = &gtk2_get_xthickness;
2523     gtk->get_ythickness = &gtk2_get_ythickness;
2524     gtk->get_color_for_state = &gtk2_get_color_for_state;
2525     gtk->get_class_value = &gtk2_get_class_value;
2526 
2527     gtk->get_pango_font_name = &gtk2_get_pango_font_name;
2528     gtk->get_icon_data = &gtk2_get_icon_data;
2529     gtk->get_file_icon_data = &gtk2_get_file_icon_data;
2530     gtk->gdk_threads_enter = fp_gdk_threads_enter;
2531     gtk->gdk_threads_leave = fp_gdk_threads_leave;
2532     gtk->gtk_show_uri = fp_gtk_show_uri;
2533     gtk->g_free = fp_g_free;
2534 
2535     gtk->gtk_file_chooser_get_filename = fp_gtk_file_chooser_get_filename;
2536     gtk->gtk_widget_hide = fp_gtk_widget_hide;
2537     gtk->gtk_main_quit = fp_gtk_main_quit;
2538     gtk->gtk_file_chooser_dialog_new = fp_gtk_file_chooser_dialog_new;
2539     gtk->gtk_file_chooser_set_current_folder =
2540                           fp_gtk_file_chooser_set_current_folder;
2541     gtk->gtk_file_chooser_set_filename = fp_gtk_file_chooser_set_filename;
2542     gtk->gtk_file_chooser_set_current_name =
2543                           fp_gtk_file_chooser_set_current_name;
2544     gtk->gtk_file_filter_add_custom = fp_gtk_file_filter_add_custom;
2545     gtk->gtk_file_chooser_set_filter = fp_gtk_file_chooser_set_filter;
2546     gtk->gtk_file_chooser_get_type = fp_gtk_file_chooser_get_type;
2547     gtk->gtk_file_filter_new = fp_gtk_file_filter_new;
2548     gtk->gtk_file_chooser_set_do_overwrite_confirmation =
2549                           fp_gtk_file_chooser_set_do_overwrite_confirmation;
2550     gtk->gtk_file_chooser_set_select_multiple =
2551                           fp_gtk_file_chooser_set_select_multiple;
2552     gtk->gtk_file_chooser_get_current_folder =
2553                           fp_gtk_file_chooser_get_current_folder;
2554     gtk->gtk_file_chooser_get_filenames = fp_gtk_file_chooser_get_filenames;
2555     gtk->gtk_g_slist_length = fp_gtk_g_slist_length;
2556     gtk->g_signal_connect_data = fp_g_signal_connect_data;
2557     gtk->gtk_widget_show = fp_gtk_widget_show;
2558     gtk->gtk_main = fp_gtk_main;
2559     gtk->gtk_main_level = fp_gtk_main_level;
2560     gtk->g_path_get_dirname = fp_g_path_get_dirname;
2561     gtk->gtk_widget_destroy = fp_gtk_widget_destroy;
2562     gtk->gtk_window_present = fp_gtk_window_present;
2563     gtk->gtk_window_move = fp_gtk_window_move;
2564     gtk->gtk_window_resize = fp_gtk_window_resize;
2565     gtk->get_window = &gtk2_get_window;
2566 
2567     gtk->g_object_unref = fp_g_object_unref;
2568     gtk->g_list_append = fp_g_list_append;
2569     gtk->g_list_free = fp_g_list_free;
2570     gtk->g_list_free_full = fp_g_list_free_full;
2571 }
< prev index next >