1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  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);
 177 static gfloat       (*fp_g_value_get_float)(const GValue *value);
 178 static gdouble      (*fp_g_value_get_double)(const GValue *value);
 179 static const gchar* (*fp_g_value_get_string)(const GValue *value);
 180 static gint         (*fp_g_value_get_enum)(const GValue *value);
 181 static guint        (*fp_g_value_get_flags)(const GValue *value);
 182 static GParamSpec*  (*fp_g_value_get_param)(const GValue *value);
 183 static gpointer*    (*fp_g_value_get_boxed)(const GValue *value);
 184 static gpointer*    (*fp_g_value_get_pointer)(const GValue *value);
 185 static GObject*     (*fp_g_value_get_object)(const GValue *value);
 186 static GParamSpec*  (*fp_g_param_spec_int)(const gchar *name,
 187         const gchar *nick, const gchar *blurb,
 188         gint minimum, gint maximum, gint default_value,
 189         GParamFlags flags);
 190 static void         (*fp_g_object_get)(gpointer object,
 191                                        const gchar* fpn, ...);
 192 static void         (*fp_g_object_set)(gpointer object,
 193                                        const gchar *first_property_name,
 194                                        ...);
 195 /************************
 196  * GDK function pointers
 197  ************************/
 198 static GdkPixmap *(*fp_gdk_pixmap_new)(GdkDrawable *drawable,
 199         gint width, gint height, gint depth);
 200 static GdkGC *(*fp_gdk_gc_new)(GdkDrawable*);
 201 static void (*fp_gdk_rgb_gc_set_foreground)(GdkGC*, guint32);
 202 static void (*fp_gdk_draw_rectangle)(GdkDrawable*, GdkGC*, gboolean,
 203         gint, gint, gint, gint);
 204 static GdkPixbuf *(*fp_gdk_pixbuf_new)(GdkColorspace colorspace,
 205         gboolean has_alpha, int bits_per_sample, int width, int height);
 206 static void (*fp_gdk_drawable_get_size)(GdkDrawable *drawable,
 207         gint* width, gint* height);
 208 
 209 /************************
 210  * Gtk function pointers
 211  ************************/
 212 static gboolean (*fp_gtk_init_check)(int* argc, char** argv);
 213 
 214 /* Painting */
 215 static void (*fp_gtk_paint_hline)(GtkStyle* style, GdkWindow* window,
 216         GtkStateType state_type, GdkRectangle* area, GtkWidget* widget,
 217         const gchar* detail, gint x1, gint x2, gint y);
 218 static void (*fp_gtk_paint_vline)(GtkStyle* style, GdkWindow* window,
 219         GtkStateType state_type, GdkRectangle* area, GtkWidget* widget,
 220         const gchar* detail, gint y1, gint y2, gint x);
 221 static void (*fp_gtk_paint_shadow)(GtkStyle* style, GdkWindow* window,
 222         GtkStateType state_type, GtkShadowType shadow_type,
 223         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 224         gint x, gint y, gint width, gint height);
 225 static void (*fp_gtk_paint_arrow)(GtkStyle* style, GdkWindow* window,
 226         GtkStateType state_type, GtkShadowType shadow_type,
 227         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 228         GtkArrowType arrow_type, gboolean fill, gint x, gint y,
 229         gint width, gint height);
 230 static void (*fp_gtk_paint_diamond)(GtkStyle* style, GdkWindow* window,
 231         GtkStateType state_type, GtkShadowType shadow_type,
 232         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 233         gint x, gint y, gint width, gint height);
 234 static void (*fp_gtk_paint_box)(GtkStyle* style, GdkWindow* window,
 235         GtkStateType state_type, GtkShadowType shadow_type,
 236         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 237         gint x, gint y, gint width, gint height);
 238 static void (*fp_gtk_paint_flat_box)(GtkStyle* style, GdkWindow* window,
 239         GtkStateType state_type, GtkShadowType shadow_type,
 240         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 241         gint x, gint y, gint width, gint height);
 242 static void (*fp_gtk_paint_check)(GtkStyle* style, GdkWindow* window,
 243         GtkStateType state_type, GtkShadowType shadow_type,
 244         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 245         gint x, gint y, gint width, gint height);
 246 static void (*fp_gtk_paint_option)(GtkStyle* style, GdkWindow* window,
 247         GtkStateType state_type, GtkShadowType shadow_type,
 248         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 249         gint x, gint y, gint width, gint height);
 250 static void (*fp_gtk_paint_box_gap)(GtkStyle* style, GdkWindow* window,
 251         GtkStateType state_type, GtkShadowType shadow_type,
 252         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 253         gint x, gint y, gint width, gint height,
 254         GtkPositionType gap_side, gint gap_x, gint gap_width);
 255 static void (*fp_gtk_paint_extension)(GtkStyle* style, GdkWindow* window,
 256         GtkStateType state_type, GtkShadowType shadow_type,
 257         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 258         gint x, gint y, gint width, gint height, GtkPositionType gap_side);
 259 static void (*fp_gtk_paint_focus)(GtkStyle* style, GdkWindow* window,
 260         GtkStateType state_type, GdkRectangle* area, GtkWidget* widget,
 261         const gchar* detail, gint x, gint y, gint width, gint height);
 262 static void (*fp_gtk_paint_slider)(GtkStyle* style, GdkWindow* window,
 263         GtkStateType state_type, GtkShadowType shadow_type,
 264         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 265         gint x, gint y, gint width, gint height, GtkOrientation orientation);
 266 static void (*fp_gtk_paint_handle)(GtkStyle* style, GdkWindow* window,
 267         GtkStateType state_type, GtkShadowType shadow_type,
 268         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 269         gint x, gint y, gint width, gint height, GtkOrientation orientation);
 270 static void (*fp_gtk_paint_expander)(GtkStyle* style, GdkWindow* window,
 271         GtkStateType state_type, GdkRectangle* area, GtkWidget* widget,
 272         const gchar* detail, gint x, gint y, GtkExpanderStyle expander_style);
 273 static void (*fp_gtk_style_apply_default_background)(GtkStyle* style,
 274         GdkWindow* window, gboolean set_bg, GtkStateType state_type,
 275         GdkRectangle* area, gint x, gint y, gint width, gint height);
 276 
 277 /* Widget creation */
 278 static GtkWidget* (*fp_gtk_arrow_new)(GtkArrowType arrow_type,
 279                                       GtkShadowType shadow_type);
 280 static GtkWidget* (*fp_gtk_button_new)();
 281 static GtkWidget* (*fp_gtk_check_button_new)();
 282 static GtkWidget* (*fp_gtk_check_menu_item_new)();
 283 static GtkWidget* (*fp_gtk_color_selection_dialog_new)(const gchar* title);
 284 static GtkWidget* (*fp_gtk_combo_box_new)();
 285 static GtkWidget* (*fp_gtk_combo_box_entry_new)();
 286 static GtkWidget* (*fp_gtk_entry_new)();
 287 static GtkWidget* (*fp_gtk_fixed_new)();
 288 static GtkWidget* (*fp_gtk_handle_box_new)();
 289 static GtkWidget* (*fp_gtk_hpaned_new)();
 290 static GtkWidget* (*fp_gtk_vpaned_new)();
 291 static GtkWidget* (*fp_gtk_hscale_new)(GtkAdjustment* adjustment);
 292 static GtkWidget* (*fp_gtk_vscale_new)(GtkAdjustment* adjustment);
 293 static GtkWidget* (*fp_gtk_hscrollbar_new)(GtkAdjustment* adjustment);
 294 static GtkWidget* (*fp_gtk_vscrollbar_new)(GtkAdjustment* adjustment);
 295 static GtkWidget* (*fp_gtk_hseparator_new)();
 296 static GtkWidget* (*fp_gtk_vseparator_new)();
 297 static GtkWidget* (*fp_gtk_image_new)();
 298 static GtkWidget* (*fp_gtk_label_new)(const gchar* str);
 299 static GtkWidget* (*fp_gtk_menu_new)();
 300 static GtkWidget* (*fp_gtk_menu_bar_new)();
 301 static GtkWidget* (*fp_gtk_menu_item_new)();
 302 static GtkWidget* (*fp_gtk_notebook_new)();
 303 static GtkWidget* (*fp_gtk_progress_bar_new)();
 304 static GtkWidget* (*fp_gtk_progress_bar_set_orientation)(
 305         GtkProgressBar *pbar,
 306         GtkProgressBarOrientation orientation);
 307 static GtkWidget* (*fp_gtk_radio_button_new)(GSList *group);
 308 static GtkWidget* (*fp_gtk_radio_menu_item_new)(GSList *group);
 309 static GtkWidget* (*fp_gtk_scrolled_window_new)(GtkAdjustment *hadjustment,
 310         GtkAdjustment *vadjustment);
 311 static GtkWidget* (*fp_gtk_separator_menu_item_new)();
 312 static GtkWidget* (*fp_gtk_separator_tool_item_new)();
 313 static GtkWidget* (*fp_gtk_text_view_new)();
 314 static GtkWidget* (*fp_gtk_toggle_button_new)();
 315 static GtkWidget* (*fp_gtk_toolbar_new)();
 316 static GtkWidget* (*fp_gtk_tree_view_new)();
 317 static GtkWidget* (*fp_gtk_viewport_new)(GtkAdjustment *hadjustment,
 318         GtkAdjustment *vadjustment);
 319 static GtkWidget* (*fp_gtk_window_new)(GtkWindowType type);
 320 static GtkWidget* (*fp_gtk_dialog_new)();
 321 static GtkWidget* (*fp_gtk_spin_button_new)(GtkAdjustment *adjustment,
 322         gdouble climb_rate, guint digits);
 323 static GtkWidget* (*fp_gtk_frame_new)(const gchar *label);
 324 
 325 /* Other widget operations */
 326 static GtkObject* (*fp_gtk_adjustment_new)(gdouble value,
 327         gdouble lower, gdouble upper, gdouble step_increment,
 328         gdouble page_increment, gdouble page_size);
 329 static void (*fp_gtk_container_add)(GtkContainer *window, GtkWidget *widget);
 330 static void (*fp_gtk_menu_shell_append)(GtkMenuShell *menu_shell,
 331         GtkWidget *child);
 332 static void (*fp_gtk_menu_item_set_submenu)(GtkMenuItem *menu_item,
 333         GtkWidget *submenu);
 334 static void (*fp_gtk_widget_realize)(GtkWidget *widget);
 335 static GdkPixbuf* (*fp_gtk_widget_render_icon)(GtkWidget *widget,
 336         const gchar *stock_id, GtkIconSize size, const gchar *detail);
 337 static void (*fp_gtk_widget_set_name)(GtkWidget *widget, const gchar *name);
 338 static void (*fp_gtk_widget_set_parent)(GtkWidget *widget, GtkWidget *parent);
 339 static void (*fp_gtk_widget_set_direction)(GtkWidget *widget,
 340         GtkTextDirection direction);
 341 static void (*fp_gtk_widget_style_get)(GtkWidget *widget,
 342         const gchar *first_property_name, ...);
 343 static void (*fp_gtk_widget_class_install_style_property)(
 344         GtkWidgetClass* class, GParamSpec *pspec);
 345 static GParamSpec* (*fp_gtk_widget_class_find_style_property)(
 346         GtkWidgetClass* class, const gchar* property_name);
 347 static void (*fp_gtk_widget_style_get_property)(GtkWidget* widget,
 348         const gchar* property_name, GValue* value);
 349 static char* (*fp_pango_font_description_to_string)(
 350         const PangoFontDescription* fd);
 351 static GtkSettings* (*fp_gtk_settings_get_default)();
 352 static GtkSettings* (*fp_gtk_widget_get_settings)(GtkWidget *widget);
 353 static GType        (*fp_gtk_border_get_type)();
 354 static void (*fp_gtk_arrow_set)(GtkWidget* arrow,
 355                                 GtkArrowType arrow_type,
 356                                 GtkShadowType shadow_type);
 357 static void (*fp_gtk_widget_size_request)(GtkWidget *widget,
 358                                           GtkRequisition *requisition);
 359 static GtkAdjustment* (*fp_gtk_range_get_adjustment)(GtkRange* range);
 360 
 361 /* Method bodies */
 362 const char *getStrFor(JNIEnv *env, jstring val)
 363 {
 364     int length = (*env)->GetStringLength(env, val);
 365     if (length > CONV_BUFFER_SIZE-1)
 366     {
 367         length = CONV_BUFFER_SIZE-1;
 368 #ifdef DEBUG
 369         fprintf(stderr, "Note: Detail is too long: %d chars\n", length);
 370 #endif /* DEBUG */
 371     }
 372 
 373     (*env)->GetStringUTFRegion(env, val, 0, length, convertionBuffer);
 374     return convertionBuffer;
 375 }
 376 
 377 static void throw_exception(JNIEnv *env, const char* name, const char* message)
 378 {
 379     jclass class = (*env)->FindClass(env, name);
 380 
 381     if (class != NULL)
 382         (*env)->ThrowNew(env, class, message);
 383 
 384     (*env)->DeleteLocalRef(env, class);
 385 }
 386 
 387 /* This is a workaround for the bug:
 388  * http://sourceware.org/bugzilla/show_bug.cgi?id=1814
 389  * (dlsym/dlopen clears dlerror state)
 390  * This bug is specific to Linux, but there is no harm in
 391  * applying this workaround on Solaris as well.
 392  */
 393 static void* dl_symbol(const char* name)
 394 {
 395     void* result = dlsym(gtk2_libhandle, name);
 396     if (!result)
 397         longjmp(j, NO_SYMBOL_EXCEPTION);
 398 
 399     return result;
 400 }
 401 
 402 static void* dl_symbol_gthread(const char* name)
 403 {
 404     void* result = dlsym(gthread_libhandle, name);
 405     if (!result)
 406         longjmp(j, NO_SYMBOL_EXCEPTION);
 407 
 408     return result;
 409 }
 410 
 411 gboolean gtk2_check_version()
 412 {
 413     if (gtk2_libhandle != NULL) {
 414         /* We've already successfully opened the GTK libs, so return true. */
 415         return TRUE;
 416     } else {
 417         void *lib = NULL;
 418         gboolean result = FALSE;
 419 
 420         lib = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 421         if (lib == NULL) {
 422             lib = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
 423             if (lib == NULL) {
 424                 return FALSE;
 425             }
 426         }
 427 
 428         fp_gtk_check_version = dlsym(lib, "gtk_check_version");
 429         /* Check for GTK 2.2+ */
 430         if (!fp_gtk_check_version(2, 2, 0)) {
 431             result = TRUE;
 432         }
 433 
 434         // 8048289: workaround for https://bugzilla.gnome.org/show_bug.cgi?id=733065
 435         // dlclose(lib);
 436 
 437         return result;
 438     }
 439 }
 440 
 441 #define ADD_SUPPORTED_ACTION(actionStr) \
 442 do { \
 443     jfieldID fld_action = (*env)->GetStaticFieldID(env, cls_action, actionStr, "Ljava/awt/Desktop$Action;"); \
 444     if (!(*env)->ExceptionCheck(env)) { \
 445         jobject action = (*env)->GetStaticObjectField(env, cls_action, fld_action); \
 446         (*env)->CallBooleanMethod(env, supportedActions, mid_arrayListAdd, action); \
 447     } else { \
 448         (*env)->ExceptionClear(env); \
 449     } \
 450 } while(0);
 451 
 452 
 453 void update_supported_actions(JNIEnv *env) {
 454     GVfs * (*fp_g_vfs_get_default) (void);
 455     const gchar * const * (*fp_g_vfs_get_supported_uri_schemes) (GVfs * vfs);
 456     const gchar * const * schemes = NULL;
 457 
 458     jclass cls_action = (*env)->FindClass(env, "java/awt/Desktop$Action");
 459     CHECK_NULL(cls_action);
 460     jclass cls_xDesktopPeer = (*env)->FindClass(env, "sun/awt/X11/XDesktopPeer");
 461     CHECK_NULL(cls_xDesktopPeer);
 462     jfieldID fld_supportedActions = (*env)->GetStaticFieldID(env, cls_xDesktopPeer, "supportedActions", "Ljava/util/List;");
 463     CHECK_NULL(fld_supportedActions);
 464     jobject supportedActions = (*env)->GetStaticObjectField(env, cls_xDesktopPeer, fld_supportedActions);
 465 
 466     jclass cls_arrayList = (*env)->FindClass(env, "java/util/ArrayList");
 467     CHECK_NULL(cls_arrayList);
 468     jmethodID mid_arrayListAdd = (*env)->GetMethodID(env, cls_arrayList, "add", "(Ljava/lang/Object;)Z");
 469     CHECK_NULL(mid_arrayListAdd);
 470     jmethodID mid_arrayListClear = (*env)->GetMethodID(env, cls_arrayList, "clear", "()V");
 471     CHECK_NULL(mid_arrayListClear);
 472 
 473     (*env)->CallVoidMethod(env, supportedActions, mid_arrayListClear);
 474 
 475     ADD_SUPPORTED_ACTION("OPEN");
 476 
 477     /**
 478      * gtk_show_uri() documentation says:
 479      *
 480      * > you need to install gvfs to get support for uri schemes such as http://
 481      * > or ftp://, as only local files are handled by GIO itself.
 482      *
 483      * So OPEN action was safely added here.
 484      * However, it looks like Solaris 11 have gvfs support only for 32-bit
 485      * applications only by default.
 486      */
 487 
 488     fp_g_vfs_get_default = dl_symbol("g_vfs_get_default");
 489     fp_g_vfs_get_supported_uri_schemes = dl_symbol("g_vfs_get_supported_uri_schemes");
 490     dlerror();
 491 
 492     if (fp_g_vfs_get_default && fp_g_vfs_get_supported_uri_schemes) {
 493         GVfs * vfs = fp_g_vfs_get_default();
 494         schemes = vfs ? fp_g_vfs_get_supported_uri_schemes(vfs) : NULL;
 495         if (schemes) {
 496             int i = 0;
 497             while (schemes[i]) {
 498                 if (strcmp(schemes[i], "http") == 0) {
 499                     ADD_SUPPORTED_ACTION("BROWSE");
 500                     ADD_SUPPORTED_ACTION("MAIL");
 501                     break;
 502                 }
 503                 i++;
 504             }
 505         }
 506     } else {
 507 #ifdef DEBUG
 508         fprintf(stderr, "Cannot load g_vfs_get_supported_uri_schemes\n");
 509 #endif /* DEBUG */
 510     }
 511 
 512 }
 513 /**
 514  * Functions for awt_Desktop.c
 515  */
 516 gboolean gtk2_show_uri_load(JNIEnv *env) {
 517      gboolean success = FALSE;
 518      dlerror();
 519      const char *gtk_version = fp_gtk_check_version(2, 14, 0);
 520      if (gtk_version != NULL) {
 521          // The gtk_show_uri is available from GTK+ 2.14
 522 #ifdef DEBUG
 523          fprintf (stderr, "The version of GTK is %s. "
 524              "The gtk_show_uri function is supported "
 525              "since GTK+ 2.14.\n", gtk_version);
 526 #endif /* DEBUG */
 527      } else {
 528          // Loading symbols only if the GTK version is 2.14 and higher
 529          fp_gtk_show_uri = dl_symbol("gtk_show_uri");
 530          const char *dlsym_error = dlerror();
 531          if (dlsym_error) {
 532 #ifdef DEBUG
 533              fprintf (stderr, "Cannot load symbol: %s \n", dlsym_error);
 534 #endif /* DEBUG */
 535          } else if (fp_gtk_show_uri == NULL) {
 536 #ifdef DEBUG
 537              fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n");
 538 #endif /* DEBUG */
 539         } else {
 540             update_supported_actions(env);
 541             success = TRUE;
 542         }
 543      }
 544      return success;
 545 }
 546 
 547 /**
 548  * Functions for sun_awt_X11_GtkFileDialogPeer.c
 549  */
 550 void gtk2_file_chooser_load()
 551 {
 552     fp_gtk_file_chooser_get_filename = dl_symbol(
 553             "gtk_file_chooser_get_filename");
 554     fp_gtk_file_chooser_dialog_new = dl_symbol("gtk_file_chooser_dialog_new");
 555     fp_gtk_file_chooser_set_current_folder = dl_symbol(
 556             "gtk_file_chooser_set_current_folder");
 557     fp_gtk_file_chooser_set_filename = dl_symbol(
 558             "gtk_file_chooser_set_filename");
 559     fp_gtk_file_chooser_set_current_name = dl_symbol(
 560             "gtk_file_chooser_set_current_name");
 561     fp_gtk_file_filter_add_custom = dl_symbol("gtk_file_filter_add_custom");
 562     fp_gtk_file_chooser_set_filter = dl_symbol("gtk_file_chooser_set_filter");
 563     fp_gtk_file_chooser_get_type = dl_symbol("gtk_file_chooser_get_type");
 564     fp_gtk_file_filter_new = dl_symbol("gtk_file_filter_new");
 565     if (fp_gtk_check_version(2, 8, 0) == NULL) {
 566         fp_gtk_file_chooser_set_do_overwrite_confirmation = dl_symbol(
 567                 "gtk_file_chooser_set_do_overwrite_confirmation");
 568     }
 569     fp_gtk_file_chooser_set_select_multiple = dl_symbol(
 570             "gtk_file_chooser_set_select_multiple");
 571     fp_gtk_file_chooser_get_current_folder = dl_symbol(
 572             "gtk_file_chooser_get_current_folder");
 573     fp_gtk_file_chooser_get_filenames = dl_symbol(
 574             "gtk_file_chooser_get_filenames");
 575     fp_gtk_g_slist_length = dl_symbol("g_slist_length");
 576     fp_gdk_x11_drawable_get_xid = dl_symbol("gdk_x11_drawable_get_xid");
 577 }
 578 
 579 gboolean gtk2_load(JNIEnv *env)
 580 {
 581     gboolean result;
 582     int i;
 583     int (*handler)();
 584     int (*io_handler)();
 585     char *gtk_modules_env;
 586 
 587     gtk2_libhandle = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 588     if (gtk2_libhandle == NULL) {
 589         gtk2_libhandle = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
 590         if (gtk2_libhandle == NULL)
 591             return FALSE;
 592     }
 593 
 594     gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 595     if (gthread_libhandle == NULL) {
 596         gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL);
 597         if (gthread_libhandle == NULL)
 598             return FALSE;
 599     }
 600 
 601     if (setjmp(j) == 0)
 602     {
 603         fp_gtk_check_version = dl_symbol("gtk_check_version");
 604         /* Check for GTK 2.2+ */
 605         if (fp_gtk_check_version(2, 2, 0)) {
 606             longjmp(j, NO_SYMBOL_EXCEPTION);
 607         }
 608 
 609         /* GLib */
 610         fp_glib_check_version = dlsym(gtk2_libhandle, "glib_check_version");
 611         if (!fp_glib_check_version) {
 612             dlerror();
 613         }
 614         fp_g_free = dl_symbol("g_free");
 615         fp_g_object_unref = dl_symbol("g_object_unref");
 616 
 617         fp_g_main_context_iteration =
 618             dl_symbol("g_main_context_iteration");
 619 
 620         fp_g_value_init = dl_symbol("g_value_init");
 621         fp_g_type_is_a = dl_symbol("g_type_is_a");
 622 
 623         fp_g_value_get_boolean = dl_symbol("g_value_get_boolean");
 624         fp_g_value_get_char = dl_symbol("g_value_get_char");
 625         fp_g_value_get_uchar = dl_symbol("g_value_get_uchar");
 626         fp_g_value_get_int = dl_symbol("g_value_get_int");
 627         fp_g_value_get_uint = dl_symbol("g_value_get_uint");
 628         fp_g_value_get_long = dl_symbol("g_value_get_long");
 629         fp_g_value_get_ulong = dl_symbol("g_value_get_ulong");
 630         fp_g_value_get_int64 = dl_symbol("g_value_get_int64");
 631         fp_g_value_get_uint64 = dl_symbol("g_value_get_uint64");
 632         fp_g_value_get_float = dl_symbol("g_value_get_float");
 633         fp_g_value_get_double = dl_symbol("g_value_get_double");
 634         fp_g_value_get_string = dl_symbol("g_value_get_string");
 635         fp_g_value_get_enum = dl_symbol("g_value_get_enum");
 636         fp_g_value_get_flags = dl_symbol("g_value_get_flags");
 637         fp_g_value_get_param = dl_symbol("g_value_get_param");
 638         fp_g_value_get_boxed = dl_symbol("g_value_get_boxed");
 639         fp_g_value_get_pointer = dl_symbol("g_value_get_pointer");
 640         fp_g_value_get_object = dl_symbol("g_value_get_object");
 641         fp_g_param_spec_int = dl_symbol("g_param_spec_int");
 642         fp_g_object_get = dl_symbol("g_object_get");
 643         fp_g_object_set = dl_symbol("g_object_set");
 644 
 645         /* GDK */
 646         fp_gdk_get_default_root_window =
 647             dl_symbol("gdk_get_default_root_window");
 648         fp_gdk_pixmap_new = dl_symbol("gdk_pixmap_new");
 649         fp_gdk_pixbuf_get_from_drawable =
 650             dl_symbol("gdk_pixbuf_get_from_drawable");
 651         fp_gdk_pixbuf_scale_simple =
 652             dl_symbol("gdk_pixbuf_scale_simple");
 653         fp_gdk_gc_new = dl_symbol("gdk_gc_new");
 654         fp_gdk_rgb_gc_set_foreground =
 655             dl_symbol("gdk_rgb_gc_set_foreground");
 656         fp_gdk_draw_rectangle = dl_symbol("gdk_draw_rectangle");
 657         fp_gdk_drawable_get_size = dl_symbol("gdk_drawable_get_size");
 658 
 659         /* Pixbuf */
 660         fp_gdk_pixbuf_new = dl_symbol("gdk_pixbuf_new");
 661         fp_gdk_pixbuf_new_from_file =
 662                 dl_symbol("gdk_pixbuf_new_from_file");
 663         fp_gdk_pixbuf_get_width = dl_symbol("gdk_pixbuf_get_width");
 664         fp_gdk_pixbuf_get_height = dl_symbol("gdk_pixbuf_get_height");
 665         fp_gdk_pixbuf_get_pixels = dl_symbol("gdk_pixbuf_get_pixels");
 666         fp_gdk_pixbuf_get_rowstride =
 667                 dl_symbol("gdk_pixbuf_get_rowstride");
 668         fp_gdk_pixbuf_get_has_alpha =
 669                 dl_symbol("gdk_pixbuf_get_has_alpha");
 670         fp_gdk_pixbuf_get_bits_per_sample =
 671                 dl_symbol("gdk_pixbuf_get_bits_per_sample");
 672         fp_gdk_pixbuf_get_n_channels =
 673                 dl_symbol("gdk_pixbuf_get_n_channels");
 674         fp_gdk_pixbuf_get_colorspace =
 675                 dl_symbol("gdk_pixbuf_get_colorspace");
 676 
 677         /* GTK painting */
 678         fp_gtk_init_check = dl_symbol("gtk_init_check");
 679         fp_gtk_paint_hline = dl_symbol("gtk_paint_hline");
 680         fp_gtk_paint_vline = dl_symbol("gtk_paint_vline");
 681         fp_gtk_paint_shadow = dl_symbol("gtk_paint_shadow");
 682         fp_gtk_paint_arrow = dl_symbol("gtk_paint_arrow");
 683         fp_gtk_paint_diamond = dl_symbol("gtk_paint_diamond");
 684         fp_gtk_paint_box = dl_symbol("gtk_paint_box");
 685         fp_gtk_paint_flat_box = dl_symbol("gtk_paint_flat_box");
 686         fp_gtk_paint_check = dl_symbol("gtk_paint_check");
 687         fp_gtk_paint_option = dl_symbol("gtk_paint_option");
 688         fp_gtk_paint_box_gap = dl_symbol("gtk_paint_box_gap");
 689         fp_gtk_paint_extension = dl_symbol("gtk_paint_extension");
 690         fp_gtk_paint_focus = dl_symbol("gtk_paint_focus");
 691         fp_gtk_paint_slider = dl_symbol("gtk_paint_slider");
 692         fp_gtk_paint_handle = dl_symbol("gtk_paint_handle");
 693         fp_gtk_paint_expander = dl_symbol("gtk_paint_expander");
 694         fp_gtk_style_apply_default_background =
 695                 dl_symbol("gtk_style_apply_default_background");
 696 
 697         /* GTK widgets */
 698         fp_gtk_arrow_new = dl_symbol("gtk_arrow_new");
 699         fp_gtk_button_new = dl_symbol("gtk_button_new");
 700         fp_gtk_spin_button_new = dl_symbol("gtk_spin_button_new");
 701         fp_gtk_check_button_new = dl_symbol("gtk_check_button_new");
 702         fp_gtk_check_menu_item_new =
 703                 dl_symbol("gtk_check_menu_item_new");
 704         fp_gtk_color_selection_dialog_new =
 705                 dl_symbol("gtk_color_selection_dialog_new");
 706         fp_gtk_entry_new = dl_symbol("gtk_entry_new");
 707         fp_gtk_fixed_new = dl_symbol("gtk_fixed_new");
 708         fp_gtk_handle_box_new = dl_symbol("gtk_handle_box_new");
 709         fp_gtk_image_new = dl_symbol("gtk_image_new");
 710         fp_gtk_hpaned_new = dl_symbol("gtk_hpaned_new");
 711         fp_gtk_vpaned_new = dl_symbol("gtk_vpaned_new");
 712         fp_gtk_hscale_new = dl_symbol("gtk_hscale_new");
 713         fp_gtk_vscale_new = dl_symbol("gtk_vscale_new");
 714         fp_gtk_hscrollbar_new = dl_symbol("gtk_hscrollbar_new");
 715         fp_gtk_vscrollbar_new = dl_symbol("gtk_vscrollbar_new");
 716         fp_gtk_hseparator_new = dl_symbol("gtk_hseparator_new");
 717         fp_gtk_vseparator_new = dl_symbol("gtk_vseparator_new");
 718         fp_gtk_label_new = dl_symbol("gtk_label_new");
 719         fp_gtk_menu_new = dl_symbol("gtk_menu_new");
 720         fp_gtk_menu_bar_new = dl_symbol("gtk_menu_bar_new");
 721         fp_gtk_menu_item_new = dl_symbol("gtk_menu_item_new");
 722         fp_gtk_menu_item_set_submenu =
 723                 dl_symbol("gtk_menu_item_set_submenu");
 724         fp_gtk_notebook_new = dl_symbol("gtk_notebook_new");
 725         fp_gtk_progress_bar_new =
 726             dl_symbol("gtk_progress_bar_new");
 727         fp_gtk_progress_bar_set_orientation =
 728             dl_symbol("gtk_progress_bar_set_orientation");
 729         fp_gtk_radio_button_new =
 730             dl_symbol("gtk_radio_button_new");
 731         fp_gtk_radio_menu_item_new =
 732             dl_symbol("gtk_radio_menu_item_new");
 733         fp_gtk_scrolled_window_new =
 734             dl_symbol("gtk_scrolled_window_new");
 735         fp_gtk_separator_menu_item_new =
 736             dl_symbol("gtk_separator_menu_item_new");
 737         fp_gtk_text_view_new = dl_symbol("gtk_text_view_new");
 738         fp_gtk_toggle_button_new =
 739             dl_symbol("gtk_toggle_button_new");
 740         fp_gtk_toolbar_new = dl_symbol("gtk_toolbar_new");
 741         fp_gtk_tree_view_new = dl_symbol("gtk_tree_view_new");
 742         fp_gtk_viewport_new = dl_symbol("gtk_viewport_new");
 743         fp_gtk_window_new = dl_symbol("gtk_window_new");
 744         fp_gtk_window_present = dl_symbol("gtk_window_present");
 745         fp_gtk_window_move = dl_symbol("gtk_window_move");
 746         fp_gtk_window_resize = dl_symbol("gtk_window_resize");
 747 
 748           fp_gtk_dialog_new = dl_symbol("gtk_dialog_new");
 749         fp_gtk_frame_new = dl_symbol("gtk_frame_new");
 750 
 751         fp_gtk_adjustment_new = dl_symbol("gtk_adjustment_new");
 752         fp_gtk_container_add = dl_symbol("gtk_container_add");
 753         fp_gtk_menu_shell_append =
 754             dl_symbol("gtk_menu_shell_append");
 755         fp_gtk_widget_realize = dl_symbol("gtk_widget_realize");
 756         fp_gtk_widget_destroy = dl_symbol("gtk_widget_destroy");
 757         fp_gtk_widget_render_icon =
 758             dl_symbol("gtk_widget_render_icon");
 759         fp_gtk_widget_set_name =
 760             dl_symbol("gtk_widget_set_name");
 761         fp_gtk_widget_set_parent =
 762             dl_symbol("gtk_widget_set_parent");
 763         fp_gtk_widget_set_direction =
 764             dl_symbol("gtk_widget_set_direction");
 765         fp_gtk_widget_style_get =
 766             dl_symbol("gtk_widget_style_get");
 767         fp_gtk_widget_class_install_style_property =
 768             dl_symbol("gtk_widget_class_install_style_property");
 769         fp_gtk_widget_class_find_style_property =
 770             dl_symbol("gtk_widget_class_find_style_property");
 771         fp_gtk_widget_style_get_property =
 772             dl_symbol("gtk_widget_style_get_property");
 773         fp_pango_font_description_to_string =
 774             dl_symbol("pango_font_description_to_string");
 775         fp_gtk_settings_get_default =
 776             dl_symbol("gtk_settings_get_default");
 777         fp_gtk_widget_get_settings =
 778             dl_symbol("gtk_widget_get_settings");
 779         fp_gtk_border_get_type =  dl_symbol("gtk_border_get_type");
 780         fp_gtk_arrow_set = dl_symbol("gtk_arrow_set");
 781         fp_gtk_widget_size_request =
 782             dl_symbol("gtk_widget_size_request");
 783         fp_gtk_range_get_adjustment =
 784             dl_symbol("gtk_range_get_adjustment");
 785 
 786         fp_gtk_widget_hide = dl_symbol("gtk_widget_hide");
 787         fp_gtk_main_quit = dl_symbol("gtk_main_quit");
 788         fp_g_signal_connect_data = dl_symbol("g_signal_connect_data");
 789         fp_gtk_widget_show = dl_symbol("gtk_widget_show");
 790         fp_gtk_main = dl_symbol("gtk_main");
 791 
 792         fp_g_path_get_dirname = dl_symbol("g_path_get_dirname");
 793 
 794         /**
 795          * GLib thread system
 796          */
 797         if (GLIB_CHECK_VERSION(2, 20, 0)) {
 798             fp_g_thread_get_initialized = dl_symbol_gthread("g_thread_get_initialized");
 799         }
 800         fp_g_thread_init = dl_symbol_gthread("g_thread_init");
 801         fp_gdk_threads_init = dl_symbol("gdk_threads_init");
 802         fp_gdk_threads_enter = dl_symbol("gdk_threads_enter");
 803         fp_gdk_threads_leave = dl_symbol("gdk_threads_leave");
 804 
 805         /**
 806          * Functions for sun_awt_X11_GtkFileDialogPeer.c
 807          */
 808         if (fp_gtk_check_version(2, 4, 0) == NULL) {
 809             // The current GtkFileChooser is available from GTK+ 2.4
 810             gtk2_file_chooser_load();
 811         }
 812 
 813         /* Some functions may be missing in pre-2.4 GTK.
 814            We handle them specially here.
 815          */
 816         fp_gtk_combo_box_new = dlsym(gtk2_libhandle, "gtk_combo_box_new");
 817         if (fp_gtk_combo_box_new == NULL) {
 818             fp_gtk_combo_box_new = dl_symbol("gtk_combo_new");
 819         }
 820 
 821         fp_gtk_combo_box_entry_new =
 822             dlsym(gtk2_libhandle, "gtk_combo_box_entry_new");
 823         if (fp_gtk_combo_box_entry_new == NULL) {
 824             fp_gtk_combo_box_entry_new = dl_symbol("gtk_combo_new");
 825             new_combo = FALSE;
 826         }
 827 
 828         fp_gtk_separator_tool_item_new =
 829             dlsym(gtk2_libhandle, "gtk_separator_tool_item_new");
 830         if (fp_gtk_separator_tool_item_new == NULL) {
 831             fp_gtk_separator_tool_item_new =
 832                 dl_symbol("gtk_vseparator_new");
 833         }




 834     }
 835     /* Now we have only one kind of exceptions: NO_SYMBOL_EXCEPTION
 836      * Otherwise we can check the return value of setjmp method.
 837      */
 838     else
 839     {
 840         dlclose(gtk2_libhandle);
 841         gtk2_libhandle = NULL;
 842 
 843         dlclose(gthread_libhandle);
 844         gthread_libhandle = NULL;
 845 
 846         return FALSE;
 847     }
 848 
 849     /*
 850      * Strip the AT-SPI GTK_MODULEs if present
 851      */
 852     gtk_modules_env = getenv ("GTK_MODULES");
 853 
 854     if (gtk_modules_env && strstr (gtk_modules_env, "atk-bridge") ||
 855         gtk_modules_env && strstr (gtk_modules_env, "gail"))
 856     {
 857         /* the new env will be smaller than the old one */
 858         gchar *s, *new_env = SAFE_SIZE_STRUCT_ALLOC(malloc,
 859                 sizeof(ENV_PREFIX), 1, strlen (gtk_modules_env));
 860 
 861         if (new_env != NULL )
 862         {
 863             /* careful, strtok modifies its args */
 864             gchar *tmp_env = strdup (gtk_modules_env);
 865             strcpy(new_env, ENV_PREFIX);
 866 
 867             /* strip out 'atk-bridge' and 'gail' */
 868             size_t PREFIX_LENGTH = strlen(ENV_PREFIX);
 869             while (s = strtok(tmp_env, ":"))
 870             {
 871                 if ((!strstr (s, "atk-bridge")) && (!strstr (s, "gail")))
 872                 {
 873                     if (strlen (new_env) > PREFIX_LENGTH) {
 874                         new_env = strcat (new_env, ":");
 875                     }
 876                     new_env = strcat(new_env, s);
 877                 }
 878                 if (tmp_env)
 879                 {
 880                     free (tmp_env);
 881                     tmp_env = NULL; /* next call to strtok arg1==NULL */
 882                 }
 883             }
 884             putenv (new_env);
 885             free (new_env);
 886             free (tmp_env);
 887         }
 888     }
 889 
 890     /*
 891      * GTK should be initialized with gtk_init_check() before use.
 892      *
 893      * gtk_init_check installs its own error handlers. It is critical that
 894      * we preserve error handler set from AWT. Otherwise we'll crash on
 895      * BadMatch errors which we would normally ignore. The IO error handler
 896      * is preserved here, too, just for consistency.
 897     */
 898     AWT_LOCK();
 899     handler = XSetErrorHandler(NULL);
 900     io_handler = XSetIOErrorHandler(NULL);
 901 
 902     if (fp_gtk_check_version(2, 2, 0) == NULL) {
 903         jclass clazz = (*env)->FindClass(env, "sun/misc/GThreadHelper");
 904         jmethodID mid_getAndSetInitializationNeededFlag =
 905                 (*env)->GetStaticMethodID(env, clazz, "getAndSetInitializationNeededFlag", "()Z");
 906         jmethodID mid_lock = (*env)->GetStaticMethodID(env, clazz, "lock", "()V");
 907         jmethodID mid_unlock = (*env)->GetStaticMethodID(env, clazz, "unlock", "()V");
 908 
 909         // Init the thread system to use GLib in a thread-safe mode
 910         (*env)->CallStaticVoidMethod(env, clazz, mid_lock);
 911         if ((*env)->ExceptionCheck(env)) {
 912             AWT_UNLOCK();
 913             return FALSE;
 914         }
 915 
 916         // Calling g_thread_init() multiple times leads to crash on GLib < 2.24
 917         // We can use g_thread_get_initialized () but it is available only for
 918         // GLib >= 2.20. We rely on GThreadHelper for GLib < 2.20.
 919         gboolean is_g_thread_get_initialized = FALSE;
 920         if (GLIB_CHECK_VERSION(2, 20, 0)) {
 921             is_g_thread_get_initialized = fp_g_thread_get_initialized();
 922         }
 923 
 924         if (!(*env)->CallStaticBooleanMethod(env, clazz, mid_getAndSetInitializationNeededFlag)) {
 925             if (!is_g_thread_get_initialized) {
 926                 fp_g_thread_init(NULL);
 927             }
 928 
 929             //According the GTK documentation, gdk_threads_init() should be
 930             //called before gtk_init() or gtk_init_check()
 931             fp_gdk_threads_init();
 932         }
 933         jthrowable pendExcpn = NULL;
 934         // Exception raised during mid_getAndSetInitializationNeededFlag
 935         // call is saved and error handling is done
 936         // after unlock method is called
 937         if ((pendExcpn = (*env)->ExceptionOccurred(env)) != NULL) {
 938             (*env)->ExceptionClear(env);
 939         }
 940         (*env)->CallStaticVoidMethod(env, clazz, mid_unlock);
 941         if (pendExcpn != NULL) {
 942             (*env)->Throw(env, pendExcpn);
 943         }
 944         // check if any exception occured during mid_unlock call
 945         if ((*env)->ExceptionCheck(env)) {
 946             AWT_UNLOCK();
 947             return FALSE;
 948         }
 949     }
 950     result = (*fp_gtk_init_check)(NULL, NULL);
 951 
 952     XSetErrorHandler(handler);
 953     XSetIOErrorHandler(io_handler);
 954     AWT_UNLOCK();
 955 
 956     /* Initialize widget array. */
 957     for (i = 0; i < _GTK_WIDGET_TYPE_SIZE; i++)
 958     {
 959         gtk2_widgets[i] = NULL;
 960     }
 961 
 962     return result;
 963 }
 964 
 965 int gtk2_unload()
 966 {
 967     int i;
 968     char *gtk2_error;
 969 
 970     if (!gtk2_libhandle)
 971         return TRUE;
 972 
 973     /* Release painting objects */
 974     if (gtk2_white_pixmap != NULL) {
 975         (*fp_g_object_unref)(gtk2_white_pixmap);
 976         (*fp_g_object_unref)(gtk2_black_pixmap);
 977         (*fp_g_object_unref)(gtk2_white_pixbuf);
 978         (*fp_g_object_unref)(gtk2_black_pixbuf);
 979         gtk2_white_pixmap = gtk2_black_pixmap =
 980             gtk2_white_pixbuf = gtk2_black_pixbuf = NULL;
 981     }
 982     gtk2_pixbuf_width = 0;
 983     gtk2_pixbuf_height = 0;
 984 
 985     if (gtk2_window != NULL) {
 986         /* Destroying toplevel widget will destroy all contained widgets */
 987         (*fp_gtk_widget_destroy)(gtk2_window);
 988 
 989         /* Unset some static data so they get reinitialized on next load */
 990         gtk2_window = NULL;
 991     }
 992 
 993     dlerror();
 994     dlclose(gtk2_libhandle);
 995     dlclose(gthread_libhandle);
 996     if ((gtk2_error = dlerror()) != NULL)
 997     {
 998         return FALSE;
 999     }
1000     return TRUE;
1001 }
1002 
1003 /* Dispatch all pending events from the GTK event loop.
1004  * This is needed to catch theme change and update widgets' style.
1005  */
1006 void flush_gtk_event_loop()
1007 {
1008     while( (*fp_g_main_context_iteration)(NULL, FALSE));
1009 }
1010 
1011 /*
1012  * Initialize components of containment hierarchy. This creates a GtkFixed
1013  * inside a GtkWindow. All widgets get realized.
1014  */
1015 static void init_containers()
1016 {
1017     if (gtk2_window == NULL)
1018     {
1019         gtk2_window = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
1020         gtk2_fixed = (GtkFixed *)(*fp_gtk_fixed_new)();
1021         (*fp_gtk_container_add)((GtkContainer*)gtk2_window,
1022                                 (GtkWidget *)gtk2_fixed);
1023         (*fp_gtk_widget_realize)(gtk2_window);
1024         (*fp_gtk_widget_realize)((GtkWidget *)gtk2_fixed);
1025     }
1026 }
1027 
1028 /*
1029  * Ensure everything is ready for drawing an element of the specified width
1030  * and height.
1031  *
1032  * We should somehow handle translucent images. GTK can draw to X Drawables
1033  * only, which don't support alpha. When we retrieve the image back from
1034  * the server, translucency information is lost. There're several ways to
1035  * work around this:
1036  * 1) Subclass GdkPixmap and cache translucent objects on client side. This
1037  * requires us to implement parts of X server drawing logic on client side.
1038  * Many X requests can potentially be "translucent"; e.g. XDrawLine with
1039  * fill=tile and a translucent tile is a "translucent" operation, whereas
1040  * XDrawLine with fill=solid is an "opaque" one. Moreover themes can (and some
1041  * do) intermix transparent and opaque operations which makes caching even
1042  * more problematic.
1043  * 2) Use Xorg 32bit ARGB visual when available. GDK has no native support
1044  * for it (as of version 2.6). Also even in JDS 3 Xorg does not support
1045  * these visuals by default, which makes optimizing for them pointless.
1046  * We can consider doing this at a later point when ARGB visuals become more
1047  * popular.
1048  * 3') GTK has plans to use Cairo as its graphical backend (presumably in
1049  * 2.8), and Cairo supports alpha. With it we could also get rid of the
1050  * unnecessary round trip to server and do all the drawing on client side.
1051  * 4) For now we draw to two different pixmaps and restore alpha channel by
1052  * comparing results. This can be optimized by using subclassed pixmap and
1053  * doing the second drawing only if necessary.
1054 */
1055 void gtk2_init_painting(JNIEnv *env, gint width, gint height)
1056 {
1057     GdkGC *gc;
1058     GdkPixbuf *white, *black;
1059 
1060     init_containers();
1061 
1062     if (gtk2_pixbuf_width < width || gtk2_pixbuf_height < height)
1063     {
1064         white = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
1065         black = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
1066 
1067         if (white == NULL || black == NULL)
1068         {
1069             snprintf(convertionBuffer, CONV_BUFFER_SIZE, "Couldn't create pixbuf of size %dx%d", width, height);
1070             throw_exception(env, "java/lang/RuntimeException", convertionBuffer);
1071             fp_gdk_threads_leave();
1072             return;
1073         }
1074 
1075         if (gtk2_white_pixmap != NULL) {
1076             /* free old stuff */
1077             (*fp_g_object_unref)(gtk2_white_pixmap);
1078             (*fp_g_object_unref)(gtk2_black_pixmap);
1079             (*fp_g_object_unref)(gtk2_white_pixbuf);
1080             (*fp_g_object_unref)(gtk2_black_pixbuf);
1081         }
1082 
1083         gtk2_white_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1);
1084         gtk2_black_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1);
1085 
1086         gtk2_white_pixbuf = white;
1087         gtk2_black_pixbuf = black;
1088 
1089         gtk2_pixbuf_width = width;
1090         gtk2_pixbuf_height = height;
1091     }
1092 
1093     /* clear the pixmaps */
1094     gc = (*fp_gdk_gc_new)(gtk2_white_pixmap);
1095     (*fp_gdk_rgb_gc_set_foreground)(gc, 0xffffff);
1096     (*fp_gdk_draw_rectangle)(gtk2_white_pixmap, gc, TRUE, 0, 0, width, height);
1097     (*fp_g_object_unref)(gc);
1098 
1099     gc = (*fp_gdk_gc_new)(gtk2_black_pixmap);
1100     (*fp_gdk_rgb_gc_set_foreground)(gc, 0x000000);
1101     (*fp_gdk_draw_rectangle)(gtk2_black_pixmap, gc, TRUE, 0, 0, width, height);
1102     (*fp_g_object_unref)(gc);
1103 }
1104 
1105 /*
1106  * Restore image from white and black pixmaps and copy it into destination
1107  * buffer. This method compares two pixbufs taken from white and black
1108  * pixmaps and decodes color and alpha components. Pixbufs are RGB without
1109  * alpha, destination buffer is ABGR.
1110  *
1111  * The return value is the transparency type of the resulting image, either
1112  * one of java_awt_Transparency_OPAQUE, java_awt_Transparency_BITMASK, and
1113  * java_awt_Transparency_TRANSLUCENT.
1114  */
1115 gint gtk2_copy_image(gint *dst, gint width, gint height)
1116 {
1117     gint i, j, r, g, b;
1118     guchar *white, *black;
1119     gint stride, padding;
1120     gboolean is_opaque = TRUE;
1121     gboolean is_bitmask = TRUE;
1122 
1123     (*fp_gdk_pixbuf_get_from_drawable)(gtk2_white_pixbuf, gtk2_white_pixmap,
1124             NULL, 0, 0, 0, 0, width, height);
1125     (*fp_gdk_pixbuf_get_from_drawable)(gtk2_black_pixbuf, gtk2_black_pixmap,
1126             NULL, 0, 0, 0, 0, width, height);
1127 
1128     white = (*fp_gdk_pixbuf_get_pixels)(gtk2_white_pixbuf);
1129     black = (*fp_gdk_pixbuf_get_pixels)(gtk2_black_pixbuf);
1130     stride = (*fp_gdk_pixbuf_get_rowstride)(gtk2_black_pixbuf);
1131     padding = stride - width * 4;
1132 
1133     for (i = 0; i < height; i++) {
1134         for (j = 0; j < width; j++) {
1135             int r1 = *white++;
1136             int r2 = *black++;
1137             int alpha = 0xff + r2 - r1;
1138 
1139             switch (alpha) {
1140                 case 0:       /* transparent pixel */
1141                     r = g = b = 0;
1142                     black += 3;
1143                     white += 3;
1144                     is_opaque = FALSE;
1145                     break;
1146 
1147                 case 0xff:    /* opaque pixel */
1148                     r = r2;
1149                     g = *black++;
1150                     b = *black++;
1151                     black++;
1152                     white += 3;
1153                     break;
1154 
1155                 default:      /* translucent pixel */
1156                     r = 0xff * r2 / alpha;
1157                     g = 0xff * *black++ / alpha;
1158                     b = 0xff * *black++ / alpha;
1159                     black++;
1160                     white += 3;
1161                     is_opaque = FALSE;
1162                     is_bitmask = FALSE;
1163                     break;
1164             }
1165 
1166             *dst++ = (alpha << 24 | r << 16 | g << 8 | b);
1167         }
1168 
1169         white += padding;
1170         black += padding;
1171     }
1172     return is_opaque ? java_awt_Transparency_OPAQUE :
1173                        (is_bitmask ? java_awt_Transparency_BITMASK :
1174                                      java_awt_Transparency_TRANSLUCENT);
1175 }
1176 
1177 static void
1178 gtk2_set_direction(GtkWidget *widget, GtkTextDirection dir)
1179 {
1180     /*
1181      * Some engines (inexplicably) look at the direction of the widget's
1182      * parent, so we need to set the direction of both the widget and its
1183      * parent.
1184      */
1185     (*fp_gtk_widget_set_direction)(widget, dir);
1186     if (widget->parent != NULL) {
1187         (*fp_gtk_widget_set_direction)(widget->parent, dir);
1188     }
1189 }
1190 
1191 /*
1192  * Initializes the widget to correct state for some engines.
1193  * This is a pure empirical method.
1194  */
1195 static void init_toggle_widget(WidgetType widget_type, gint synth_state)
1196 {
1197     gboolean is_active = ((synth_state & SELECTED) != 0);
1198 
1199     if (widget_type == RADIO_BUTTON ||
1200         widget_type == CHECK_BOX ||
1201         widget_type == TOGGLE_BUTTON) {
1202         ((GtkToggleButton*)gtk2_widget)->active = is_active;
1203     }
1204 
1205     if ((synth_state & FOCUSED) != 0) {
1206         ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS;
1207     } else {
1208         ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
1209     }
1210 
1211     if ((synth_state & MOUSE_OVER) != 0 && (synth_state & PRESSED) == 0 ||
1212            (synth_state & FOCUSED) != 0 && (synth_state & PRESSED) != 0) {
1213         gtk2_widget->state = GTK_STATE_PRELIGHT;
1214     } else if ((synth_state & DISABLED) != 0) {
1215         gtk2_widget->state = GTK_STATE_INSENSITIVE;
1216     } else {
1217         gtk2_widget->state = is_active ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL;
1218     }
1219 }
1220 
1221 /* GTK state_type filter */
1222 static GtkStateType get_gtk_state_type(WidgetType widget_type, gint synth_state)
1223 {
1224     GtkStateType result = GTK_STATE_NORMAL;
1225 
1226     if ((synth_state & DISABLED) != 0) {
1227         result = GTK_STATE_INSENSITIVE;
1228     } else if ((synth_state & PRESSED) != 0) {
1229         result = GTK_STATE_ACTIVE;
1230     } else if ((synth_state & MOUSE_OVER) != 0) {
1231         result = GTK_STATE_PRELIGHT;
1232     }
1233     return result;
1234 }
1235 
1236 /* GTK shadow_type filter */
1237 static GtkShadowType get_gtk_shadow_type(WidgetType widget_type, gint synth_state)
1238 {
1239     GtkShadowType result = GTK_SHADOW_OUT;
1240 
1241     if ((synth_state & SELECTED) != 0) {
1242         result = GTK_SHADOW_IN;
1243     }
1244     return result;
1245 }
1246 
1247 
1248 static GtkWidget* gtk2_get_arrow(GtkArrowType arrow_type, GtkShadowType shadow_type)
1249 {
1250     GtkWidget *arrow = NULL;
1251     if (NULL == gtk2_widgets[_GTK_ARROW_TYPE])
1252     {
1253         gtk2_widgets[_GTK_ARROW_TYPE] = (*fp_gtk_arrow_new)(arrow_type, shadow_type);
1254         (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, gtk2_widgets[_GTK_ARROW_TYPE]);
1255         (*fp_gtk_widget_realize)(gtk2_widgets[_GTK_ARROW_TYPE]);
1256     }
1257     arrow = gtk2_widgets[_GTK_ARROW_TYPE];
1258 
1259     (*fp_gtk_arrow_set)(arrow, arrow_type, shadow_type);
1260     return arrow;
1261 }
1262 
1263 static GtkAdjustment* create_adjustment()
1264 {
1265     return (GtkAdjustment *)
1266             (*fp_gtk_adjustment_new)(50.0, 0.0, 100.0, 10.0, 20.0, 20.0);
1267 }
1268 
1269 /**
1270  * Returns a pointer to the cached native widget for the specified widget
1271  * type.
1272  */
1273 static GtkWidget *gtk2_get_widget(WidgetType widget_type)
1274 {
1275     gboolean init_result = FALSE;
1276     GtkWidget *result = NULL;
1277     switch (widget_type)
1278     {
1279         case BUTTON:
1280         case TABLE_HEADER:
1281             if (init_result = (NULL == gtk2_widgets[_GTK_BUTTON_TYPE]))
1282             {
1283                 gtk2_widgets[_GTK_BUTTON_TYPE] = (*fp_gtk_button_new)();
1284             }
1285             result = gtk2_widgets[_GTK_BUTTON_TYPE];
1286             break;
1287         case CHECK_BOX:
1288             if (init_result = (NULL == gtk2_widgets[_GTK_CHECK_BUTTON_TYPE]))
1289             {
1290                 gtk2_widgets[_GTK_CHECK_BUTTON_TYPE] =
1291                     (*fp_gtk_check_button_new)();
1292             }
1293             result = gtk2_widgets[_GTK_CHECK_BUTTON_TYPE];
1294             break;
1295         case CHECK_BOX_MENU_ITEM:
1296             if (init_result = (NULL == gtk2_widgets[_GTK_CHECK_MENU_ITEM_TYPE]))
1297             {
1298                 gtk2_widgets[_GTK_CHECK_MENU_ITEM_TYPE] =
1299                     (*fp_gtk_check_menu_item_new)();
1300             }
1301             result = gtk2_widgets[_GTK_CHECK_MENU_ITEM_TYPE];
1302             break;
1303         /************************************************************
1304          *    Creation a dedicated color chooser is dangerous because
1305          * it deadlocks the EDT
1306          ************************************************************/
1307 /*        case COLOR_CHOOSER:
1308             if (init_result =
1309                     (NULL == gtk2_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE]))
1310             {
1311                 gtk2_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE] =
1312                     (*fp_gtk_color_selection_dialog_new)(NULL);
1313             }
1314             result = gtk2_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE];
1315             break;*/
1316         case COMBO_BOX:
1317             if (init_result = (NULL == gtk2_widgets[_GTK_COMBO_BOX_TYPE]))
1318             {
1319                 gtk2_widgets[_GTK_COMBO_BOX_TYPE] =
1320                     (*fp_gtk_combo_box_new)();
1321             }
1322             result = gtk2_widgets[_GTK_COMBO_BOX_TYPE];
1323             break;
1324         case COMBO_BOX_ARROW_BUTTON:
1325             if (init_result =
1326                     (NULL == gtk2_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE]))
1327             {
1328                 gtk2_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE] =
1329                      (*fp_gtk_toggle_button_new)();
1330             }
1331             result = gtk2_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE];
1332             break;
1333         case COMBO_BOX_TEXT_FIELD:
1334             if (init_result =
1335                     (NULL == gtk2_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE]))
1336             {
1337                 result = gtk2_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE] =
1338                      (*fp_gtk_entry_new)();
1339             }
1340             result = gtk2_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE];
1341             break;
1342         case DESKTOP_ICON:
1343         case INTERNAL_FRAME_TITLE_PANE:
1344         case LABEL:
1345             if (init_result = (NULL == gtk2_widgets[_GTK_LABEL_TYPE]))
1346             {
1347                 gtk2_widgets[_GTK_LABEL_TYPE] =
1348                     (*fp_gtk_label_new)(NULL);
1349             }
1350             result = gtk2_widgets[_GTK_LABEL_TYPE];
1351             break;
1352         case DESKTOP_PANE:
1353         case PANEL:
1354         case ROOT_PANE:
1355             if (init_result = (NULL == gtk2_widgets[_GTK_CONTAINER_TYPE]))
1356             {
1357                 /* There is no constructor for a container type.  I've
1358                  * chosen GtkFixed container since it has a default
1359                  * constructor.
1360                  */
1361                 gtk2_widgets[_GTK_CONTAINER_TYPE] =
1362                     (*fp_gtk_fixed_new)();
1363             }
1364             result = gtk2_widgets[_GTK_CONTAINER_TYPE];
1365             break;
1366         case EDITOR_PANE:
1367         case TEXT_AREA:
1368         case TEXT_PANE:
1369             if (init_result = (NULL == gtk2_widgets[_GTK_TEXT_VIEW_TYPE]))
1370             {
1371                 gtk2_widgets[_GTK_TEXT_VIEW_TYPE] =
1372                     (*fp_gtk_text_view_new)();
1373             }
1374             result = gtk2_widgets[_GTK_TEXT_VIEW_TYPE];
1375             break;
1376         case FORMATTED_TEXT_FIELD:
1377         case PASSWORD_FIELD:
1378         case TEXT_FIELD:
1379             if (init_result = (NULL == gtk2_widgets[_GTK_ENTRY_TYPE]))
1380             {
1381                 gtk2_widgets[_GTK_ENTRY_TYPE] =
1382                     (*fp_gtk_entry_new)();
1383             }
1384             result = gtk2_widgets[_GTK_ENTRY_TYPE];
1385             break;
1386         case HANDLE_BOX:
1387             if (init_result = (NULL == gtk2_widgets[_GTK_HANDLE_BOX_TYPE]))
1388             {
1389                 gtk2_widgets[_GTK_HANDLE_BOX_TYPE] =
1390                     (*fp_gtk_handle_box_new)();
1391             }
1392             result = gtk2_widgets[_GTK_HANDLE_BOX_TYPE];
1393             break;
1394         case HSCROLL_BAR:
1395         case HSCROLL_BAR_BUTTON_LEFT:
1396         case HSCROLL_BAR_BUTTON_RIGHT:
1397         case HSCROLL_BAR_TRACK:
1398         case HSCROLL_BAR_THUMB:
1399             if (init_result = (NULL == gtk2_widgets[_GTK_HSCROLLBAR_TYPE]))
1400             {
1401                 gtk2_widgets[_GTK_HSCROLLBAR_TYPE] =
1402                     (*fp_gtk_hscrollbar_new)(create_adjustment());
1403             }
1404             result = gtk2_widgets[_GTK_HSCROLLBAR_TYPE];
1405             break;
1406         case HSEPARATOR:
1407             if (init_result = (NULL == gtk2_widgets[_GTK_HSEPARATOR_TYPE]))
1408             {
1409                 gtk2_widgets[_GTK_HSEPARATOR_TYPE] =
1410                     (*fp_gtk_hseparator_new)();
1411             }
1412             result = gtk2_widgets[_GTK_HSEPARATOR_TYPE];
1413             break;
1414         case HSLIDER:
1415         case HSLIDER_THUMB:
1416         case HSLIDER_TRACK:
1417             if (init_result = (NULL == gtk2_widgets[_GTK_HSCALE_TYPE]))
1418             {
1419                 gtk2_widgets[_GTK_HSCALE_TYPE] =
1420                     (*fp_gtk_hscale_new)(NULL);
1421             }
1422             result = gtk2_widgets[_GTK_HSCALE_TYPE];
1423             break;
1424         case HSPLIT_PANE_DIVIDER:
1425         case SPLIT_PANE:
1426             if (init_result = (NULL == gtk2_widgets[_GTK_HPANED_TYPE]))
1427             {
1428                 gtk2_widgets[_GTK_HPANED_TYPE] = (*fp_gtk_hpaned_new)();
1429             }
1430             result = gtk2_widgets[_GTK_HPANED_TYPE];
1431             break;
1432         case IMAGE:
1433             if (init_result = (NULL == gtk2_widgets[_GTK_IMAGE_TYPE]))
1434             {
1435                 gtk2_widgets[_GTK_IMAGE_TYPE] = (*fp_gtk_image_new)();
1436             }
1437             result = gtk2_widgets[_GTK_IMAGE_TYPE];
1438             break;
1439         case INTERNAL_FRAME:
1440             if (init_result = (NULL == gtk2_widgets[_GTK_WINDOW_TYPE]))
1441             {
1442                 gtk2_widgets[_GTK_WINDOW_TYPE] =
1443                     (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
1444             }
1445             result = gtk2_widgets[_GTK_WINDOW_TYPE];
1446             break;
1447         case TOOL_TIP:
1448             if (init_result = (NULL == gtk2_widgets[_GTK_TOOLTIP_TYPE]))
1449             {
1450                 result = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
1451                 (*fp_gtk_widget_set_name)(result, "gtk-tooltips");
1452                 gtk2_widgets[_GTK_TOOLTIP_TYPE] = result;
1453             }
1454             result = gtk2_widgets[_GTK_TOOLTIP_TYPE];
1455             break;
1456         case LIST:
1457         case TABLE:
1458         case TREE:
1459         case TREE_CELL:
1460             if (init_result = (NULL == gtk2_widgets[_GTK_TREE_VIEW_TYPE]))
1461             {
1462                 gtk2_widgets[_GTK_TREE_VIEW_TYPE] =
1463                     (*fp_gtk_tree_view_new)();
1464             }
1465             result = gtk2_widgets[_GTK_TREE_VIEW_TYPE];
1466             break;
1467         case TITLED_BORDER:
1468             if (init_result = (NULL == gtk2_widgets[_GTK_FRAME_TYPE]))
1469             {
1470                 gtk2_widgets[_GTK_FRAME_TYPE] = fp_gtk_frame_new(NULL);
1471             }
1472             result = gtk2_widgets[_GTK_FRAME_TYPE];
1473             break;
1474         case POPUP_MENU:
1475             if (init_result = (NULL == gtk2_widgets[_GTK_MENU_TYPE]))
1476             {
1477                 gtk2_widgets[_GTK_MENU_TYPE] =
1478                     (*fp_gtk_menu_new)();
1479             }
1480             result = gtk2_widgets[_GTK_MENU_TYPE];
1481             break;
1482         case MENU:
1483         case MENU_ITEM:
1484         case MENU_ITEM_ACCELERATOR:
1485             if (init_result = (NULL == gtk2_widgets[_GTK_MENU_ITEM_TYPE]))
1486             {
1487                 gtk2_widgets[_GTK_MENU_ITEM_TYPE] =
1488                     (*fp_gtk_menu_item_new)();
1489             }
1490             result = gtk2_widgets[_GTK_MENU_ITEM_TYPE];
1491             break;
1492         case MENU_BAR:
1493             if (init_result = (NULL == gtk2_widgets[_GTK_MENU_BAR_TYPE]))
1494             {
1495                 gtk2_widgets[_GTK_MENU_BAR_TYPE] =
1496                     (*fp_gtk_menu_bar_new)();
1497             }
1498             result = gtk2_widgets[_GTK_MENU_BAR_TYPE];
1499             break;
1500         case COLOR_CHOOSER:
1501         case OPTION_PANE:
1502             if (init_result = (NULL == gtk2_widgets[_GTK_DIALOG_TYPE]))
1503             {
1504                 gtk2_widgets[_GTK_DIALOG_TYPE] =
1505                     (*fp_gtk_dialog_new)();
1506             }
1507             result = gtk2_widgets[_GTK_DIALOG_TYPE];
1508             break;
1509         case POPUP_MENU_SEPARATOR:
1510             if (init_result =
1511                     (NULL == gtk2_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE]))
1512             {
1513                 gtk2_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE] =
1514                     (*fp_gtk_separator_menu_item_new)();
1515             }
1516             result = gtk2_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE];
1517             break;
1518         case HPROGRESS_BAR:
1519             if (init_result = (NULL == gtk2_widgets[_GTK_HPROGRESS_BAR_TYPE]))
1520             {
1521                 gtk2_widgets[_GTK_HPROGRESS_BAR_TYPE] =
1522                     (*fp_gtk_progress_bar_new)();
1523             }
1524             result = gtk2_widgets[_GTK_HPROGRESS_BAR_TYPE];
1525             break;
1526         case VPROGRESS_BAR:
1527             if (init_result = (NULL == gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE]))
1528             {
1529                 gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE] =
1530                     (*fp_gtk_progress_bar_new)();
1531                 /*
1532                  * Vertical JProgressBars always go bottom-to-top,
1533                  * regardless of the ComponentOrientation.
1534                  */
1535                 (*fp_gtk_progress_bar_set_orientation)(
1536                     (GtkProgressBar *)gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE],
1537                     GTK_PROGRESS_BOTTOM_TO_TOP);
1538             }
1539             result = gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE];
1540             break;
1541         case RADIO_BUTTON:
1542             if (init_result = (NULL == gtk2_widgets[_GTK_RADIO_BUTTON_TYPE]))
1543             {
1544                 gtk2_widgets[_GTK_RADIO_BUTTON_TYPE] =
1545                     (*fp_gtk_radio_button_new)(NULL);
1546             }
1547             result = gtk2_widgets[_GTK_RADIO_BUTTON_TYPE];
1548             break;
1549         case RADIO_BUTTON_MENU_ITEM:
1550             if (init_result =
1551                     (NULL == gtk2_widgets[_GTK_RADIO_MENU_ITEM_TYPE]))
1552             {
1553                 gtk2_widgets[_GTK_RADIO_MENU_ITEM_TYPE] =
1554                     (*fp_gtk_radio_menu_item_new)(NULL);
1555             }
1556             result = gtk2_widgets[_GTK_RADIO_MENU_ITEM_TYPE];
1557             break;
1558         case SCROLL_PANE:
1559             if (init_result =
1560                     (NULL == gtk2_widgets[_GTK_SCROLLED_WINDOW_TYPE]))
1561             {
1562                 gtk2_widgets[_GTK_SCROLLED_WINDOW_TYPE] =
1563                     (*fp_gtk_scrolled_window_new)(NULL, NULL);
1564             }
1565             result = gtk2_widgets[_GTK_SCROLLED_WINDOW_TYPE];
1566             break;
1567         case SPINNER:
1568         case SPINNER_ARROW_BUTTON:
1569         case SPINNER_TEXT_FIELD:
1570             if (init_result = (NULL == gtk2_widgets[_GTK_SPIN_BUTTON_TYPE]))
1571             {
1572                 result = gtk2_widgets[_GTK_SPIN_BUTTON_TYPE] =
1573                     (*fp_gtk_spin_button_new)(NULL, 0, 0);
1574             }
1575             result = gtk2_widgets[_GTK_SPIN_BUTTON_TYPE];
1576             break;
1577         case TABBED_PANE:
1578         case TABBED_PANE_TAB_AREA:
1579         case TABBED_PANE_CONTENT:
1580         case TABBED_PANE_TAB:
1581             if (init_result = (NULL == gtk2_widgets[_GTK_NOTEBOOK_TYPE]))
1582             {
1583                 gtk2_widgets[_GTK_NOTEBOOK_TYPE] =
1584                     (*fp_gtk_notebook_new)(NULL);
1585             }
1586             result = gtk2_widgets[_GTK_NOTEBOOK_TYPE];
1587             break;
1588         case TOGGLE_BUTTON:
1589             if (init_result = (NULL == gtk2_widgets[_GTK_TOGGLE_BUTTON_TYPE]))
1590             {
1591                 gtk2_widgets[_GTK_TOGGLE_BUTTON_TYPE] =
1592                     (*fp_gtk_toggle_button_new)(NULL);
1593             }
1594             result = gtk2_widgets[_GTK_TOGGLE_BUTTON_TYPE];
1595             break;
1596         case TOOL_BAR:
1597         case TOOL_BAR_DRAG_WINDOW:
1598             if (init_result = (NULL == gtk2_widgets[_GTK_TOOLBAR_TYPE]))
1599             {
1600                 gtk2_widgets[_GTK_TOOLBAR_TYPE] =
1601                     (*fp_gtk_toolbar_new)(NULL);
1602             }
1603             result = gtk2_widgets[_GTK_TOOLBAR_TYPE];
1604             break;
1605         case TOOL_BAR_SEPARATOR:
1606             if (init_result =
1607                     (NULL == gtk2_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE]))
1608             {
1609                 gtk2_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE] =
1610                     (*fp_gtk_separator_tool_item_new)();
1611             }
1612             result = gtk2_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE];
1613             break;
1614         case VIEWPORT:
1615             if (init_result = (NULL == gtk2_widgets[_GTK_VIEWPORT_TYPE]))
1616             {
1617                 GtkAdjustment *adjustment = create_adjustment();
1618                 gtk2_widgets[_GTK_VIEWPORT_TYPE] =
1619                     (*fp_gtk_viewport_new)(adjustment, adjustment);
1620             }
1621             result = gtk2_widgets[_GTK_VIEWPORT_TYPE];
1622             break;
1623         case VSCROLL_BAR:
1624         case VSCROLL_BAR_BUTTON_UP:
1625         case VSCROLL_BAR_BUTTON_DOWN:
1626         case VSCROLL_BAR_TRACK:
1627         case VSCROLL_BAR_THUMB:
1628             if (init_result = (NULL == gtk2_widgets[_GTK_VSCROLLBAR_TYPE]))
1629             {
1630                 gtk2_widgets[_GTK_VSCROLLBAR_TYPE] =
1631                     (*fp_gtk_vscrollbar_new)(create_adjustment());
1632             }
1633             result = gtk2_widgets[_GTK_VSCROLLBAR_TYPE];
1634             break;
1635         case VSEPARATOR:
1636             if (init_result = (NULL == gtk2_widgets[_GTK_VSEPARATOR_TYPE]))
1637             {
1638                 gtk2_widgets[_GTK_VSEPARATOR_TYPE] =
1639                     (*fp_gtk_vseparator_new)();
1640             }
1641             result = gtk2_widgets[_GTK_VSEPARATOR_TYPE];
1642             break;
1643         case VSLIDER:
1644         case VSLIDER_THUMB:
1645         case VSLIDER_TRACK:
1646             if (init_result = (NULL == gtk2_widgets[_GTK_VSCALE_TYPE]))
1647             {
1648                 gtk2_widgets[_GTK_VSCALE_TYPE] =
1649                     (*fp_gtk_vscale_new)(NULL);
1650             }
1651             result = gtk2_widgets[_GTK_VSCALE_TYPE];
1652             /*
1653              * Vertical JSliders start at the bottom, while vertical
1654              * GtkVScale widgets start at the top (by default), so to fix
1655              * this we set the "inverted" flag to get the Swing behavior.
1656              */
1657             ((GtkRange*)result)->inverted = 1;
1658             break;
1659         case VSPLIT_PANE_DIVIDER:
1660             if (init_result = (NULL == gtk2_widgets[_GTK_VPANED_TYPE]))
1661             {
1662                 gtk2_widgets[_GTK_VPANED_TYPE] = (*fp_gtk_vpaned_new)();
1663             }
1664             result = gtk2_widgets[_GTK_VPANED_TYPE];
1665             break;
1666         default:
1667             result = NULL;
1668             break;
1669     }
1670 
1671     if (result != NULL && init_result)
1672     {
1673         if (widget_type == RADIO_BUTTON_MENU_ITEM ||
1674                 widget_type == CHECK_BOX_MENU_ITEM ||
1675                 widget_type == MENU_ITEM ||
1676                 widget_type == MENU ||
1677                 widget_type == POPUP_MENU_SEPARATOR)
1678         {
1679             GtkWidget *menu = gtk2_get_widget(POPUP_MENU);
1680             (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu, result);
1681         }
1682         else if (widget_type == POPUP_MENU)
1683         {
1684             GtkWidget *menu_bar = gtk2_get_widget(MENU_BAR);
1685             GtkWidget *root_menu = (*fp_gtk_menu_item_new)();
1686             (*fp_gtk_menu_item_set_submenu)((GtkMenuItem*)root_menu, result);
1687             (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu_bar, root_menu);
1688         }
1689         else if (widget_type == COMBO_BOX_ARROW_BUTTON ||
1690                  widget_type == COMBO_BOX_TEXT_FIELD)
1691         {
1692             /*
1693             * We add a regular GtkButton/GtkEntry to a GtkComboBoxEntry
1694             * in order to trick engines into thinking it's a real combobox
1695             * arrow button/text field.
1696             */
1697             GtkWidget *combo = (*fp_gtk_combo_box_entry_new)();
1698 
1699             if (new_combo && widget_type == COMBO_BOX_ARROW_BUTTON) {
1700                 (*fp_gtk_widget_set_parent)(result, combo);
1701                 ((GtkBin*)combo)->child = result;
1702             } else {
1703                 (*fp_gtk_container_add)((GtkContainer *)combo, result);
1704             }
1705             (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, combo);
1706         }
1707         else if (widget_type != TOOL_TIP &&
1708                  widget_type != INTERNAL_FRAME &&
1709                  widget_type != OPTION_PANE)
1710         {
1711             (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, result);
1712         }
1713         (*fp_gtk_widget_realize)(result);
1714     }
1715     return result;
1716 }
1717 
1718 void gtk2_paint_arrow(WidgetType widget_type, GtkStateType state_type,
1719         GtkShadowType shadow_type, const gchar *detail,
1720         gint x, gint y, gint width, gint height,
1721         GtkArrowType arrow_type, gboolean fill)
1722 {
1723     static int w, h;
1724     static GtkRequisition size;
1725 
1726     if (widget_type == COMBO_BOX_ARROW_BUTTON || widget_type == TABLE)
1727         gtk2_widget = gtk2_get_arrow(arrow_type, shadow_type);
1728     else
1729         gtk2_widget = gtk2_get_widget(widget_type);
1730 
1731     switch (widget_type)
1732     {
1733         case SPINNER_ARROW_BUTTON:
1734             x = 1;
1735             y = ((arrow_type == GTK_ARROW_UP) ? 2 : 0);
1736             height -= 2;
1737             width -= 3;
1738 
1739             w = width / 2;
1740             w -= w % 2 - 1;
1741             h = (w + 1) / 2;
1742             break;
1743 
1744         case HSCROLL_BAR_BUTTON_LEFT:
1745         case HSCROLL_BAR_BUTTON_RIGHT:
1746         case VSCROLL_BAR_BUTTON_UP:
1747         case VSCROLL_BAR_BUTTON_DOWN:
1748             w = width / 2;
1749             h = height / 2;
1750             break;
1751 
1752         case COMBO_BOX_ARROW_BUTTON:
1753         case TABLE:
1754             x = 1;
1755             (*fp_gtk_widget_size_request)(gtk2_widget, &size);
1756             w = size.width - ((GtkMisc*)gtk2_widget)->xpad * 2;
1757             h = size.height - ((GtkMisc*)gtk2_widget)->ypad * 2;
1758             w = h = MIN(MIN(w, h), MIN(width,height)) * 0.7;
1759             break;
1760 
1761         default:
1762             w = width;
1763             h = height;
1764             break;
1765     }
1766     x += (width - w) / 2;
1767     y += (height - h) / 2;
1768 
1769     (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1770             shadow_type, NULL, gtk2_widget, detail, arrow_type, fill,
1771             x, y, w, h);
1772     (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1773             shadow_type, NULL, gtk2_widget, detail, arrow_type, fill,
1774             x, y, w, h);
1775 }
1776 
1777 void gtk2_paint_box(WidgetType widget_type, GtkStateType state_type,
1778                     GtkShadowType shadow_type, const gchar *detail,
1779                     gint x, gint y, gint width, gint height,
1780                     gint synth_state, GtkTextDirection dir)
1781 {
1782     gtk2_widget = gtk2_get_widget(widget_type);
1783 
1784     /*
1785      * The clearlooks engine sometimes looks at the widget's state field
1786      * instead of just the state_type variable that we pass in, so to account
1787      * for those cases we set the widget's state field accordingly.  The
1788      * flags field is similarly important for things like focus/default state.
1789      */
1790     gtk2_widget->state = state_type;
1791 
1792     if (widget_type == HSLIDER_TRACK) {
1793         /*
1794          * For horizontal JSliders with right-to-left orientation, we need
1795          * to set the "inverted" flag to match the native GTK behavior where
1796          * the foreground highlight is on the right side of the slider thumb.
1797          * This is needed especially for the ubuntulooks engine, which looks
1798          * exclusively at the "inverted" flag to determine on which side of
1799          * the thumb to paint the highlight...
1800          */
1801         ((GtkRange*)gtk2_widget)->inverted = (dir == GTK_TEXT_DIR_RTL);
1802 
1803         /*
1804          * Note however that other engines like clearlooks will look at both
1805          * the "inverted" field and the text direction to determine how
1806          * the foreground highlight is painted:
1807          *     !inverted && ltr --> paint highlight on left side
1808          *     !inverted && rtl --> paint highlight on right side
1809          *      inverted && ltr --> paint highlight on right side
1810          *      inverted && rtl --> paint highlight on left side
1811          * So the only way to reliably get the desired results for horizontal
1812          * JSlider (i.e., highlight on left side for LTR ComponentOrientation
1813          * and highlight on right side for RTL ComponentOrientation) is to
1814          * always override text direction as LTR, and then set the "inverted"
1815          * flag accordingly (as we have done above).
1816          */
1817         dir = GTK_TEXT_DIR_LTR;
1818     }
1819 
1820     /*
1821      * Some engines (e.g. clearlooks) will paint the shadow of certain
1822      * widgets (e.g. COMBO_BOX_ARROW_BUTTON) differently depending on the
1823      * the text direction.
1824      */
1825     gtk2_set_direction(gtk2_widget, dir);
1826 
1827     switch (widget_type) {
1828     case BUTTON:
1829         if (synth_state & DEFAULT) {
1830             ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_DEFAULT;
1831         } else {
1832             ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_DEFAULT;
1833         }
1834         break;
1835     case TOGGLE_BUTTON:
1836         init_toggle_widget(widget_type, synth_state);
1837         break;
1838     case HSCROLL_BAR_BUTTON_LEFT:
1839         /*
1840          * The clearlooks engine will draw a "left" button when:
1841          *   x == w->allocation.x
1842          *
1843          * The ubuntulooks engine will draw a "left" button when:
1844          *   [x,y,width,height]
1845          *     intersects
1846          *   [w->alloc.x,w->alloc.y,width,height]
1847          *
1848          * The values that are set below should ensure that a "left"
1849          * button is rendered for both of these (and other) engines.
1850          */
1851         gtk2_widget->allocation.x = x;
1852         gtk2_widget->allocation.y = y;
1853         gtk2_widget->allocation.width = width;
1854         gtk2_widget->allocation.height = height;
1855         break;
1856     case HSCROLL_BAR_BUTTON_RIGHT:
1857         /*
1858          * The clearlooks engine will draw a "right" button when:
1859          *   x + width == w->allocation.x + w->allocation.width
1860          *
1861          * The ubuntulooks engine will draw a "right" button when:
1862          *   [x,y,width,height]
1863          *     does not intersect
1864          *   [w->alloc.x,w->alloc.y,width,height]
1865          *     but does intersect
1866          *   [w->alloc.x+width,w->alloc.y,width,height]
1867          *
1868          * The values that are set below should ensure that a "right"
1869          * button is rendered for both of these (and other) engines.
1870          */
1871         gtk2_widget->allocation.x = x+width;
1872         gtk2_widget->allocation.y = 0;
1873         gtk2_widget->allocation.width = 0;
1874         gtk2_widget->allocation.height = height;
1875         break;
1876     case VSCROLL_BAR_BUTTON_UP:
1877         /*
1878          * The clearlooks engine will draw an "up" button when:
1879          *   y == w->allocation.y
1880          *
1881          * The ubuntulooks engine will draw an "up" button when:
1882          *   [x,y,width,height]
1883          *     intersects
1884          *   [w->alloc.x,w->alloc.y,width,height]
1885          *
1886          * The values that are set below should ensure that an "up"
1887          * button is rendered for both of these (and other) engines.
1888          */
1889         gtk2_widget->allocation.x = x;
1890         gtk2_widget->allocation.y = y;
1891         gtk2_widget->allocation.width = width;
1892         gtk2_widget->allocation.height = height;
1893         break;
1894     case VSCROLL_BAR_BUTTON_DOWN:
1895         /*
1896          * The clearlooks engine will draw a "down" button when:
1897          *   y + height == w->allocation.y + w->allocation.height
1898          *
1899          * The ubuntulooks engine will draw a "down" button when:
1900          *   [x,y,width,height]
1901          *     does not intersect
1902          *   [w->alloc.x,w->alloc.y,width,height]
1903          *     but does intersect
1904          *   [w->alloc.x,w->alloc.y+height,width,height]
1905          *
1906          * The values that are set below should ensure that a "down"
1907          * button is rendered for both of these (and other) engines.
1908          */
1909         gtk2_widget->allocation.x = x;
1910         gtk2_widget->allocation.y = y+height;
1911         gtk2_widget->allocation.width = width;
1912         gtk2_widget->allocation.height = 0;
1913         break;
1914     default:
1915         break;
1916     }
1917 
1918     (*fp_gtk_paint_box)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1919             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
1920     (*fp_gtk_paint_box)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1921             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
1922 
1923     /*
1924      * Reset the text direction to the default value so that we don't
1925      * accidentally affect other operations and widgets.
1926      */
1927     gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR);
1928 }
1929 
1930 void gtk2_paint_box_gap(WidgetType widget_type, GtkStateType state_type,
1931         GtkShadowType shadow_type, const gchar *detail,
1932         gint x, gint y, gint width, gint height,
1933         GtkPositionType gap_side, gint gap_x, gint gap_width)
1934 {
1935     /* Clearlooks needs a real clip area to paint the gap properly */
1936     GdkRectangle area = { x, y, width, height };
1937 
1938     gtk2_widget = gtk2_get_widget(widget_type);
1939     (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1940             shadow_type, &area, gtk2_widget, detail,
1941             x, y, width, height, gap_side, gap_x, gap_width);
1942     (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1943             shadow_type, &area, gtk2_widget, detail,
1944             x, y, width, height, gap_side, gap_x, gap_width);
1945 }
1946 
1947 void gtk2_paint_check(WidgetType widget_type, gint synth_state,
1948         const gchar *detail, gint x, gint y, gint width, gint height)
1949 {
1950     GtkStateType state_type = get_gtk_state_type(widget_type, synth_state);
1951     GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state);
1952 
1953     gtk2_widget = gtk2_get_widget(widget_type);
1954     init_toggle_widget(widget_type, synth_state);
1955 
1956     (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1957             shadow_type, NULL, gtk2_widget, detail,
1958             x, y, width, height);
1959     (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1960             shadow_type, NULL, gtk2_widget, detail,
1961             x, y, width, height);
1962 }
1963 
1964 void gtk2_paint_diamond(WidgetType widget_type, GtkStateType state_type,
1965         GtkShadowType shadow_type, const gchar *detail,
1966         gint x, gint y, gint width, gint height)
1967 {
1968     gtk2_widget = gtk2_get_widget(widget_type);
1969     (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1970             shadow_type, NULL, gtk2_widget, detail,
1971             x, y, width, height);
1972     (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1973             shadow_type, NULL, gtk2_widget, detail,
1974             x, y, width, height);
1975 }
1976 
1977 void gtk2_paint_expander(WidgetType widget_type, GtkStateType state_type,
1978         const gchar *detail, gint x, gint y, gint width, gint height,
1979         GtkExpanderStyle expander_style)
1980 {
1981     gtk2_widget = gtk2_get_widget(widget_type);
1982     (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_white_pixmap,
1983             state_type, NULL, gtk2_widget, detail,
1984             x + width / 2, y + height / 2, expander_style);
1985     (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_black_pixmap,
1986             state_type, NULL, gtk2_widget, detail,
1987             x + width / 2, y + height / 2, expander_style);
1988 }
1989 
1990 void gtk2_paint_extension(WidgetType widget_type, GtkStateType state_type,
1991         GtkShadowType shadow_type, const gchar *detail,
1992         gint x, gint y, gint width, gint height, GtkPositionType gap_side)
1993 {
1994     gtk2_widget = gtk2_get_widget(widget_type);
1995     (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_white_pixmap,
1996             state_type, shadow_type, NULL, gtk2_widget, detail,
1997             x, y, width, height, gap_side);
1998     (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_black_pixmap,
1999             state_type, shadow_type, NULL, gtk2_widget, detail,
2000             x, y, width, height, gap_side);
2001 }
2002 
2003 void gtk2_paint_flat_box(WidgetType widget_type, GtkStateType state_type,
2004         GtkShadowType shadow_type, const gchar *detail,
2005         gint x, gint y, gint width, gint height, gboolean has_focus)
2006 {
2007     gtk2_widget = gtk2_get_widget(widget_type);
2008 
2009     if (has_focus)
2010         ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS;
2011     else
2012         ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
2013 
2014     (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_white_pixmap,
2015             state_type, shadow_type, NULL, gtk2_widget, detail,
2016             x, y, width, height);
2017     (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_black_pixmap,
2018             state_type, shadow_type, NULL, gtk2_widget, detail,
2019             x, y, width, height);
2020 }
2021 
2022 void gtk2_paint_focus(WidgetType widget_type, GtkStateType state_type,
2023         const char *detail, gint x, gint y, gint width, gint height)
2024 {
2025     gtk2_widget = gtk2_get_widget(widget_type);
2026     (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2027             NULL, gtk2_widget, detail, x, y, width, height);
2028     (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2029             NULL, gtk2_widget, detail, x, y, width, height);
2030 }
2031 
2032 void gtk2_paint_handle(WidgetType widget_type, GtkStateType state_type,
2033         GtkShadowType shadow_type, const gchar *detail,
2034         gint x, gint y, gint width, gint height, GtkOrientation orientation)
2035 {
2036     gtk2_widget = gtk2_get_widget(widget_type);
2037     (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2038             shadow_type, NULL, gtk2_widget, detail,
2039             x, y, width, height, orientation);
2040     (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2041             shadow_type, NULL, gtk2_widget, detail,
2042             x, y, width, height, orientation);
2043 }
2044 
2045 void gtk2_paint_hline(WidgetType widget_type, GtkStateType state_type,
2046         const gchar *detail, gint x, gint y, gint width, gint height)
2047 {
2048     gtk2_widget = gtk2_get_widget(widget_type);
2049     (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2050             NULL, gtk2_widget, detail, x, x + width, y);
2051     (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2052             NULL, gtk2_widget, detail, x, x + width, y);
2053 }
2054 
2055 void gtk2_paint_option(WidgetType widget_type, gint synth_state,
2056         const gchar *detail, gint x, gint y, gint width, gint height)
2057 {
2058     GtkStateType state_type = get_gtk_state_type(widget_type, synth_state);
2059     GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state);
2060 
2061     gtk2_widget = gtk2_get_widget(widget_type);
2062     init_toggle_widget(widget_type, synth_state);
2063 
2064     (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2065             shadow_type, NULL, gtk2_widget, detail,
2066             x, y, width, height);
2067     (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2068             shadow_type, NULL, gtk2_widget, detail,
2069             x, y, width, height);
2070 }
2071 
2072 void gtk2_paint_shadow(WidgetType widget_type, GtkStateType state_type,
2073                        GtkShadowType shadow_type, const gchar *detail,
2074                        gint x, gint y, gint width, gint height,
2075                        gint synth_state, GtkTextDirection dir)
2076 {
2077     gtk2_widget = gtk2_get_widget(widget_type);
2078 
2079     /*
2080      * The clearlooks engine sometimes looks at the widget's state field
2081      * instead of just the state_type variable that we pass in, so to account
2082      * for those cases we set the widget's state field accordingly.  The
2083      * flags field is similarly important for things like focus state.
2084      */
2085     gtk2_widget->state = state_type;
2086 
2087     /*
2088      * Some engines (e.g. clearlooks) will paint the shadow of certain
2089      * widgets (e.g. COMBO_BOX_TEXT_FIELD) differently depending on the
2090      * the text direction.
2091      */
2092     gtk2_set_direction(gtk2_widget, dir);
2093 
2094     switch (widget_type) {
2095     case COMBO_BOX_TEXT_FIELD:
2096     case FORMATTED_TEXT_FIELD:
2097     case PASSWORD_FIELD:
2098     case SPINNER_TEXT_FIELD:
2099     case TEXT_FIELD:
2100         if (synth_state & FOCUSED) {
2101             ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS;
2102         } else {
2103             ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
2104         }
2105         break;
2106     default:
2107         break;
2108     }
2109 
2110     (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2111             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
2112     (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2113             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
2114 
2115     /*
2116      * Reset the text direction to the default value so that we don't
2117      * accidentally affect other operations and widgets.
2118      */
2119     gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR);
2120 }
2121 
2122 void gtk2_paint_slider(WidgetType widget_type, GtkStateType state_type,
2123         GtkShadowType shadow_type, const gchar *detail,
2124         gint x, gint y, gint width, gint height, GtkOrientation orientation)
2125 {
2126     gtk2_widget = gtk2_get_widget(widget_type);
2127     (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2128             shadow_type, NULL, gtk2_widget, detail,
2129             x, y, width, height, orientation);
2130     (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2131             shadow_type, NULL, gtk2_widget, detail,
2132             x, y, width, height, orientation);
2133 }
2134 
2135 void gtk2_paint_vline(WidgetType widget_type, GtkStateType state_type,
2136         const gchar *detail, gint x, gint y, gint width, gint height)
2137 {
2138     gtk2_widget = gtk2_get_widget(widget_type);
2139     (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2140             NULL, gtk2_widget, detail, y, y + height, x);
2141     (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2142             NULL, gtk2_widget, detail, y, y + height, x);
2143 }
2144 
2145 void gtk_paint_background(WidgetType widget_type, GtkStateType state_type,
2146         gint x, gint y, gint width, gint height)
2147 {
2148     gtk2_widget = gtk2_get_widget(widget_type);
2149     (*fp_gtk_style_apply_default_background)(gtk2_widget->style,
2150             gtk2_white_pixmap, TRUE, state_type, NULL, x, y, width, height);
2151     (*fp_gtk_style_apply_default_background)(gtk2_widget->style,
2152             gtk2_black_pixmap, TRUE, state_type, NULL, x, y, width, height);
2153 }
2154 
2155 GdkPixbuf *gtk2_get_stock_icon(gint widget_type, const gchar *stock_id,
2156         GtkIconSize size, GtkTextDirection direction, const char *detail)
2157 {
2158     init_containers();
2159     gtk2_widget = gtk2_get_widget((widget_type < 0) ? IMAGE : widget_type);
2160     gtk2_widget->state = GTK_STATE_NORMAL;
2161     (*fp_gtk_widget_set_direction)(gtk2_widget, direction);
2162     return (*fp_gtk_widget_render_icon)(gtk2_widget, stock_id, size, detail);
2163 }
2164 
2165 /*************************************************/
2166 gint gtk2_get_xthickness(JNIEnv *env, WidgetType widget_type)
2167 {
2168     init_containers();
2169 
2170     gtk2_widget = gtk2_get_widget(widget_type);
2171     GtkStyle* style = gtk2_widget->style;
2172     return style->xthickness;
2173 }
2174 
2175 gint gtk2_get_ythickness(JNIEnv *env, WidgetType widget_type)
2176 {
2177     init_containers();
2178 
2179     gtk2_widget = gtk2_get_widget(widget_type);
2180     GtkStyle* style = gtk2_widget->style;
2181     return style->ythickness;
2182 }
2183 
2184 /*************************************************/
2185 guint8 recode_color(guint16 channel)
2186 {
2187     return (guint8)(channel>>8);
2188 }
2189 
2190 gint gtk2_get_color_for_state(JNIEnv *env, WidgetType widget_type,
2191                               GtkStateType state_type, ColorType color_type)
2192 {
2193     gint result = 0;
2194     GdkColor *color = NULL;
2195 
2196     init_containers();
2197 
2198     gtk2_widget = gtk2_get_widget(widget_type);
2199     GtkStyle* style = gtk2_widget->style;
2200 
2201     switch (color_type)
2202     {
2203         case FOREGROUND:
2204             color = &(style->fg[state_type]);
2205             break;
2206         case BACKGROUND:
2207             color = &(style->bg[state_type]);
2208             break;
2209         case TEXT_FOREGROUND:
2210             color = &(style->text[state_type]);
2211             break;
2212         case TEXT_BACKGROUND:
2213             color = &(style->base[state_type]);
2214             break;
2215         case LIGHT:
2216             color = &(style->light[state_type]);
2217             break;
2218         case DARK:
2219             color = &(style->dark[state_type]);
2220             break;
2221         case MID:
2222             color = &(style->mid[state_type]);
2223             break;
2224         case FOCUS:
2225         case BLACK:
2226             color = &(style->black);
2227             break;
2228         case WHITE:
2229             color = &(style->white);
2230             break;
2231     }
2232 
2233     if (color)
2234         result = recode_color(color->red)   << 16 |
2235                  recode_color(color->green) << 8  |
2236                  recode_color(color->blue);
2237 
2238     return result;
2239 }
2240 
2241 /*************************************************/
2242 jobject create_Boolean(JNIEnv *env, jboolean boolean_value);
2243 jobject create_Integer(JNIEnv *env, jint int_value);
2244 jobject create_Long(JNIEnv *env, jlong long_value);
2245 jobject create_Float(JNIEnv *env, jfloat float_value);
2246 jobject create_Double(JNIEnv *env, jdouble double_value);
2247 jobject create_Character(JNIEnv *env, jchar char_value);
2248 jobject create_Insets(JNIEnv *env, GtkBorder *border);
2249 
2250 jobject gtk2_get_class_value(JNIEnv *env, WidgetType widget_type, jstring jkey)
2251 {
2252     init_containers();
2253 
2254     const char* key = getStrFor(env, jkey);
2255     gtk2_widget = gtk2_get_widget(widget_type);
2256 
2257     GValue value;
2258     value.g_type = 0;
2259 
2260     GParamSpec* param = (*fp_gtk_widget_class_find_style_property)(
2261                                     ((GTypeInstance*)gtk2_widget)->g_class, key);
2262     if( param )
2263     {
2264         (*fp_g_value_init)( &value, param->value_type );
2265         (*fp_gtk_widget_style_get_property)(gtk2_widget, key, &value);
2266 
2267         if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOOLEAN ))
2268         {
2269             gboolean val = (*fp_g_value_get_boolean)(&value);
2270             return create_Boolean(env, (jboolean)val);
2271         }
2272         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_CHAR ))
2273         {
2274             gchar val = (*fp_g_value_get_char)(&value);
2275             return create_Character(env, (jchar)val);
2276         }
2277         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_UCHAR ))
2278         {
2279             guchar val = (*fp_g_value_get_uchar)(&value);
2280             return create_Character(env, (jchar)val);
2281         }
2282         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_INT ))
2283         {
2284             gint val = (*fp_g_value_get_int)(&value);
2285             return create_Integer(env, (jint)val);
2286         }
2287         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_UINT ))
2288         {
2289             guint val = (*fp_g_value_get_uint)(&value);
2290             return create_Integer(env, (jint)val);
2291         }
2292         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_LONG ))
2293         {
2294             glong val = (*fp_g_value_get_long)(&value);
2295             return create_Long(env, (jlong)val);
2296         }
2297         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_ULONG ))
2298         {
2299             gulong val = (*fp_g_value_get_ulong)(&value);
2300             return create_Long(env, (jlong)val);
2301         }
2302         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_INT64 ))
2303         {
2304             gint64 val = (*fp_g_value_get_int64)(&value);
2305             return create_Long(env, (jlong)val);
2306         }
2307         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_UINT64 ))
2308         {
2309             guint64 val = (*fp_g_value_get_uint64)(&value);
2310             return create_Long(env, (jlong)val);
2311         }
2312         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_FLOAT ))
2313         {
2314             gfloat val = (*fp_g_value_get_float)(&value);
2315             return create_Float(env, (jfloat)val);
2316         }
2317         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_DOUBLE ))
2318         {
2319             gdouble val = (*fp_g_value_get_double)(&value);
2320             return create_Double(env, (jdouble)val);
2321         }
2322         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_ENUM ))
2323         {
2324             gint val = (*fp_g_value_get_enum)(&value);
2325             return create_Integer(env, (jint)val);
2326         }
2327         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_FLAGS ))
2328         {
2329             guint val = (*fp_g_value_get_flags)(&value);
2330             return create_Integer(env, (jint)val);
2331         }
2332         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_STRING ))
2333         {
2334             const gchar* val = (*fp_g_value_get_string)(&value);
2335 
2336             /* We suppose that all values come in C locale and
2337              * utf-8 representation of a string is the same as
2338              * the string itself. If this isn't so we should
2339              * use g_convert.
2340              */
2341             return (*env)->NewStringUTF(env, val);
2342         }
2343         else if( (*fp_g_type_is_a)( param->value_type, GTK_TYPE_BORDER ))
2344         {
2345             GtkBorder *border = (GtkBorder*)(*fp_g_value_get_boxed)(&value);
2346             return border ? create_Insets(env, border) : NULL;
2347         }
2348 
2349         /*      TODO: Other types are not supported yet.*/
2350 /*        else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_PARAM ))
2351         {
2352             GParamSpec* val = (*fp_g_value_get_param)(&value);
2353             printf( "Param: %p\n", val );
2354         }
2355         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOXED ))
2356         {
2357             gpointer* val = (*fp_g_value_get_boxed)(&value);
2358             printf( "Boxed: %p\n", val );
2359         }
2360         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_POINTER ))
2361         {
2362             gpointer* val = (*fp_g_value_get_pointer)(&value);
2363             printf( "Pointer: %p\n", val );
2364         }
2365         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_OBJECT ))
2366         {
2367             GObject* val = (GObject*)(*fp_g_value_get_object)(&value);
2368             printf( "Object: %p\n", val );
2369         }*/
2370     }
2371 
2372     return NULL;
2373 }
2374 
2375 void gtk2_set_range_value(WidgetType widget_type, jdouble value,
2376                           jdouble min, jdouble max, jdouble visible)
2377 {
2378     GtkAdjustment *adj;
2379 
2380     gtk2_widget = gtk2_get_widget(widget_type);
2381 
2382     adj = (*fp_gtk_range_get_adjustment)((GtkRange *)gtk2_widget);
2383     adj->value = (gdouble)value;
2384     adj->lower = (gdouble)min;
2385     adj->upper = (gdouble)max;
2386     adj->page_size = (gdouble)visible;
2387 }
2388 
2389 /*************************************************/
2390 jobject create_Object(JNIEnv *env, jmethodID *cid,
2391                              const char* class_name,
2392                              const char* signature,
2393                              jvalue* value)
2394 {
2395     jclass  class;
2396     jobject result;
2397 
2398     class = (*env)->FindClass(env, class_name);
2399     if( class == NULL )
2400         return NULL; /* can't find/load the class, exception thrown */
2401 
2402     if( *cid == NULL)
2403     {
2404         *cid = (*env)->GetMethodID(env, class, "<init>", signature);
2405         if( *cid == NULL )
2406         {
2407             (*env)->DeleteLocalRef(env, class);
2408             return NULL; /* can't find/get the method, exception thrown */
2409         }
2410     }
2411 
2412     result = (*env)->NewObjectA(env, class, *cid, value);
2413 
2414     (*env)->DeleteLocalRef(env, class);
2415     return result;
2416 }
2417 
2418 jobject create_Boolean(JNIEnv *env, jboolean boolean_value)
2419 {
2420     static jmethodID cid = NULL;
2421     jvalue value;
2422 
2423     value.z = boolean_value;
2424 
2425     return create_Object(env, &cid, "java/lang/Boolean", "(Z)V", &value);
2426 }
2427 
2428 jobject create_Integer(JNIEnv *env, jint int_value)
2429 {
2430     static jmethodID cid = NULL;
2431     jvalue value;
2432 
2433     value.i = int_value;
2434 
2435     return create_Object(env, &cid, "java/lang/Integer", "(I)V", &value);
2436 }
2437 
2438 jobject create_Long(JNIEnv *env, jlong long_value)
2439 {
2440     static jmethodID cid = NULL;
2441     jvalue value;
2442 
2443     value.j = long_value;
2444 
2445     return create_Object(env, &cid, "java/lang/Long", "(J)V", &value);
2446 }
2447 
2448 jobject create_Float(JNIEnv *env, jfloat float_value)
2449 {
2450     static jmethodID cid = NULL;
2451     jvalue value;
2452 
2453     value.f = float_value;
2454 
2455     return create_Object(env, &cid, "java/lang/Float", "(F)V", &value);
2456 }
2457 
2458 jobject create_Double(JNIEnv *env, jdouble double_value)
2459 {
2460     static jmethodID cid = NULL;
2461     jvalue value;
2462 
2463     value.d = double_value;
2464 
2465     return create_Object(env, &cid, "java/lang/Double", "(D)V", &value);
2466 }
2467 
2468 jobject create_Character(JNIEnv *env, jchar char_value)
2469 {
2470     static jmethodID cid = NULL;
2471     jvalue value;
2472 
2473     value.c = char_value;
2474 
2475     return create_Object(env, &cid, "java/lang/Character", "(C)V", &value);
2476 }
2477 
2478 
2479 jobject create_Insets(JNIEnv *env, GtkBorder *border)
2480 {
2481     static jmethodID cid = NULL;
2482     jvalue values[4];
2483 
2484     values[0].i = border->top;
2485     values[1].i = border->left;
2486     values[2].i = border->bottom;
2487     values[3].i = border->right;
2488 
2489     return create_Object(env, &cid, "java/awt/Insets", "(IIII)V", values);
2490 }
2491 
2492 /*********************************************/
2493 jstring gtk2_get_pango_font_name(JNIEnv *env, WidgetType widget_type)
2494 {
2495     init_containers();
2496 
2497     gtk2_widget = gtk2_get_widget(widget_type);
2498     jstring  result = NULL;
2499     GtkStyle* style = gtk2_widget->style;
2500 
2501     if (style && style->font_desc)
2502     {
2503         gchar* val = (*fp_pango_font_description_to_string)(style->font_desc);
2504         result = (*env)->NewStringUTF(env, val);
2505         (*fp_g_free)( val );
2506     }
2507 
2508     return result;
2509 }
2510 
2511 /***********************************************/
2512 jobject get_string_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2513 {
2514     jobject result = NULL;
2515     gchar*  strval = NULL;
2516 
2517     (*fp_g_object_get)(settings, key, &strval, NULL);
2518     result = (*env)->NewStringUTF(env, strval);
2519     (*fp_g_free)(strval);
2520 
2521     return result;
2522 }
2523 
2524 jobject get_integer_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2525 {
2526     gint intval = NULL;
2527     (*fp_g_object_get)(settings, key, &intval, NULL);
2528     return create_Integer(env, intval);
2529 }
2530 
2531 jobject get_boolean_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2532 {
2533     gint intval = NULL;
2534     (*fp_g_object_get)(settings, key, &intval, NULL);
2535     return create_Boolean(env, intval);
2536 }
2537 
2538 jobject gtk2_get_setting(JNIEnv *env, Setting property)
2539 {
2540     GtkSettings* settings = (*fp_gtk_settings_get_default)();
2541 
2542     switch (property)
2543     {
2544         case GTK_FONT_NAME:
2545             return get_string_property(env, settings, "gtk-font-name");
2546         case GTK_ICON_SIZES:
2547             return get_string_property(env, settings, "gtk-icon-sizes");
2548         case GTK_CURSOR_BLINK:
2549             return get_boolean_property(env, settings, "gtk-cursor-blink");
2550         case GTK_CURSOR_BLINK_TIME:
2551             return get_integer_property(env, settings, "gtk-cursor-blink-time");
2552     }
2553 
2554     return NULL;
2555 }
--- EOF ---