Bug Summary

File:jdk/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c
Warning:line 1809, column 19
Value stored to 'flags' during its initialization 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 gtk3_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/gtk3_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 <string.h>
35#include "gtk3_interface.h"
36#include "java_awt_Transparency.h"
37#include "sizecalc.h"
38#include <jni_util.h>
39#include <stdio.h>
40#include "awt.h"
41
42static void *gtk3_libhandle = NULL((void*)0);
43static void *gthread_libhandle = NULL((void*)0);
44
45static jmp_buf j;
46
47/* Widgets */
48static GtkWidget *gtk3_widget = NULL((void*)0);
49static GtkWidget *gtk3_window = NULL((void*)0);
50static GtkFixed *gtk3_fixed = NULL((void*)0);
51static GtkStyleProvider *gtk3_css = NULL((void*)0);
52
53/* Paint system */
54static cairo_surface_t *surface = NULL((void*)0);
55static cairo_t *cr = NULL((void*)0);
56
57static const char ENV_PREFIX[] = "GTK_MODULES=";
58
59static GtkWidget *gtk3_widgets[_GTK_WIDGET_TYPE_SIZE];
60
61/* This is a workaround for the bug:
62 * http://sourceware.org/bugzilla/show_bug.cgi?id=1814
63 * (dlsym/dlopen clears dlerror state)
64 * This bug is specific to Linux, but there is no harm in
65 * applying this workaround on Solaris as well.
66 */
67static void* dl_symbol(const char* name)
68{
69 void* result = dlsym(gtk3_libhandle, name);
70 if (!result)
71 longjmp(j, NO_SYMBOL_EXCEPTION1);
72
73 return result;
74}
75
76static void* dl_symbol_gthread(const char* name)
77{
78 void* result = dlsym(gthread_libhandle, name);
79 if (!result)
80 longjmp(j, NO_SYMBOL_EXCEPTION1);
81
82 return result;
83}
84
85gboolean gtk3_check(const char* lib_name, gboolean load)
86{
87 if (gtk3_libhandle != NULL((void*)0)) {
88 /* We've already successfully opened the GTK libs, so return true. */
89 return TRUE(!(0));
90 } else {
91#ifdef RTLD_NOLOAD0x00004
92 void *lib = dlopen(lib_name, RTLD_LAZY0x00001 | RTLD_NOLOAD0x00004);
93 if (!load || lib != NULL((void*)0)) {
94 return lib != NULL((void*)0);
95 }
96#else
97#ifdef _AIX
98 /* On AIX we could implement this with the help of loadquery(L_GETINFO, ..) */
99 /* (see reload_table() in hotspot/src/os/aix/vm/loadlib_aix.cpp) but it is */
100 /* probably not worth it because most AIX servers don't have GTK libs anyway */
101#endif
102#endif
103 return dlopen(lib_name, RTLD_LAZY0x00001 | RTLD_LOCAL0) != NULL((void*)0);
104 }
105}
106
107#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);
\
108do { \
109 jfieldID fld_action = (*env)->GetStaticFieldID(env, cls_action, actionStr, \
110 "Ljava/awt/Desktop$Action;"); \
111 if (!(*env)->ExceptionCheck(env)) { \
112 jobject action = (*env)->GetStaticObjectField(env, cls_action, \
113 fld_action); \
114 (*env)->CallBooleanMethod(env, supportedActions, mid_arrayListAdd, \
115 action); \
116 } else { \
117 (*env)->ExceptionClear(env); \
118 } \
119} while(0);
120
121
122static void update_supported_actions(JNIEnv *env) {
123 GVfs * (*fp_g_vfs_get_default) (void);
124 const gchar * const * (*fp_g_vfs_get_supported_uri_schemes) (GVfs * vfs);
125 const gchar * const * schemes = NULL((void*)0);
126
127 jclass cls_action = (*env)->FindClass(env, "java/awt/Desktop$Action");
128 CHECK_NULL(cls_action)do { if ((cls_action) == ((void*)0)) { return; } } while (0);
129 jclass cls_xDesktopPeer = (*env)->
130 FindClass(env, "sun/awt/X11/XDesktopPeer");
131 CHECK_NULL(cls_xDesktopPeer)do { if ((cls_xDesktopPeer) == ((void*)0)) { return; } } while
(0)
;
132 jfieldID fld_supportedActions = (*env)->GetStaticFieldID(env,
133 cls_xDesktopPeer, "supportedActions", "Ljava/util/List;");
134 CHECK_NULL(fld_supportedActions)do { if ((fld_supportedActions) == ((void*)0)) { return; } } while
(0)
;
135 jobject supportedActions = (*env)->GetStaticObjectField(env,
136 cls_xDesktopPeer, fld_supportedActions);
137
138 jclass cls_arrayList = (*env)->FindClass(env, "java/util/ArrayList");
139 CHECK_NULL(cls_arrayList)do { if ((cls_arrayList) == ((void*)0)) { return; } } while (
0)
;
140 jmethodID mid_arrayListAdd = (*env)->GetMethodID(env, cls_arrayList, "add",
141 "(Ljava/lang/Object;)Z");
142 CHECK_NULL(mid_arrayListAdd)do { if ((mid_arrayListAdd) == ((void*)0)) { return; } } while
(0)
;
143 jmethodID mid_arrayListClear = (*env)->GetMethodID(env, cls_arrayList,
144 "clear", "()V");
145 CHECK_NULL(mid_arrayListClear)do { if ((mid_arrayListClear) == ((void*)0)) { return; } } while
(0)
;
146
147 (*env)->CallVoidMethod(env, supportedActions, mid_arrayListClear);
148
149 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);
;
150
151 /**
152 * gtk_show_uri() documentation says:
153 *
154 * > you need to install gvfs to get support for uri schemes such as http://
155 * > or ftp://, as only local files are handled by GIO itself.
156 *
157 * So OPEN action was safely added here.
158 * However, it looks like Solaris 11 have gvfs support only for 32-bit
159 * applications only by default.
160 */
161
162 fp_g_vfs_get_default = dl_symbol("g_vfs_get_default");
163 fp_g_vfs_get_supported_uri_schemes =
164 dl_symbol("g_vfs_get_supported_uri_schemes");
165 dlerror();
166
167 if (fp_g_vfs_get_default && fp_g_vfs_get_supported_uri_schemes) {
168 GVfs * vfs = fp_g_vfs_get_default();
169 schemes = vfs ? fp_g_vfs_get_supported_uri_schemes(vfs) : NULL((void*)0);
170 if (schemes) {
171 int i = 0;
172 while (schemes[i]) {
173 if (strcmp(schemes[i], "http") == 0) {
174 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);
;
175 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);
;
176 break;
177 }
178 i++;
179 }
180 }
181 } else {
182#ifdef DEBUG1
183 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"
)
;
184#endif /* DEBUG */
185 }
186
187}
188/**
189 * Functions for awt_Desktop.c
190 */
191static gboolean gtk3_show_uri_load(JNIEnv *env) {
192 gboolean success = FALSE(0);
193 dlerror();
194 fp_gtk_show_uri = dl_symbol("gtk_show_uri");
195 const char *dlsym_error = dlerror();
196 if (dlsym_error) {
197#ifdef DEBUG1
198 fprintf (stderr, "Cannot load symbol: %s \n", dlsym_error)__fprintf_chk (stderr, 2 - 1, "Cannot load symbol: %s \n", dlsym_error
)
;
199#endif /* DEBUG */
200 } else if (fp_gtk_show_uri == NULL((void*)0)) {
201#ifdef DEBUG1
202 fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n")__fprintf_chk (stderr, 2 - 1, "dlsym(gtk_show_uri) returned NULL\n"
)
;
203#endif /* DEBUG */
204 } else {
205 gtk->gtk_show_uri = fp_gtk_show_uri;
206 update_supported_actions(env);
207 success = TRUE(!(0));
208 }
209 return success;
210}
211
212/**
213 * Functions for sun_awt_X11_GtkFileDialogPeer.c
214 */
215static void gtk3_file_chooser_load()
216{
217 fp_gtk_file_chooser_get_filename = dl_symbol(
218 "gtk_file_chooser_get_filename");
219 fp_gtk_file_chooser_dialog_new = dl_symbol("gtk_file_chooser_dialog_new");
220 fp_gtk_file_chooser_set_current_folder = dl_symbol(
221 "gtk_file_chooser_set_current_folder");
222 fp_gtk_file_chooser_set_filename = dl_symbol(
223 "gtk_file_chooser_set_filename");
224 fp_gtk_file_chooser_set_current_name = dl_symbol(
225 "gtk_file_chooser_set_current_name");
226 fp_gtk_file_filter_add_custom = dl_symbol("gtk_file_filter_add_custom");
227 fp_gtk_file_chooser_set_filter = dl_symbol("gtk_file_chooser_set_filter");
228 fp_gtk_file_chooser_get_type = dl_symbol("gtk_file_chooser_get_type");
229 fp_gtk_file_filter_new = dl_symbol("gtk_file_filter_new");
230 fp_gtk_file_chooser_set_do_overwrite_confirmation = dl_symbol(
231 "gtk_file_chooser_set_do_overwrite_confirmation");
232 fp_gtk_file_chooser_set_select_multiple = dl_symbol(
233 "gtk_file_chooser_set_select_multiple");
234 fp_gtk_file_chooser_get_current_folder = dl_symbol(
235 "gtk_file_chooser_get_current_folder");
236 fp_gtk_file_chooser_get_filenames = dl_symbol(
237 "gtk_file_chooser_get_filenames");
238 fp_gtk_g_slist_length = dl_symbol("g_slist_length");
239 fp_gdk_x11_drawable_get_xid = dl_symbol("gdk_x11_window_get_xid");
240}
241
242static void empty() {}
243
244static gboolean gtk3_version_3_10 = TRUE(!(0));
245static gboolean gtk3_version_3_14 = FALSE(0);
246static gboolean gtk3_version_3_20 = FALSE(0);
247
248GtkApi* gtk3_load(JNIEnv *env, const char* lib_name)
249{
250 gboolean result;
251 int i;
252 int (*handler)();
253 int (*io_handler)();
254 char *gtk_modules_env;
255 gtk3_libhandle = dlopen(lib_name, RTLD_LAZY0x00001 | RTLD_LOCAL0);
256 if (gtk3_libhandle == NULL((void*)0)) {
257 return FALSE(0);
258 }
259
260 gthread_libhandle = dlopen(GTHREAD_LIB_VERSIONED"lib" "gthread-2.0" ".so" "." "0", RTLD_LAZY0x00001 | RTLD_LOCAL0);
261 if (gthread_libhandle == NULL((void*)0)) {
262 gthread_libhandle = dlopen(GTHREAD_LIB"lib" "gthread-2.0" ".so", RTLD_LAZY0x00001 | RTLD_LOCAL0);
263 if (gthread_libhandle == NULL((void*)0))
264 return FALSE(0);
265 }
266
267 if (setjmp(j)_setjmp (j) == 0)
268 {
269 fp_gtk_check_version = dl_symbol("gtk_check_version");
270
271 /* GLib */
272 fp_glib_check_version = dlsym(gtk3_libhandle, "glib_check_version");
273 if (!fp_glib_check_version) {
274 dlerror();
275 }
276 fp_g_free = dl_symbol("g_free");
277 fp_g_object_unref = dl_symbol("g_object_unref");
278
279 fp_g_main_context_iteration =
280 dl_symbol("g_main_context_iteration");
281
282 fp_g_value_init = dl_symbol("g_value_init");
283 fp_g_type_is_a = dl_symbol("g_type_is_a");
284 fp_g_value_get_boolean = dl_symbol("g_value_get_boolean");
285 fp_g_value_get_char = dl_symbol("g_value_get_char");
286 fp_g_value_get_uchar = dl_symbol("g_value_get_uchar");
287 fp_g_value_get_int = dl_symbol("g_value_get_int");
288 fp_g_value_get_uint = dl_symbol("g_value_get_uint");
289 fp_g_value_get_long = dl_symbol("g_value_get_long");
290 fp_g_value_get_ulong = dl_symbol("g_value_get_ulong");
291 fp_g_value_get_int64 = dl_symbol("g_value_get_int64");
292 fp_g_value_get_uint64 = dl_symbol("g_value_get_uint64");
293 fp_g_value_get_float = dl_symbol("g_value_get_float");
294 fp_g_value_get_double = dl_symbol("g_value_get_double");
295 fp_g_value_get_string = dl_symbol("g_value_get_string");
296 fp_g_value_get_enum = dl_symbol("g_value_get_enum");
297 fp_g_value_get_flags = dl_symbol("g_value_get_flags");
298 fp_g_value_get_param = dl_symbol("g_value_get_param");
299 fp_g_value_get_boxed = dl_symbol("g_value_get_boxed");
300 fp_g_value_get_pointer = dl_symbol("g_value_get_pointer");
301
302 fp_g_object_get = dl_symbol("g_object_get");
303 fp_g_object_set = dl_symbol("g_object_set");
304
305 fp_g_str_has_prefix = dl_symbol("g_str_has_prefix");
306 fp_g_strsplit = dl_symbol("g_strsplit");
307 fp_g_strfreev = dl_symbol("g_strfreev");
308
309 /* GDK */
310 fp_gdk_get_default_root_window =
311 dl_symbol("gdk_get_default_root_window");
312
313 /* Pixbuf */
314 fp_gdk_pixbuf_new = dl_symbol("gdk_pixbuf_new");
315 fp_gdk_pixbuf_new_from_file =
316 dl_symbol("gdk_pixbuf_new_from_file");
317 fp_gdk_pixbuf_get_from_drawable =
318 dl_symbol("gdk_pixbuf_get_from_window");
319 fp_gdk_pixbuf_get_width = dl_symbol("gdk_pixbuf_get_width");
320 fp_gdk_pixbuf_get_height = dl_symbol("gdk_pixbuf_get_height");
321 fp_gdk_pixbuf_get_pixels = dl_symbol("gdk_pixbuf_get_pixels");
322 fp_gdk_pixbuf_get_rowstride =
323 dl_symbol("gdk_pixbuf_get_rowstride");
324 fp_gdk_pixbuf_get_has_alpha =
325 dl_symbol("gdk_pixbuf_get_has_alpha");
326 fp_gdk_pixbuf_get_bits_per_sample =
327 dl_symbol("gdk_pixbuf_get_bits_per_sample");
328 fp_gdk_pixbuf_get_n_channels =
329 dl_symbol("gdk_pixbuf_get_n_channels");
330 fp_gdk_pixbuf_get_colorspace =
331 dl_symbol("gdk_pixbuf_get_colorspace");
332
333 fp_cairo_image_surface_create = dl_symbol("cairo_image_surface_create");
334 fp_cairo_surface_destroy = dl_symbol("cairo_surface_destroy");
335 fp_cairo_surface_status = dl_symbol("cairo_surface_status");
336 fp_cairo_create = dl_symbol("cairo_create");
337 fp_cairo_destroy = dl_symbol("cairo_destroy");
338 fp_cairo_status = dl_symbol("cairo_status");
339 fp_cairo_fill = dl_symbol("cairo_fill");
340 fp_cairo_rectangle = dl_symbol("cairo_rectangle");
341 fp_cairo_set_source_rgb = dl_symbol("cairo_set_source_rgb");
342 fp_cairo_set_source_rgba = dl_symbol("cairo_set_source_rgba");
343 fp_cairo_surface_flush = dl_symbol("cairo_surface_flush");
344 fp_cairo_paint = dl_symbol("cairo_paint");
345 fp_cairo_clip = dl_symbol("cairo_clip");
346 fp_cairo_image_surface_get_data =
347 dl_symbol("cairo_image_surface_get_data");
348 fp_cairo_image_surface_get_stride =
349 dl_symbol("cairo_image_surface_get_stride");
350
351 fp_gdk_pixbuf_get_from_surface =
352 dl_symbol("gdk_pixbuf_get_from_surface");
353
354 fp_gtk_widget_get_state = dl_symbol("gtk_widget_get_state");
355 fp_gtk_widget_set_state = dl_symbol("gtk_widget_set_state");
356
357 fp_gtk_widget_is_focus = dl_symbol("gtk_widget_is_focus");
358 fp_gtk_widget_set_allocation = dl_symbol("gtk_widget_set_allocation");
359 fp_gtk_widget_get_parent = dl_symbol("gtk_widget_get_parent");
360 fp_gtk_widget_get_window = dl_symbol("gtk_widget_get_window");
361
362 fp_gtk_widget_get_style_context =
363 dl_symbol("gtk_widget_get_style_context");
364 fp_gtk_style_context_get_color =
365 dl_symbol("gtk_style_context_get_color");
366 fp_gtk_style_context_get_background_color =
367 dl_symbol("gtk_style_context_get_background_color");
368 fp_gtk_widget_get_state_flags = dl_symbol("gtk_widget_get_state_flags");
369 fp_gtk_style_context_set_state =
370 dl_symbol("gtk_style_context_set_state");
371 fp_gtk_style_context_add_class =
372 dl_symbol("gtk_style_context_add_class");
373 fp_gtk_style_context_save = dl_symbol("gtk_style_context_save");
374 fp_gtk_style_context_restore = dl_symbol("gtk_style_context_restore");
375 fp_gtk_render_check = dl_symbol("gtk_render_check");
376 fp_gtk_render_option = dl_symbol("gtk_render_option");
377 fp_gtk_render_extension = dl_symbol("gtk_render_extension");
378 fp_gtk_render_expander = dl_symbol("gtk_render_expander");
379 fp_gtk_render_frame_gap = dl_symbol("gtk_render_frame_gap");
380 fp_gtk_render_line = dl_symbol("gtk_render_line");
381 fp_gtk_widget_render_icon_pixbuf =
382 dl_symbol("gtk_widget_render_icon_pixbuf");
383 if (fp_gtk_check_version(3, 10, 0)) {
384 gtk3_version_3_10 = FALSE(0);
385 } else {
386 fp_gdk_window_create_similar_image_surface =
387 dl_symbol("gdk_window_create_similar_image_surface");
388 fp_gdk_window_get_scale_factor =
389 dl_symbol("gdk_window_get_scale_factor");
390 }
391 gtk3_version_3_14 = !fp_gtk_check_version(3, 14, 0);
392
393 if (!fp_gtk_check_version(3, 20, 0)) {
394 gtk3_version_3_20 = TRUE(!(0));
395 fp_gtk_widget_path_copy = dl_symbol("gtk_widget_path_copy");
396 fp_gtk_widget_path_new = dl_symbol("gtk_widget_path_new");
397 fp_gtk_widget_path_append_type = dl_symbol("gtk_widget_path_append_type");
398 fp_gtk_widget_path_iter_set_object_name = dl_symbol("gtk_widget_path_iter_set_object_name");
399 fp_gtk_style_context_set_path = dl_symbol("gtk_style_context_set_path");
400 fp_gtk_widget_path_unref = dl_symbol("gtk_widget_path_unref");
401 fp_gtk_style_context_get_path = dl_symbol("gtk_style_context_get_path");
402 fp_gtk_style_context_new = dl_symbol("gtk_style_context_new");
403 }
404
405 fp_gdk_window_create_similar_surface =
406 dl_symbol("gdk_window_create_similar_surface");
407 fp_gtk_settings_get_for_screen =
408 dl_symbol("gtk_settings_get_for_screen");
409 fp_gtk_widget_get_screen = dl_symbol("gtk_widget_get_screen");
410 fp_gtk_css_provider_get_named = dl_symbol("gtk_css_provider_get_named");
411 fp_gtk_style_context_add_provider =
412 dl_symbol("gtk_style_context_add_provider");
413 fp_gtk_render_frame = dl_symbol("gtk_render_frame");
414 fp_gtk_render_focus = dl_symbol("gtk_render_focus");
415 fp_gtk_render_handle = dl_symbol("gtk_render_handle");
416 fp_gtk_render_arrow = dl_symbol("gtk_render_arrow");
417
418 fp_gtk_style_context_get_property =
419 dl_symbol("gtk_style_context_get_property");
420 fp_gtk_scrolled_window_set_shadow_type =
421 dl_symbol("gtk_scrolled_window_set_shadow_type");
422 fp_gtk_render_slider = dl_symbol("gtk_render_slider");
423 fp_gtk_style_context_get_padding =
424 dl_symbol("gtk_style_context_get_padding");
425 fp_gtk_range_set_inverted = dl_symbol("gtk_range_set_inverted");
426 fp_gtk_style_context_get_font = dl_symbol("gtk_style_context_get_font");
427 fp_gtk_widget_get_allocated_width =
428 dl_symbol("gtk_widget_get_allocated_width");
429 fp_gtk_widget_get_allocated_height =
430 dl_symbol("gtk_widget_get_allocated_height");
431 fp_gtk_icon_theme_get_default = dl_symbol("gtk_icon_theme_get_default");
432 fp_gtk_icon_theme_load_icon = dl_symbol("gtk_icon_theme_load_icon");
433
434 fp_gtk_adjustment_set_lower = dl_symbol("gtk_adjustment_set_lower");
435 fp_gtk_adjustment_set_page_increment =
436 dl_symbol("gtk_adjustment_set_page_increment");
437 fp_gtk_adjustment_set_page_size =
438 dl_symbol("gtk_adjustment_set_page_size");
439 fp_gtk_adjustment_set_step_increment =
440 dl_symbol("gtk_adjustment_set_step_increment");
441 fp_gtk_adjustment_set_upper = dl_symbol("gtk_adjustment_set_upper");
442 fp_gtk_adjustment_set_value = dl_symbol("gtk_adjustment_set_value");
443
444 fp_gtk_render_activity = dl_symbol("gtk_render_activity");
445 fp_gtk_render_background = dl_symbol("gtk_render_background");
446 fp_gtk_style_context_has_class =
447 dl_symbol("gtk_style_context_has_class");
448
449 fp_gtk_style_context_set_junction_sides =
450 dl_symbol("gtk_style_context_set_junction_sides");
451 fp_gtk_style_context_add_region =
452 dl_symbol("gtk_style_context_add_region");
453
454 fp_gtk_init_check = dl_symbol("gtk_init_check");
455
456 /* GTK widgets */
457 fp_gtk_arrow_new = dl_symbol("gtk_arrow_new");
458 fp_gtk_button_new = dl_symbol("gtk_button_new");
459 fp_gtk_spin_button_new = dl_symbol("gtk_spin_button_new");
460 fp_gtk_check_button_new = dl_symbol("gtk_check_button_new");
461 fp_gtk_check_menu_item_new =
462 dl_symbol("gtk_check_menu_item_new");
463 fp_gtk_color_selection_dialog_new =
464 dl_symbol("gtk_color_selection_dialog_new");
465 fp_gtk_entry_new = dl_symbol("gtk_entry_new");
466 fp_gtk_fixed_new = dl_symbol("gtk_fixed_new");
467 fp_gtk_handle_box_new = dl_symbol("gtk_handle_box_new");
468 fp_gtk_image_new = dl_symbol("gtk_image_new");
469 fp_gtk_paned_new = dl_symbol("gtk_paned_new");
470 fp_gtk_scale_new = dl_symbol("gtk_scale_new");
471 fp_gtk_hscrollbar_new = dl_symbol("gtk_hscrollbar_new");
472 fp_gtk_vscrollbar_new = dl_symbol("gtk_vscrollbar_new");
473 fp_gtk_hseparator_new = dl_symbol("gtk_hseparator_new");
474 fp_gtk_vseparator_new = dl_symbol("gtk_vseparator_new");
475 fp_gtk_label_new = dl_symbol("gtk_label_new");
476 fp_gtk_menu_new = dl_symbol("gtk_menu_new");
477 fp_gtk_menu_bar_new = dl_symbol("gtk_menu_bar_new");
478 fp_gtk_menu_item_new = dl_symbol("gtk_menu_item_new");
479 fp_gtk_menu_item_set_submenu =
480 dl_symbol("gtk_menu_item_set_submenu");
481 fp_gtk_notebook_new = dl_symbol("gtk_notebook_new");
482 fp_gtk_progress_bar_new =
483 dl_symbol("gtk_progress_bar_new");
484 fp_gtk_progress_bar_set_orientation =
485 dl_symbol("gtk_orientable_set_orientation");
486 fp_gtk_radio_button_new =
487 dl_symbol("gtk_radio_button_new");
488 fp_gtk_radio_menu_item_new =
489 dl_symbol("gtk_radio_menu_item_new");
490 fp_gtk_scrolled_window_new =
491 dl_symbol("gtk_scrolled_window_new");
492 fp_gtk_separator_menu_item_new =
493 dl_symbol("gtk_separator_menu_item_new");
494 fp_gtk_text_view_new = dl_symbol("gtk_text_view_new");
495 fp_gtk_toggle_button_new =
496 dl_symbol("gtk_toggle_button_new");
497 fp_gtk_toolbar_new = dl_symbol("gtk_toolbar_new");
498 fp_gtk_tree_view_new = dl_symbol("gtk_tree_view_new");
499 fp_gtk_viewport_new = dl_symbol("gtk_viewport_new");
500 fp_gtk_window_new = dl_symbol("gtk_window_new");
501 fp_gtk_window_present = dl_symbol("gtk_window_present");
502 fp_gtk_window_move = dl_symbol("gtk_window_move");
503 fp_gtk_window_resize = dl_symbol("gtk_window_resize");
504
505 fp_gtk_dialog_new = dl_symbol("gtk_dialog_new");
506 fp_gtk_frame_new = dl_symbol("gtk_frame_new");
507
508 fp_gtk_adjustment_new = dl_symbol("gtk_adjustment_new");
509 fp_gtk_container_add = dl_symbol("gtk_container_add");
510 fp_gtk_menu_shell_append =
511 dl_symbol("gtk_menu_shell_append");
512 fp_gtk_widget_realize = dl_symbol("gtk_widget_realize");
513 fp_gtk_widget_destroy = dl_symbol("gtk_widget_destroy");
514 fp_gtk_widget_render_icon =
515 dl_symbol("gtk_widget_render_icon");
516 fp_gtk_widget_set_name =
517 dl_symbol("gtk_widget_set_name");
518 fp_gtk_widget_set_parent =
519 dl_symbol("gtk_widget_set_parent");
520 fp_gtk_widget_set_direction =
521 dl_symbol("gtk_widget_set_direction");
522 fp_gtk_widget_style_get =
523 dl_symbol("gtk_widget_style_get");
524 fp_gtk_widget_class_install_style_property =
525 dl_symbol("gtk_widget_class_install_style_property");
526 fp_gtk_widget_class_find_style_property =
527 dl_symbol("gtk_widget_class_find_style_property");
528 fp_gtk_widget_style_get_property =
529 dl_symbol("gtk_widget_style_get_property");
530 fp_pango_font_description_to_string =
531 dl_symbol("pango_font_description_to_string");
532 fp_gtk_settings_get_default =
533 dl_symbol("gtk_settings_get_default");
534 fp_gtk_widget_get_settings =
535 dl_symbol("gtk_widget_get_settings");
536 fp_gtk_border_get_type = dl_symbol("gtk_border_get_type");
537 fp_gtk_arrow_set = dl_symbol("gtk_arrow_set");
538 fp_gtk_widget_size_request =
539 dl_symbol("gtk_widget_size_request");
540 fp_gtk_range_get_adjustment =
541 dl_symbol("gtk_range_get_adjustment");
542
543 fp_gtk_widget_hide = dl_symbol("gtk_widget_hide");
544 fp_gtk_main_quit = dl_symbol("gtk_main_quit");
545 fp_g_signal_connect_data = dl_symbol("g_signal_connect_data");
546 fp_gtk_widget_show = dl_symbol("gtk_widget_show");
547 fp_gtk_main = dl_symbol("gtk_main");
548
549 fp_g_path_get_dirname = dl_symbol("g_path_get_dirname");
550
551 fp_gdk_threads_init = dl_symbol("gdk_threads_init");
552 fp_gdk_threads_enter = dl_symbol("gdk_threads_enter");
553 fp_gdk_threads_leave = dl_symbol("gdk_threads_leave");
554
555 /**
556 * Functions for sun_awt_X11_GtkFileDialogPeer.c
557 */
558 gtk3_file_chooser_load();
559
560 fp_gtk_combo_box_new = dlsym(gtk3_libhandle, "gtk_combo_box_new");
561 fp_gtk_combo_box_entry_new = dlsym(gtk3_libhandle,
562 "gtk_combo_box_new_with_entry");
563 fp_gtk_separator_tool_item_new = dlsym(gtk3_libhandle,
564 "gtk_separator_tool_item_new");
565 fp_g_list_append = dl_symbol("g_list_append");
566 fp_g_list_free = dl_symbol("g_list_free");
567 fp_g_list_free_full = dl_symbol("g_list_free_full");
568 }
569 /* Now we have only one kind of exceptions: NO_SYMBOL_EXCEPTION
570 * Otherwise we can check the return value of setjmp method.
571 */
572 else
573 {
574 dlclose(gtk3_libhandle);
575 gtk3_libhandle = NULL((void*)0);
576
577 dlclose(gthread_libhandle);
578 gthread_libhandle = NULL((void*)0);
579
580 return NULL((void*)0);
581 }
582
583 /*
584 * Strip the AT-SPI GTK_MODULES if present
585 */
586 gtk_modules_env = getenv ("GTK_MODULES");
587 if ((gtk_modules_env && strstr(gtk_modules_env, "atk-bridge")) ||
588 (gtk_modules_env && strstr(gtk_modules_env, "gail"))) {
589 /* careful, strtok modifies its args */
590 gchar *tmp_env = strdup(gtk_modules_env);
591 if (tmp_env) {
592 /* the new env will be smaller than the old one */
593 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))
594 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))
;
595
596 if (new_env) {
597 strcpy(new_env, ENV_PREFIX);
598
599 /* strip out 'atk-bridge' and 'gail' */
600 size_t PREFIX_LENGTH = strlen(ENV_PREFIX);
601 gchar *tmp_ptr = NULL((void*)0);
602 for (s = strtok_r(tmp_env, ":", &tmp_ptr); s;
603 s = strtok_r(NULL((void*)0), ":", &tmp_ptr)) {
604 if ((!strstr(s, "atk-bridge")) && (!strstr(s, "gail"))) {
605 if (strlen(new_env) > PREFIX_LENGTH) {
606 new_env = strcat(new_env, ":");
607 }
608 new_env = strcat(new_env, s);
609 }
610 }
611 if (putenv(new_env) != 0) {
612 /* no free() on success, putenv() doesn't copy string */
613 free(new_env);
614 }
615 }
616 free(tmp_env);
617 }
618 }
619 /*
620 * GTK should be initialized with gtk_init_check() before use.
621 *
622 * gtk_init_check installs its own error handlers. It is critical that
623 * we preserve error handler set from AWT. Otherwise we'll crash on
624 * BadMatch errors which we would normally ignore. The IO error handler
625 * is preserved here, too, just for consistency.
626 */
627 AWT_LOCK()do { (*env)->CallStaticVoidMethod(env, tkClass, awtLockMID
); if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear
(env); } } while(0)
;
628 handler = XSetErrorHandler(NULL((void*)0));
629 io_handler = XSetIOErrorHandler(NULL((void*)0));
630
631 //According the GTK documentation, gdk_threads_init() should be
632 //called before gtk_init() or gtk_init_check()
633 fp_gdk_threads_init();
634 result = (*fp_gtk_init_check)(NULL((void*)0), NULL((void*)0));
635
636 XSetErrorHandler(handler);
637 XSetIOErrorHandler(io_handler);
638 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)
;
639
640 /* Initialize widget array. */
641 for (i = 0; i < _GTK_WIDGET_TYPE_SIZE; i++)
642 {
643 gtk3_widgets[i] = NULL((void*)0);
644 }
645 if (result) {
646 GtkApi* gtk = (GtkApi*)malloc(sizeof(GtkApi));
647 gtk3_init(gtk);
648 return gtk;
649 }
650 return NULL((void*)0);
651}
652
653static int gtk3_unload()
654{
655 int i;
656 char *gtk3_error;
657
658 if (!gtk3_libhandle)
659 return TRUE(!(0));
660
661 /* Release painting objects */
662 if (surface != NULL((void*)0)) {
663 fp_cairo_destroy(cr);
664 fp_cairo_surface_destroy(surface);
665 surface = NULL((void*)0);
666 }
667
668 if (gtk3_window != NULL((void*)0)) {
669 /* Destroying toplevel widget will destroy all contained widgets */
670 (*fp_gtk_widget_destroy)(gtk3_window);
671
672 /* Unset some static data so they get reinitialized on next load */
673 gtk3_window = NULL((void*)0);
674 }
675
676 dlerror();
677 dlclose(gtk3_libhandle);
678 dlclose(gthread_libhandle);
679 if ((gtk3_error = dlerror()) != NULL((void*)0))
680 {
681 return FALSE(0);
682 }
683 return TRUE(!(0));
684}
685
686/* Dispatch all pending events from the GTK event loop.
687 * This is needed to catch theme change and update widgets' style.
688 */
689static void flush_gtk_event_loop()
690{
691 while((*fp_g_main_context_iteration)(NULL((void*)0), FALSE(0)));
692}
693
694/*
695 * Initialize components of containment hierarchy. This creates a GtkFixed
696 * inside a GtkWindow. All widgets get realized.
697 */
698static void init_containers()
699{
700 if (gtk3_window == NULL((void*)0))
701 {
702 gtk3_window = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
703 gtk3_fixed = (GtkFixed *)(*fp_gtk_fixed_new)();
704 (*fp_gtk_container_add)((GtkContainer*)gtk3_window,
705 (GtkWidget *)gtk3_fixed);
706 (*fp_gtk_widget_realize)(gtk3_window);
707 (*fp_gtk_widget_realize)((GtkWidget *)gtk3_fixed);
708
709 GtkSettings* settings = fp_gtk_settings_get_for_screen(
710 fp_gtk_widget_get_screen(gtk3_window));
711 gchar* strval = NULL((void*)0);
712 fp_g_object_get(settings, "gtk-theme-name", &strval, NULL((void*)0));
713 gtk3_css = fp_gtk_css_provider_get_named(strval, NULL((void*)0));
714 }
715}
716
717/*
718 * Ensure everything is ready for drawing an element of the specified width
719 * and height.
720 *
721 * We should somehow handle translucent images. GTK can draw to X Drawables
722 * only, which don't support alpha. When we retrieve the image back from
723 * the server, translucency information is lost. There're several ways to
724 * work around this:
725 * 1) Subclass GdkPixmap and cache translucent objects on client side. This
726 * requires us to implement parts of X server drawing logic on client side.
727 * Many X requests can potentially be "translucent"; e.g. XDrawLine with
728 * fill=tile and a translucent tile is a "translucent" operation, whereas
729 * XDrawLine with fill=solid is an "opaque" one. Moreover themes can (and some
730 * do) intermix transparent and opaque operations which makes caching even
731 * more problematic.
732 * 2) Use Xorg 32bit ARGB visual when available. GDK has no native support
733 * for it (as of version 2.6). Also even in JDS 3 Xorg does not support
734 * these visuals by default, which makes optimizing for them pointless.
735 * We can consider doing this at a later point when ARGB visuals become more
736 * popular.
737 * 3') GTK has plans to use Cairo as its graphical backend (presumably in
738 * 2.8), and Cairo supports alpha. With it we could also get rid of the
739 * unnecessary round trip to server and do all the drawing on client side.
740 * 4) For now we draw to two different pixmaps and restore alpha channel by
741 * comparing results. This can be optimized by using subclassed pixmap and
742*/
743static void gtk3_init_painting(JNIEnv *env, gint width, gint height)
744{
745 init_containers();
746
747 if (cr) {
748 fp_cairo_destroy(cr);
749 }
750
751 if (surface != NULL((void*)0)) {
752 /* free old stuff */
753 fp_cairo_surface_destroy(surface);
754
755 }
756
757 if (gtk3_version_3_10) {
758 surface = fp_gdk_window_create_similar_image_surface(
759 fp_gtk_widget_get_window(gtk3_window),
760 CAIRO_FORMAT_ARGB32, width, height, 1);
761 } else {
762 surface = fp_cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
763 width, height);
764 }
765
766 cr = fp_cairo_create(surface);
767 if (fp_cairo_surface_status(surface) || fp_cairo_status(cr)) {
768 JNU_ThrowOutOfMemoryError(env, "The surface size is too big");
769 }
770}
771
772/*
773 * Restore image from white and black pixmaps and copy it into destination
774 * buffer. This method compares two pixbufs taken from white and black
775 * pixmaps and decodes color and alpha components. Pixbufs are RGB without
776 * alpha, destination buffer is ABGR.
777 *
778 * The return value is the transparency type of the resulting image, either
779 * one of java_awt_Transparency_OPAQUE, java_awt_Transparency_BITMASK, and
780 * java_awt_Transparency_TRANSLUCENT.
781 */
782static gint gtk3_copy_image(gint *dst, gint width, gint height)
783{
784 gint i, j, r, g, b;
785 guchar *data;
786 gint stride, padding;
787
788 fp_cairo_surface_flush(surface);
789 data = (*fp_cairo_image_surface_get_data)(surface);
790 stride = (*fp_cairo_image_surface_get_stride)(surface);
791 padding = stride - width * 4;
792 if (stride > 0 && padding >= 0) {
793 for (i = 0; i < height; i++) {
794 for (j = 0; j < width; j++) {
795 int r = *data++;
796 int g = *data++;
797 int b = *data++;
798 int a = *data++;
799 *dst++ = (a << 24 | b << 16 | g << 8 | r);
800 }
801 data += padding;
802 }
803 }
804 return java_awt_Transparency_TRANSLUCENT3L;
805}
806
807static void gtk3_set_direction(GtkWidget *widget, GtkTextDirection dir)
808{
809 /*
810 * Some engines (inexplicably) look at the direction of the widget's
811 * parent, so we need to set the direction of both the widget and its
812 * parent.
813 */
814 (*fp_gtk_widget_set_direction)(widget, dir);
815 GtkWidget* parent = fp_gtk_widget_get_parent(widget);
816 if (parent != NULL((void*)0)) {
817 fp_gtk_widget_set_direction(parent, dir);
818 }
819}
820
821static GtkStateFlags get_gtk_state_flags(gint synth_state)
822{
823 GtkStateFlags flags = 0;
824
825 if ((synth_state & DISABLED) != 0) {
826 flags |= GTK_STATE_FLAG_INSENSITIVE;
827 }
828 if (((synth_state & PRESSED) != 0 || (synth_state & SELECTED) != 0)) {
829 flags |= GTK_STATE_FLAG_ACTIVE;
830 }
831 if ((synth_state & MOUSE_OVER) != 0) {
832 flags |= GTK_STATE_FLAG_PRELIGHT;
833 }
834 if ((synth_state & FOCUSED) != 0) {
835 flags |= GTK_STATE_FLAG_FOCUSED;
836 }
837 return flags;
838}
839
840static GtkStateFlags get_gtk_flags(GtkStateType state_type) {
841 GtkStateFlags flags = 0;
842 switch (state_type)
843 {
844 case GTK_STATE_PRELIGHT:
845 flags |= GTK_STATE_FLAG_PRELIGHT;
846 break;
847 case GTK_STATE_SELECTED:
848 flags |= GTK_STATE_FLAG_SELECTED;
849 break;
850 case GTK_STATE_INSENSITIVE:
851 flags |= GTK_STATE_FLAG_INSENSITIVE;
852 break;
853 case GTK_STATE_ACTIVE:
854 flags |= GTK_STATE_FLAG_ACTIVE;
855 break;
856 case GTK_STATE_FOCUSED:
857 flags |= GTK_STATE_FLAG_FOCUSED;
858 break;
859 default:
860 break;
861 }
862 return flags;
863}
864
865static GtkWidget* gtk3_get_arrow(GtkArrowType arrow_type,
866 GtkShadowType shadow_type)
867{
868 GtkWidget *arrow = NULL((void*)0);
869 if (NULL((void*)0) == gtk3_widgets[_GTK_ARROW_TYPE])
870 {
871 gtk3_widgets[_GTK_ARROW_TYPE] = (*fp_gtk_arrow_new)(arrow_type,
872 shadow_type);
873 (*fp_gtk_container_add)((GtkContainer *)gtk3_fixed,
874 gtk3_widgets[_GTK_ARROW_TYPE]);
875 (*fp_gtk_widget_realize)(gtk3_widgets[_GTK_ARROW_TYPE]);
876 }
877 arrow = gtk3_widgets[_GTK_ARROW_TYPE];
878
879 (*fp_gtk_arrow_set)(arrow, arrow_type, shadow_type);
880 return arrow;
881}
882
883static GtkAdjustment* create_adjustment()
884{
885 return (GtkAdjustment *)
886 (*fp_gtk_adjustment_new)(50.0, 0.0, 100.0, 10.0, 20.0, 20.0);
887}
888
889/**
890 * Returns a pointer to the cached native widget for the specified widget
891 * type.
892 */
893static GtkWidget *gtk3_get_widget(WidgetType widget_type)
894{
895 gboolean init_result = FALSE(0);
896 GtkWidget *result = NULL((void*)0);
897 switch (widget_type)
898 {
899 case BUTTON:
900 case TABLE_HEADER:
901 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_BUTTON_TYPE]))
902 {
903 gtk3_widgets[_GTK_BUTTON_TYPE] = (*fp_gtk_button_new)();
904 }
905 result = gtk3_widgets[_GTK_BUTTON_TYPE];
906 break;
907 case CHECK_BOX:
908 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_CHECK_BUTTON_TYPE]))
909 {
910 gtk3_widgets[_GTK_CHECK_BUTTON_TYPE] =
911 (*fp_gtk_check_button_new)();
912 }
913 result = gtk3_widgets[_GTK_CHECK_BUTTON_TYPE];
914 break;
915 case CHECK_BOX_MENU_ITEM:
916 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_CHECK_MENU_ITEM_TYPE]))
917 {
918 gtk3_widgets[_GTK_CHECK_MENU_ITEM_TYPE] =
919 (*fp_gtk_check_menu_item_new)();
920 }
921 result = gtk3_widgets[_GTK_CHECK_MENU_ITEM_TYPE];
922 break;
923 /************************************************************
924 * Creation a dedicated color chooser is dangerous because
925 * it deadlocks the EDT
926 ************************************************************/
927/* case COLOR_CHOOSER:
928 if (init_result =
929 (NULL == gtk3_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE]))
930 {
931 gtk3_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE] =
932 (*fp_gtk_color_selection_dialog_new)(NULL);
933 }
934 result = gtk3_widgets[_GTK_COLOR_SELECTION_DIALOG_TYPE];
935 break;*/
936 case COMBO_BOX:
937 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_COMBO_BOX_TYPE]))
938 {
939 gtk3_widgets[_GTK_COMBO_BOX_TYPE] =
940 (*fp_gtk_combo_box_new)();
941 }
942 result = gtk3_widgets[_GTK_COMBO_BOX_TYPE];
943 break;
944 case COMBO_BOX_ARROW_BUTTON:
945 if (init_result =
946 (NULL((void*)0) == gtk3_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE]))
947 {
948 gtk3_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE] =
949 (*fp_gtk_toggle_button_new)();
950 }
951 result = gtk3_widgets[_GTK_COMBO_BOX_ARROW_BUTTON_TYPE];
952 break;
953 case COMBO_BOX_TEXT_FIELD:
954 if (init_result =
955 (NULL((void*)0) == gtk3_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE]))
956 {
957 result = gtk3_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE] =
958 (*fp_gtk_entry_new)();
959 }
960 result = gtk3_widgets[_GTK_COMBO_BOX_TEXT_FIELD_TYPE];
961 break;
962 case DESKTOP_ICON:
963 case INTERNAL_FRAME_TITLE_PANE:
964 case LABEL:
965 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_LABEL_TYPE]))
966 {
967 gtk3_widgets[_GTK_LABEL_TYPE] =
968 (*fp_gtk_label_new)(NULL((void*)0));
969 }
970 result = gtk3_widgets[_GTK_LABEL_TYPE];
971 break;
972 case DESKTOP_PANE:
973 case PANEL:
974 case ROOT_PANE:
975 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_CONTAINER_TYPE]))
976 {
977 /* There is no constructor for a container type. I've
978 * chosen GtkFixed container since it has a default
979 * constructor.
980 */
981 gtk3_widgets[_GTK_CONTAINER_TYPE] =
982 (*fp_gtk_fixed_new)();
983 }
984 result = gtk3_widgets[_GTK_CONTAINER_TYPE];
985 break;
986 case EDITOR_PANE:
987 case TEXT_AREA:
988 case TEXT_PANE:
989 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_TEXT_VIEW_TYPE]))
990 {
991 gtk3_widgets[_GTK_TEXT_VIEW_TYPE] =
992 (*fp_gtk_text_view_new)();
993 }
994 result = gtk3_widgets[_GTK_TEXT_VIEW_TYPE];
995 break;
996 case FORMATTED_TEXT_FIELD:
997 case PASSWORD_FIELD:
998 case TEXT_FIELD:
999 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_ENTRY_TYPE]))
1000 {
1001 gtk3_widgets[_GTK_ENTRY_TYPE] =
1002 (*fp_gtk_entry_new)();
1003 }
1004 result = gtk3_widgets[_GTK_ENTRY_TYPE];
1005 break;
1006 case HANDLE_BOX:
1007 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_HANDLE_BOX_TYPE]))
1008 {
1009 gtk3_widgets[_GTK_HANDLE_BOX_TYPE] =
1010 (*fp_gtk_handle_box_new)();
1011 }
1012 result = gtk3_widgets[_GTK_HANDLE_BOX_TYPE];
1013 break;
1014 case HSCROLL_BAR:
1015 case HSCROLL_BAR_BUTTON_LEFT:
1016 case HSCROLL_BAR_BUTTON_RIGHT:
1017 case HSCROLL_BAR_TRACK:
1018 case HSCROLL_BAR_THUMB:
1019 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_HSCROLLBAR_TYPE]))
1020 {
1021 gtk3_widgets[_GTK_HSCROLLBAR_TYPE] =
1022 (*fp_gtk_hscrollbar_new)(create_adjustment());
1023 }
1024 result = gtk3_widgets[_GTK_HSCROLLBAR_TYPE];
1025 break;
1026 case HSEPARATOR:
1027 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_HSEPARATOR_TYPE]))
1028 {
1029 gtk3_widgets[_GTK_HSEPARATOR_TYPE] =
1030 (*fp_gtk_hseparator_new)();
1031 }
1032 result = gtk3_widgets[_GTK_HSEPARATOR_TYPE];
1033 break;
1034 case HSLIDER:
1035 case HSLIDER_THUMB:
1036 case HSLIDER_TRACK:
1037 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_HSCALE_TYPE]))
1038 {
1039 gtk3_widgets[_GTK_HSCALE_TYPE] =
1040 (*fp_gtk_scale_new)(GTK_ORIENTATION_HORIZONTAL, NULL((void*)0));
1041 }
1042 result = gtk3_widgets[_GTK_HSCALE_TYPE];
1043 break;
1044 case HSPLIT_PANE_DIVIDER:
1045 case SPLIT_PANE:
1046 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_HPANED_TYPE]))
1047 {
1048 gtk3_widgets[_GTK_HPANED_TYPE] = (*fp_gtk_paned_new)(GTK_ORIENTATION_HORIZONTAL);
1049 }
1050 result = gtk3_widgets[_GTK_HPANED_TYPE];
1051 break;
1052 case IMAGE:
1053 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_IMAGE_TYPE]))
1054 {
1055 gtk3_widgets[_GTK_IMAGE_TYPE] = (*fp_gtk_image_new)();
1056 }
1057 result = gtk3_widgets[_GTK_IMAGE_TYPE];
1058 break;
1059 case INTERNAL_FRAME:
1060 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_WINDOW_TYPE]))
1061 {
1062 gtk3_widgets[_GTK_WINDOW_TYPE] =
1063 (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
1064 }
1065 result = gtk3_widgets[_GTK_WINDOW_TYPE];
1066 break;
1067 case TOOL_TIP:
1068 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_TOOLTIP_TYPE]))
1069 {
1070 result = (*fp_gtk_window_new)(GTK_WINDOW_TOPLEVEL);
1071 gtk3_widgets[_GTK_TOOLTIP_TYPE] = result;
1072 }
1073 result = gtk3_widgets[_GTK_TOOLTIP_TYPE];
1074 break;
1075 case LIST:
1076 case TABLE:
1077 case TREE:
1078 case TREE_CELL:
1079 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_TREE_VIEW_TYPE]))
1080 {
1081 gtk3_widgets[_GTK_TREE_VIEW_TYPE] =
1082 (*fp_gtk_tree_view_new)();
1083 }
1084 result = gtk3_widgets[_GTK_TREE_VIEW_TYPE];
1085 break;
1086 case TITLED_BORDER:
1087 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_FRAME_TYPE]))
1088 {
1089 gtk3_widgets[_GTK_FRAME_TYPE] = fp_gtk_frame_new(NULL((void*)0));
1090 }
1091 result = gtk3_widgets[_GTK_FRAME_TYPE];
1092 break;
1093 case POPUP_MENU:
1094 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_MENU_TYPE]))
1095 {
1096 gtk3_widgets[_GTK_MENU_TYPE] =
1097 (*fp_gtk_menu_new)();
1098 }
1099 result = gtk3_widgets[_GTK_MENU_TYPE];
1100 break;
1101 case MENU:
1102 case MENU_ITEM:
1103 case MENU_ITEM_ACCELERATOR:
1104 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_MENU_ITEM_TYPE]))
1105 {
1106 gtk3_widgets[_GTK_MENU_ITEM_TYPE] =
1107 (*fp_gtk_menu_item_new)();
1108 }
1109 result = gtk3_widgets[_GTK_MENU_ITEM_TYPE];
1110 break;
1111 case MENU_BAR:
1112 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_MENU_BAR_TYPE]))
1113 {
1114 gtk3_widgets[_GTK_MENU_BAR_TYPE] =
1115 (*fp_gtk_menu_bar_new)();
1116 }
1117 result = gtk3_widgets[_GTK_MENU_BAR_TYPE];
1118 break;
1119 case COLOR_CHOOSER:
1120 case OPTION_PANE:
1121 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_DIALOG_TYPE]))
1122 {
1123 gtk3_widgets[_GTK_DIALOG_TYPE] =
1124 (*fp_gtk_dialog_new)();
1125 }
1126 result = gtk3_widgets[_GTK_DIALOG_TYPE];
1127 break;
1128 case POPUP_MENU_SEPARATOR:
1129 if (init_result =
1130 (NULL((void*)0) == gtk3_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE]))
1131 {
1132 gtk3_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE] =
1133 (*fp_gtk_separator_menu_item_new)();
1134 }
1135 result = gtk3_widgets[_GTK_SEPARATOR_MENU_ITEM_TYPE];
1136 break;
1137 case HPROGRESS_BAR:
1138 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_HPROGRESS_BAR_TYPE]))
1139 {
1140 gtk3_widgets[_GTK_HPROGRESS_BAR_TYPE] =
1141 (*fp_gtk_progress_bar_new)();
1142 }
1143 result = gtk3_widgets[_GTK_HPROGRESS_BAR_TYPE];
1144 break;
1145 case VPROGRESS_BAR:
1146 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_VPROGRESS_BAR_TYPE]))
1147 {
1148 gtk3_widgets[_GTK_VPROGRESS_BAR_TYPE] =
1149 (*fp_gtk_progress_bar_new)();
1150 /*
1151 * Vertical JProgressBars always go bottom-to-top,
1152 * regardless of the ComponentOrientation.
1153 */
1154 (*fp_gtk_progress_bar_set_orientation)(
1155 (GtkProgressBar *)gtk3_widgets[_GTK_VPROGRESS_BAR_TYPE],
1156 GTK_PROGRESS_BOTTOM_TO_TOP);
1157 }
1158 result = gtk3_widgets[_GTK_VPROGRESS_BAR_TYPE];
1159 break;
1160 case RADIO_BUTTON:
1161 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_RADIO_BUTTON_TYPE]))
1162 {
1163 gtk3_widgets[_GTK_RADIO_BUTTON_TYPE] =
1164 (*fp_gtk_radio_button_new)(NULL((void*)0));
1165 }
1166 result = gtk3_widgets[_GTK_RADIO_BUTTON_TYPE];
1167 break;
1168 case RADIO_BUTTON_MENU_ITEM:
1169 if (init_result =
1170 (NULL((void*)0) == gtk3_widgets[_GTK_RADIO_MENU_ITEM_TYPE]))
1171 {
1172 gtk3_widgets[_GTK_RADIO_MENU_ITEM_TYPE] =
1173 (*fp_gtk_radio_menu_item_new)(NULL((void*)0));
1174 }
1175 result = gtk3_widgets[_GTK_RADIO_MENU_ITEM_TYPE];
1176 break;
1177 case SCROLL_PANE:
1178 if (init_result =
1179 (NULL((void*)0) == gtk3_widgets[_GTK_SCROLLED_WINDOW_TYPE]))
1180 {
1181 gtk3_widgets[_GTK_SCROLLED_WINDOW_TYPE] =
1182 (*fp_gtk_scrolled_window_new)(NULL((void*)0), NULL((void*)0));
1183 }
1184 result = gtk3_widgets[_GTK_SCROLLED_WINDOW_TYPE];
1185 break;
1186 case SPINNER:
1187 case SPINNER_ARROW_BUTTON:
1188 case SPINNER_TEXT_FIELD:
1189 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_SPIN_BUTTON_TYPE]))
1190 {
1191 result = gtk3_widgets[_GTK_SPIN_BUTTON_TYPE] =
1192 (*fp_gtk_spin_button_new)(NULL((void*)0), 0, 0);
1193 }
1194 result = gtk3_widgets[_GTK_SPIN_BUTTON_TYPE];
1195 break;
1196 case TABBED_PANE:
1197 case TABBED_PANE_TAB_AREA:
1198 case TABBED_PANE_CONTENT:
1199 case TABBED_PANE_TAB:
1200 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_NOTEBOOK_TYPE]))
1201 {
1202 gtk3_widgets[_GTK_NOTEBOOK_TYPE] =
1203 (*fp_gtk_notebook_new)(NULL((void*)0));
1204 }
1205 result = gtk3_widgets[_GTK_NOTEBOOK_TYPE];
1206 break;
1207 case TOGGLE_BUTTON:
1208 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_TOGGLE_BUTTON_TYPE]))
1209 {
1210 gtk3_widgets[_GTK_TOGGLE_BUTTON_TYPE] =
1211 (*fp_gtk_toggle_button_new)(NULL((void*)0));
1212 }
1213 result = gtk3_widgets[_GTK_TOGGLE_BUTTON_TYPE];
1214 break;
1215 case TOOL_BAR:
1216 case TOOL_BAR_DRAG_WINDOW:
1217 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_TOOLBAR_TYPE]))
1218 {
1219 gtk3_widgets[_GTK_TOOLBAR_TYPE] =
1220 (*fp_gtk_toolbar_new)(NULL((void*)0));
1221 }
1222 result = gtk3_widgets[_GTK_TOOLBAR_TYPE];
1223 break;
1224 case TOOL_BAR_SEPARATOR:
1225 if (init_result =
1226 (NULL((void*)0) == gtk3_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE]))
1227 {
1228 gtk3_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE] =
1229 (*fp_gtk_separator_tool_item_new)();
1230 }
1231 result = gtk3_widgets[_GTK_SEPARATOR_TOOL_ITEM_TYPE];
1232 break;
1233 case VIEWPORT:
1234 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_VIEWPORT_TYPE]))
1235 {
1236 GtkAdjustment *adjustment = create_adjustment();
1237 gtk3_widgets[_GTK_VIEWPORT_TYPE] =
1238 (*fp_gtk_viewport_new)(adjustment, adjustment);
1239 }
1240 result = gtk3_widgets[_GTK_VIEWPORT_TYPE];
1241 break;
1242 case VSCROLL_BAR:
1243 case VSCROLL_BAR_BUTTON_UP:
1244 case VSCROLL_BAR_BUTTON_DOWN:
1245 case VSCROLL_BAR_TRACK:
1246 case VSCROLL_BAR_THUMB:
1247 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_VSCROLLBAR_TYPE]))
1248 {
1249 gtk3_widgets[_GTK_VSCROLLBAR_TYPE] =
1250 (*fp_gtk_vscrollbar_new)(create_adjustment());
1251 }
1252 result = gtk3_widgets[_GTK_VSCROLLBAR_TYPE];
1253 break;
1254 case VSEPARATOR:
1255 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_VSEPARATOR_TYPE]))
1256 {
1257 gtk3_widgets[_GTK_VSEPARATOR_TYPE] =
1258 (*fp_gtk_vseparator_new)();
1259 }
1260 result = gtk3_widgets[_GTK_VSEPARATOR_TYPE];
1261 break;
1262 case VSLIDER:
1263 case VSLIDER_THUMB:
1264 case VSLIDER_TRACK:
1265 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_VSCALE_TYPE]))
1266 {
1267 gtk3_widgets[_GTK_VSCALE_TYPE] =
1268 (*fp_gtk_scale_new)(GTK_ORIENTATION_VERTICAL, NULL((void*)0));
1269 }
1270 result = gtk3_widgets[_GTK_VSCALE_TYPE];
1271 /*
1272 * Vertical JSliders start at the bottom, while vertical
1273 * GtkVScale widgets start at the top (by default), so to fix
1274 * this we set the "inverted" flag to get the Swing behavior.
1275 */
1276 fp_gtk_range_set_inverted((GtkRange*)result, TRUE(!(0)));
1277 break;
1278 case VSPLIT_PANE_DIVIDER:
1279 if (init_result = (NULL((void*)0) == gtk3_widgets[_GTK_VPANED_TYPE]))
1280 {
1281 gtk3_widgets[_GTK_VPANED_TYPE] = (*fp_gtk_paned_new)(GTK_ORIENTATION_VERTICAL);
1282 }
1283 result = gtk3_widgets[_GTK_VPANED_TYPE];
1284 break;
1285 default:
1286 result = NULL((void*)0);
1287 break;
1288 }
1289
1290 if (result != NULL((void*)0) && init_result)
1291 {
1292 if (widget_type == RADIO_BUTTON_MENU_ITEM ||
1293 widget_type == CHECK_BOX_MENU_ITEM ||
1294 widget_type == MENU_ITEM ||
1295 widget_type == MENU ||
1296 widget_type == POPUP_MENU_SEPARATOR)
1297 {
1298 GtkWidget *menu = gtk3_get_widget(POPUP_MENU);
1299 (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu, result);
1300 }
1301 else if (widget_type == POPUP_MENU)
1302 {
1303 GtkWidget *menu_bar = gtk3_get_widget(MENU_BAR);
1304 GtkWidget *root_menu = (*fp_gtk_menu_item_new)();
1305 (*fp_gtk_menu_item_set_submenu)((GtkMenuItem*)root_menu, result);
1306 (*fp_gtk_menu_shell_append)((GtkMenuShell *)menu_bar, root_menu);
1307 }
1308 else if (widget_type == COMBO_BOX_TEXT_FIELD )
1309 {
1310 GtkWidget* combo = gtk3_get_widget(COMBO_BOX);
1311
1312 /*
1313 * We add a regular GtkButton/GtkEntry to a GtkComboBoxEntry
1314 * in order to trick engines into thinking it's a real combobox
1315 * arrow button/text field.
1316 */
1317
1318 fp_gtk_container_add ((GtkContainer*)(combo), result);
1319 GtkStyleContext* context = fp_gtk_widget_get_style_context (combo);
1320 fp_gtk_style_context_add_class (context, "combobox-entry");
1321 context = fp_gtk_widget_get_style_context (result);
1322 fp_gtk_style_context_add_class (context, "combobox");
1323 fp_gtk_style_context_add_class (context, "entry");
1324 }
1325 else if (widget_type == COMBO_BOX_ARROW_BUTTON )
1326 {
1327 GtkWidget* combo = gtk3_get_widget(COMBO_BOX);
1328 fp_gtk_widget_set_parent(result, combo);
1329 }
1330 else if (widget_type != TOOL_TIP &&
1331 widget_type != INTERNAL_FRAME &&
1332 widget_type != OPTION_PANE)
1333 {
1334 (*fp_gtk_container_add)((GtkContainer *)gtk3_fixed, result);
1335 }
1336 (*fp_gtk_widget_realize)(result);
1337 }
1338 return result;
1339}
1340
1341static void append_element (GtkWidgetPath *path, const gchar *selector)
1342{
1343 fp_gtk_widget_path_append_type (path, G_TYPE_NONE((GType) ((1) << (2))));
1344 fp_gtk_widget_path_iter_set_object_name (path, -1, selector);
1345}
1346
1347static GtkWidgetPath* createWidgetPath(const GtkWidgetPath* path) {
1348 if (path == NULL((void*)0)) {
1349 return fp_gtk_widget_path_new();
1350 } else {
1351 return fp_gtk_widget_path_copy(path);
1352 }
1353}
1354
1355static GtkStyleContext* get_style(WidgetType widget_type, const gchar *detail)
1356{
1357 if (!gtk3_version_3_20) {
1358 gtk3_widget = gtk3_get_widget(widget_type);
1359 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1360 fp_gtk_style_context_save (context);
1361 if (detail != 0) {
1362 transform_detail_string(detail, context);
1363 }
1364 return context;
1365 } else {
1366 gtk3_widget = gtk3_get_widget(widget_type);
1367 GtkStyleContext* widget_context = fp_gtk_widget_get_style_context (gtk3_widget);
1368 GtkWidgetPath *path = NULL((void*)0);
1369 if (detail != 0) {
1370 if (strcmp(detail, "checkbutton") == 0) {
1371 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1372 append_element(path, "check");
1373 } else if (strcmp(detail, "radiobutton") == 0) {
1374 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1375 append_element(path, "radio");
1376 } else if (strcmp(detail, "vscale") == 0 || strcmp(detail, "hscale") == 0) {
1377 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1378 append_element(path, "slider");
1379 } else if (strcmp(detail, "trough") == 0) {
1380 //This is a fast solution to the scrollbar trough not being rendered properly
1381 if (widget_type == HSCROLL_BAR || widget_type == HSCROLL_BAR_TRACK ||
1382 widget_type == VSCROLL_BAR || widget_type == VSCROLL_BAR_TRACK) {
1383 path = createWidgetPath (NULL((void*)0));
1384 } else {
1385 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1386 }
1387 append_element(path, detail);
1388 } else if (strcmp(detail, "bar") == 0) {
1389 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1390 append_element(path, "trough");
1391 append_element(path, "progress");
1392 } else if (strcmp(detail, "vscrollbar") == 0 || strcmp(detail, "hscrollbar") == 0) {
1393 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1394 append_element(path, "button");
1395 } else if (strcmp(detail, "check") == 0) {
1396 path = createWidgetPath (NULL((void*)0));
1397 append_element(path, detail);
1398 } else if (strcmp(detail, "option") == 0) {
1399 path = createWidgetPath (NULL((void*)0));
1400 append_element(path, "radio");
1401 } else if (strcmp(detail, "paned") == 0) {
1402 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1403 append_element(path, "paned");
1404 append_element(path, "separator");
1405 } else if (strcmp(detail, "spinbutton_down") == 0 || strcmp(detail, "spinbutton_up") == 0) {
1406 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1407 append_element(path, "spinbutton");
1408 append_element(path, "button");
1409 } else {
1410 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1411 append_element(path, detail);
1412 }
1413 } else {
1414 path = createWidgetPath (fp_gtk_style_context_get_path (widget_context));
1415 }
1416
1417 GtkStyleContext *context = fp_gtk_style_context_new ();
1418 fp_gtk_style_context_set_path (context, path);
1419 fp_gtk_widget_path_unref (path);
1420 return context;
1421 }
1422}
1423
1424static void disposeOrRestoreContext(GtkStyleContext *context)
1425{
1426 if (!gtk3_version_3_20) {
1427 fp_gtk_style_context_restore (context);
1428 } else {
1429 fp_g_object_unref (context);
1430 }
1431}
1432
1433static void gtk3_paint_arrow(WidgetType widget_type, GtkStateType state_type,
1434 GtkShadowType shadow_type, const gchar *detail,
1435 gint x, gint y, gint width, gint height,
1436 GtkArrowType arrow_type, gboolean fill)
1437{
1438 gdouble xx, yy, a = G_PI3.1415926535897932384626433832795028841971693993751;
1439 int s = width;
1440 gtk3_widget = gtk3_get_arrow(arrow_type, shadow_type);
1441
1442 switch (widget_type)
1443 {
1444 case SPINNER_ARROW_BUTTON:
1445 s = (int)(0.4 * width + 0.5) + 1;
1446 if (arrow_type == GTK_ARROW_UP) {
1447 a = 0;
1448 } else if (arrow_type == GTK_ARROW_DOWN) {
1449 a = G_PI3.1415926535897932384626433832795028841971693993751;
1450 }
1451 break;
1452
1453 case HSCROLL_BAR_BUTTON_LEFT:
1454 s = (int)(0.5 * MIN(height, width * 2)(((height)<(width * 2))?(height):(width * 2)) + 0.5) + 1;
1455 a = 3 * G_PI3.1415926535897932384626433832795028841971693993751 / 2;
1456 break;
1457
1458 case HSCROLL_BAR_BUTTON_RIGHT:
1459 s = (int)(0.5 * MIN(height, width * 2)(((height)<(width * 2))?(height):(width * 2)) + 0.5) + 1;
1460 a = G_PI3.1415926535897932384626433832795028841971693993751 / 2;
1461 break;
1462
1463 case VSCROLL_BAR_BUTTON_UP:
1464 s = (int)(0.5 * MIN(height * 2, width)(((height * 2)<(width))?(height * 2):(width)) + 0.5) + 1;
1465 a = 0;
1466 break;
1467
1468 case VSCROLL_BAR_BUTTON_DOWN:
1469 s = (int)(0.5 * MIN(height * 2, width)(((height * 2)<(width))?(height * 2):(width)) + 0.5) + 1;
1470 a = G_PI3.1415926535897932384626433832795028841971693993751;
1471 break;
1472
1473 case COMBO_BOX_ARROW_BUTTON:
1474 s = (int)(0.3 * height + 0.5) + 1;
1475 a = G_PI3.1415926535897932384626433832795028841971693993751;
1476 break;
1477
1478 case TABLE:
1479 s = (int)(0.8 * height + 0.5) + 1;
1480 if (arrow_type == GTK_ARROW_UP) {
1481 a = G_PI3.1415926535897932384626433832795028841971693993751;
1482 } else if (arrow_type == GTK_ARROW_DOWN) {
1483 a = 0;
1484 }
1485 break;
1486
1487 case MENU_ITEM:
1488 if (arrow_type == GTK_ARROW_UP) {
1489 a = G_PI3.1415926535897932384626433832795028841971693993751;
1490 } else if (arrow_type == GTK_ARROW_DOWN) {
1491 a = 0;
1492 } else if (arrow_type == GTK_ARROW_RIGHT) {
1493 a = G_PI3.1415926535897932384626433832795028841971693993751 / 2;
1494 } else if (arrow_type == GTK_ARROW_LEFT) {
1495 a = 3 * G_PI3.1415926535897932384626433832795028841971693993751 / 2;
1496 }
1497 break;
1498
1499 default:
1500 if (arrow_type == GTK_ARROW_UP) {
1501 a = G_PI3.1415926535897932384626433832795028841971693993751;
1502 } else if (arrow_type == GTK_ARROW_DOWN) {
1503 a = 0;
1504 } else if (arrow_type == GTK_ARROW_RIGHT) {
1505 a = G_PI3.1415926535897932384626433832795028841971693993751 / 2;
1506 } else if (arrow_type == GTK_ARROW_LEFT) {
1507 a = 3 * G_PI3.1415926535897932384626433832795028841971693993751 / 2;
1508 }
1509 break;
1510 }
1511
1512 if (s < width && s < height) {
1513 xx = x + (0.5 * (width - s) + 0.5);
1514 yy = y + (0.5 * (height - s) + 0.5);
1515 } else {
1516 xx = x;
1517 yy = y;
1518 }
1519
1520 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1521 fp_gtk_style_context_save (context);
1522
1523
1524 if (detail != NULL((void*)0)) {
1525 transform_detail_string(detail, context);
1526 }
1527
1528 GtkStateFlags flags = get_gtk_flags(state_type);
1529
1530 fp_gtk_style_context_set_state (context, flags);
1531
1532 (*fp_gtk_render_arrow)(context, cr, a, xx, yy, s);
1533
1534 fp_gtk_style_context_restore (context);
1535}
1536
1537static void gtk3_paint_box(WidgetType widget_type, GtkStateType state_type,
1538 GtkShadowType shadow_type, const gchar *detail,
1539 gint x, gint y, gint width, gint height,
1540 gint synth_state, GtkTextDirection dir)
1541{
1542 gtk3_widget = gtk3_get_widget(widget_type);
1543
1544 if (widget_type == HSLIDER_TRACK) {
1545 /*
1546 * For horizontal JSliders with right-to-left orientation, we need
1547 * to set the "inverted" flag to match the native GTK behavior where
1548 * the foreground highlight is on the right side of the slider thumb.
1549 * This is needed especially for the ubuntulooks engine, which looks
1550 * exclusively at the "inverted" flag to determine on which side of
1551 * the thumb to paint the highlight...
1552 */
1553 fp_gtk_range_set_inverted((GtkRange*)gtk3_widget, dir ==
1554 GTK_TEXT_DIR_RTL);
1555
1556 /*
1557 * Note however that other engines like clearlooks will look at both
1558 * the "inverted" field and the text direction to determine how
1559 * the foreground highlight is painted:
1560 * !inverted && ltr --> paint highlight on left side
1561 * !inverted && rtl --> paint highlight on right side
1562 * inverted && ltr --> paint highlight on right side
1563 * inverted && rtl --> paint highlight on left side
1564 * So the only way to reliably get the desired results for horizontal
1565 * JSlider (i.e., highlight on left side for LTR ComponentOrientation
1566 * and highlight on right side for RTL ComponentOrientation) is to
1567 * always override text direction as LTR, and then set the "inverted"
1568 * flag accordingly (as we have done above).
1569 */
1570 dir = GTK_TEXT_DIR_LTR;
1571 }
1572
1573 /*
1574 * Some engines (e.g. clearlooks) will paint the shadow of certain
1575 * widgets (e.g. COMBO_BOX_ARROW_BUTTON) differently depending on the
1576 * the text direction.
1577 */
1578 gtk3_set_direction(gtk3_widget, dir);
1579
1580 GtkStyleContext* context = get_style(widget_type, detail);
1581
1582 GtkStateFlags flags = get_gtk_flags(state_type);
1583 if (shadow_type == GTK_SHADOW_IN && widget_type != COMBO_BOX_ARROW_BUTTON) {
1584 flags |= GTK_STATE_FLAG_ACTIVE;
1585 }
1586
1587 if (synth_state & MOUSE_OVER) {
1588 flags |= GTK_STATE_FLAG_PRELIGHT;
1589 }
1590
1591 if (synth_state & FOCUSED) {
1592 flags |= GTK_STATE_FLAG_FOCUSED;
1593 }
1594
1595 if (synth_state & DEFAULT) {
1596 fp_gtk_style_context_add_class (context, "default");
1597 }
1598
1599 if (fp_gtk_style_context_has_class(context, "trough")) {
1600 flags |= GTK_STATE_FLAG_BACKDROP;
1601 }
1602
1603 fp_gtk_style_context_set_state (context, flags);
1604
1605 fp_gtk_render_background (context, cr, x, y, width, height);
1606 if (shadow_type != GTK_SHADOW_NONE) {
1607 fp_gtk_render_frame(context, cr, x, y, width, height);
1608 }
1609
1610 disposeOrRestoreContext(context);
1611
1612 /*
1613 * Reset the text direction to the default value so that we don't
1614 * accidentally affect other operations and widgets.
1615 */
1616 gtk3_set_direction(gtk3_widget, GTK_TEXT_DIR_LTR);
1617
1618 //This is a fast solution to the scrollbar trough not being rendered properly
1619 if ((widget_type == HSCROLL_BAR || widget_type == HSCROLL_BAR_TRACK ||
1620 widget_type == VSCROLL_BAR || widget_type == VSCROLL_BAR_TRACK) && detail != 0) {
1621 gtk3_paint_box(widget_type, state_type, shadow_type, NULL((void*)0),
1622 x, y, width, height, synth_state, dir);
1623 }
1624}
1625
1626static void gtk3_paint_box_gap(WidgetType widget_type, GtkStateType state_type,
1627 GtkShadowType shadow_type, const gchar *detail,
1628 gint x, gint y, gint width, gint height,
1629 GtkPositionType gap_side, gint gap_x, gint gap_width)
1630{
1631 gtk3_widget = gtk3_get_widget(widget_type);
1632
1633 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1634
1635 fp_gtk_style_context_save (context);
1636
1637 GtkStateFlags flags = get_gtk_flags(state_type);
1638 fp_gtk_style_context_set_state(context, flags);
1639
1640 if (detail != 0) {
1641 transform_detail_string(detail, context);
1642 }
1643 fp_gtk_render_background(context, cr, x, y, width, height);
1644
1645 if (shadow_type != GTK_SHADOW_NONE) {
1646 fp_gtk_render_frame_gap(context, cr, x, y, width, height, gap_side,
1647 (gdouble)gap_x, (gdouble)gap_x + gap_width);
1648 }
1649 fp_gtk_style_context_restore (context);
1650}
1651
1652static void gtk3_paint_check(WidgetType widget_type, gint synth_state,
1653 const gchar *detail, gint x, gint y, gint width, gint height)
1654{
1655 GtkStyleContext* context = get_style(widget_type, detail);
1656
1657 GtkStateFlags flags = get_gtk_state_flags(synth_state);
1658 if (gtk3_version_3_14 && (synth_state & SELECTED)) {
1659 flags &= ~GTK_STATE_FLAG_SELECTED;
1660 flags |= GTK_STATE_FLAG_CHECKED;
1661 }
1662 fp_gtk_style_context_set_state(context, flags);
1663
1664 fp_gtk_render_background(context, cr, x, y, width, height);
1665 fp_gtk_render_frame(context, cr, x, y, width, height);
1666 fp_gtk_render_check(context, cr, x, y, width, height);
1667 disposeOrRestoreContext(context);
1668}
1669
1670
1671static void gtk3_paint_expander(WidgetType widget_type, GtkStateType state_type,
1672 const gchar *detail, gint x, gint y, gint width, gint height,
1673 GtkExpanderStyle expander_style)
1674{
1675 gtk3_widget = gtk3_get_widget(widget_type);
1676
1677 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1678
1679 fp_gtk_style_context_save (context);
1680
1681 GtkStateFlags flags = get_gtk_flags(state_type);
1682 if (expander_style == GTK_EXPANDER_EXPANDED) {
1683 if (gtk3_version_3_14) {
1684 flags |= GTK_STATE_FLAG_CHECKED;
1685 } else {
1686 flags |= GTK_STATE_FLAG_ACTIVE;
1687 }
1688 }
1689
1690 fp_gtk_style_context_set_state(context, flags);
1691
1692 if (detail != 0) {
1693 transform_detail_string(detail, context);
1694 }
1695
1696 fp_gtk_render_expander (context, cr, x + 2, y + 2, width - 4, height - 4);
1697
1698 fp_gtk_style_context_restore (context);
1699}
1700
1701static void gtk3_paint_extension(WidgetType widget_type, GtkStateType state_type,
1702 GtkShadowType shadow_type, const gchar *detail,
1703 gint x, gint y, gint width, gint height, GtkPositionType gap_side)
1704{
1705 gtk3_widget = gtk3_get_widget(widget_type);
1706
1707 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1708
1709 fp_gtk_style_context_save (context);
1710
1711 GtkStateFlags flags = GTK_STATE_FLAG_NORMAL;
1712
1713 if (state_type == 0) {
1714 flags = GTK_STATE_FLAG_ACTIVE;
1715 }
1716
1717 fp_gtk_style_context_set_state(context, flags);
1718
1719 if (detail != 0) {
1720 transform_detail_string(detail, context);
1721 }
1722 switch(gap_side) {
1723 case GTK_POS_LEFT:
1724 fp_gtk_style_context_add_class(context, "right");
1725 break;
1726 case GTK_POS_RIGHT:
1727 fp_gtk_style_context_add_class(context, "left");
1728 break;
1729 case GTK_POS_TOP:
1730 fp_gtk_style_context_add_class(context, "bottom");
1731 break;
1732 case GTK_POS_BOTTOM:
1733 fp_gtk_style_context_add_class(context, "top");
1734 break;
1735 default:
1736 break;
1737 }
1738
1739 fp_gtk_render_extension(context, cr, x, y, width, height, gap_side);
1740
1741 fp_gtk_style_context_restore (context);
1742}
1743
1744static void gtk3_paint_flat_box(WidgetType widget_type, GtkStateType state_type,
1745 GtkShadowType shadow_type, const gchar *detail,
1746 gint x, gint y, gint width, gint height, gboolean has_focus)
1747{
1748 if (state_type == GTK_STATE_PRELIGHT &&
1749 (widget_type == CHECK_BOX || widget_type == RADIO_BUTTON)) {
1750 return;
1751 }
1752
1753 GtkStyleContext* context = NULL((void*)0);
1754 if (widget_type == TOOL_TIP) {
1755 context = get_style(widget_type, detail);
1756 fp_gtk_style_context_add_class(context, "background");
1757 } else {
1758 gtk3_widget = gtk3_get_widget(widget_type);
1759 context = fp_gtk_widget_get_style_context (gtk3_widget);
1760 fp_gtk_style_context_save (context);
1761 if (detail != 0) {
1762 transform_detail_string(detail, context);
1763 }
1764 }
1765
1766 GtkStateFlags flags = get_gtk_flags(state_type);
1767
1768 if (has_focus) {
1769 flags |= GTK_STATE_FLAG_FOCUSED;
1770 }
1771
1772 fp_gtk_style_context_set_state (context, flags);
1773
1774 if (widget_type == COMBO_BOX_TEXT_FIELD) {
1775 width += height /2;
1776 }
1777
1778 fp_gtk_render_background (context, cr, x, y, width, height);
1779 if (widget_type == TOOL_TIP) {
1780 disposeOrRestoreContext(context);
1781 } else {
1782 fp_gtk_style_context_restore (context);
1783 }
1784}
1785
1786static void gtk3_paint_focus(WidgetType widget_type, GtkStateType state_type,
1787 const char *detail, gint x, gint y, gint width, gint height)
1788{
1789 gtk3_widget = gtk3_get_widget(widget_type);
1790
1791 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1792 fp_gtk_style_context_save (context);
1793
1794 transform_detail_string(detail, context);
1795 fp_gtk_render_focus (context, cr, x, y, width, height);
1796
1797 fp_gtk_style_context_restore (context);
1798
1799}
1800
1801static void gtk3_paint_handle(WidgetType widget_type, GtkStateType state_type,
1802 GtkShadowType shadow_type, const gchar *detail,
1803 gint x, gint y, gint width, gint height, GtkOrientation orientation)
1804{
1805 gtk3_widget = gtk3_get_widget(widget_type);
1806
1807 GtkStyleContext* context = get_style(widget_type, detail);
1808
1809 GtkStateFlags flags = get_gtk_flags(state_type);
Value stored to 'flags' during its initialization is never read
1810 fp_gtk_style_context_set_state(context, GTK_STATE_FLAG_PRELIGHT);
1811
1812 if (detail != 0 && !(strcmp(detail, "paned") == 0)) {
1813 transform_detail_string(detail, context);
1814 fp_gtk_style_context_add_class (context, "handlebox_bin");
1815 }
1816
1817 if (!(strcmp(detail, "paned") == 0)) {
1818 fp_gtk_render_handle(context, cr, x, y, width, height);
1819 fp_gtk_render_background(context, cr, x, y, width, height);
1820 } else {
1821 if (orientation == GTK_ORIENTATION_VERTICAL) {
1822 fp_gtk_render_handle(context, cr, x+width/2, y, 2, height);
1823 fp_gtk_render_background(context, cr, x+width/2, y, 2, height);
1824 } else {
1825 fp_gtk_render_handle(context, cr, x, y+height/2, width, 2);
1826 fp_gtk_render_background(context, cr, x, y+height/2, width, 2);
1827 }
1828 }
1829
1830 disposeOrRestoreContext(context);
1831}
1832
1833static void gtk3_paint_hline(WidgetType widget_type, GtkStateType state_type,
1834 const gchar *detail, gint x, gint y, gint width, gint height)
1835{
1836 gtk3_widget = gtk3_get_widget(widget_type);
1837
1838 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1839
1840 fp_gtk_style_context_save (context);
1841
1842 if (detail != 0) {
1843 transform_detail_string(detail, context);
1844 }
1845
1846 fp_gtk_render_line(context, cr, x, y, x + width, y);
1847
1848 fp_gtk_style_context_restore (context);
1849}
1850
1851static void gtk3_paint_vline(WidgetType widget_type, GtkStateType state_type,
1852 const gchar *detail, gint x, gint y, gint width, gint height)
1853{
1854 gtk3_widget = gtk3_get_widget(widget_type);
1855
1856
1857 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1858
1859 fp_gtk_style_context_save (context);
1860
1861 if (detail != 0) {
1862 transform_detail_string(detail, context);
1863 }
1864
1865 fp_gtk_render_line(context, cr, x, y, x, y + height);
1866
1867 fp_gtk_style_context_restore (context);
1868}
1869
1870static void gtk3_paint_option(WidgetType widget_type, gint synth_state,
1871 const gchar *detail, gint x, gint y, gint width, gint height)
1872{
1873 GtkStyleContext* context = get_style(widget_type, detail);
1874
1875 GtkStateFlags flags = get_gtk_state_flags(synth_state);
1876 if (gtk3_version_3_14 && (synth_state & SELECTED)) {
1877 flags &= ~GTK_STATE_FLAG_SELECTED;
1878 flags |= GTK_STATE_FLAG_CHECKED;
1879 }
1880 fp_gtk_style_context_set_state(context, flags);
1881
1882 fp_gtk_render_background(context, cr, x, y, width, height);
1883 fp_gtk_render_frame(context, cr, x, y, width, height);
1884 fp_gtk_render_option(context, cr, x, y, width, height);
1885 disposeOrRestoreContext(context);
1886}
1887
1888static void gtk3_paint_shadow(WidgetType widget_type, GtkStateType state_type,
1889 GtkShadowType shadow_type, const gchar *detail,
1890 gint x, gint y, gint width, gint height,
1891 gint synth_state, GtkTextDirection dir)
1892{
1893 if (shadow_type == GTK_SHADOW_NONE) {
1894 return;
1895 }
1896 gtk3_widget = gtk3_get_widget(widget_type);
1897
1898 /*
1899 * Some engines (e.g. clearlooks) will paint the shadow of certain
1900 * widgets (e.g. COMBO_BOX_TEXT_FIELD) differently depending on the
1901 * the text direction.
1902 */
1903 gtk3_set_direction(gtk3_widget, dir);
1904
1905
1906 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1907 fp_gtk_style_context_save (context);
1908
1909 if (detail) {
1910 transform_detail_string(detail, context);
1911 }
1912
1913 GtkStateFlags flags = get_gtk_flags(state_type);
1914
1915 if (synth_state & MOUSE_OVER) {
1916 flags |= GTK_STATE_FLAG_PRELIGHT;
1917 }
1918
1919 if (synth_state & FOCUSED) {
1920 flags |= GTK_STATE_FLAG_FOCUSED;
1921 }
1922
1923 fp_gtk_style_context_set_state (context, flags);
1924
1925 if (widget_type == COMBO_BOX_TEXT_FIELD) {
1926 width += height / 2;
1927 }
1928 fp_gtk_render_frame(context, cr, x, y, width, height);
1929
1930 fp_gtk_style_context_restore (context);
1931
1932 /*
1933 * Reset the text direction to the default value so that we don't
1934 * accidentally affect other operations and widgets.
1935 */
1936 gtk3_set_direction(gtk3_widget, GTK_TEXT_DIR_LTR);
1937}
1938
1939static void gtk3_paint_slider(WidgetType widget_type, GtkStateType state_type,
1940 GtkShadowType shadow_type, const gchar *detail,
1941 gint x, gint y, gint width, gint height, GtkOrientation orientation,
1942 gboolean has_focus)
1943{
1944 GtkStyleContext *context = get_style(widget_type, detail);
1945
1946 GtkStateFlags flags = get_gtk_flags(state_type);
1947
1948 if (state_type == GTK_STATE_ACTIVE) {
1949 flags |= GTK_STATE_FLAG_PRELIGHT;
1950 }
1951
1952 if (has_focus) {
1953 flags |= GTK_STATE_FLAG_FOCUSED;
1954 }
1955
1956 fp_gtk_style_context_set_state (context, flags);
1957
1958 fp_gtk_render_background (context, cr, x, y, width, height);
1959 fp_gtk_render_frame(context, cr, x, y, width, height);
1960 (*fp_gtk_render_slider)(context, cr, x, y, width, height, orientation);
1961 disposeOrRestoreContext(context);
1962}
1963
1964static void gtk3_paint_background(WidgetType widget_type,
1965 GtkStateType state_type, gint x, gint y, gint width, gint height) {
1966 gtk3_widget = gtk3_get_widget(widget_type);
1967
1968 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
1969 fp_gtk_style_context_save (context);
1970
1971 GtkStateFlags flags = get_gtk_flags(state_type);
1972
1973 fp_gtk_style_context_set_state (context, flags);
1974
1975 fp_gtk_render_background (context, cr, x, y, width, height);
1976
1977 fp_gtk_style_context_restore (context);
1978}
1979
1980static GdkPixbuf *gtk3_get_stock_icon(gint widget_type, const gchar *stock_id,
1981 GtkIconSize size, GtkTextDirection direction, const char *detail)
1982{
1983 int sz;
1984
1985 switch(size) {
1986 case GTK_ICON_SIZE_MENU:
1987 sz = 16;
1988 break;
1989 case GTK_ICON_SIZE_SMALL_TOOLBAR:
1990 sz = 18;
1991 break;
1992 case GTK_ICON_SIZE_LARGE_TOOLBAR:
1993 sz = 24;
1994 break;
1995 case GTK_ICON_SIZE_BUTTON:
1996 sz = 20;
1997 break;
1998 case GTK_ICON_SIZE_DND:
1999 sz = 32;
2000 break;
2001 case GTK_ICON_SIZE_DIALOG:
2002 sz = 48;
2003 break;
2004 default:
2005 sz = 0;
2006 break;
2007 }
2008
2009 init_containers();
2010 gtk3_widget = gtk3_get_widget((widget_type < 0) ? IMAGE : widget_type);
2011 (*fp_gtk_widget_set_direction)(gtk3_widget, direction);
2012 GtkIconTheme *icon_theme = fp_gtk_icon_theme_get_default();
2013 GdkPixbuf *result = fp_gtk_icon_theme_load_icon(icon_theme, stock_id, sz,
2014 GTK_ICON_LOOKUP_USE_BUILTIN, NULL((void*)0));
2015 return result;
2016}
2017
2018static jboolean gtk3_get_pixbuf_data(JNIEnv *env, GdkPixbuf* pixbuf,
2019 jmethodID icon_upcall_method, jobject this) {
2020 if (!pixbuf) {
2021 return JNI_FALSE0;
2022 }
2023 guchar *pixbuf_data = (*fp_gdk_pixbuf_get_pixels)(pixbuf);
2024 if (pixbuf_data) {
2025 int row_stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
2026 int width = (*fp_gdk_pixbuf_get_width)(pixbuf);
2027 int height = (*fp_gdk_pixbuf_get_height)(pixbuf);
2028 int bps = (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf);
2029 int channels = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
2030 gboolean alpha = (*fp_gdk_pixbuf_get_has_alpha)(pixbuf);
2031
2032 jbyteArray data = (*env)->NewByteArray(env, (row_stride * height));
2033 JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE)do { if ((*env)->ExceptionCheck(env)) { return (0); } } while
(0)
;
2034
2035 (*env)->SetByteArrayRegion(env, data, 0, (row_stride * height),
2036 (jbyte *)pixbuf_data);
2037 (*fp_g_object_unref)(pixbuf);
2038
2039 /* Call the callback method to create the image on the Java side. */
2040 (*env)->CallVoidMethod(env, this, icon_upcall_method, data,
2041 width, height, row_stride, bps, channels, alpha);
2042 return JNI_TRUE1;
2043 }
2044 return JNI_FALSE0;
2045}
2046
2047static jboolean gtk3_get_file_icon_data(JNIEnv *env, const char *filename,
2048 GError **error, jmethodID icon_upcall_method, jobject this) {
2049 GdkPixbuf* pixbuf = fp_gdk_pixbuf_new_from_file(filename, error);
2050 return gtk3_get_pixbuf_data(env, pixbuf, icon_upcall_method, this);
2051}
2052
2053static jboolean gtk3_get_icon_data(JNIEnv *env, gint widget_type,
2054 const gchar *stock_id, GtkIconSize size,
2055 GtkTextDirection direction, const char *detail,
2056 jmethodID icon_upcall_method, jobject this) {
2057 GdkPixbuf* pixbuf = gtk3_get_stock_icon(widget_type, stock_id, size,
2058 direction, detail);
2059 return gtk3_get_pixbuf_data(env, pixbuf, icon_upcall_method, this);
2060}
2061
2062/*************************************************/
2063static gint gtk3_get_xthickness(JNIEnv *env, WidgetType widget_type)
2064{
2065 init_containers();
2066
2067 gtk3_widget = gtk3_get_widget(widget_type);
2068 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
2069 if (context) {
2070 GtkBorder padding;
2071 fp_gtk_style_context_get_padding(context, 0, &padding);
2072 return padding.left + 1;
2073 }
2074 return 0;
2075}
2076
2077static gint gtk3_get_ythickness(JNIEnv *env, WidgetType widget_type)
2078{
2079 init_containers();
2080
2081 gtk3_widget = gtk3_get_widget(widget_type);
2082 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
2083 if (context) {
2084 GtkBorder padding;
2085 fp_gtk_style_context_get_padding(context, 0, &padding);
2086 return padding.top + 1;
2087 }
2088 return 0;
2089}
2090
2091/*************************************************/
2092static guint8 recode_color(gdouble channel)
2093{
2094 guint16 result = (guint16)(channel * 65535);
2095 if (result > 65535) {
2096 result = 65535;
2097 }
2098 return (guint8)( result >> 8);
2099}
2100
2101static GtkStateFlags gtk3_get_state_flags(GtkStateType state_type) {
2102 switch (state_type)
2103 {
2104 case GTK_STATE_NORMAL:
2105 return GTK_STATE_FLAG_NORMAL;
2106 case GTK_STATE_ACTIVE:
2107 return GTK_STATE_FLAG_ACTIVE;
2108 case GTK_STATE_PRELIGHT:
2109 return GTK_STATE_FLAG_PRELIGHT;
2110 case GTK_STATE_SELECTED:
2111 return GTK_STATE_FLAG_SELECTED;
2112 case GTK_STATE_INSENSITIVE:
2113 return GTK_STATE_FLAG_INSENSITIVE;
2114 case GTK_STATE_INCONSISTENT:
2115 return GTK_STATE_FLAG_INCONSISTENT;
2116 case GTK_STATE_FOCUSED:
2117 return GTK_STATE_FLAG_FOCUSED;
2118 }
2119 return 0;
2120}
2121
2122
2123static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b) {
2124 gdouble min;
2125 gdouble max;
2126 gdouble red;
2127 gdouble green;
2128 gdouble blue;
2129 gdouble h, l, s;
2130 gdouble delta;
2131
2132 red = *r;
2133 green = *g;
2134 blue = *b;
2135
2136 if (red > green)
2137 {
2138 if (red > blue)
2139 max = red;
2140 else
2141 max = blue;
2142
2143 if (green < blue)
2144 min = green;
2145 else
2146 min = blue;
2147 }
2148 else
2149 {
2150 if (green > blue)
2151 max = green;
2152 else
2153 max = blue;
2154
2155 if (red < blue)
2156 min = red;
2157 else
2158 min = blue;
2159 }
2160
2161 l = (max + min) / 2;
2162 s = 0;
2163 h = 0;
2164
2165 if (max != min)
2166 {
2167 if (l <= 0.5)
2168 s = (max - min) / (max + min);
2169 else
2170 s = (max - min) / (2 - max - min);
2171
2172 delta = max -min;
2173 if (red == max)
2174 h = (green - blue) / delta;
2175 else if (green == max)
2176 h = 2 + (blue - red) / delta;
2177 else if (blue == max)
2178 h = 4 + (red - green) / delta;
2179
2180 h *= 60;
2181 if (h < 0.0)
2182 h += 360;
2183 }
2184
2185 *r = h;
2186 *g = l;
2187 *b = s;
2188}
2189
2190static void hls_to_rgb (gdouble *h, gdouble *l, gdouble *s)
2191{
2192 gdouble hue;
2193 gdouble lightness;
2194 gdouble saturation;
2195 gdouble m1, m2;
2196 gdouble r, g, b;
2197
2198 lightness = *l;
2199 saturation = *s;
2200
2201 if (lightness <= 0.5)
2202 m2 = lightness * (1 + saturation);
2203 else
2204 m2 = lightness + saturation - lightness * saturation;
2205 m1 = 2 * lightness - m2;
2206
2207 if (saturation == 0)
2208 {
2209 *h = lightness;
2210 *l = lightness;
2211 *s = lightness;
2212 }
2213 else
2214 {
2215 hue = *h + 120;
2216 while (hue > 360)
2217 hue -= 360;
2218 while (hue < 0)
2219 hue += 360;
2220
2221 if (hue < 60)
2222 r = m1 + (m2 - m1) * hue / 60;
2223 else if (hue < 180)
2224 r = m2;
2225 else if (hue < 240)
2226 r = m1 + (m2 - m1) * (240 - hue) / 60;
2227 else
2228 r = m1;
2229
2230 hue = *h;
2231 while (hue > 360)
2232 hue -= 360;
2233 while (hue < 0)
2234 hue += 360;
2235
2236 if (hue < 60)
2237 g = m1 + (m2 - m1) * hue / 60;
2238 else if (hue < 180)
2239 g = m2;
2240 else if (hue < 240)
2241 g = m1 + (m2 - m1) * (240 - hue) / 60;
2242 else
2243 g = m1;
2244
2245 hue = *h - 120;
2246 while (hue > 360)
2247 hue -= 360;
2248 while (hue < 0)
2249 hue += 360;
2250
2251 if (hue < 60)
2252 b = m1 + (m2 - m1) * hue / 60;
2253 else if (hue < 180)
2254 b = m2;
2255 else if (hue < 240)
2256 b = m1 + (m2 - m1) * (240 - hue) / 60;
2257 else
2258 b = m1;
2259
2260 *h = r;
2261 *l = g;
2262 *s = b;
2263 }
2264}
2265
2266
2267
2268static void gtk3_style_shade (const GdkRGBA *a, GdkRGBA *b, gdouble k) {
2269 gdouble red = a->red;
2270 gdouble green = a->green;
2271 gdouble blue = a->blue;
2272
2273 rgb_to_hls (&red, &green, &blue);
2274
2275 green *= k;
2276 if (green > 1.0)
2277 green = 1.0;
2278 else if (green < 0.0)
2279 green = 0.0;
2280
2281 blue *= k;
2282 if (blue > 1.0)
2283 blue = 1.0;
2284 else if (blue < 0.0)
2285 blue = 0.0;
2286
2287 hls_to_rgb (&red, &green, &blue);
2288
2289 b->red = red;
2290 b->green = green;
2291 b->blue = blue;
2292}
2293
2294static GdkRGBA gtk3_get_color_for_flags(GtkStyleContext* context,
2295 GtkStateFlags flags, ColorType color_type) {
2296 GdkRGBA c, color;
2297 color.alpha = 1;
2298
2299 switch (color_type)
2300 {
2301 case FOREGROUND:
2302 case TEXT_FOREGROUND:
2303 fp_gtk_style_context_get_color(context, flags, &color);
2304 break;
2305 case BACKGROUND:
2306 case TEXT_BACKGROUND:
2307 fp_gtk_style_context_get_background_color(context, flags, &color);
2308 break;
2309 case LIGHT:
2310 c = gtk3_get_color_for_flags(context, flags, BACKGROUND);
2311 gtk3_style_shade(&c, &color, LIGHTNESS_MULT1.3);
2312 break;
2313 case DARK:
2314 c = gtk3_get_color_for_flags(context, flags, BACKGROUND);
2315 gtk3_style_shade (&c, &color, DARKNESS_MULT0.7);
2316 break;
2317 case MID:
2318 {
2319 GdkRGBA c1 = gtk3_get_color_for_flags(context, flags, LIGHT);
2320 GdkRGBA c2 = gtk3_get_color_for_flags(context, flags, DARK);
2321 color.red = (c1.red + c2.red) / 2;
2322 color.green = (c1.green + c2.green) / 2;
2323 color.blue = (c1.blue + c2.blue) / 2;
2324 }
2325 break;
2326 case FOCUS:
2327 case BLACK:
2328 color.red = 0;
2329 color.green = 0;
2330 color.blue = 0;
2331 break;
2332 case WHITE:
2333 color.red = 1;
2334 color.green = 1;
2335 color.blue = 1;
2336 break;
2337 }
2338 return color;
2339}
2340
2341static gint gtk3_get_color_for_state(JNIEnv *env, WidgetType widget_type,
2342 GtkStateType state_type, ColorType color_type)
2343{
2344
2345 gint result = 0;
2346
2347 GtkStateFlags flags = gtk3_get_state_flags(state_type);
2348
2349 init_containers();
2350
2351 if (gtk3_version_3_20) {
2352 if ((widget_type == TEXT_FIELD || widget_type == PASSWORD_FIELD || widget_type == SPINNER_TEXT_FIELD ||
2353 widget_type == FORMATTED_TEXT_FIELD) && state_type == GTK_STATE_SELECTED && color_type == TEXT_BACKGROUND) {
2354 widget_type = TEXT_AREA;
2355 }
2356 }
2357
2358 GtkStyleContext* context = NULL((void*)0);
2359 if (widget_type == TOOL_TIP) {
2360 context = get_style(widget_type, "tooltip");
2361 } else {
2362 gtk3_widget = gtk3_get_widget(widget_type);
2363 context = fp_gtk_widget_get_style_context(gtk3_widget);
2364 }
2365 if (widget_type == CHECK_BOX_MENU_ITEM
2366 || widget_type == RADIO_BUTTON_MENU_ITEM) {
2367 flags &= GTK_STATE_FLAG_NORMAL | GTK_STATE_FLAG_SELECTED
2368 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_FOCUSED;
2369 }
2370
2371 GdkRGBA color = gtk3_get_color_for_flags(context, flags, color_type);
2372
2373 if (recode_color(color.alpha) == 0) {
2374 color = gtk3_get_color_for_flags(
2375 fp_gtk_widget_get_style_context(gtk3_get_widget(INTERNAL_FRAME)),
2376 0, BACKGROUND);
2377 }
2378
2379 result = recode_color(color.alpha) << 24 | recode_color(color.red) << 16 |
2380 recode_color(color.green) << 8 | recode_color(color.blue);
2381 if (widget_type == TOOL_TIP) {
2382 disposeOrRestoreContext(context);
2383 }
2384 return result;
2385}
2386
2387/*************************************************/
2388static jobject create_Boolean(JNIEnv *env, jboolean boolean_value);
2389static jobject create_Integer(JNIEnv *env, jint int_value);
2390static jobject create_Long(JNIEnv *env, jlong long_value);
2391static jobject create_Float(JNIEnv *env, jfloat float_value);
2392static jobject create_Double(JNIEnv *env, jdouble double_value);
2393static jobject create_Character(JNIEnv *env, jchar char_value);
2394static jobject create_Insets(JNIEnv *env, GtkBorder *border);
2395
2396static jobject gtk3_get_class_value(JNIEnv *env, WidgetType widget_type,
2397 const char* key)
2398{
2399 init_containers();
2400
2401 gtk3_widget = gtk3_get_widget(widget_type);
2402
2403 GValue value = { 0, { { 0 } } };
2404
2405 GParamSpec* param = (*fp_gtk_widget_class_find_style_property)(
2406 ((GTypeInstance*)gtk3_widget)->g_class, key);
2407 if ( param )
2408 {
2409 (*fp_g_value_init)( &value, param->value_type );
2410 (*fp_gtk_widget_style_get_property)(gtk3_widget, key, &value);
2411
2412 if ((*fp_g_type_is_a)( param->value_type, G_TYPE_BOOLEAN((GType) ((5) << (2))) ))
2413 {
2414 gboolean val = (*fp_g_value_get_boolean)(&value);
2415 return create_Boolean(env, (jboolean)val);
2416 }
2417 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_CHAR((GType) ((3) << (2))) ))
2418 {
2419 gchar val = (*fp_g_value_get_char)(&value);
2420 return create_Character(env, (jchar)val);
2421 }
2422 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_UCHAR((GType) ((4) << (2))) ))
2423 {
2424 guchar val = (*fp_g_value_get_uchar)(&value);
2425 return create_Character(env, (jchar)val);
2426 }
2427 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_INT((GType) ((6) << (2))) ))
2428 {
2429 gint val = (*fp_g_value_get_int)(&value);
2430 return create_Integer(env, (jint)val);
2431 }
2432 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_UINT((GType) ((7) << (2))) ))
2433 {
2434 guint val = (*fp_g_value_get_uint)(&value);
2435 return create_Integer(env, (jint)val);
2436 }
2437 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_LONG((GType) ((8) << (2))) ))
2438 {
2439 glong val = (*fp_g_value_get_long)(&value);
2440 return create_Long(env, (jlong)val);
2441 }
2442 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_ULONG((GType) ((9) << (2))) ))
2443 {
2444 gulong val = (*fp_g_value_get_ulong)(&value);
2445 return create_Long(env, (jlong)val);
2446 }
2447 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_INT64((GType) ((10) << (2))) ))
2448 {
2449 gint64 val = (*fp_g_value_get_int64)(&value);
2450 return create_Long(env, (jlong)val);
2451 }
2452 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_UINT64((GType) ((11) << (2))) ))
2453 {
2454 guint64 val = (*fp_g_value_get_uint64)(&value);
2455 return create_Long(env, (jlong)val);
2456 }
2457 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_FLOAT((GType) ((14) << (2))) ))
2458 {
2459 gfloat val = (*fp_g_value_get_float)(&value);
2460 return create_Float(env, (jfloat)val);
2461 }
2462 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_DOUBLE((GType) ((15) << (2))) ))
2463 {
2464 gdouble val = (*fp_g_value_get_double)(&value);
2465 return create_Double(env, (jdouble)val);
2466 }
2467 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_ENUM((GType) ((12) << (2))) ))
2468 {
2469 gint val = (*fp_g_value_get_enum)(&value);
2470 return create_Integer(env, (jint)val);
2471 }
2472 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_FLAGS((GType) ((13) << (2))) ))
2473 {
2474 guint val = (*fp_g_value_get_flags)(&value);
2475 return create_Integer(env, (jint)val);
2476 }
2477 else if ((*fp_g_type_is_a)( param->value_type, G_TYPE_STRING((GType) ((16) << (2))) ))
2478 {
2479 const gchar* val = (*fp_g_value_get_string)(&value);
2480
2481 /* We suppose that all values come in C locale and
2482 * utf-8 representation of a string is the same as
2483 * the string itself. If this isn't so we should
2484 * use g_convert.
2485 */
2486 return (*env)->NewStringUTF(env, val);
2487 }
2488 else if ((*fp_g_type_is_a)( param->value_type, GTK_TYPE_BORDER((*fp_gtk_border_get_type)()) ))
2489 {
2490 GtkBorder *border = (GtkBorder*)(*fp_g_value_get_boxed)(&value);
2491 return border ? create_Insets(env, border) : NULL((void*)0);
2492 }
2493
2494 /* TODO: Other types are not supported yet.*/
2495/* else if((*fp_g_type_is_a)( param->value_type, G_TYPE_PARAM ))
2496 {
2497 GParamSpec* val = (*fp_g_value_get_param)(&value);
2498 printf( "Param: %p\n", val );
2499 }
2500 else if((*fp_g_type_is_a)( param->value_type, G_TYPE_BOXED ))
2501 {
2502 gpointer* val = (*fp_g_value_get_boxed)(&value);
2503 printf( "Boxed: %p\n", val );
2504 }
2505 else if((*fp_g_type_is_a)( param->value_type, G_TYPE_POINTER ))
2506 {
2507 gpointer* val = (*fp_g_value_get_pointer)(&value);
2508 printf( "Pointer: %p\n", val );
2509 }
2510 else if((*fp_g_type_is_a)( param->value_type, G_TYPE_OBJECT ))
2511 {
2512 GObject* val = (GObject*)(*fp_g_value_get_object)(&value);
2513 printf( "Object: %p\n", val );
2514 }*/
2515 }
2516
2517 return NULL((void*)0);
2518}
2519
2520static void gtk3_set_range_value(WidgetType widget_type, jdouble value,
2521 jdouble min, jdouble max, jdouble visible)
2522{
2523 GtkAdjustment *adj;
2524
2525 gtk3_widget = gtk3_get_widget(widget_type);
2526
2527 adj = (*fp_gtk_range_get_adjustment)((GtkRange *)gtk3_widget);
2528
2529 fp_gtk_adjustment_set_value(adj, value);
2530 fp_gtk_adjustment_set_lower(adj, min);
2531 fp_gtk_adjustment_set_upper(adj, max);
2532 fp_gtk_adjustment_set_page_size(adj, visible);
2533}
2534
2535/*************************************************/
2536static jobject create_Object(JNIEnv *env, jmethodID *cid,
2537 const char* class_name,
2538 const char* signature,
2539 jvalue* value)
2540{
2541 jclass class;
2542 jobject result;
2543
2544 class = (*env)->FindClass(env, class_name);
2545 if (class == NULL((void*)0))
2546 return NULL((void*)0); /* can't find/load the class, exception thrown */
2547
2548 if (*cid == NULL((void*)0))
2549 {
2550 *cid = (*env)->GetMethodID(env, class, "<init>", signature);
2551 if (*cid == NULL((void*)0))
2552 {
2553 (*env)->DeleteLocalRef(env, class);
2554 return NULL((void*)0); /* can't find/get the method, exception thrown */
2555 }
2556 }
2557
2558 result = (*env)->NewObjectA(env, class, *cid, value);
2559
2560 (*env)->DeleteLocalRef(env, class);
2561 return result;
2562}
2563
2564jobject create_Boolean(JNIEnv *env, jboolean boolean_value)
2565{
2566 static jmethodID cid = NULL((void*)0);
2567 jvalue value;
2568
2569 value.z = boolean_value;
2570
2571 return create_Object(env, &cid, "java/lang/Boolean", "(Z)V", &value);
2572}
2573
2574jobject create_Integer(JNIEnv *env, jint int_value)
2575{
2576 static jmethodID cid = NULL((void*)0);
2577 jvalue value;
2578
2579 value.i = int_value;
2580
2581 return create_Object(env, &cid, "java/lang/Integer", "(I)V", &value);
2582}
2583
2584jobject create_Long(JNIEnv *env, jlong long_value)
2585{
2586 static jmethodID cid = NULL((void*)0);
2587 jvalue value;
2588
2589 value.j = long_value;
2590
2591 return create_Object(env, &cid, "java/lang/Long", "(J)V", &value);
2592}
2593
2594jobject create_Float(JNIEnv *env, jfloat float_value)
2595{
2596 static jmethodID cid = NULL((void*)0);
2597 jvalue value;
2598
2599 value.f = float_value;
2600
2601 return create_Object(env, &cid, "java/lang/Float", "(F)V", &value);
2602}
2603
2604jobject create_Double(JNIEnv *env, jdouble double_value)
2605{
2606 static jmethodID cid = NULL((void*)0);
2607 jvalue value;
2608
2609 value.d = double_value;
2610
2611 return create_Object(env, &cid, "java/lang/Double", "(D)V", &value);
2612}
2613
2614jobject create_Character(JNIEnv *env, jchar char_value)
2615{
2616 static jmethodID cid = NULL((void*)0);
2617 jvalue value;
2618
2619 value.c = char_value;
2620
2621 return create_Object(env, &cid, "java/lang/Character", "(C)V", &value);
2622}
2623
2624
2625jobject create_Insets(JNIEnv *env, GtkBorder *border)
2626{
2627 static jmethodID cid = NULL((void*)0);
2628 jvalue values[4];
2629
2630 values[0].i = border->top;
2631 values[1].i = border->left;
2632 values[2].i = border->bottom;
2633 values[3].i = border->right;
2634
2635 return create_Object(env, &cid, "java/awt/Insets", "(IIII)V", values);
2636}
2637
2638/*********************************************/
2639static jstring gtk3_get_pango_font_name(JNIEnv *env, WidgetType widget_type)
2640{
2641 init_containers();
2642
2643 gtk3_widget = gtk3_get_widget(widget_type);
2644 jstring result = NULL((void*)0);
2645 GtkStyleContext* context = fp_gtk_widget_get_style_context (gtk3_widget);
2646 if (context)
2647 {
2648 PangoFontDescription* fd = fp_gtk_style_context_get_font(context, 0);
2649 gchar* val = (*fp_pango_font_description_to_string)(fd);
2650 result = (*env)->NewStringUTF(env, val);
2651 (*fp_g_free)( val );
2652 }
2653
2654 return result;
2655}
2656
2657/***********************************************/
2658static jobject get_string_property(JNIEnv *env, GtkSettings* settings,
2659 const gchar* key) {
2660 jobject result = NULL((void*)0);
2661 gchar* strval = NULL((void*)0);
2662
2663 (*fp_g_object_get)(settings, key, &strval, NULL((void*)0));
2664 result = (*env)->NewStringUTF(env, strval);
2665 (*fp_g_free)(strval);
2666
2667 return result;
2668}
2669
2670static jobject get_integer_property(JNIEnv *env, GtkSettings* settings,
2671 const gchar* key) {
2672 gint intval = 0;
2673 (*fp_g_object_get)(settings, key, &intval, NULL((void*)0));
2674 return create_Integer(env, intval);
2675}
2676
2677static jobject get_boolean_property(JNIEnv *env, GtkSettings* settings,
2678 const gchar* key) {
2679 gint intval = 0;
2680 (*fp_g_object_get)(settings, key, &intval, NULL((void*)0));
2681 return create_Boolean(env, intval);
2682}
2683
2684static jobject gtk3_get_setting(JNIEnv *env, Setting property)
2685{
2686 GtkSettings* settings = (*fp_gtk_settings_get_default)();
2687
2688 switch (property)
2689 {
2690 case GTK_FONT_NAME:
2691 return get_string_property(env, settings, "gtk-font-name");
2692 case GTK_ICON_SIZES:
2693 return get_string_property(env, settings, "gtk-icon-sizes");
2694 case GTK_CURSOR_BLINK:
2695 return get_boolean_property(env, settings, "gtk-cursor-blink");
2696 case GTK_CURSOR_BLINK_TIME:
2697 return get_integer_property(env, settings, "gtk-cursor-blink-time");
2698 }
2699
2700 return NULL((void*)0);
2701}
2702
2703static void transform_detail_string (const gchar *detail,
2704 GtkStyleContext *context) {
2705 if (!detail)
2706 return;
2707
2708 if (strcmp (detail, "arrow") == 0)
2709 fp_gtk_style_context_add_class (context, "arrow");
2710 else if (strcmp (detail, "button") == 0)
2711 fp_gtk_style_context_add_class (context, "button");
2712 else if (strcmp (detail, "buttondefault") == 0)
2713 {
2714 fp_gtk_style_context_add_class (context, "button");
2715 fp_gtk_style_context_add_class (context, "default");
2716 }
2717 else if (strcmp (detail, "calendar") == 0)
2718 fp_gtk_style_context_add_class (context, "calendar");
2719 else if (strcmp (detail, "cellcheck") == 0)
2720 {
2721 fp_gtk_style_context_add_class (context, "cell");
2722 fp_gtk_style_context_add_class (context, "check");
2723 }
2724 else if (strcmp (detail, "cellradio") == 0)
2725 {
2726 fp_gtk_style_context_add_class (context, "cell");
2727 fp_gtk_style_context_add_class (context, "radio");
2728 }
2729 else if (strcmp (detail, "checkbutton") == 0)
2730 fp_gtk_style_context_add_class (context, "check");
2731 else if (strcmp (detail, "check") == 0)
2732 {
2733 fp_gtk_style_context_add_class (context, "check");
2734 fp_gtk_style_context_add_class (context, "menu");
2735 }
2736 else if (strcmp (detail, "radiobutton") == 0)
2737 {
2738 fp_gtk_style_context_add_class (context, "radio");
2739 }
2740 else if (strcmp (detail, "option") == 0)
2741 {
2742 fp_gtk_style_context_add_class (context, "radio");
2743 fp_gtk_style_context_add_class (context, "menu");
2744 }
2745 else if (strcmp (detail, "entry") == 0 ||
2746 strcmp (detail, "entry_bg") == 0)
2747 fp_gtk_style_context_add_class (context, "entry");
2748 else if (strcmp (detail, "expander") == 0)
2749 fp_gtk_style_context_add_class (context, "expander");
2750 else if (strcmp (detail, "tooltip") == 0)
2751 fp_gtk_style_context_add_class (context, "tooltip");
2752 else if (strcmp (detail, "frame") == 0)
2753 fp_gtk_style_context_add_class (context, "frame");
2754 else if (strcmp (detail, "scrolled_window") == 0)
2755 fp_gtk_style_context_add_class (context, "scrolled-window");
2756 else if (strcmp (detail, "viewport") == 0 ||
2757 strcmp (detail, "viewportbin") == 0)
2758 fp_gtk_style_context_add_class (context, "viewport");
2759 else if (strncmp (detail, "trough", 6) == 0)
2760 fp_gtk_style_context_add_class (context, "trough");
2761 else if (strcmp (detail, "spinbutton") == 0)
2762 fp_gtk_style_context_add_class (context, "spinbutton");
2763 else if (strcmp (detail, "spinbutton_up") == 0)
2764 {
2765 fp_gtk_style_context_add_class (context, "spinbutton");
2766 fp_gtk_style_context_add_class (context, "button");
2767 fp_gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2768 }
2769 else if (strcmp (detail, "spinbutton_down") == 0)
2770 {
2771 fp_gtk_style_context_add_class (context, "spinbutton");
2772 fp_gtk_style_context_add_class (context, "button");
2773 fp_gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2774 }
2775 else if ((detail[0] == 'h' || detail[0] == 'v') &&
2776 strncmp (&detail[1], "scrollbar_", 9) == 0)
2777 {
2778 fp_gtk_style_context_add_class (context, "button");
2779 fp_gtk_style_context_add_class (context, "scrollbar");
2780 }
2781 else if (strcmp (detail, "slider") == 0)
2782 {
2783 fp_gtk_style_context_add_class (context, "slider");
2784 fp_gtk_style_context_add_class (context, "scrollbar");
2785 }
2786 else if (strcmp (detail, "vscale") == 0 ||
2787 strcmp (detail, "hscale") == 0)
2788 {
2789 fp_gtk_style_context_add_class (context, "slider");
2790 fp_gtk_style_context_add_class (context, "scale");
2791 }
2792 else if (strcmp (detail, "menuitem") == 0)
2793 {
2794 fp_gtk_style_context_add_class (context, "menuitem");
2795 fp_gtk_style_context_add_class (context, "menu");
2796 }
2797 else if (strcmp (detail, "menu") == 0)
2798 {
2799 fp_gtk_style_context_add_class (context, "popup");
2800 fp_gtk_style_context_add_class (context, "menu");
2801 }
2802 else if (strcmp (detail, "accellabel") == 0)
2803 fp_gtk_style_context_add_class (context, "accelerator");
2804 else if (strcmp (detail, "menubar") == 0)
2805 fp_gtk_style_context_add_class (context, "menubar");
2806 else if (strcmp (detail, "base") == 0)
2807 fp_gtk_style_context_add_class (context, "background");
2808 else if (strcmp (detail, "bar") == 0 ||
2809 strcmp (detail, "progressbar") == 0)
2810 fp_gtk_style_context_add_class (context, "progressbar");
2811 else if (strcmp (detail, "toolbar") == 0)
2812 fp_gtk_style_context_add_class (context, "toolbar");
2813 else if (strcmp (detail, "handlebox_bin") == 0)
2814 fp_gtk_style_context_add_class (context, "dock");
2815 else if (strcmp (detail, "notebook") == 0)
2816 fp_gtk_style_context_add_class (context, "notebook");
2817 else if (strcmp (detail, "tab") == 0)
2818 {
2819 fp_gtk_style_context_add_class (context, "notebook");
2820 fp_gtk_style_context_add_region (context, "tab", 0);
2821 } else if (strcmp (detail, "paned") == 0) {
2822 fp_gtk_style_context_add_class (context, "pane-separator");
2823 }
2824 else if (fp_g_str_has_prefix (detail, "cell"))
2825 {
2826 GtkRegionFlags row, col;
2827 gboolean ruled = FALSE(0);
2828 gchar** tokens;
2829 guint i;
2830
2831 tokens = fp_g_strsplit (detail, "_", -1);
2832 row = col = 0;
2833 i = 0;
2834
2835 while (tokens[i])
2836 {
2837 if (strcmp (tokens[i], "even") == 0)
2838 row |= GTK_REGION_EVEN;
2839 else if (strcmp (tokens[i], "odd") == 0)
2840 row |= GTK_REGION_ODD;
2841 else if (strcmp (tokens[i], "start") == 0)
2842 col |= GTK_REGION_FIRST;
2843 else if (strcmp (tokens[i], "end") == 0)
2844 col |= GTK_REGION_LAST;
2845 else if (strcmp (tokens[i], "ruled") == 0)
2846 ruled = TRUE(!(0));
2847 else if (strcmp (tokens[i], "sorted") == 0)
2848 col |= GTK_REGION_SORTED;
2849
2850 i++;
2851 }
2852
2853 if (!ruled)
2854 row &= ~(GTK_REGION_EVEN | GTK_REGION_ODD);
2855
2856 fp_gtk_style_context_add_class (context, "cell");
2857 fp_gtk_style_context_add_region (context, "row", row);
2858 fp_gtk_style_context_add_region (context, "column", col);
2859
2860 fp_g_strfreev (tokens);
2861 }
2862}
2863
2864static gboolean gtk3_get_drawable_data(JNIEnv *env, jintArray pixelArray,
2865 int x, jint y, jint width, jint height, jint jwidth, int dx, int dy,
2866 jint scale) {
2867 GdkPixbuf *pixbuf;
2868 jint *ary;
2869
2870 GdkWindow *root = (*fp_gdk_get_default_root_window)();
2871 if (gtk3_version_3_10) {
2872 int win_scale = (*fp_gdk_window_get_scale_factor)(root);
2873 pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(
2874 root, x, y, (int) (width / (float) win_scale + 0.5), (int) (height / (float) win_scale + 0.5));
2875 } else {
2876 pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(root, x, y, width, height);
2877 }
2878
2879 if (pixbuf && scale != 1) {
2880 GdkPixbuf *scaledPixbuf;
2881 x /= scale;
2882 y /= scale;
2883 width /= scale;
2884 height /= scale;
2885 dx /= scale;
2886 dy /= scale;
2887 scaledPixbuf = (*fp_gdk_pixbuf_scale_simple)(pixbuf, width, height,
2888 GDK_INTERP_BILINEAR);
2889 (*fp_g_object_unref)(pixbuf);
2890 pixbuf = scaledPixbuf;
2891 }
2892
2893 if (pixbuf) {
2894 int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
2895 int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
2896 if ((*fp_gdk_pixbuf_get_width)(pixbuf) >= width
2897 && (*fp_gdk_pixbuf_get_height)(pixbuf) >= height
2898 && (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8
2899 && (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB
2900 && nchan >= 3
2901 ) {
2902 guchar *p, *pix = (*fp_gdk_pixbuf_get_pixels)(pixbuf);
2903 ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL((void*)0));
2904 if (ary) {
2905 jint _x, _y;
2906 int index;
2907 for (_y = 0; _y < height; _y++) {
2908 for (_x = 0; _x < width; _x++) {
2909 p = pix + (intptr_t) _y * stride + _x * nchan;
2910
2911 index = (_y + dy) * jwidth + (_x + dx);
2912 ary[index] = 0xff000000
2913 | (p[0] << 16)
2914 | (p[1] << 8)
2915 | (p[2]);
2916
2917 }
2918 }
2919 (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
2920 }
2921 }
2922 (*fp_g_object_unref)(pixbuf);
2923 }
2924 return JNI_FALSE0;
2925}
2926
2927static GdkWindow* gtk3_get_window(void *widget) {
2928 return fp_gtk_widget_get_window((GtkWidget*)widget);
2929}
2930
2931static void gtk3_init(GtkApi* gtk) {
2932 gtk->version = GTK_3;
2933
2934 gtk->show_uri_load = &gtk3_show_uri_load;
2935 gtk->unload = &gtk3_unload;
2936 gtk->flush_event_loop = &flush_gtk_event_loop;
2937 gtk->gtk_check_version = fp_gtk_check_version;
2938 gtk->get_setting = &gtk3_get_setting;
2939
2940 gtk->paint_arrow = &gtk3_paint_arrow;
2941 gtk->paint_box = &gtk3_paint_box;
2942 gtk->paint_box_gap = &gtk3_paint_box_gap;
2943 gtk->paint_expander = &gtk3_paint_expander;
2944 gtk->paint_extension = &gtk3_paint_extension;
2945 gtk->paint_flat_box = &gtk3_paint_flat_box;
2946 gtk->paint_focus = &gtk3_paint_focus;
2947 gtk->paint_handle = &gtk3_paint_handle;
2948 gtk->paint_hline = &gtk3_paint_hline;
2949 gtk->paint_vline = &gtk3_paint_vline;
2950 gtk->paint_option = &gtk3_paint_option;
2951 gtk->paint_shadow = &gtk3_paint_shadow;
2952 gtk->paint_slider = &gtk3_paint_slider;
2953 gtk->paint_background = &gtk3_paint_background;
2954 gtk->paint_check = &gtk3_paint_check;
2955 gtk->set_range_value = &gtk3_set_range_value;
2956
2957 gtk->init_painting = &gtk3_init_painting;
2958 gtk->copy_image = &gtk3_copy_image;
2959
2960 gtk->get_xthickness = &gtk3_get_xthickness;
2961 gtk->get_ythickness = &gtk3_get_ythickness;
2962 gtk->get_color_for_state = &gtk3_get_color_for_state;
2963 gtk->get_class_value = &gtk3_get_class_value;
2964
2965 gtk->get_pango_font_name = &gtk3_get_pango_font_name;
2966 gtk->get_icon_data = &gtk3_get_icon_data;
2967 gtk->get_file_icon_data = &gtk3_get_file_icon_data;
2968 gtk->gdk_threads_enter = fp_gdk_threads_enter;
2969 gtk->gdk_threads_leave = fp_gdk_threads_leave;
2970 gtk->gtk_show_uri = fp_gtk_show_uri;
2971 gtk->get_drawable_data = &gtk3_get_drawable_data;
2972 gtk->g_free = fp_g_free;
2973
2974 gtk->gtk_file_chooser_get_filename = fp_gtk_file_chooser_get_filename;
2975 gtk->gtk_widget_hide = fp_gtk_widget_hide;
2976 gtk->gtk_main_quit = fp_gtk_main_quit;
2977 gtk->gtk_file_chooser_dialog_new = fp_gtk_file_chooser_dialog_new;
2978 gtk->gtk_file_chooser_set_current_folder =
2979 fp_gtk_file_chooser_set_current_folder;
2980 gtk->gtk_file_chooser_set_filename = fp_gtk_file_chooser_set_filename;
2981 gtk->gtk_file_chooser_set_current_name =
2982 fp_gtk_file_chooser_set_current_name;
2983 gtk->gtk_file_filter_add_custom = fp_gtk_file_filter_add_custom;
2984 gtk->gtk_file_chooser_set_filter = fp_gtk_file_chooser_set_filter;
2985 gtk->gtk_file_chooser_get_type = fp_gtk_file_chooser_get_type;
2986 gtk->gtk_file_filter_new = fp_gtk_file_filter_new;
2987 gtk->gtk_file_chooser_set_do_overwrite_confirmation =
2988 fp_gtk_file_chooser_set_do_overwrite_confirmation;
2989 gtk->gtk_file_chooser_set_select_multiple =
2990 fp_gtk_file_chooser_set_select_multiple;
2991 gtk->gtk_file_chooser_get_current_folder =
2992 fp_gtk_file_chooser_get_current_folder;
2993 gtk->gtk_file_chooser_get_filenames = fp_gtk_file_chooser_get_filenames;
2994 gtk->gtk_g_slist_length = fp_gtk_g_slist_length;
2995 gtk->g_signal_connect_data = fp_g_signal_connect_data;
2996 gtk->gtk_widget_show = fp_gtk_widget_show;
2997 gtk->gtk_main = fp_gtk_main;
2998 gtk->gtk_main_level = fp_gtk_main_level;
2999 gtk->g_path_get_dirname = fp_g_path_get_dirname;
3000 gtk->gdk_x11_drawable_get_xid = fp_gdk_x11_drawable_get_xid;
3001 gtk->gtk_widget_destroy = fp_gtk_widget_destroy;
3002 gtk->gtk_window_present = fp_gtk_window_present;
3003 gtk->gtk_window_move = fp_gtk_window_move;
3004 gtk->gtk_window_resize = fp_gtk_window_resize;
3005 gtk->get_window = &gtk3_get_window;
3006
3007 gtk->g_object_unref = fp_g_object_unref;
3008 gtk->g_list_append = fp_g_list_append;
3009 gtk->g_list_free = fp_g_list_free;
3010 gtk->g_list_free_full = fp_g_list_free_full;
3011}