Bug Summary

File:jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk2_interface.c
Warning:line 1221, column 17
Value stored to 'result' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

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