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 GdkPixbuf *(*fp_gdk_pixbuf_get_from_drawable)(GdkPixbuf *dest,
 207         GdkDrawable *src, GdkColormap *cmap, int src_x, int src_y,
 208         int dest_x, int dest_y, int width, int height);
 209 static void (*fp_gdk_drawable_get_size)(GdkDrawable *drawable,
 210         gint* width, gint* height);
 211 
 212 /************************
 213  * Gtk function pointers
 214  ************************/
 215 static gboolean (*fp_gtk_init_check)(int* argc, char** argv);
 216 
 217 /* Painting */
 218 static void (*fp_gtk_paint_hline)(GtkStyle* style, GdkWindow* window,
 219         GtkStateType state_type, GdkRectangle* area, GtkWidget* widget,
 220         const gchar* detail, gint x1, gint x2, gint y);
 221 static void (*fp_gtk_paint_vline)(GtkStyle* style, GdkWindow* window,
 222         GtkStateType state_type, GdkRectangle* area, GtkWidget* widget,
 223         const gchar* detail, gint y1, gint y2, gint x);
 224 static void (*fp_gtk_paint_shadow)(GtkStyle* style, GdkWindow* window,
 225         GtkStateType state_type, GtkShadowType shadow_type,
 226         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 227         gint x, gint y, gint width, gint height);
 228 static void (*fp_gtk_paint_arrow)(GtkStyle* style, GdkWindow* window,
 229         GtkStateType state_type, GtkShadowType shadow_type,
 230         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 231         GtkArrowType arrow_type, gboolean fill, gint x, gint y,
 232         gint width, gint height);
 233 static void (*fp_gtk_paint_diamond)(GtkStyle* style, GdkWindow* window,
 234         GtkStateType state_type, GtkShadowType shadow_type,
 235         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 236         gint x, gint y, gint width, gint height);
 237 static void (*fp_gtk_paint_box)(GtkStyle* style, GdkWindow* window,
 238         GtkStateType state_type, GtkShadowType shadow_type,
 239         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 240         gint x, gint y, gint width, gint height);
 241 static void (*fp_gtk_paint_flat_box)(GtkStyle* style, GdkWindow* window,
 242         GtkStateType state_type, GtkShadowType shadow_type,
 243         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 244         gint x, gint y, gint width, gint height);
 245 static void (*fp_gtk_paint_check)(GtkStyle* style, GdkWindow* window,
 246         GtkStateType state_type, GtkShadowType shadow_type,
 247         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 248         gint x, gint y, gint width, gint height);
 249 static void (*fp_gtk_paint_option)(GtkStyle* style, GdkWindow* window,
 250         GtkStateType state_type, GtkShadowType shadow_type,
 251         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 252         gint x, gint y, gint width, gint height);
 253 static void (*fp_gtk_paint_box_gap)(GtkStyle* style, GdkWindow* window,
 254         GtkStateType state_type, GtkShadowType shadow_type,
 255         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 256         gint x, gint y, gint width, gint height,
 257         GtkPositionType gap_side, gint gap_x, gint gap_width);
 258 static void (*fp_gtk_paint_extension)(GtkStyle* style, GdkWindow* window,
 259         GtkStateType state_type, GtkShadowType shadow_type,
 260         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 261         gint x, gint y, gint width, gint height, GtkPositionType gap_side);
 262 static void (*fp_gtk_paint_focus)(GtkStyle* style, GdkWindow* window,
 263         GtkStateType state_type, GdkRectangle* area, GtkWidget* widget,
 264         const gchar* detail, gint x, gint y, gint width, gint height);
 265 static void (*fp_gtk_paint_slider)(GtkStyle* style, GdkWindow* window,
 266         GtkStateType state_type, GtkShadowType shadow_type,
 267         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 268         gint x, gint y, gint width, gint height, GtkOrientation orientation);
 269 static void (*fp_gtk_paint_handle)(GtkStyle* style, GdkWindow* window,
 270         GtkStateType state_type, GtkShadowType shadow_type,
 271         GdkRectangle* area, GtkWidget* widget, const gchar* detail,
 272         gint x, gint y, gint width, gint height, GtkOrientation orientation);
 273 static void (*fp_gtk_paint_expander)(GtkStyle* style, GdkWindow* window,
 274         GtkStateType state_type, GdkRectangle* area, GtkWidget* widget,
 275         const gchar* detail, gint x, gint y, GtkExpanderStyle expander_style);
 276 static void (*fp_gtk_style_apply_default_background)(GtkStyle* style,
 277         GdkWindow* window, gboolean set_bg, GtkStateType state_type,
 278         GdkRectangle* area, gint x, gint y, gint width, gint height);
 279 
 280 /* Widget creation */
 281 static GtkWidget* (*fp_gtk_arrow_new)(GtkArrowType arrow_type,
 282                                       GtkShadowType shadow_type);
 283 static GtkWidget* (*fp_gtk_button_new)();
 284 static GtkWidget* (*fp_gtk_check_button_new)();
 285 static GtkWidget* (*fp_gtk_check_menu_item_new)();
 286 static GtkWidget* (*fp_gtk_color_selection_dialog_new)(const gchar* title);
 287 static GtkWidget* (*fp_gtk_combo_box_new)();
 288 static GtkWidget* (*fp_gtk_combo_box_entry_new)();
 289 static GtkWidget* (*fp_gtk_entry_new)();
 290 static GtkWidget* (*fp_gtk_fixed_new)();
 291 static GtkWidget* (*fp_gtk_handle_box_new)();
 292 static GtkWidget* (*fp_gtk_hpaned_new)();
 293 static GtkWidget* (*fp_gtk_vpaned_new)();
 294 static GtkWidget* (*fp_gtk_hscale_new)(GtkAdjustment* adjustment);
 295 static GtkWidget* (*fp_gtk_vscale_new)(GtkAdjustment* adjustment);
 296 static GtkWidget* (*fp_gtk_hscrollbar_new)(GtkAdjustment* adjustment);
 297 static GtkWidget* (*fp_gtk_vscrollbar_new)(GtkAdjustment* adjustment);
 298 static GtkWidget* (*fp_gtk_hseparator_new)();
 299 static GtkWidget* (*fp_gtk_vseparator_new)();
 300 static GtkWidget* (*fp_gtk_image_new)();
 301 static GtkWidget* (*fp_gtk_label_new)(const gchar* str);
 302 static GtkWidget* (*fp_gtk_menu_new)();
 303 static GtkWidget* (*fp_gtk_menu_bar_new)();
 304 static GtkWidget* (*fp_gtk_menu_item_new)();
 305 static GtkWidget* (*fp_gtk_notebook_new)();
 306 static GtkWidget* (*fp_gtk_progress_bar_new)();
 307 static GtkWidget* (*fp_gtk_progress_bar_set_orientation)(
 308         GtkProgressBar *pbar,
 309         GtkProgressBarOrientation orientation);
 310 static GtkWidget* (*fp_gtk_radio_button_new)(GSList *group);
 311 static GtkWidget* (*fp_gtk_radio_menu_item_new)(GSList *group);
 312 static GtkWidget* (*fp_gtk_scrolled_window_new)(GtkAdjustment *hadjustment,
 313         GtkAdjustment *vadjustment);
 314 static GtkWidget* (*fp_gtk_separator_menu_item_new)();
 315 static GtkWidget* (*fp_gtk_separator_tool_item_new)();
 316 static GtkWidget* (*fp_gtk_text_view_new)();
 317 static GtkWidget* (*fp_gtk_toggle_button_new)();
 318 static GtkWidget* (*fp_gtk_toolbar_new)();
 319 static GtkWidget* (*fp_gtk_tree_view_new)();
 320 static GtkWidget* (*fp_gtk_viewport_new)(GtkAdjustment *hadjustment,
 321         GtkAdjustment *vadjustment);
 322 static GtkWidget* (*fp_gtk_window_new)(GtkWindowType type);
 323 static GtkWidget* (*fp_gtk_dialog_new)();
 324 static GtkWidget* (*fp_gtk_spin_button_new)(GtkAdjustment *adjustment,
 325         gdouble climb_rate, guint digits);
 326 static GtkWidget* (*fp_gtk_frame_new)(const gchar *label);
 327 
 328 /* Other widget operations */
 329 static GtkObject* (*fp_gtk_adjustment_new)(gdouble value,
 330         gdouble lower, gdouble upper, gdouble step_increment,
 331         gdouble page_increment, gdouble page_size);
 332 static void (*fp_gtk_container_add)(GtkContainer *window, GtkWidget *widget);
 333 static void (*fp_gtk_menu_shell_append)(GtkMenuShell *menu_shell,
 334         GtkWidget *child);
 335 static void (*fp_gtk_menu_item_set_submenu)(GtkMenuItem *menu_item,
 336         GtkWidget *submenu);
 337 static void (*fp_gtk_widget_realize)(GtkWidget *widget);
 338 static GdkPixbuf* (*fp_gtk_widget_render_icon)(GtkWidget *widget,
 339         const gchar *stock_id, GtkIconSize size, const gchar *detail);
 340 static void (*fp_gtk_widget_set_name)(GtkWidget *widget, const gchar *name);
 341 static void (*fp_gtk_widget_set_parent)(GtkWidget *widget, GtkWidget *parent);
 342 static void (*fp_gtk_widget_set_direction)(GtkWidget *widget,
 343         GtkTextDirection direction);
 344 static void (*fp_gtk_widget_style_get)(GtkWidget *widget,
 345         const gchar *first_property_name, ...);
 346 static void (*fp_gtk_widget_class_install_style_property)(
 347         GtkWidgetClass* class, GParamSpec *pspec);
 348 static GParamSpec* (*fp_gtk_widget_class_find_style_property)(
 349         GtkWidgetClass* class, const gchar* property_name);
 350 static void (*fp_gtk_widget_style_get_property)(GtkWidget* widget,
 351         const gchar* property_name, GValue* value);
 352 static char* (*fp_pango_font_description_to_string)(
 353         const PangoFontDescription* fd);
 354 static GtkSettings* (*fp_gtk_settings_get_default)();
 355 static GtkSettings* (*fp_gtk_widget_get_settings)(GtkWidget *widget);
 356 static GType        (*fp_gtk_border_get_type)();
 357 static void (*fp_gtk_arrow_set)(GtkWidget* arrow,
 358                                 GtkArrowType arrow_type,
 359                                 GtkShadowType shadow_type);
 360 static void (*fp_gtk_widget_size_request)(GtkWidget *widget,
 361                                           GtkRequisition *requisition);
 362 static GtkAdjustment* (*fp_gtk_range_get_adjustment)(GtkRange* range);
 363 
 364 /* Method bodies */
 365 const char *getStrFor(JNIEnv *env, jstring val)
 366 {
 367     int length = (*env)->GetStringLength(env, val);
 368     if (length > CONV_BUFFER_SIZE-1)
 369     {
 370         length = CONV_BUFFER_SIZE-1;
 371 #ifdef DEBUG
 372         fprintf(stderr, "Note: Detail is too long: %d chars\n", length);
 373 #endif /* DEBUG */
 374     }
 375 
 376     (*env)->GetStringUTFRegion(env, val, 0, length, convertionBuffer);
 377     return convertionBuffer;
 378 }
 379 
 380 static void throw_exception(JNIEnv *env, const char* name, const char* message)
 381 {
 382     jclass class = (*env)->FindClass(env, name);
 383 
 384     if (class != NULL)
 385         (*env)->ThrowNew(env, class, message);
 386 
 387     (*env)->DeleteLocalRef(env, class);
 388 }
 389 
 390 /* This is a workaround for the bug:
 391  * http://sourceware.org/bugzilla/show_bug.cgi?id=1814
 392  * (dlsym/dlopen clears dlerror state)
 393  * This bug is specific to Linux, but there is no harm in
 394  * applying this workaround on Solaris as well.
 395  */
 396 static void* dl_symbol(const char* name)
 397 {
 398     void* result = dlsym(gtk2_libhandle, name);
 399     if (!result)
 400         longjmp(j, NO_SYMBOL_EXCEPTION);
 401 
 402     return result;
 403 }
 404 
 405 static void* dl_symbol_gthread(const char* name)
 406 {
 407     void* result = dlsym(gthread_libhandle, name);
 408     if (!result)
 409         longjmp(j, NO_SYMBOL_EXCEPTION);
 410 
 411     return result;
 412 }
 413 
 414 gboolean gtk2_check_version()
 415 {
 416     if (gtk2_libhandle != NULL) {
 417         /* We've already successfully opened the GTK libs, so return true. */
 418         return TRUE;
 419     } else {
 420         void *lib = NULL;
 421         gboolean result = FALSE;
 422 
 423         lib = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 424         if (lib == NULL) {
 425             lib = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
 426             if (lib == NULL) {
 427                 return FALSE;
 428             }
 429         }
 430 
 431         fp_gtk_check_version = dlsym(lib, "gtk_check_version");
 432         /* Check for GTK 2.2+ */
 433         if (!fp_gtk_check_version(2, 2, 0)) {
 434             result = TRUE;
 435         }
 436 
 437         // 8048289: workaround for https://bugzilla.gnome.org/show_bug.cgi?id=733065
 438         // dlclose(lib);
 439 
 440         return result;
 441     }
 442 }
 443 
 444 #define ADD_SUPPORTED_ACTION(actionStr) \
 445 do { \
 446     jfieldID fld_action = (*env)->GetStaticFieldID(env, cls_action, actionStr, "Ljava/awt/Desktop$Action;"); \
 447     if (!(*env)->ExceptionCheck(env)) { \
 448         jobject action = (*env)->GetStaticObjectField(env, cls_action, fld_action); \
 449         (*env)->CallBooleanMethod(env, supportedActions, mid_arrayListAdd, action); \
 450     } else { \
 451         (*env)->ExceptionClear(env); \
 452     } \
 453 } while(0);
 454 
 455 
 456 void update_supported_actions(JNIEnv *env) {
 457     GVfs * (*fp_g_vfs_get_default) (void);
 458     const gchar * const * (*fp_g_vfs_get_supported_uri_schemes) (GVfs * vfs);
 459     const gchar * const * schemes = NULL;
 460 
 461     jclass cls_action = (*env)->FindClass(env, "java/awt/Desktop$Action");
 462     CHECK_NULL(cls_action);
 463     jclass cls_xDesktopPeer = (*env)->FindClass(env, "sun/awt/X11/XDesktopPeer");
 464     CHECK_NULL(cls_xDesktopPeer);
 465     jfieldID fld_supportedActions = (*env)->GetStaticFieldID(env, cls_xDesktopPeer, "supportedActions", "Ljava/util/List;");
 466     CHECK_NULL(fld_supportedActions);
 467     jobject supportedActions = (*env)->GetStaticObjectField(env, cls_xDesktopPeer, fld_supportedActions);
 468 
 469     jclass cls_arrayList = (*env)->FindClass(env, "java/util/ArrayList");
 470     CHECK_NULL(cls_arrayList);
 471     jmethodID mid_arrayListAdd = (*env)->GetMethodID(env, cls_arrayList, "add", "(Ljava/lang/Object;)Z");
 472     CHECK_NULL(mid_arrayListAdd);
 473     jmethodID mid_arrayListClear = (*env)->GetMethodID(env, cls_arrayList, "clear", "()V");
 474     CHECK_NULL(mid_arrayListClear);
 475 
 476     (*env)->CallVoidMethod(env, supportedActions, mid_arrayListClear);
 477 
 478     ADD_SUPPORTED_ACTION("OPEN");
 479 
 480     /**
 481      * gtk_show_uri() documentation says:
 482      *
 483      * > you need to install gvfs to get support for uri schemes such as http://
 484      * > or ftp://, as only local files are handled by GIO itself.
 485      *
 486      * So OPEN action was safely added here.
 487      * However, it looks like Solaris 11 have gvfs support only for 32-bit
 488      * applications only by default.
 489      */
 490 
 491     fp_g_vfs_get_default = dl_symbol("g_vfs_get_default");
 492     fp_g_vfs_get_supported_uri_schemes = dl_symbol("g_vfs_get_supported_uri_schemes");
 493     dlerror();
 494 
 495     if (fp_g_vfs_get_default && fp_g_vfs_get_supported_uri_schemes) {
 496         GVfs * vfs = fp_g_vfs_get_default();
 497         schemes = vfs ? fp_g_vfs_get_supported_uri_schemes(vfs) : NULL;
 498         if (schemes) {
 499             int i = 0;
 500             while (schemes[i]) {
 501                 if (strcmp(schemes[i], "http") == 0) {
 502                     ADD_SUPPORTED_ACTION("BROWSE");
 503                     ADD_SUPPORTED_ACTION("MAIL");
 504                     break;
 505                 }
 506                 i++;
 507             }
 508         }
 509     } else {
 510 #ifdef DEBUG
 511         fprintf(stderr, "Cannot load g_vfs_get_supported_uri_schemes\n");
 512 #endif /* DEBUG */
 513     }
 514 
 515 }
 516 /**
 517  * Functions for awt_Desktop.c
 518  */
 519 gboolean gtk2_show_uri_load(JNIEnv *env) {
 520      gboolean success = FALSE;
 521      dlerror();
 522      const char *gtk_version = fp_gtk_check_version(2, 14, 0);
 523      if (gtk_version != NULL) {
 524          // The gtk_show_uri is available from GTK+ 2.14
 525 #ifdef DEBUG
 526          fprintf (stderr, "The version of GTK is %s. "
 527              "The gtk_show_uri function is supported "
 528              "since GTK+ 2.14.\n", gtk_version);
 529 #endif /* DEBUG */
 530      } else {
 531          // Loading symbols only if the GTK version is 2.14 and higher
 532          fp_gtk_show_uri = dl_symbol("gtk_show_uri");
 533          const char *dlsym_error = dlerror();
 534          if (dlsym_error) {
 535 #ifdef DEBUG
 536              fprintf (stderr, "Cannot load symbol: %s \n", dlsym_error);
 537 #endif /* DEBUG */
 538          } else if (fp_gtk_show_uri == NULL) {
 539 #ifdef DEBUG
 540              fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n");
 541 #endif /* DEBUG */
 542         } else {
 543             update_supported_actions(env);
 544             success = TRUE;
 545         }
 546      }
 547      return success;
 548 }
 549 
 550 /**
 551  * Functions for sun_awt_X11_GtkFileDialogPeer.c
 552  */
 553 void gtk2_file_chooser_load()
 554 {
 555     fp_gtk_file_chooser_get_filename = dl_symbol(
 556             "gtk_file_chooser_get_filename");
 557     fp_gtk_file_chooser_dialog_new = dl_symbol("gtk_file_chooser_dialog_new");
 558     fp_gtk_file_chooser_set_current_folder = dl_symbol(
 559             "gtk_file_chooser_set_current_folder");
 560     fp_gtk_file_chooser_set_filename = dl_symbol(
 561             "gtk_file_chooser_set_filename");
 562     fp_gtk_file_chooser_set_current_name = dl_symbol(
 563             "gtk_file_chooser_set_current_name");
 564     fp_gtk_file_filter_add_custom = dl_symbol("gtk_file_filter_add_custom");
 565     fp_gtk_file_chooser_set_filter = dl_symbol("gtk_file_chooser_set_filter");
 566     fp_gtk_file_chooser_get_type = dl_symbol("gtk_file_chooser_get_type");
 567     fp_gtk_file_filter_new = dl_symbol("gtk_file_filter_new");
 568     if (fp_gtk_check_version(2, 8, 0) == NULL) {
 569         fp_gtk_file_chooser_set_do_overwrite_confirmation = dl_symbol(
 570                 "gtk_file_chooser_set_do_overwrite_confirmation");
 571     }
 572     fp_gtk_file_chooser_set_select_multiple = dl_symbol(
 573             "gtk_file_chooser_set_select_multiple");
 574     fp_gtk_file_chooser_get_current_folder = dl_symbol(
 575             "gtk_file_chooser_get_current_folder");
 576     fp_gtk_file_chooser_get_filenames = dl_symbol(
 577             "gtk_file_chooser_get_filenames");
 578     fp_gtk_g_slist_length = dl_symbol("g_slist_length");
 579 }
 580 
 581 gboolean gtk2_load(JNIEnv *env)
 582 {
 583     gboolean result;
 584     int i;
 585     int (*handler)();
 586     int (*io_handler)();
 587     char *gtk_modules_env;
 588 
 589     gtk2_libhandle = dlopen(GTK2_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 590     if (gtk2_libhandle == NULL) {
 591         gtk2_libhandle = dlopen(GTK2_LIB, RTLD_LAZY | RTLD_LOCAL);
 592         if (gtk2_libhandle == NULL)
 593             return FALSE;
 594     }
 595 
 596     gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED, RTLD_LAZY | RTLD_LOCAL);
 597     if (gthread_libhandle == NULL) {
 598         gthread_libhandle = dlopen(GTHREAD_LIB, RTLD_LAZY | RTLD_LOCAL);
 599         if (gthread_libhandle == NULL)
 600             return FALSE;
 601     }
 602 
 603     if (setjmp(j) == 0)
 604     {
 605         fp_gtk_check_version = dl_symbol("gtk_check_version");
 606         /* Check for GTK 2.2+ */
 607         if (fp_gtk_check_version(2, 2, 0)) {
 608             longjmp(j, NO_SYMBOL_EXCEPTION);
 609         }
 610 
 611         /* GLib */
 612         fp_glib_check_version = dlsym(gtk2_libhandle, "glib_check_version");
 613         if (!fp_glib_check_version) {
 614             dlerror();
 615         }
 616         fp_g_free = dl_symbol("g_free");
 617         fp_g_object_unref = dl_symbol("g_object_unref");
 618 
 619         fp_g_main_context_iteration =
 620             dl_symbol("g_main_context_iteration");
 621 
 622         fp_g_value_init = dl_symbol("g_value_init");
 623         fp_g_type_is_a = dl_symbol("g_type_is_a");
 624 
 625         fp_g_value_get_boolean = dl_symbol("g_value_get_boolean");
 626         fp_g_value_get_char = dl_symbol("g_value_get_char");
 627         fp_g_value_get_uchar = dl_symbol("g_value_get_uchar");
 628         fp_g_value_get_int = dl_symbol("g_value_get_int");
 629         fp_g_value_get_uint = dl_symbol("g_value_get_uint");
 630         fp_g_value_get_long = dl_symbol("g_value_get_long");
 631         fp_g_value_get_ulong = dl_symbol("g_value_get_ulong");
 632         fp_g_value_get_int64 = dl_symbol("g_value_get_int64");
 633         fp_g_value_get_uint64 = dl_symbol("g_value_get_uint64");
 634         fp_g_value_get_float = dl_symbol("g_value_get_float");
 635         fp_g_value_get_double = dl_symbol("g_value_get_double");
 636         fp_g_value_get_string = dl_symbol("g_value_get_string");
 637         fp_g_value_get_enum = dl_symbol("g_value_get_enum");
 638         fp_g_value_get_flags = dl_symbol("g_value_get_flags");
 639         fp_g_value_get_param = dl_symbol("g_value_get_param");
 640         fp_g_value_get_boxed = dl_symbol("g_value_get_boxed");
 641         fp_g_value_get_pointer = dl_symbol("g_value_get_pointer");
 642         fp_g_value_get_object = dl_symbol("g_value_get_object");
 643         fp_g_param_spec_int = dl_symbol("g_param_spec_int");
 644         fp_g_object_get = dl_symbol("g_object_get");
 645         fp_g_object_set = dl_symbol("g_object_set");
 646 
 647         /* GDK */
 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_gc_new = dl_symbol("gdk_gc_new");
 652         fp_gdk_rgb_gc_set_foreground =
 653             dl_symbol("gdk_rgb_gc_set_foreground");
 654         fp_gdk_draw_rectangle = dl_symbol("gdk_draw_rectangle");
 655         fp_gdk_drawable_get_size = dl_symbol("gdk_drawable_get_size");
 656 
 657         /* Pixbuf */
 658         fp_gdk_pixbuf_new = dl_symbol("gdk_pixbuf_new");
 659         fp_gdk_pixbuf_new_from_file =
 660                 dl_symbol("gdk_pixbuf_new_from_file");
 661         fp_gdk_pixbuf_get_width = dl_symbol("gdk_pixbuf_get_width");
 662         fp_gdk_pixbuf_get_height = dl_symbol("gdk_pixbuf_get_height");
 663         fp_gdk_pixbuf_get_pixels = dl_symbol("gdk_pixbuf_get_pixels");
 664         fp_gdk_pixbuf_get_rowstride =
 665                 dl_symbol("gdk_pixbuf_get_rowstride");
 666         fp_gdk_pixbuf_get_has_alpha =
 667                 dl_symbol("gdk_pixbuf_get_has_alpha");
 668         fp_gdk_pixbuf_get_bits_per_sample =
 669                 dl_symbol("gdk_pixbuf_get_bits_per_sample");
 670         fp_gdk_pixbuf_get_n_channels =
 671                 dl_symbol("gdk_pixbuf_get_n_channels");
 672 
 673         /* GTK painting */
 674         fp_gtk_init_check = dl_symbol("gtk_init_check");
 675         fp_gtk_paint_hline = dl_symbol("gtk_paint_hline");
 676         fp_gtk_paint_vline = dl_symbol("gtk_paint_vline");
 677         fp_gtk_paint_shadow = dl_symbol("gtk_paint_shadow");
 678         fp_gtk_paint_arrow = dl_symbol("gtk_paint_arrow");
 679         fp_gtk_paint_diamond = dl_symbol("gtk_paint_diamond");
 680         fp_gtk_paint_box = dl_symbol("gtk_paint_box");
 681         fp_gtk_paint_flat_box = dl_symbol("gtk_paint_flat_box");
 682         fp_gtk_paint_check = dl_symbol("gtk_paint_check");
 683         fp_gtk_paint_option = dl_symbol("gtk_paint_option");
 684         fp_gtk_paint_box_gap = dl_symbol("gtk_paint_box_gap");
 685         fp_gtk_paint_extension = dl_symbol("gtk_paint_extension");
 686         fp_gtk_paint_focus = dl_symbol("gtk_paint_focus");
 687         fp_gtk_paint_slider = dl_symbol("gtk_paint_slider");
 688         fp_gtk_paint_handle = dl_symbol("gtk_paint_handle");
 689         fp_gtk_paint_expander = dl_symbol("gtk_paint_expander");
 690         fp_gtk_style_apply_default_background =
 691                 dl_symbol("gtk_style_apply_default_background");
 692 
 693         /* GTK widgets */
 694         fp_gtk_arrow_new = dl_symbol("gtk_arrow_new");
 695         fp_gtk_button_new = dl_symbol("gtk_button_new");
 696         fp_gtk_spin_button_new = dl_symbol("gtk_spin_button_new");
 697         fp_gtk_check_button_new = dl_symbol("gtk_check_button_new");
 698         fp_gtk_check_menu_item_new =
 699                 dl_symbol("gtk_check_menu_item_new");
 700         fp_gtk_color_selection_dialog_new =
 701                 dl_symbol("gtk_color_selection_dialog_new");
 702         fp_gtk_entry_new = dl_symbol("gtk_entry_new");
 703         fp_gtk_fixed_new = dl_symbol("gtk_fixed_new");
 704         fp_gtk_handle_box_new = dl_symbol("gtk_handle_box_new");
 705         fp_gtk_image_new = dl_symbol("gtk_image_new");
 706         fp_gtk_hpaned_new = dl_symbol("gtk_hpaned_new");
 707         fp_gtk_vpaned_new = dl_symbol("gtk_vpaned_new");
 708         fp_gtk_hscale_new = dl_symbol("gtk_hscale_new");
 709         fp_gtk_vscale_new = dl_symbol("gtk_vscale_new");
 710         fp_gtk_hscrollbar_new = dl_symbol("gtk_hscrollbar_new");
 711         fp_gtk_vscrollbar_new = dl_symbol("gtk_vscrollbar_new");
 712         fp_gtk_hseparator_new = dl_symbol("gtk_hseparator_new");
 713         fp_gtk_vseparator_new = dl_symbol("gtk_vseparator_new");
 714         fp_gtk_label_new = dl_symbol("gtk_label_new");
 715         fp_gtk_menu_new = dl_symbol("gtk_menu_new");
 716         fp_gtk_menu_bar_new = dl_symbol("gtk_menu_bar_new");
 717         fp_gtk_menu_item_new = dl_symbol("gtk_menu_item_new");
 718         fp_gtk_menu_item_set_submenu =
 719                 dl_symbol("gtk_menu_item_set_submenu");
 720         fp_gtk_notebook_new = dl_symbol("gtk_notebook_new");
 721         fp_gtk_progress_bar_new =
 722             dl_symbol("gtk_progress_bar_new");
 723         fp_gtk_progress_bar_set_orientation =
 724             dl_symbol("gtk_progress_bar_set_orientation");
 725         fp_gtk_radio_button_new =
 726             dl_symbol("gtk_radio_button_new");
 727         fp_gtk_radio_menu_item_new =
 728             dl_symbol("gtk_radio_menu_item_new");
 729         fp_gtk_scrolled_window_new =
 730             dl_symbol("gtk_scrolled_window_new");
 731         fp_gtk_separator_menu_item_new =
 732             dl_symbol("gtk_separator_menu_item_new");
 733         fp_gtk_text_view_new = dl_symbol("gtk_text_view_new");
 734         fp_gtk_toggle_button_new =
 735             dl_symbol("gtk_toggle_button_new");
 736         fp_gtk_toolbar_new = dl_symbol("gtk_toolbar_new");
 737         fp_gtk_tree_view_new = dl_symbol("gtk_tree_view_new");
 738         fp_gtk_viewport_new = dl_symbol("gtk_viewport_new");
 739         fp_gtk_window_new = dl_symbol("gtk_window_new");
 740         fp_gtk_window_present = dl_symbol("gtk_window_present");
 741         fp_gtk_window_move = dl_symbol("gtk_window_move");
 742         fp_gtk_window_resize = dl_symbol("gtk_window_resize");
 743 
 744           fp_gtk_dialog_new = dl_symbol("gtk_dialog_new");
 745         fp_gtk_frame_new = dl_symbol("gtk_frame_new");
 746 
 747         fp_gtk_adjustment_new = dl_symbol("gtk_adjustment_new");
 748         fp_gtk_container_add = dl_symbol("gtk_container_add");
 749         fp_gtk_menu_shell_append =
 750             dl_symbol("gtk_menu_shell_append");
 751         fp_gtk_widget_realize = dl_symbol("gtk_widget_realize");
 752         fp_gtk_widget_destroy = dl_symbol("gtk_widget_destroy");
 753         fp_gtk_widget_render_icon =
 754             dl_symbol("gtk_widget_render_icon");
 755         fp_gtk_widget_set_name =
 756             dl_symbol("gtk_widget_set_name");
 757         fp_gtk_widget_set_parent =
 758             dl_symbol("gtk_widget_set_parent");
 759         fp_gtk_widget_set_direction =
 760             dl_symbol("gtk_widget_set_direction");
 761         fp_gtk_widget_style_get =
 762             dl_symbol("gtk_widget_style_get");
 763         fp_gtk_widget_class_install_style_property =
 764             dl_symbol("gtk_widget_class_install_style_property");
 765         fp_gtk_widget_class_find_style_property =
 766             dl_symbol("gtk_widget_class_find_style_property");
 767         fp_gtk_widget_style_get_property =
 768             dl_symbol("gtk_widget_style_get_property");
 769         fp_pango_font_description_to_string =
 770             dl_symbol("pango_font_description_to_string");
 771         fp_gtk_settings_get_default =
 772             dl_symbol("gtk_settings_get_default");
 773         fp_gtk_widget_get_settings =
 774             dl_symbol("gtk_widget_get_settings");
 775         fp_gtk_border_get_type =  dl_symbol("gtk_border_get_type");
 776         fp_gtk_arrow_set = dl_symbol("gtk_arrow_set");
 777         fp_gtk_widget_size_request =
 778             dl_symbol("gtk_widget_size_request");
 779         fp_gtk_range_get_adjustment =
 780             dl_symbol("gtk_range_get_adjustment");
 781 
 782         fp_gtk_widget_hide = dl_symbol("gtk_widget_hide");
 783         fp_gtk_main_quit = dl_symbol("gtk_main_quit");
 784         fp_g_signal_connect_data = dl_symbol("g_signal_connect_data");
 785         fp_gtk_widget_show = dl_symbol("gtk_widget_show");
 786         fp_gtk_main = dl_symbol("gtk_main");
 787 
 788         fp_g_path_get_dirname = dl_symbol("g_path_get_dirname");
 789 
 790         /**
 791          * GLib thread system
 792          */
 793         if (GLIB_CHECK_VERSION(2, 20, 0)) {
 794             fp_g_thread_get_initialized = dl_symbol_gthread("g_thread_get_initialized");
 795         }
 796         fp_g_thread_init = dl_symbol_gthread("g_thread_init");
 797         fp_gdk_threads_init = dl_symbol("gdk_threads_init");
 798         fp_gdk_threads_enter = dl_symbol("gdk_threads_enter");
 799         fp_gdk_threads_leave = dl_symbol("gdk_threads_leave");
 800 
 801         /**
 802          * Functions for sun_awt_X11_GtkFileDialogPeer.c
 803          */
 804         if (fp_gtk_check_version(2, 4, 0) == NULL) {
 805             // The current GtkFileChooser is available from GTK+ 2.4
 806             gtk2_file_chooser_load();
 807         }
 808 
 809         /* Some functions may be missing in pre-2.4 GTK.
 810            We handle them specially here.
 811          */
 812         fp_gtk_combo_box_new = dlsym(gtk2_libhandle, "gtk_combo_box_new");
 813         if (fp_gtk_combo_box_new == NULL) {
 814             fp_gtk_combo_box_new = dl_symbol("gtk_combo_new");
 815         }
 816 
 817         fp_gtk_combo_box_entry_new =
 818             dlsym(gtk2_libhandle, "gtk_combo_box_entry_new");
 819         if (fp_gtk_combo_box_entry_new == NULL) {
 820             fp_gtk_combo_box_entry_new = dl_symbol("gtk_combo_new");
 821             new_combo = FALSE;
 822         }
 823 
 824         fp_gtk_separator_tool_item_new =
 825             dlsym(gtk2_libhandle, "gtk_separator_tool_item_new");
 826         if (fp_gtk_separator_tool_item_new == NULL) {
 827             fp_gtk_separator_tool_item_new =
 828                 dl_symbol("gtk_vseparator_new");
 829         }
 830     }
 831     /* Now we have only one kind of exceptions: NO_SYMBOL_EXCEPTION
 832      * Otherwise we can check the return value of setjmp method.
 833      */
 834     else
 835     {
 836         dlclose(gtk2_libhandle);
 837         gtk2_libhandle = NULL;
 838 
 839         dlclose(gthread_libhandle);
 840         gthread_libhandle = NULL;
 841 
 842         return FALSE;
 843     }
 844 
 845     /*
 846      * Strip the AT-SPI GTK_MODULEs if present
 847      */
 848     gtk_modules_env = getenv ("GTK_MODULES");
 849 
 850     if (gtk_modules_env && strstr (gtk_modules_env, "atk-bridge") ||
 851         gtk_modules_env && strstr (gtk_modules_env, "gail"))
 852     {
 853         /* the new env will be smaller than the old one */
 854         gchar *s, *new_env = SAFE_SIZE_STRUCT_ALLOC(malloc,
 855                 sizeof(ENV_PREFIX), 1, strlen (gtk_modules_env));
 856 
 857         if (new_env != NULL )
 858         {
 859             /* careful, strtok modifies its args */
 860             gchar *tmp_env = strdup (gtk_modules_env);
 861             strcpy(new_env, ENV_PREFIX);
 862 
 863             /* strip out 'atk-bridge' and 'gail' */
 864             size_t PREFIX_LENGTH = strlen(ENV_PREFIX);
 865             while (s = strtok(tmp_env, ":"))
 866             {
 867                 if ((!strstr (s, "atk-bridge")) && (!strstr (s, "gail")))
 868                 {
 869                     if (strlen (new_env) > PREFIX_LENGTH) {
 870                         new_env = strcat (new_env, ":");
 871                     }
 872                     new_env = strcat(new_env, s);
 873                 }
 874                 if (tmp_env)
 875                 {
 876                     free (tmp_env);
 877                     tmp_env = NULL; /* next call to strtok arg1==NULL */
 878                 }
 879             }
 880             putenv (new_env);
 881             free (new_env);
 882             free (tmp_env);
 883         }
 884     }
 885 
 886     /*
 887      * GTK should be initialized with gtk_init_check() before use.
 888      *
 889      * gtk_init_check installs its own error handlers. It is critical that
 890      * we preserve error handler set from AWT. Otherwise we'll crash on
 891      * BadMatch errors which we would normally ignore. The IO error handler
 892      * is preserved here, too, just for consistency.
 893     */
 894     AWT_LOCK();
 895     handler = XSetErrorHandler(NULL);
 896     io_handler = XSetIOErrorHandler(NULL);
 897 
 898     if (fp_gtk_check_version(2, 2, 0) == NULL) {
 899         jclass clazz = (*env)->FindClass(env, "sun/misc/GThreadHelper");
 900         jmethodID mid_getAndSetInitializationNeededFlag =
 901                 (*env)->GetStaticMethodID(env, clazz, "getAndSetInitializationNeededFlag", "()Z");
 902         jmethodID mid_lock = (*env)->GetStaticMethodID(env, clazz, "lock", "()V");
 903         jmethodID mid_unlock = (*env)->GetStaticMethodID(env, clazz, "unlock", "()V");
 904 
 905         // Init the thread system to use GLib in a thread-safe mode
 906         (*env)->CallStaticVoidMethod(env, clazz, mid_lock);
 907 
 908         // Calling g_thread_init() multiple times leads to crash on GLib < 2.24
 909         // We can use g_thread_get_initialized () but it is available only for
 910         // GLib >= 2.20. We rely on GThreadHelper for GLib < 2.20.
 911         gboolean is_g_thread_get_initialized = FALSE;
 912         if (GLIB_CHECK_VERSION(2, 20, 0)) {
 913             is_g_thread_get_initialized = fp_g_thread_get_initialized();
 914         }
 915 
 916         if (!(*env)->CallStaticBooleanMethod(env, clazz, mid_getAndSetInitializationNeededFlag)) {
 917             if (!is_g_thread_get_initialized) {
 918                 fp_g_thread_init(NULL);
 919             }
 920 
 921             //According the GTK documentation, gdk_threads_init() should be
 922             //called before gtk_init() or gtk_init_check()
 923             fp_gdk_threads_init();
 924         }
 925         (*env)->CallStaticVoidMethod(env, clazz, mid_unlock);
 926     }
 927     result = (*fp_gtk_init_check)(NULL, NULL);
 928 
 929     XSetErrorHandler(handler);
 930     XSetIOErrorHandler(io_handler);
 931     AWT_UNLOCK();
 932 
 933     /* Initialize widget array. */
 934     for (i = 0; i < _GTK_WIDGET_TYPE_SIZE; i++)
 935     {
 936         gtk2_widgets[i] = NULL;
 937     }
 938 
 939     return result;
 940 }
 941 
 942 int gtk2_unload()
 943 {
 944     int i;
 945     char *gtk2_error;
 946 
 947     if (!gtk2_libhandle)
 948         return TRUE;
 949 
 950     /* Release painting objects */
 951     if (gtk2_white_pixmap != NULL) {
 952         (*fp_g_object_unref)(gtk2_white_pixmap);
 953         (*fp_g_object_unref)(gtk2_black_pixmap);
 954         (*fp_g_object_unref)(gtk2_white_pixbuf);
 955         (*fp_g_object_unref)(gtk2_black_pixbuf);
 956         gtk2_white_pixmap = gtk2_black_pixmap =
 957             gtk2_white_pixbuf = gtk2_black_pixbuf = NULL;
 958     }
 959     gtk2_pixbuf_width = 0;
 960     gtk2_pixbuf_height = 0;
 961 
 962     if (gtk2_window != NULL) {
 963         /* Destroying toplevel widget will destroy all contained widgets */
 964         (*fp_gtk_widget_destroy)(gtk2_window);
 965 
 966         /* Unset some static data so they get reinitialized on next load */
 967         gtk2_window = NULL;
 968     }
 969 
 970     dlerror();
 971     dlclose(gtk2_libhandle);
 972     dlclose(gthread_libhandle);
 973     if ((gtk2_error = dlerror()) != NULL)
 974     {
 975         return FALSE;
 976     }
 977     return TRUE;
 978 }
 979 
 980 /* Dispatch all pending events from the GTK event loop.
 981  * This is needed to catch theme change and update widgets' style.
 982  */
 983 void flush_gtk_event_loop()
 984 {
 985     while( (*fp_g_main_context_iteration)(NULL, FALSE));
 986 }
 987 
 988 /*
 989  * Initialize components of containment hierarchy. This creates a GtkFixed
 990  * inside a GtkWindow. All widgets get realized.
 991  */
 992 static void init_containers()
 993 {
 994     if (gtk2_window == NULL)
 995     {
 996         gtk2_window = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
 997         gtk2_fixed = (GtkFixed *)(*fp_gtk_fixed_new)();
 998         (*fp_gtk_container_add)((GtkContainer*)gtk2_window,
 999                                 (GtkWidget *)gtk2_fixed);
1000         (*fp_gtk_widget_realize)(gtk2_window);
1001         (*fp_gtk_widget_realize)((GtkWidget *)gtk2_fixed);
1002     }
1003 }
1004 
1005 /*
1006  * Ensure everything is ready for drawing an element of the specified width
1007  * and height.
1008  *
1009  * We should somehow handle translucent images. GTK can draw to X Drawables
1010  * only, which don't support alpha. When we retrieve the image back from
1011  * the server, translucency information is lost. There're several ways to
1012  * work around this:
1013  * 1) Subclass GdkPixmap and cache translucent objects on client side. This
1014  * requires us to implement parts of X server drawing logic on client side.
1015  * Many X requests can potentially be "translucent"; e.g. XDrawLine with
1016  * fill=tile and a translucent tile is a "translucent" operation, whereas
1017  * XDrawLine with fill=solid is an "opaque" one. Moreover themes can (and some
1018  * do) intermix transparent and opaque operations which makes caching even
1019  * more problematic.
1020  * 2) Use Xorg 32bit ARGB visual when available. GDK has no native support
1021  * for it (as of version 2.6). Also even in JDS 3 Xorg does not support
1022  * these visuals by default, which makes optimizing for them pointless.
1023  * We can consider doing this at a later point when ARGB visuals become more
1024  * popular.
1025  * 3') GTK has plans to use Cairo as its graphical backend (presumably in
1026  * 2.8), and Cairo supports alpha. With it we could also get rid of the
1027  * unnecessary round trip to server and do all the drawing on client side.
1028  * 4) For now we draw to two different pixmaps and restore alpha channel by
1029  * comparing results. This can be optimized by using subclassed pixmap and
1030  * doing the second drawing only if necessary.
1031 */
1032 void gtk2_init_painting(JNIEnv *env, gint width, gint height)
1033 {
1034     GdkGC *gc;
1035     GdkPixbuf *white, *black;
1036 
1037     init_containers();
1038 
1039     if (gtk2_pixbuf_width < width || gtk2_pixbuf_height < height)
1040     {
1041         white = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
1042         black = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
1043 
1044         if (white == NULL || black == NULL)
1045         {
1046             snprintf(convertionBuffer, CONV_BUFFER_SIZE, "Couldn't create pixbuf of size %dx%d", width, height);
1047             throw_exception(env, "java/lang/RuntimeException", convertionBuffer);
1048             fp_gdk_threads_leave();
1049             return;
1050         }
1051 
1052         if (gtk2_white_pixmap != NULL) {
1053             /* free old stuff */
1054             (*fp_g_object_unref)(gtk2_white_pixmap);
1055             (*fp_g_object_unref)(gtk2_black_pixmap);
1056             (*fp_g_object_unref)(gtk2_white_pixbuf);
1057             (*fp_g_object_unref)(gtk2_black_pixbuf);
1058         }
1059 
1060         gtk2_white_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1);
1061         gtk2_black_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1);
1062 
1063         gtk2_white_pixbuf = white;
1064         gtk2_black_pixbuf = black;
1065 
1066         gtk2_pixbuf_width = width;
1067         gtk2_pixbuf_height = height;
1068     }
1069 
1070     /* clear the pixmaps */
1071     gc = (*fp_gdk_gc_new)(gtk2_white_pixmap);
1072     (*fp_gdk_rgb_gc_set_foreground)(gc, 0xffffff);
1073     (*fp_gdk_draw_rectangle)(gtk2_white_pixmap, gc, TRUE, 0, 0, width, height);
1074     (*fp_g_object_unref)(gc);
1075 
1076     gc = (*fp_gdk_gc_new)(gtk2_black_pixmap);
1077     (*fp_gdk_rgb_gc_set_foreground)(gc, 0x000000);
1078     (*fp_gdk_draw_rectangle)(gtk2_black_pixmap, gc, TRUE, 0, 0, width, height);
1079     (*fp_g_object_unref)(gc);
1080 }
1081 
1082 /*
1083  * Restore image from white and black pixmaps and copy it into destination
1084  * buffer. This method compares two pixbufs taken from white and black
1085  * pixmaps and decodes color and alpha components. Pixbufs are RGB without
1086  * alpha, destination buffer is ABGR.
1087  *
1088  * The return value is the transparency type of the resulting image, either
1089  * one of java_awt_Transparency_OPAQUE, java_awt_Transparency_BITMASK, and
1090  * java_awt_Transparency_TRANSLUCENT.
1091  */
1092 gint gtk2_copy_image(gint *dst, gint width, gint height)
1093 {
1094     gint i, j, r, g, b;
1095     guchar *white, *black;
1096     gint stride, padding;
1097     gboolean is_opaque = TRUE;
1098     gboolean is_bitmask = TRUE;
1099 
1100     (*fp_gdk_pixbuf_get_from_drawable)(gtk2_white_pixbuf, gtk2_white_pixmap,
1101             NULL, 0, 0, 0, 0, width, height);
1102     (*fp_gdk_pixbuf_get_from_drawable)(gtk2_black_pixbuf, gtk2_black_pixmap,
1103             NULL, 0, 0, 0, 0, width, height);
1104 
1105     white = (*fp_gdk_pixbuf_get_pixels)(gtk2_white_pixbuf);
1106     black = (*fp_gdk_pixbuf_get_pixels)(gtk2_black_pixbuf);
1107     stride = (*fp_gdk_pixbuf_get_rowstride)(gtk2_black_pixbuf);
1108     padding = stride - width * 4;
1109 
1110     for (i = 0; i < height; i++) {
1111         for (j = 0; j < width; j++) {
1112             int r1 = *white++;
1113             int r2 = *black++;
1114             int alpha = 0xff + r2 - r1;
1115 
1116             switch (alpha) {
1117                 case 0:       /* transparent pixel */
1118                     r = g = b = 0;
1119                     black += 3;
1120                     white += 3;
1121                     is_opaque = FALSE;
1122                     break;
1123 
1124                 case 0xff:    /* opaque pixel */
1125                     r = r2;
1126                     g = *black++;
1127                     b = *black++;
1128                     black++;
1129                     white += 3;
1130                     break;
1131 
1132                 default:      /* translucent pixel */
1133                     r = 0xff * r2 / alpha;
1134                     g = 0xff * *black++ / alpha;
1135                     b = 0xff * *black++ / alpha;
1136                     black++;
1137                     white += 3;
1138                     is_opaque = FALSE;
1139                     is_bitmask = FALSE;
1140                     break;
1141             }
1142 
1143             *dst++ = (alpha << 24 | r << 16 | g << 8 | b);
1144         }
1145 
1146         white += padding;
1147         black += padding;
1148     }
1149     return is_opaque ? java_awt_Transparency_OPAQUE :
1150                        (is_bitmask ? java_awt_Transparency_BITMASK :
1151                                      java_awt_Transparency_TRANSLUCENT);
1152 }
1153 
1154 static void
1155 gtk2_set_direction(GtkWidget *widget, GtkTextDirection dir)
1156 {
1157     /*
1158      * Some engines (inexplicably) look at the direction of the widget's
1159      * parent, so we need to set the direction of both the widget and its
1160      * parent.
1161      */
1162     (*fp_gtk_widget_set_direction)(widget, dir);
1163     if (widget->parent != NULL) {
1164         (*fp_gtk_widget_set_direction)(widget->parent, dir);
1165     }
1166 }
1167 
1168 /*
1169  * Initializes the widget to correct state for some engines.
1170  * This is a pure empirical method.
1171  */
1172 static void init_toggle_widget(WidgetType widget_type, gint synth_state)
1173 {
1174     gboolean is_active = ((synth_state & SELECTED) != 0);
1175 
1176     if (widget_type == RADIO_BUTTON ||
1177         widget_type == CHECK_BOX ||
1178         widget_type == TOGGLE_BUTTON) {
1179         ((GtkToggleButton*)gtk2_widget)->active = is_active;
1180     }
1181 
1182     if ((synth_state & FOCUSED) != 0) {
1183         ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS;
1184     } else {
1185         ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
1186     }
1187 
1188     if ((synth_state & MOUSE_OVER) != 0 && (synth_state & PRESSED) == 0 ||
1189            (synth_state & FOCUSED) != 0 && (synth_state & PRESSED) != 0) {
1190         gtk2_widget->state = GTK_STATE_PRELIGHT;
1191     } else if ((synth_state & DISABLED) != 0) {
1192         gtk2_widget->state = GTK_STATE_INSENSITIVE;
1193     } else {
1194         gtk2_widget->state = is_active ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL;
1195     }
1196 }
1197 
1198 /* GTK state_type filter */
1199 static GtkStateType get_gtk_state_type(WidgetType widget_type, gint synth_state)
1200 {
1201     GtkStateType result = GTK_STATE_NORMAL;
1202 
1203     if ((synth_state & DISABLED) != 0) {
1204         result = GTK_STATE_INSENSITIVE;
1205     } else if ((synth_state & PRESSED) != 0) {
1206         result = GTK_STATE_ACTIVE;
1207     } else if ((synth_state & MOUSE_OVER) != 0) {
1208         result = GTK_STATE_PRELIGHT;
1209     }
1210     return result;
1211 }
1212 
1213 /* GTK shadow_type filter */
1214 static GtkShadowType get_gtk_shadow_type(WidgetType widget_type, gint synth_state)
1215 {
1216     GtkShadowType result = GTK_SHADOW_OUT;
1217 
1218     if ((synth_state & SELECTED) != 0) {
1219         result = GTK_SHADOW_IN;
1220     }
1221     return result;
1222 }
1223 
1224 
1225 static GtkWidget* gtk2_get_arrow(GtkArrowType arrow_type, GtkShadowType shadow_type)
1226 {
1227     GtkWidget *arrow = NULL;
1228     if (NULL == gtk2_widgets[_GTK_ARROW_TYPE])
1229     {
1230         gtk2_widgets[_GTK_ARROW_TYPE] = (*fp_gtk_arrow_new)(arrow_type, shadow_type);
1231         (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, gtk2_widgets[_GTK_ARROW_TYPE]);
1232         (*fp_gtk_widget_realize)(gtk2_widgets[_GTK_ARROW_TYPE]);
1233     }
1234     arrow = gtk2_widgets[_GTK_ARROW_TYPE];
1235 
1236     (*fp_gtk_arrow_set)(arrow, arrow_type, shadow_type);
1237     return arrow;
1238 }
1239 
1240 static GtkAdjustment* create_adjustment()
1241 {
1242     return (GtkAdjustment *)
1243             (*fp_gtk_adjustment_new)(50.0, 0.0, 100.0, 10.0, 20.0, 20.0);
1244 }
1245 
1246 /**
1247  * Returns a pointer to the cached native widget for the specified widget
1248  * type.
1249  */
1250 static GtkWidget *gtk2_get_widget(WidgetType widget_type)
1251 {
1252     gboolean init_result = FALSE;
1253     GtkWidget *result = NULL;
1254     switch (widget_type)
1255     {
1256         case BUTTON:
1257         case TABLE_HEADER:
1258             if (init_result = (NULL == gtk2_widgets[_GTK_BUTTON_TYPE]))
1259             {
1260                 gtk2_widgets[_GTK_BUTTON_TYPE] = (*fp_gtk_button_new)();
1261             }
1262             result = gtk2_widgets[_GTK_BUTTON_TYPE];
1263             break;
1264         case CHECK_BOX:
1265             if (init_result = (NULL == gtk2_widgets[_GTK_CHECK_BUTTON_TYPE]))
1266             {
1267                 gtk2_widgets[_GTK_CHECK_BUTTON_TYPE] =
1268                     (*fp_gtk_check_button_new)();
1269             }
1270             result = gtk2_widgets[_GTK_CHECK_BUTTON_TYPE];
1271             break;
1272         case CHECK_BOX_MENU_ITEM:
1273             if (init_result = (NULL == gtk2_widgets[_GTK_CHECK_MENU_ITEM_TYPE]))
1274             {
1275                 gtk2_widgets[_GTK_CHECK_MENU_ITEM_TYPE] =
1276                     (*fp_gtk_check_menu_item_new)();
1277             }
1278             result = gtk2_widgets[_GTK_CHECK_MENU_ITEM_TYPE];
1279             break;
1280         /************************************************************
1281          *    Creation a dedicated color chooser is dangerous because
1282          * it deadlocks the EDT
1283          ************************************************************/
1284 /*        case COLOR_CHOOSER:
1285             if (init_result =
1286                     (NULL == gtk2_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE]))
1287             {
1288                 gtk2_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE] =
1289                     (*fp_gtk_color_selection_dialog_new)(NULL);
1290             }
1291             result = gtk2_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE];
1292             break;*/
1293         case COMBO_BOX:
1294             if (init_result = (NULL == gtk2_widgets[_GTK_COMBO_BOX_TYPE]))
1295             {
1296                 gtk2_widgets[_GTK_COMBO_BOX_TYPE] =
1297                     (*fp_gtk_combo_box_new)();
1298             }
1299             result = gtk2_widgets[_GTK_COMBO_BOX_TYPE];
1300             break;
1301         case COMBO_BOX_ARROW_BUTTON:
1302             if (init_result =
1303                     (NULL == gtk2_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE]))
1304             {
1305                 gtk2_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE] =
1306                      (*fp_gtk_toggle_button_new)();
1307             }
1308             result = gtk2_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE];
1309             break;
1310         case COMBO_BOX_TEXT_FIELD:
1311             if (init_result =
1312                     (NULL == gtk2_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE]))
1313             {
1314                 result = gtk2_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE] =
1315                      (*fp_gtk_entry_new)();
1316             }
1317             result = gtk2_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE];
1318             break;
1319         case DESKTOP_ICON:
1320         case INTERNAL_FRAME_TITLE_PANE:
1321         case LABEL:
1322             if (init_result = (NULL == gtk2_widgets[_GTK_LABEL_TYPE]))
1323             {
1324                 gtk2_widgets[_GTK_LABEL_TYPE] =
1325                     (*fp_gtk_label_new)(NULL);
1326             }
1327             result = gtk2_widgets[_GTK_LABEL_TYPE];
1328             break;
1329         case DESKTOP_PANE:
1330         case PANEL:
1331         case ROOT_PANE:
1332             if (init_result = (NULL == gtk2_widgets[_GTK_CONTAINER_TYPE]))
1333             {
1334                 /* There is no constructor for a container type.  I've
1335                  * chosen GtkFixed container since it has a default
1336                  * constructor.
1337                  */
1338                 gtk2_widgets[_GTK_CONTAINER_TYPE] =
1339                     (*fp_gtk_fixed_new)();
1340             }
1341             result = gtk2_widgets[_GTK_CONTAINER_TYPE];
1342             break;
1343         case EDITOR_PANE:
1344         case TEXT_AREA:
1345         case TEXT_PANE:
1346             if (init_result = (NULL == gtk2_widgets[_GTK_TEXT_VIEW_TYPE]))
1347             {
1348                 gtk2_widgets[_GTK_TEXT_VIEW_TYPE] =
1349                     (*fp_gtk_text_view_new)();
1350             }
1351             result = gtk2_widgets[_GTK_TEXT_VIEW_TYPE];
1352             break;
1353         case FORMATTED_TEXT_FIELD:
1354         case PASSWORD_FIELD:
1355         case TEXT_FIELD:
1356             if (init_result = (NULL == gtk2_widgets[_GTK_ENTRY_TYPE]))
1357             {
1358                 gtk2_widgets[_GTK_ENTRY_TYPE] =
1359                     (*fp_gtk_entry_new)();
1360             }
1361             result = gtk2_widgets[_GTK_ENTRY_TYPE];
1362             break;
1363         case HANDLE_BOX:
1364             if (init_result = (NULL == gtk2_widgets[_GTK_HANDLE_BOX_TYPE]))
1365             {
1366                 gtk2_widgets[_GTK_HANDLE_BOX_TYPE] =
1367                     (*fp_gtk_handle_box_new)();
1368             }
1369             result = gtk2_widgets[_GTK_HANDLE_BOX_TYPE];
1370             break;
1371         case HSCROLL_BAR:
1372         case HSCROLL_BAR_BUTTON_LEFT:
1373         case HSCROLL_BAR_BUTTON_RIGHT:
1374         case HSCROLL_BAR_TRACK:
1375         case HSCROLL_BAR_THUMB:
1376             if (init_result = (NULL == gtk2_widgets[_GTK_HSCROLLBAR_TYPE]))
1377             {
1378                 gtk2_widgets[_GTK_HSCROLLBAR_TYPE] =
1379                     (*fp_gtk_hscrollbar_new)(create_adjustment());
1380             }
1381             result = gtk2_widgets[_GTK_HSCROLLBAR_TYPE];
1382             break;
1383         case HSEPARATOR:
1384             if (init_result = (NULL == gtk2_widgets[_GTK_HSEPARATOR_TYPE]))
1385             {
1386                 gtk2_widgets[_GTK_HSEPARATOR_TYPE] =
1387                     (*fp_gtk_hseparator_new)();
1388             }
1389             result = gtk2_widgets[_GTK_HSEPARATOR_TYPE];
1390             break;
1391         case HSLIDER:
1392         case HSLIDER_THUMB:
1393         case HSLIDER_TRACK:
1394             if (init_result = (NULL == gtk2_widgets[_GTK_HSCALE_TYPE]))
1395             {
1396                 gtk2_widgets[_GTK_HSCALE_TYPE] =
1397                     (*fp_gtk_hscale_new)(NULL);
1398             }
1399             result = gtk2_widgets[_GTK_HSCALE_TYPE];
1400             break;
1401         case HSPLIT_PANE_DIVIDER:
1402         case SPLIT_PANE:
1403             if (init_result = (NULL == gtk2_widgets[_GTK_HPANED_TYPE]))
1404             {
1405                 gtk2_widgets[_GTK_HPANED_TYPE] = (*fp_gtk_hpaned_new)();
1406             }
1407             result = gtk2_widgets[_GTK_HPANED_TYPE];
1408             break;
1409         case IMAGE:
1410             if (init_result = (NULL == gtk2_widgets[_GTK_IMAGE_TYPE]))
1411             {
1412                 gtk2_widgets[_GTK_IMAGE_TYPE] = (*fp_gtk_image_new)();
1413             }
1414             result = gtk2_widgets[_GTK_IMAGE_TYPE];
1415             break;
1416         case INTERNAL_FRAME:
1417             if (init_result = (NULL == gtk2_widgets[_GTK_WINDOW_TYPE]))
1418             {
1419                 gtk2_widgets[_GTK_WINDOW_TYPE] =
1420                     (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
1421             }
1422             result = gtk2_widgets[_GTK_WINDOW_TYPE];
1423             break;
1424         case TOOL_TIP:
1425             if (init_result = (NULL == gtk2_widgets[_GTK_TOOLTIP_TYPE]))
1426             {
1427                 result = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
1428                 (*fp_gtk_widget_set_name)(result, "gtk-tooltips");
1429                 gtk2_widgets[_GTK_TOOLTIP_TYPE] = result;
1430             }
1431             result = gtk2_widgets[_GTK_TOOLTIP_TYPE];
1432             break;
1433         case LIST:
1434         case TABLE:
1435         case TREE:
1436         case TREE_CELL:
1437             if (init_result = (NULL == gtk2_widgets[_GTK_TREE_VIEW_TYPE]))
1438             {
1439                 gtk2_widgets[_GTK_TREE_VIEW_TYPE] =
1440                     (*fp_gtk_tree_view_new)();
1441             }
1442             result = gtk2_widgets[_GTK_TREE_VIEW_TYPE];
1443             break;
1444         case TITLED_BORDER:
1445             if (init_result = (NULL == gtk2_widgets[_GTK_FRAME_TYPE]))
1446             {
1447                 gtk2_widgets[_GTK_FRAME_TYPE] = fp_gtk_frame_new(NULL);
1448             }
1449             result = gtk2_widgets[_GTK_FRAME_TYPE];
1450             break;
1451         case POPUP_MENU:
1452             if (init_result = (NULL == gtk2_widgets[_GTK_MENU_TYPE]))
1453             {
1454                 gtk2_widgets[_GTK_MENU_TYPE] =
1455                     (*fp_gtk_menu_new)();
1456             }
1457             result = gtk2_widgets[_GTK_MENU_TYPE];
1458             break;
1459         case MENU:
1460         case MENU_ITEM:
1461         case MENU_ITEM_ACCELERATOR:
1462             if (init_result = (NULL == gtk2_widgets[_GTK_MENU_ITEM_TYPE]))
1463             {
1464                 gtk2_widgets[_GTK_MENU_ITEM_TYPE] =
1465                     (*fp_gtk_menu_item_new)();
1466             }
1467             result = gtk2_widgets[_GTK_MENU_ITEM_TYPE];
1468             break;
1469         case MENU_BAR:
1470             if (init_result = (NULL == gtk2_widgets[_GTK_MENU_BAR_TYPE]))
1471             {
1472                 gtk2_widgets[_GTK_MENU_BAR_TYPE] =
1473                     (*fp_gtk_menu_bar_new)();
1474             }
1475             result = gtk2_widgets[_GTK_MENU_BAR_TYPE];
1476             break;
1477         case COLOR_CHOOSER:
1478         case OPTION_PANE:
1479             if (init_result = (NULL == gtk2_widgets[_GTK_DIALOG_TYPE]))
1480             {
1481                 gtk2_widgets[_GTK_DIALOG_TYPE] =
1482                     (*fp_gtk_dialog_new)();
1483             }
1484             result = gtk2_widgets[_GTK_DIALOG_TYPE];
1485             break;
1486         case POPUP_MENU_SEPARATOR:
1487             if (init_result =
1488                     (NULL == gtk2_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE]))
1489             {
1490                 gtk2_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE] =
1491                     (*fp_gtk_separator_menu_item_new)();
1492             }
1493             result = gtk2_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE];
1494             break;
1495         case HPROGRESS_BAR:
1496             if (init_result = (NULL == gtk2_widgets[_GTK_HPROGRESS_BAR_TYPE]))
1497             {
1498                 gtk2_widgets[_GTK_HPROGRESS_BAR_TYPE] =
1499                     (*fp_gtk_progress_bar_new)();
1500             }
1501             result = gtk2_widgets[_GTK_HPROGRESS_BAR_TYPE];
1502             break;
1503         case VPROGRESS_BAR:
1504             if (init_result = (NULL == gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE]))
1505             {
1506                 gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE] =
1507                     (*fp_gtk_progress_bar_new)();
1508                 /*
1509                  * Vertical JProgressBars always go bottom-to-top,
1510                  * regardless of the ComponentOrientation.
1511                  */
1512                 (*fp_gtk_progress_bar_set_orientation)(
1513                     (GtkProgressBar *)gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE],
1514                     GTK_PROGRESS_BOTTOM_TO_TOP);
1515             }
1516             result = gtk2_widgets[_GTK_VPROGRESS_BAR_TYPE];
1517             break;
1518         case RADIO_BUTTON:
1519             if (init_result = (NULL == gtk2_widgets[_GTK_RADIO_BUTTON_TYPE]))
1520             {
1521                 gtk2_widgets[_GTK_RADIO_BUTTON_TYPE] =
1522                     (*fp_gtk_radio_button_new)(NULL);
1523             }
1524             result = gtk2_widgets[_GTK_RADIO_BUTTON_TYPE];
1525             break;
1526         case RADIO_BUTTON_MENU_ITEM:
1527             if (init_result =
1528                     (NULL == gtk2_widgets[_GTK_RADIO_MENU_ITEM_TYPE]))
1529             {
1530                 gtk2_widgets[_GTK_RADIO_MENU_ITEM_TYPE] =
1531                     (*fp_gtk_radio_menu_item_new)(NULL);
1532             }
1533             result = gtk2_widgets[_GTK_RADIO_MENU_ITEM_TYPE];
1534             break;
1535         case SCROLL_PANE:
1536             if (init_result =
1537                     (NULL == gtk2_widgets[_GTK_SCROLLED_WINDOW_TYPE]))
1538             {
1539                 gtk2_widgets[_GTK_SCROLLED_WINDOW_TYPE] =
1540                     (*fp_gtk_scrolled_window_new)(NULL, NULL);
1541             }
1542             result = gtk2_widgets[_GTK_SCROLLED_WINDOW_TYPE];
1543             break;
1544         case SPINNER:
1545         case SPINNER_ARROW_BUTTON:
1546         case SPINNER_TEXT_FIELD:
1547             if (init_result = (NULL == gtk2_widgets[_GTK_SPIN_BUTTON_TYPE]))
1548             {
1549                 result = gtk2_widgets[_GTK_SPIN_BUTTON_TYPE] =
1550                     (*fp_gtk_spin_button_new)(NULL, 0, 0);
1551             }
1552             result = gtk2_widgets[_GTK_SPIN_BUTTON_TYPE];
1553             break;
1554         case TABBED_PANE:
1555         case TABBED_PANE_TAB_AREA:
1556         case TABBED_PANE_CONTENT:
1557         case TABBED_PANE_TAB:
1558             if (init_result = (NULL == gtk2_widgets[_GTK_NOTEBOOK_TYPE]))
1559             {
1560                 gtk2_widgets[_GTK_NOTEBOOK_TYPE] =
1561                     (*fp_gtk_notebook_new)(NULL);
1562             }
1563             result = gtk2_widgets[_GTK_NOTEBOOK_TYPE];
1564             break;
1565         case TOGGLE_BUTTON:
1566             if (init_result = (NULL == gtk2_widgets[_GTK_TOGGLE_BUTTON_TYPE]))
1567             {
1568                 gtk2_widgets[_GTK_TOGGLE_BUTTON_TYPE] =
1569                     (*fp_gtk_toggle_button_new)(NULL);
1570             }
1571             result = gtk2_widgets[_GTK_TOGGLE_BUTTON_TYPE];
1572             break;
1573         case TOOL_BAR:
1574         case TOOL_BAR_DRAG_WINDOW:
1575             if (init_result = (NULL == gtk2_widgets[_GTK_TOOLBAR_TYPE]))
1576             {
1577                 gtk2_widgets[_GTK_TOOLBAR_TYPE] =
1578                     (*fp_gtk_toolbar_new)(NULL);
1579             }
1580             result = gtk2_widgets[_GTK_TOOLBAR_TYPE];
1581             break;
1582         case TOOL_BAR_SEPARATOR:
1583             if (init_result =
1584                     (NULL == gtk2_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE]))
1585             {
1586                 gtk2_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE] =
1587                     (*fp_gtk_separator_tool_item_new)();
1588             }
1589             result = gtk2_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE];
1590             break;
1591         case VIEWPORT:
1592             if (init_result = (NULL == gtk2_widgets[_GTK_VIEWPORT_TYPE]))
1593             {
1594                 GtkAdjustment *adjustment = create_adjustment();
1595                 gtk2_widgets[_GTK_VIEWPORT_TYPE] =
1596                     (*fp_gtk_viewport_new)(adjustment, adjustment);
1597             }
1598             result = gtk2_widgets[_GTK_VIEWPORT_TYPE];
1599             break;
1600         case VSCROLL_BAR:
1601         case VSCROLL_BAR_BUTTON_UP:
1602         case VSCROLL_BAR_BUTTON_DOWN:
1603         case VSCROLL_BAR_TRACK:
1604         case VSCROLL_BAR_THUMB:
1605             if (init_result = (NULL == gtk2_widgets[_GTK_VSCROLLBAR_TYPE]))
1606             {
1607                 gtk2_widgets[_GTK_VSCROLLBAR_TYPE] =
1608                     (*fp_gtk_vscrollbar_new)(create_adjustment());
1609             }
1610             result = gtk2_widgets[_GTK_VSCROLLBAR_TYPE];
1611             break;
1612         case VSEPARATOR:
1613             if (init_result = (NULL == gtk2_widgets[_GTK_VSEPARATOR_TYPE]))
1614             {
1615                 gtk2_widgets[_GTK_VSEPARATOR_TYPE] =
1616                     (*fp_gtk_vseparator_new)();
1617             }
1618             result = gtk2_widgets[_GTK_VSEPARATOR_TYPE];
1619             break;
1620         case VSLIDER:
1621         case VSLIDER_THUMB:
1622         case VSLIDER_TRACK:
1623             if (init_result = (NULL == gtk2_widgets[_GTK_VSCALE_TYPE]))
1624             {
1625                 gtk2_widgets[_GTK_VSCALE_TYPE] =
1626                     (*fp_gtk_vscale_new)(NULL);
1627             }
1628             result = gtk2_widgets[_GTK_VSCALE_TYPE];
1629             /*
1630              * Vertical JSliders start at the bottom, while vertical
1631              * GtkVScale widgets start at the top (by default), so to fix
1632              * this we set the "inverted" flag to get the Swing behavior.
1633              */
1634             ((GtkRange*)result)->inverted = 1;
1635             break;
1636         case VSPLIT_PANE_DIVIDER:
1637             if (init_result = (NULL == gtk2_widgets[_GTK_VPANED_TYPE]))
1638             {
1639                 gtk2_widgets[_GTK_VPANED_TYPE] = (*fp_gtk_vpaned_new)();
1640             }
1641             result = gtk2_widgets[_GTK_VPANED_TYPE];
1642             break;
1643         default:
1644             result = NULL;
1645             break;
1646     }
1647 
1648     if (result != NULL && init_result)
1649     {
1650         if (widget_type == RADIO_BUTTON_MENU_ITEM ||
1651                 widget_type == CHECK_BOX_MENU_ITEM ||
1652                 widget_type == MENU_ITEM ||
1653                 widget_type == MENU ||
1654                 widget_type == POPUP_MENU_SEPARATOR)
1655         {
1656             GtkWidget *menu = gtk2_get_widget(POPUP_MENU);
1657             (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu, result);
1658         }
1659         else if (widget_type == POPUP_MENU)
1660         {
1661             GtkWidget *menu_bar = gtk2_get_widget(MENU_BAR);
1662             GtkWidget *root_menu = (*fp_gtk_menu_item_new)();
1663             (*fp_gtk_menu_item_set_submenu)((GtkMenuItem*)root_menu, result);
1664             (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu_bar, root_menu);
1665         }
1666         else if (widget_type == COMBO_BOX_ARROW_BUTTON ||
1667                  widget_type == COMBO_BOX_TEXT_FIELD)
1668         {
1669             /*
1670             * We add a regular GtkButton/GtkEntry to a GtkComboBoxEntry
1671             * in order to trick engines into thinking it's a real combobox
1672             * arrow button/text field.
1673             */
1674             GtkWidget *combo = (*fp_gtk_combo_box_entry_new)();
1675 
1676             if (new_combo && widget_type == COMBO_BOX_ARROW_BUTTON) {
1677                 (*fp_gtk_widget_set_parent)(result, combo);
1678                 ((GtkBin*)combo)->child = result;
1679             } else {
1680                 (*fp_gtk_container_add)((GtkContainer *)combo, result);
1681             }
1682             (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, combo);
1683         }
1684         else if (widget_type != TOOL_TIP &&
1685                  widget_type != INTERNAL_FRAME &&
1686                  widget_type != OPTION_PANE)
1687         {
1688             (*fp_gtk_container_add)((GtkContainer *)gtk2_fixed, result);
1689         }
1690         (*fp_gtk_widget_realize)(result);
1691     }
1692     return result;
1693 }
1694 
1695 void gtk2_paint_arrow(WidgetType widget_type, GtkStateType state_type,
1696         GtkShadowType shadow_type, const gchar *detail,
1697         gint x, gint y, gint width, gint height,
1698         GtkArrowType arrow_type, gboolean fill)
1699 {
1700     static int w, h;
1701     static GtkRequisition size;
1702 
1703     if (widget_type == COMBO_BOX_ARROW_BUTTON || widget_type == TABLE)
1704         gtk2_widget = gtk2_get_arrow(arrow_type, shadow_type);
1705     else
1706         gtk2_widget = gtk2_get_widget(widget_type);
1707 
1708     switch (widget_type)
1709     {
1710         case SPINNER_ARROW_BUTTON:
1711             x = 1;
1712             y = ((arrow_type == GTK_ARROW_UP) ? 2 : 0);
1713             height -= 2;
1714             width -= 3;
1715 
1716             w = width / 2;
1717             w -= w % 2 - 1;
1718             h = (w + 1) / 2;
1719             break;
1720 
1721         case HSCROLL_BAR_BUTTON_LEFT:
1722         case HSCROLL_BAR_BUTTON_RIGHT:
1723         case VSCROLL_BAR_BUTTON_UP:
1724         case VSCROLL_BAR_BUTTON_DOWN:
1725             w = width / 2;
1726             h = height / 2;
1727             break;
1728 
1729         case COMBO_BOX_ARROW_BUTTON:
1730         case TABLE:
1731             x = 1;
1732             (*fp_gtk_widget_size_request)(gtk2_widget, &size);
1733             w = size.width - ((GtkMisc*)gtk2_widget)->xpad * 2;
1734             h = size.height - ((GtkMisc*)gtk2_widget)->ypad * 2;
1735             w = h = MIN(MIN(w, h), MIN(width,height)) * 0.7;
1736             break;
1737 
1738         default:
1739             w = width;
1740             h = height;
1741             break;
1742     }
1743     x += (width - w) / 2;
1744     y += (height - h) / 2;
1745 
1746     (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1747             shadow_type, NULL, gtk2_widget, detail, arrow_type, fill,
1748             x, y, w, h);
1749     (*fp_gtk_paint_arrow)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1750             shadow_type, NULL, gtk2_widget, detail, arrow_type, fill,
1751             x, y, w, h);
1752 }
1753 
1754 void gtk2_paint_box(WidgetType widget_type, GtkStateType state_type,
1755                     GtkShadowType shadow_type, const gchar *detail,
1756                     gint x, gint y, gint width, gint height,
1757                     gint synth_state, GtkTextDirection dir)
1758 {
1759     gtk2_widget = gtk2_get_widget(widget_type);
1760 
1761     /*
1762      * The clearlooks engine sometimes looks at the widget's state field
1763      * instead of just the state_type variable that we pass in, so to account
1764      * for those cases we set the widget's state field accordingly.  The
1765      * flags field is similarly important for things like focus/default state.
1766      */
1767     gtk2_widget->state = state_type;
1768 
1769     if (widget_type == HSLIDER_TRACK) {
1770         /*
1771          * For horizontal JSliders with right-to-left orientation, we need
1772          * to set the "inverted" flag to match the native GTK behavior where
1773          * the foreground highlight is on the right side of the slider thumb.
1774          * This is needed especially for the ubuntulooks engine, which looks
1775          * exclusively at the "inverted" flag to determine on which side of
1776          * the thumb to paint the highlight...
1777          */
1778         ((GtkRange*)gtk2_widget)->inverted = (dir == GTK_TEXT_DIR_RTL);
1779 
1780         /*
1781          * Note however that other engines like clearlooks will look at both
1782          * the "inverted" field and the text direction to determine how
1783          * the foreground highlight is painted:
1784          *     !inverted && ltr --> paint highlight on left side
1785          *     !inverted && rtl --> paint highlight on right side
1786          *      inverted && ltr --> paint highlight on right side
1787          *      inverted && rtl --> paint highlight on left side
1788          * So the only way to reliably get the desired results for horizontal
1789          * JSlider (i.e., highlight on left side for LTR ComponentOrientation
1790          * and highlight on right side for RTL ComponentOrientation) is to
1791          * always override text direction as LTR, and then set the "inverted"
1792          * flag accordingly (as we have done above).
1793          */
1794         dir = GTK_TEXT_DIR_LTR;
1795     }
1796 
1797     /*
1798      * Some engines (e.g. clearlooks) will paint the shadow of certain
1799      * widgets (e.g. COMBO_BOX_ARROW_BUTTON) differently depending on the
1800      * the text direction.
1801      */
1802     gtk2_set_direction(gtk2_widget, dir);
1803 
1804     switch (widget_type) {
1805     case BUTTON:
1806         if (synth_state & DEFAULT) {
1807             ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_DEFAULT;
1808         } else {
1809             ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_DEFAULT;
1810         }
1811         break;
1812     case TOGGLE_BUTTON:
1813         init_toggle_widget(widget_type, synth_state);
1814         break;
1815     case HSCROLL_BAR_BUTTON_LEFT:
1816         /*
1817          * The clearlooks engine will draw a "left" button when:
1818          *   x == w->allocation.x
1819          *
1820          * The ubuntulooks engine will draw a "left" button when:
1821          *   [x,y,width,height]
1822          *     intersects
1823          *   [w->alloc.x,w->alloc.y,width,height]
1824          *
1825          * The values that are set below should ensure that a "left"
1826          * button is rendered for both of these (and other) engines.
1827          */
1828         gtk2_widget->allocation.x = x;
1829         gtk2_widget->allocation.y = y;
1830         gtk2_widget->allocation.width = width;
1831         gtk2_widget->allocation.height = height;
1832         break;
1833     case HSCROLL_BAR_BUTTON_RIGHT:
1834         /*
1835          * The clearlooks engine will draw a "right" button when:
1836          *   x + width == w->allocation.x + w->allocation.width
1837          *
1838          * The ubuntulooks engine will draw a "right" button when:
1839          *   [x,y,width,height]
1840          *     does not intersect
1841          *   [w->alloc.x,w->alloc.y,width,height]
1842          *     but does intersect
1843          *   [w->alloc.x+width,w->alloc.y,width,height]
1844          *
1845          * The values that are set below should ensure that a "right"
1846          * button is rendered for both of these (and other) engines.
1847          */
1848         gtk2_widget->allocation.x = x+width;
1849         gtk2_widget->allocation.y = 0;
1850         gtk2_widget->allocation.width = 0;
1851         gtk2_widget->allocation.height = height;
1852         break;
1853     case VSCROLL_BAR_BUTTON_UP:
1854         /*
1855          * The clearlooks engine will draw an "up" button when:
1856          *   y == w->allocation.y
1857          *
1858          * The ubuntulooks engine will draw an "up" button when:
1859          *   [x,y,width,height]
1860          *     intersects
1861          *   [w->alloc.x,w->alloc.y,width,height]
1862          *
1863          * The values that are set below should ensure that an "up"
1864          * button is rendered for both of these (and other) engines.
1865          */
1866         gtk2_widget->allocation.x = x;
1867         gtk2_widget->allocation.y = y;
1868         gtk2_widget->allocation.width = width;
1869         gtk2_widget->allocation.height = height;
1870         break;
1871     case VSCROLL_BAR_BUTTON_DOWN:
1872         /*
1873          * The clearlooks engine will draw a "down" button when:
1874          *   y + height == w->allocation.y + w->allocation.height
1875          *
1876          * The ubuntulooks engine will draw a "down" button when:
1877          *   [x,y,width,height]
1878          *     does not intersect
1879          *   [w->alloc.x,w->alloc.y,width,height]
1880          *     but does intersect
1881          *   [w->alloc.x,w->alloc.y+height,width,height]
1882          *
1883          * The values that are set below should ensure that a "down"
1884          * button is rendered for both of these (and other) engines.
1885          */
1886         gtk2_widget->allocation.x = x;
1887         gtk2_widget->allocation.y = y+height;
1888         gtk2_widget->allocation.width = width;
1889         gtk2_widget->allocation.height = 0;
1890         break;
1891     default:
1892         break;
1893     }
1894 
1895     (*fp_gtk_paint_box)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1896             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
1897     (*fp_gtk_paint_box)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1898             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
1899 
1900     /*
1901      * Reset the text direction to the default value so that we don't
1902      * accidentally affect other operations and widgets.
1903      */
1904     gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR);
1905 }
1906 
1907 void gtk2_paint_box_gap(WidgetType widget_type, GtkStateType state_type,
1908         GtkShadowType shadow_type, const gchar *detail,
1909         gint x, gint y, gint width, gint height,
1910         GtkPositionType gap_side, gint gap_x, gint gap_width)
1911 {
1912     /* Clearlooks needs a real clip area to paint the gap properly */
1913     GdkRectangle area = { x, y, width, height };
1914 
1915     gtk2_widget = gtk2_get_widget(widget_type);
1916     (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1917             shadow_type, &area, gtk2_widget, detail,
1918             x, y, width, height, gap_side, gap_x, gap_width);
1919     (*fp_gtk_paint_box_gap)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1920             shadow_type, &area, gtk2_widget, detail,
1921             x, y, width, height, gap_side, gap_x, gap_width);
1922 }
1923 
1924 void gtk2_paint_check(WidgetType widget_type, gint synth_state,
1925         const gchar *detail, gint x, gint y, gint width, gint height)
1926 {
1927     GtkStateType state_type = get_gtk_state_type(widget_type, synth_state);
1928     GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state);
1929 
1930     gtk2_widget = gtk2_get_widget(widget_type);
1931     init_toggle_widget(widget_type, synth_state);
1932 
1933     (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1934             shadow_type, NULL, gtk2_widget, detail,
1935             x, y, width, height);
1936     (*fp_gtk_paint_check)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1937             shadow_type, NULL, gtk2_widget, detail,
1938             x, y, width, height);
1939 }
1940 
1941 void gtk2_paint_diamond(WidgetType widget_type, GtkStateType state_type,
1942         GtkShadowType shadow_type, const gchar *detail,
1943         gint x, gint y, gint width, gint height)
1944 {
1945     gtk2_widget = gtk2_get_widget(widget_type);
1946     (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_white_pixmap, state_type,
1947             shadow_type, NULL, gtk2_widget, detail,
1948             x, y, width, height);
1949     (*fp_gtk_paint_diamond)(gtk2_widget->style, gtk2_black_pixmap, state_type,
1950             shadow_type, NULL, gtk2_widget, detail,
1951             x, y, width, height);
1952 }
1953 
1954 void gtk2_paint_expander(WidgetType widget_type, GtkStateType state_type,
1955         const gchar *detail, gint x, gint y, gint width, gint height,
1956         GtkExpanderStyle expander_style)
1957 {
1958     gtk2_widget = gtk2_get_widget(widget_type);
1959     (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_white_pixmap,
1960             state_type, NULL, gtk2_widget, detail,
1961             x + width / 2, y + height / 2, expander_style);
1962     (*fp_gtk_paint_expander)(gtk2_widget->style, gtk2_black_pixmap,
1963             state_type, NULL, gtk2_widget, detail,
1964             x + width / 2, y + height / 2, expander_style);
1965 }
1966 
1967 void gtk2_paint_extension(WidgetType widget_type, GtkStateType state_type,
1968         GtkShadowType shadow_type, const gchar *detail,
1969         gint x, gint y, gint width, gint height, GtkPositionType gap_side)
1970 {
1971     gtk2_widget = gtk2_get_widget(widget_type);
1972     (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_white_pixmap,
1973             state_type, shadow_type, NULL, gtk2_widget, detail,
1974             x, y, width, height, gap_side);
1975     (*fp_gtk_paint_extension)(gtk2_widget->style, gtk2_black_pixmap,
1976             state_type, shadow_type, NULL, gtk2_widget, detail,
1977             x, y, width, height, gap_side);
1978 }
1979 
1980 void gtk2_paint_flat_box(WidgetType widget_type, GtkStateType state_type,
1981         GtkShadowType shadow_type, const gchar *detail,
1982         gint x, gint y, gint width, gint height, gboolean has_focus)
1983 {
1984     gtk2_widget = gtk2_get_widget(widget_type);
1985 
1986     if (has_focus)
1987         ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS;
1988     else
1989         ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
1990 
1991     (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_white_pixmap,
1992             state_type, shadow_type, NULL, gtk2_widget, detail,
1993             x, y, width, height);
1994     (*fp_gtk_paint_flat_box)(gtk2_widget->style, gtk2_black_pixmap,
1995             state_type, shadow_type, NULL, gtk2_widget, detail,
1996             x, y, width, height);
1997 }
1998 
1999 void gtk2_paint_focus(WidgetType widget_type, GtkStateType state_type,
2000         const char *detail, gint x, gint y, gint width, gint height)
2001 {
2002     gtk2_widget = gtk2_get_widget(widget_type);
2003     (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2004             NULL, gtk2_widget, detail, x, y, width, height);
2005     (*fp_gtk_paint_focus)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2006             NULL, gtk2_widget, detail, x, y, width, height);
2007 }
2008 
2009 void gtk2_paint_handle(WidgetType widget_type, GtkStateType state_type,
2010         GtkShadowType shadow_type, const gchar *detail,
2011         gint x, gint y, gint width, gint height, GtkOrientation orientation)
2012 {
2013     gtk2_widget = gtk2_get_widget(widget_type);
2014     (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2015             shadow_type, NULL, gtk2_widget, detail,
2016             x, y, width, height, orientation);
2017     (*fp_gtk_paint_handle)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2018             shadow_type, NULL, gtk2_widget, detail,
2019             x, y, width, height, orientation);
2020 }
2021 
2022 void gtk2_paint_hline(WidgetType widget_type, GtkStateType state_type,
2023         const gchar *detail, gint x, gint y, gint width, gint height)
2024 {
2025     gtk2_widget = gtk2_get_widget(widget_type);
2026     (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2027             NULL, gtk2_widget, detail, x, x + width, y);
2028     (*fp_gtk_paint_hline)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2029             NULL, gtk2_widget, detail, x, x + width, y);
2030 }
2031 
2032 void gtk2_paint_option(WidgetType widget_type, gint synth_state,
2033         const gchar *detail, gint x, gint y, gint width, gint height)
2034 {
2035     GtkStateType state_type = get_gtk_state_type(widget_type, synth_state);
2036     GtkShadowType shadow_type = get_gtk_shadow_type(widget_type, synth_state);
2037 
2038     gtk2_widget = gtk2_get_widget(widget_type);
2039     init_toggle_widget(widget_type, synth_state);
2040 
2041     (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2042             shadow_type, NULL, gtk2_widget, detail,
2043             x, y, width, height);
2044     (*fp_gtk_paint_option)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2045             shadow_type, NULL, gtk2_widget, detail,
2046             x, y, width, height);
2047 }
2048 
2049 void gtk2_paint_shadow(WidgetType widget_type, GtkStateType state_type,
2050                        GtkShadowType shadow_type, const gchar *detail,
2051                        gint x, gint y, gint width, gint height,
2052                        gint synth_state, GtkTextDirection dir)
2053 {
2054     gtk2_widget = gtk2_get_widget(widget_type);
2055 
2056     /*
2057      * The clearlooks engine sometimes looks at the widget's state field
2058      * instead of just the state_type variable that we pass in, so to account
2059      * for those cases we set the widget's state field accordingly.  The
2060      * flags field is similarly important for things like focus state.
2061      */
2062     gtk2_widget->state = state_type;
2063 
2064     /*
2065      * Some engines (e.g. clearlooks) will paint the shadow of certain
2066      * widgets (e.g. COMBO_BOX_TEXT_FIELD) differently depending on the
2067      * the text direction.
2068      */
2069     gtk2_set_direction(gtk2_widget, dir);
2070 
2071     switch (widget_type) {
2072     case COMBO_BOX_TEXT_FIELD:
2073     case FORMATTED_TEXT_FIELD:
2074     case PASSWORD_FIELD:
2075     case SPINNER_TEXT_FIELD:
2076     case TEXT_FIELD:
2077         if (synth_state & FOCUSED) {
2078             ((GtkObject*)gtk2_widget)->flags |= GTK_HAS_FOCUS;
2079         } else {
2080             ((GtkObject*)gtk2_widget)->flags &= ~GTK_HAS_FOCUS;
2081         }
2082         break;
2083     default:
2084         break;
2085     }
2086 
2087     (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2088             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
2089     (*fp_gtk_paint_shadow)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2090             shadow_type, NULL, gtk2_widget, detail, x, y, width, height);
2091 
2092     /*
2093      * Reset the text direction to the default value so that we don't
2094      * accidentally affect other operations and widgets.
2095      */
2096     gtk2_set_direction(gtk2_widget, GTK_TEXT_DIR_LTR);
2097 }
2098 
2099 void gtk2_paint_slider(WidgetType widget_type, GtkStateType state_type,
2100         GtkShadowType shadow_type, const gchar *detail,
2101         gint x, gint y, gint width, gint height, GtkOrientation orientation)
2102 {
2103     gtk2_widget = gtk2_get_widget(widget_type);
2104     (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2105             shadow_type, NULL, gtk2_widget, detail,
2106             x, y, width, height, orientation);
2107     (*fp_gtk_paint_slider)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2108             shadow_type, NULL, gtk2_widget, detail,
2109             x, y, width, height, orientation);
2110 }
2111 
2112 void gtk2_paint_vline(WidgetType widget_type, GtkStateType state_type,
2113         const gchar *detail, gint x, gint y, gint width, gint height)
2114 {
2115     gtk2_widget = gtk2_get_widget(widget_type);
2116     (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_white_pixmap, state_type,
2117             NULL, gtk2_widget, detail, y, y + height, x);
2118     (*fp_gtk_paint_vline)(gtk2_widget->style, gtk2_black_pixmap, state_type,
2119             NULL, gtk2_widget, detail, y, y + height, x);
2120 }
2121 
2122 void gtk_paint_background(WidgetType widget_type, GtkStateType state_type,
2123         gint x, gint y, gint width, gint height)
2124 {
2125     gtk2_widget = gtk2_get_widget(widget_type);
2126     (*fp_gtk_style_apply_default_background)(gtk2_widget->style,
2127             gtk2_white_pixmap, TRUE, state_type, NULL, x, y, width, height);
2128     (*fp_gtk_style_apply_default_background)(gtk2_widget->style,
2129             gtk2_black_pixmap, TRUE, state_type, NULL, x, y, width, height);
2130 }
2131 
2132 GdkPixbuf *gtk2_get_stock_icon(gint widget_type, const gchar *stock_id,
2133         GtkIconSize size, GtkTextDirection direction, const char *detail)
2134 {
2135     init_containers();
2136     gtk2_widget = gtk2_get_widget((widget_type < 0) ? IMAGE : widget_type);
2137     gtk2_widget->state = GTK_STATE_NORMAL;
2138     (*fp_gtk_widget_set_direction)(gtk2_widget, direction);
2139     return (*fp_gtk_widget_render_icon)(gtk2_widget, stock_id, size, detail);
2140 }
2141 
2142 /*************************************************/
2143 gint gtk2_get_xthickness(JNIEnv *env, WidgetType widget_type)
2144 {
2145     init_containers();
2146 
2147     gtk2_widget = gtk2_get_widget(widget_type);
2148     GtkStyle* style = gtk2_widget->style;
2149     return style->xthickness;
2150 }
2151 
2152 gint gtk2_get_ythickness(JNIEnv *env, WidgetType widget_type)
2153 {
2154     init_containers();
2155 
2156     gtk2_widget = gtk2_get_widget(widget_type);
2157     GtkStyle* style = gtk2_widget->style;
2158     return style->ythickness;
2159 }
2160 
2161 /*************************************************/
2162 guint8 recode_color(guint16 channel)
2163 {
2164     return (guint8)(channel>>8);
2165 }
2166 
2167 gint gtk2_get_color_for_state(JNIEnv *env, WidgetType widget_type,
2168                               GtkStateType state_type, ColorType color_type)
2169 {
2170     gint result = 0;
2171     GdkColor *color = NULL;
2172 
2173     init_containers();
2174 
2175     gtk2_widget = gtk2_get_widget(widget_type);
2176     GtkStyle* style = gtk2_widget->style;
2177 
2178     switch (color_type)
2179     {
2180         case FOREGROUND:
2181             color = &(style->fg[state_type]);
2182             break;
2183         case BACKGROUND:
2184             color = &(style->bg[state_type]);
2185             break;
2186         case TEXT_FOREGROUND:
2187             color = &(style->text[state_type]);
2188             break;
2189         case TEXT_BACKGROUND:
2190             color = &(style->base[state_type]);
2191             break;
2192         case LIGHT:
2193             color = &(style->light[state_type]);
2194             break;
2195         case DARK:
2196             color = &(style->dark[state_type]);
2197             break;
2198         case MID:
2199             color = &(style->mid[state_type]);
2200             break;
2201         case FOCUS:
2202         case BLACK:
2203             color = &(style->black);
2204             break;
2205         case WHITE:
2206             color = &(style->white);
2207             break;
2208     }
2209 
2210     if (color)
2211         result = recode_color(color->red)   << 16 |
2212                  recode_color(color->green) << 8  |
2213                  recode_color(color->blue);
2214 
2215     return result;
2216 }
2217 
2218 /*************************************************/
2219 jobject create_Boolean(JNIEnv *env, jboolean boolean_value);
2220 jobject create_Integer(JNIEnv *env, jint int_value);
2221 jobject create_Long(JNIEnv *env, jlong long_value);
2222 jobject create_Float(JNIEnv *env, jfloat float_value);
2223 jobject create_Double(JNIEnv *env, jdouble double_value);
2224 jobject create_Character(JNIEnv *env, jchar char_value);
2225 jobject create_Insets(JNIEnv *env, GtkBorder *border);
2226 
2227 jobject gtk2_get_class_value(JNIEnv *env, WidgetType widget_type, jstring jkey)
2228 {
2229     init_containers();
2230 
2231     const char* key = getStrFor(env, jkey);
2232     gtk2_widget = gtk2_get_widget(widget_type);
2233 
2234     GValue value;
2235     value.g_type = 0;
2236 
2237     GParamSpec* param = (*fp_gtk_widget_class_find_style_property)(
2238                                     ((GTypeInstance*)gtk2_widget)->g_class, key);
2239     if( param )
2240     {
2241         (*fp_g_value_init)( &value, param->value_type );
2242         (*fp_gtk_widget_style_get_property)(gtk2_widget, key, &value);
2243 
2244         if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOOLEAN ))
2245         {
2246             gboolean val = (*fp_g_value_get_boolean)(&value);
2247             return create_Boolean(env, (jboolean)val);
2248         }
2249         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_CHAR ))
2250         {
2251             gchar val = (*fp_g_value_get_char)(&value);
2252             return create_Character(env, (jchar)val);
2253         }
2254         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_UCHAR ))
2255         {
2256             guchar val = (*fp_g_value_get_uchar)(&value);
2257             return create_Character(env, (jchar)val);
2258         }
2259         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_INT ))
2260         {
2261             gint val = (*fp_g_value_get_int)(&value);
2262             return create_Integer(env, (jint)val);
2263         }
2264         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_UINT ))
2265         {
2266             guint val = (*fp_g_value_get_uint)(&value);
2267             return create_Integer(env, (jint)val);
2268         }
2269         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_LONG ))
2270         {
2271             glong val = (*fp_g_value_get_long)(&value);
2272             return create_Long(env, (jlong)val);
2273         }
2274         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_ULONG ))
2275         {
2276             gulong val = (*fp_g_value_get_ulong)(&value);
2277             return create_Long(env, (jlong)val);
2278         }
2279         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_INT64 ))
2280         {
2281             gint64 val = (*fp_g_value_get_int64)(&value);
2282             return create_Long(env, (jlong)val);
2283         }
2284         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_UINT64 ))
2285         {
2286             guint64 val = (*fp_g_value_get_uint64)(&value);
2287             return create_Long(env, (jlong)val);
2288         }
2289         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_FLOAT ))
2290         {
2291             gfloat val = (*fp_g_value_get_float)(&value);
2292             return create_Float(env, (jfloat)val);
2293         }
2294         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_DOUBLE ))
2295         {
2296             gdouble val = (*fp_g_value_get_double)(&value);
2297             return create_Double(env, (jdouble)val);
2298         }
2299         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_ENUM ))
2300         {
2301             gint val = (*fp_g_value_get_enum)(&value);
2302             return create_Integer(env, (jint)val);
2303         }
2304         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_FLAGS ))
2305         {
2306             guint val = (*fp_g_value_get_flags)(&value);
2307             return create_Integer(env, (jint)val);
2308         }
2309         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_STRING ))
2310         {
2311             const gchar* val = (*fp_g_value_get_string)(&value);
2312 
2313             /* We suppose that all values come in C locale and
2314              * utf-8 representation of a string is the same as
2315              * the string itself. If this isn't so we should
2316              * use g_convert.
2317              */
2318             return (*env)->NewStringUTF(env, val);
2319         }
2320         else if( (*fp_g_type_is_a)( param->value_type, GTK_TYPE_BORDER ))
2321         {
2322             GtkBorder *border = (GtkBorder*)(*fp_g_value_get_boxed)(&value);
2323             return border ? create_Insets(env, border) : NULL;
2324         }
2325 
2326         /*      TODO: Other types are not supported yet.*/
2327 /*        else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_PARAM ))
2328         {
2329             GParamSpec* val = (*fp_g_value_get_param)(&value);
2330             printf( "Param: %p\n", val );
2331         }
2332         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_BOXED ))
2333         {
2334             gpointer* val = (*fp_g_value_get_boxed)(&value);
2335             printf( "Boxed: %p\n", val );
2336         }
2337         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_POINTER ))
2338         {
2339             gpointer* val = (*fp_g_value_get_pointer)(&value);
2340             printf( "Pointer: %p\n", val );
2341         }
2342         else if( (*fp_g_type_is_a)( param->value_type, G_TYPE_OBJECT ))
2343         {
2344             GObject* val = (GObject*)(*fp_g_value_get_object)(&value);
2345             printf( "Object: %p\n", val );
2346         }*/
2347     }
2348 
2349     return NULL;
2350 }
2351 
2352 void gtk2_set_range_value(WidgetType widget_type, jdouble value,
2353                           jdouble min, jdouble max, jdouble visible)
2354 {
2355     GtkAdjustment *adj;
2356 
2357     gtk2_widget = gtk2_get_widget(widget_type);
2358 
2359     adj = (*fp_gtk_range_get_adjustment)((GtkRange *)gtk2_widget);
2360     adj->value = (gdouble)value;
2361     adj->lower = (gdouble)min;
2362     adj->upper = (gdouble)max;
2363     adj->page_size = (gdouble)visible;
2364 }
2365 
2366 /*************************************************/
2367 jobject create_Object(JNIEnv *env, jmethodID *cid,
2368                              const char* class_name,
2369                              const char* signature,
2370                              jvalue* value)
2371 {
2372     jclass  class;
2373     jobject result;
2374 
2375     class = (*env)->FindClass(env, class_name);
2376     if( class == NULL )
2377         return NULL; /* can't find/load the class, exception thrown */
2378 
2379     if( *cid == NULL)
2380     {
2381         *cid = (*env)->GetMethodID(env, class, "<init>", signature);
2382         if( *cid == NULL )
2383         {
2384             (*env)->DeleteLocalRef(env, class);
2385             return NULL; /* can't find/get the method, exception thrown */
2386         }
2387     }
2388 
2389     result = (*env)->NewObjectA(env, class, *cid, value);
2390 
2391     (*env)->DeleteLocalRef(env, class);
2392     return result;
2393 }
2394 
2395 jobject create_Boolean(JNIEnv *env, jboolean boolean_value)
2396 {
2397     static jmethodID cid = NULL;
2398     jvalue value;
2399 
2400     value.z = boolean_value;
2401 
2402     return create_Object(env, &cid, "java/lang/Boolean", "(Z)V", &value);
2403 }
2404 
2405 jobject create_Integer(JNIEnv *env, jint int_value)
2406 {
2407     static jmethodID cid = NULL;
2408     jvalue value;
2409 
2410     value.i = int_value;
2411 
2412     return create_Object(env, &cid, "java/lang/Integer", "(I)V", &value);
2413 }
2414 
2415 jobject create_Long(JNIEnv *env, jlong long_value)
2416 {
2417     static jmethodID cid = NULL;
2418     jvalue value;
2419 
2420     value.j = long_value;
2421 
2422     return create_Object(env, &cid, "java/lang/Long", "(J)V", &value);
2423 }
2424 
2425 jobject create_Float(JNIEnv *env, jfloat float_value)
2426 {
2427     static jmethodID cid = NULL;
2428     jvalue value;
2429 
2430     value.f = float_value;
2431 
2432     return create_Object(env, &cid, "java/lang/Float", "(F)V", &value);
2433 }
2434 
2435 jobject create_Double(JNIEnv *env, jdouble double_value)
2436 {
2437     static jmethodID cid = NULL;
2438     jvalue value;
2439 
2440     value.d = double_value;
2441 
2442     return create_Object(env, &cid, "java/lang/Double", "(D)V", &value);
2443 }
2444 
2445 jobject create_Character(JNIEnv *env, jchar char_value)
2446 {
2447     static jmethodID cid = NULL;
2448     jvalue value;
2449 
2450     value.c = char_value;
2451 
2452     return create_Object(env, &cid, "java/lang/Character", "(C)V", &value);
2453 }
2454 
2455 
2456 jobject create_Insets(JNIEnv *env, GtkBorder *border)
2457 {
2458     static jmethodID cid = NULL;
2459     jvalue values[4];
2460 
2461     values[0].i = border->top;
2462     values[1].i = border->left;
2463     values[2].i = border->bottom;
2464     values[3].i = border->right;
2465 
2466     return create_Object(env, &cid, "java/awt/Insets", "(IIII)V", values);
2467 }
2468 
2469 /*********************************************/
2470 jstring gtk2_get_pango_font_name(JNIEnv *env, WidgetType widget_type)
2471 {
2472     init_containers();
2473 
2474     gtk2_widget = gtk2_get_widget(widget_type);
2475     jstring  result = NULL;
2476     GtkStyle* style = gtk2_widget->style;
2477 
2478     if (style && style->font_desc)
2479     {
2480         gchar* val = (*fp_pango_font_description_to_string)(style->font_desc);
2481         result = (*env)->NewStringUTF(env, val);
2482         (*fp_g_free)( val );
2483     }
2484 
2485     return result;
2486 }
2487 
2488 /***********************************************/
2489 jobject get_string_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2490 {
2491     jobject result = NULL;
2492     gchar*  strval = NULL;
2493 
2494     (*fp_g_object_get)(settings, key, &strval, NULL);
2495     result = (*env)->NewStringUTF(env, strval);
2496     (*fp_g_free)(strval);
2497 
2498     return result;
2499 }
2500 
2501 jobject get_integer_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2502 {
2503     gint intval = NULL;
2504     (*fp_g_object_get)(settings, key, &intval, NULL);
2505     return create_Integer(env, intval);
2506 }
2507 
2508 jobject get_boolean_property(JNIEnv *env, GtkSettings* settings, const gchar* key)
2509 {
2510     gint intval = NULL;
2511     (*fp_g_object_get)(settings, key, &intval, NULL);
2512     return create_Boolean(env, intval);
2513 }
2514 
2515 jobject gtk2_get_setting(JNIEnv *env, Setting property)
2516 {
2517     GtkSettings* settings = (*fp_gtk_settings_get_default)();
2518 
2519     switch (property)
2520     {
2521         case GTK_FONT_NAME:
2522             return get_string_property(env, settings, "gtk-font-name");
2523         case GTK_ICON_SIZES:
2524             return get_string_property(env, settings, "gtk-icon-sizes");
2525         case GTK_CURSOR_BLINK:
2526             return get_boolean_property(env, settings, "gtk-cursor-blink");
2527         case GTK_CURSOR_BLINK_TIME:
2528             return get_integer_property(env, settings, "gtk-cursor-blink-time");
2529     }
2530 
2531     return NULL;
2532 }