1 |
774 |
jeremybenn |
|
2 |
|
|
/* gtktoolkit.c -- Native portion of GtkToolkit
|
3 |
|
|
Copyright (C) 1998, 1999, 2005, 2007 Free Software Foundation, Inc.
|
4 |
|
|
|
5 |
|
|
This file is part of GNU Classpath.
|
6 |
|
|
|
7 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
8 |
|
|
it under the terms of the GNU General Public License as published by
|
9 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
10 |
|
|
any later version.
|
11 |
|
|
|
12 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
13 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 |
|
|
General Public License for more details.
|
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License
|
18 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
19 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
20 |
|
|
02110-1301 USA.
|
21 |
|
|
|
22 |
|
|
Linking this library statically or dynamically with other modules is
|
23 |
|
|
making a combined work based on this library. Thus, the terms and
|
24 |
|
|
conditions of the GNU General Public License cover the whole
|
25 |
|
|
combination.
|
26 |
|
|
|
27 |
|
|
As a special exception, the copyright holders of this library give you
|
28 |
|
|
permission to link this library with independent modules to produce an
|
29 |
|
|
executable, regardless of the license terms of these independent
|
30 |
|
|
modules, and to copy and distribute the resulting executable under
|
31 |
|
|
terms of your choice, provided that you also meet, for each linked
|
32 |
|
|
independent module, the terms and conditions of the license of that
|
33 |
|
|
module. An independent module is a module which is not derived from
|
34 |
|
|
or based on this library. If you modify this library, you may extend
|
35 |
|
|
this exception to your version of the library, but you are not
|
36 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
37 |
|
|
exception statement from your version. */
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
#include "gtkpeer.h"
|
41 |
|
|
#include "gnu_java_awt_peer_gtk_GtkToolkit.h"
|
42 |
|
|
#include "jcl.h"
|
43 |
|
|
|
44 |
|
|
#define RC_FILE ".classpath-gtkrc"
|
45 |
|
|
|
46 |
|
|
/* From java.awt.SystemColor */
|
47 |
|
|
#define AWT_DESKTOP 0
|
48 |
|
|
#define AWT_ACTIVE_CAPTION 1
|
49 |
|
|
#define AWT_ACTIVE_CAPTION_TEXT 2
|
50 |
|
|
#define AWT_ACTIVE_CAPTION_BORDER 3
|
51 |
|
|
#define AWT_INACTIVE_CAPTION 4
|
52 |
|
|
#define AWT_INACTIVE_CAPTION_TEXT 5
|
53 |
|
|
#define AWT_INACTIVE_CAPTION_BORDER 6
|
54 |
|
|
#define AWT_WINDOW 7
|
55 |
|
|
#define AWT_WINDOW_BORDER 8
|
56 |
|
|
#define AWT_WINDOW_TEXT 9
|
57 |
|
|
#define AWT_MENU 10
|
58 |
|
|
#define AWT_MENU_TEXT 11
|
59 |
|
|
#define AWT_TEXT 12
|
60 |
|
|
#define AWT_TEXT_TEXT 13
|
61 |
|
|
#define AWT_TEXT_HIGHLIGHT 14
|
62 |
|
|
#define AWT_TEXT_HIGHLIGHT_TEXT 15
|
63 |
|
|
#define AWT_TEXT_INACTIVE_TEXT 16
|
64 |
|
|
#define AWT_CONTROL 17
|
65 |
|
|
#define AWT_CONTROL_TEXT 18
|
66 |
|
|
#define AWT_CONTROL_HIGHLIGHT 19
|
67 |
|
|
#define AWT_CONTROL_LT_HIGHLIGHT 20
|
68 |
|
|
#define AWT_CONTROL_SHADOW 21
|
69 |
|
|
#define AWT_CONTROL_DK_SHADOW 22
|
70 |
|
|
#define AWT_SCROLLBAR 23
|
71 |
|
|
#define AWT_INFO 24
|
72 |
|
|
#define AWT_INFO_TEXT 25
|
73 |
|
|
#define AWT_NUM_COLORS 26
|
74 |
|
|
|
75 |
|
|
#define VK_SHIFT 16
|
76 |
|
|
#define VK_CONTROL 17
|
77 |
|
|
#define VK_ALT 18
|
78 |
|
|
#define VK_CAPS_LOCK 20
|
79 |
|
|
#define VK_META 157
|
80 |
|
|
|
81 |
|
|
static jclass gtkgenericpeer;
|
82 |
|
|
static jclass gtktoolkit;
|
83 |
|
|
static JavaVM *java_vm;
|
84 |
|
|
static jmethodID printCurrentThreadID;
|
85 |
|
|
static jmethodID setRunningID;
|
86 |
|
|
|
87 |
|
|
/**
|
88 |
|
|
* The global AWT lock object.
|
89 |
|
|
*/
|
90 |
|
|
static jobject global_lock;
|
91 |
|
|
|
92 |
|
|
union env_union
|
93 |
|
|
{
|
94 |
|
|
void *void_env;
|
95 |
|
|
JNIEnv *jni_env;
|
96 |
|
|
};
|
97 |
|
|
|
98 |
|
|
JNIEnv *
|
99 |
|
|
cp_gtk_gdk_env()
|
100 |
|
|
{
|
101 |
|
|
union env_union tmp;
|
102 |
|
|
g_assert((*java_vm)->GetEnv(java_vm, &tmp.void_env, JNI_VERSION_1_2) == JNI_OK);
|
103 |
|
|
return tmp.jni_env;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
GtkWindowGroup *cp_gtk_global_window_group;
|
108 |
|
|
double cp_gtk_dpi_conversion_factor;
|
109 |
|
|
|
110 |
|
|
static void jni_lock_cb();
|
111 |
|
|
static void jni_unlock_cb();
|
112 |
|
|
static void init_glib_threads(JNIEnv*, jint, jobject);
|
113 |
|
|
static gboolean post_set_running_flag (gpointer);
|
114 |
|
|
static gboolean set_running_flag (gpointer);
|
115 |
|
|
static gboolean clear_running_flag (gpointer);
|
116 |
|
|
static void init_dpi_conversion_factor (void);
|
117 |
|
|
static void dpi_changed_cb (GtkSettings *settings,
|
118 |
|
|
GParamSpec *pspec);
|
119 |
|
|
|
120 |
|
|
#if GTK_MINOR_VERSION > 4
|
121 |
|
|
static GLogFunc old_glog_func;
|
122 |
|
|
static void glog_func (const gchar *log_domain,
|
123 |
|
|
GLogLevelFlags log_level,
|
124 |
|
|
const gchar *message,
|
125 |
|
|
gpointer user_data);
|
126 |
|
|
#endif
|
127 |
|
|
|
128 |
|
|
JNIEXPORT void JNICALL
|
129 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_initIDs
|
130 |
|
|
(JNIEnv *env, jclass cls __attribute__((unused)))
|
131 |
|
|
{
|
132 |
|
|
gtkpeer_init_pointer_IDs(env);
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
/*
|
136 |
|
|
* Call gtk_init. It is very important that this happen before any other
|
137 |
|
|
* gtk calls.
|
138 |
|
|
*
|
139 |
|
|
* The portableNativeSync argument may have the values:
|
140 |
|
|
* 1 if the Java property gnu.classpath.awt.gtk.portable.native.sync
|
141 |
|
|
* is set to "true".
|
142 |
|
|
* 0 if it is set to "false"
|
143 |
|
|
* -1 if unset.
|
144 |
|
|
*/
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
JNIEXPORT void JNICALL
|
148 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit (JNIEnv *env,
|
149 |
|
|
jclass clazz __attribute__((unused)),
|
150 |
|
|
jint portableNativeSync,
|
151 |
|
|
jobject lock)
|
152 |
|
|
{
|
153 |
|
|
int argc = 1;
|
154 |
|
|
char **argv;
|
155 |
|
|
char *homedir, *rcpath = NULL;
|
156 |
|
|
|
157 |
|
|
gtkgenericpeer = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkGenericPeer");
|
158 |
|
|
|
159 |
|
|
gtkgenericpeer = (*env)->NewGlobalRef(env, gtkgenericpeer);
|
160 |
|
|
|
161 |
|
|
printCurrentThreadID = (*env)->GetStaticMethodID (env, gtkgenericpeer,
|
162 |
|
|
"printCurrentThread", "()V");
|
163 |
|
|
|
164 |
|
|
g_assert((*env)->GetJavaVM(env, &java_vm) == 0);
|
165 |
|
|
|
166 |
|
|
/* GTK requires a program's argc and argv variables, and requires that they
|
167 |
|
|
be valid. Set it up. */
|
168 |
|
|
argv = (char **) g_malloc (sizeof (char *) * 2);
|
169 |
|
|
argv[0] = (char *) g_malloc(1);
|
170 |
|
|
argv[0][0] = '\0';
|
171 |
|
|
argv[1] = NULL;
|
172 |
|
|
|
173 |
|
|
init_glib_threads(env, portableNativeSync, lock);
|
174 |
|
|
|
175 |
|
|
/* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */
|
176 |
|
|
gdk_threads_init();
|
177 |
|
|
|
178 |
|
|
gtk_init (&argc, &argv);
|
179 |
|
|
|
180 |
|
|
#if SYNCHRONIZE_GDK
|
181 |
|
|
XSynchronize (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), True);
|
182 |
|
|
#endif
|
183 |
|
|
|
184 |
|
|
gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
|
185 |
|
|
|
186 |
|
|
if ((homedir = getenv ("HOME")))
|
187 |
|
|
{
|
188 |
|
|
rcpath = (char *) g_malloc (strlen (homedir) + strlen (RC_FILE) + 2);
|
189 |
|
|
sprintf (rcpath, "%s/%s", homedir, RC_FILE);
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
gtk_rc_parse ((rcpath) ? rcpath : RC_FILE);
|
193 |
|
|
|
194 |
|
|
g_free (rcpath);
|
195 |
|
|
g_free (argv[0]);
|
196 |
|
|
g_free (argv);
|
197 |
|
|
|
198 |
|
|
/* On errors or warning print a whole stacktrace. */
|
199 |
|
|
#if GTK_MINOR_VERSION > 4
|
200 |
|
|
old_glog_func = g_log_set_default_handler (&glog_func, NULL);
|
201 |
|
|
#endif
|
202 |
|
|
|
203 |
|
|
cp_gtk_button_init_jni (env);
|
204 |
|
|
cp_gtk_checkbox_init_jni ();
|
205 |
|
|
cp_gtk_choice_init_jni ();
|
206 |
|
|
cp_gtk_component_init_jni ();
|
207 |
|
|
cp_gtk_filedialog_init_jni ();
|
208 |
|
|
cp_gtk_list_init_jni ();
|
209 |
|
|
cp_gtk_menuitem_init_jni ();
|
210 |
|
|
cp_gtk_scrollbar_init_jni ();
|
211 |
|
|
cp_gtk_textcomponent_init_jni ();
|
212 |
|
|
cp_gtk_window_init_jni ();
|
213 |
|
|
|
214 |
|
|
cp_gtk_global_window_group = gtk_window_group_new ();
|
215 |
|
|
|
216 |
|
|
init_dpi_conversion_factor ();
|
217 |
|
|
|
218 |
|
|
gtktoolkit = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkMainThread");
|
219 |
|
|
setRunningID = (*env)->GetStaticMethodID (env, gtktoolkit,
|
220 |
|
|
"setRunning", "(Z)V");
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
/**
|
224 |
|
|
* A callback function that implements gdk_threads_enter(). This is
|
225 |
|
|
* implemented to wrap the JNI MonitorEnter() function.
|
226 |
|
|
*/
|
227 |
|
|
static void jni_lock_cb()
|
228 |
|
|
{
|
229 |
|
|
JNIEnv * env = cp_gtk_gdk_env();
|
230 |
|
|
if ((*env)->MonitorEnter(env, global_lock) != JNI_OK)
|
231 |
|
|
{
|
232 |
|
|
printf("failure while entering GTK monitor\n");
|
233 |
|
|
}
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
/**
|
237 |
|
|
* A callback function that implements gdk_threads_leave(). This is
|
238 |
|
|
* implemented to wrap the JNI MonitorExit() function.
|
239 |
|
|
*/
|
240 |
|
|
static void jni_unlock_cb()
|
241 |
|
|
{
|
242 |
|
|
|
243 |
|
|
JNIEnv * env = cp_gtk_gdk_env();
|
244 |
|
|
if ((*env)->MonitorExit(env, global_lock))
|
245 |
|
|
{
|
246 |
|
|
printf("failure while exiting GTK monitor\n");
|
247 |
|
|
}
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
/** Initialize GLIB's threads properly, based on the value of the
|
251 |
|
|
gnu.classpath.awt.gtk.portable.native.sync Java system property. If
|
252 |
|
|
that's unset, use the PORTABLE_NATIVE_SYNC config.h macro. (TODO:
|
253 |
|
|
In some release following 0.10, that config.h macro will go away.)
|
254 |
|
|
*/
|
255 |
|
|
static void
|
256 |
|
|
init_glib_threads(JNIEnv *env, jint portableNativeSync, jobject lock)
|
257 |
|
|
{
|
258 |
|
|
if (portableNativeSync < 0)
|
259 |
|
|
{
|
260 |
|
|
#ifdef PORTABLE_NATIVE_SYNC /* Default value, if not set by the Java system
|
261 |
|
|
property */
|
262 |
|
|
portableNativeSync = 1;
|
263 |
|
|
#else
|
264 |
|
|
portableNativeSync = 0;
|
265 |
|
|
#endif
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
if (!g_thread_supported ())
|
269 |
|
|
{
|
270 |
|
|
if (portableNativeSync)
|
271 |
|
|
{
|
272 |
|
|
global_lock = (*env)->NewGlobalRef(env, lock);
|
273 |
|
|
gdk_threads_set_lock_functions(&jni_lock_cb, &jni_unlock_cb);
|
274 |
|
|
}
|
275 |
|
|
g_thread_init(NULL);
|
276 |
|
|
}
|
277 |
|
|
else
|
278 |
|
|
{
|
279 |
|
|
/* Warn if portable native sync is desired but the threading
|
280 |
|
|
system is already initialized. In that case we can't
|
281 |
|
|
override the threading implementation with our portable
|
282 |
|
|
native sync functions. */
|
283 |
|
|
if (portableNativeSync)
|
284 |
|
|
g_printerr ("peer warning: portable native sync disabled.\n");
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
/* Debugging progress message; uncomment if needed: */
|
288 |
|
|
/* printf("called gthread init\n"); */
|
289 |
|
|
}
|
290 |
|
|
|
291 |
|
|
void
|
292 |
|
|
cp_gtk_print_current_thread (void)
|
293 |
|
|
{
|
294 |
|
|
(*cp_gtk_gdk_env())->CallStaticVoidMethod (cp_gtk_gdk_env(), gtkgenericpeer, printCurrentThreadID);
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
/* This is a big hack, needed until this pango bug is resolved:
|
298 |
|
|
http://bugzilla.gnome.org/show_bug.cgi?id=119081.
|
299 |
|
|
See: http://mail.gnome.org/archives/gtk-i18n-list/2003-August/msg00001.html
|
300 |
|
|
for details. */
|
301 |
|
|
static void
|
302 |
|
|
init_dpi_conversion_factor ()
|
303 |
|
|
{
|
304 |
|
|
GtkSettings *settings = gtk_settings_get_default ();
|
305 |
|
|
GObjectClass *klass;
|
306 |
|
|
|
307 |
|
|
klass = G_OBJECT_CLASS (GTK_SETTINGS_GET_CLASS (settings));
|
308 |
|
|
if (g_object_class_find_property (klass, "gtk-xft-dpi"))
|
309 |
|
|
{
|
310 |
|
|
int int_dpi;
|
311 |
|
|
g_object_get (settings, "gtk-xft-dpi", &int_dpi, NULL);
|
312 |
|
|
/* If int_dpi == -1 gtk-xft-dpi returns the default value. So we
|
313 |
|
|
have to do approximate calculation here. */
|
314 |
|
|
if (int_dpi < 0)
|
315 |
|
|
cp_gtk_dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.;
|
316 |
|
|
else
|
317 |
|
|
cp_gtk_dpi_conversion_factor =
|
318 |
|
|
PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE);
|
319 |
|
|
|
320 |
|
|
g_signal_connect (settings, "notify::gtk-xft-dpi",
|
321 |
|
|
G_CALLBACK (dpi_changed_cb), NULL);
|
322 |
|
|
}
|
323 |
|
|
else
|
324 |
|
|
/* Approximate. */
|
325 |
|
|
cp_gtk_dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.;
|
326 |
|
|
}
|
327 |
|
|
|
328 |
|
|
static void
|
329 |
|
|
dpi_changed_cb (GtkSettings *settings,
|
330 |
|
|
GParamSpec *pspec __attribute__((unused)))
|
331 |
|
|
{
|
332 |
|
|
int int_dpi;
|
333 |
|
|
g_object_get (settings, "gtk-xft-dpi", &int_dpi, NULL);
|
334 |
|
|
if (int_dpi < 0)
|
335 |
|
|
cp_gtk_dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.;
|
336 |
|
|
else
|
337 |
|
|
cp_gtk_dpi_conversion_factor =
|
338 |
|
|
PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE);
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
#if GTK_MINOR_VERSION > 4
|
342 |
|
|
static void
|
343 |
|
|
glog_func (const gchar *log_domain,
|
344 |
|
|
GLogLevelFlags log_level,
|
345 |
|
|
const gchar *message,
|
346 |
|
|
gpointer user_data)
|
347 |
|
|
{
|
348 |
|
|
old_glog_func (log_domain, log_level, message, user_data);
|
349 |
|
|
if (log_level & (G_LOG_LEVEL_ERROR
|
350 |
|
|
| G_LOG_LEVEL_CRITICAL
|
351 |
|
|
| G_LOG_LEVEL_WARNING))
|
352 |
|
|
{
|
353 |
|
|
JNIEnv *env = cp_gtk_gdk_env ();
|
354 |
|
|
jthrowable *exc = (*env)->ExceptionOccurred(env);
|
355 |
|
|
gchar *detail = g_strconcat (log_domain, ": ", message, NULL);
|
356 |
|
|
JCL_ThrowException (env, "java/lang/InternalError", detail);
|
357 |
|
|
g_free (detail);
|
358 |
|
|
(*env)->ExceptionDescribe (env);
|
359 |
|
|
if (exc != NULL)
|
360 |
|
|
(*env)->Throw (env, exc);
|
361 |
|
|
else
|
362 |
|
|
(*env)->ExceptionClear (env);
|
363 |
|
|
}
|
364 |
|
|
}
|
365 |
|
|
#endif
|
366 |
|
|
|
367 |
|
|
JNIEXPORT void JNICALL
|
368 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkMain
|
369 |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
|
370 |
|
|
{
|
371 |
|
|
gdk_threads_enter();
|
372 |
|
|
|
373 |
|
|
gtk_init_add (post_set_running_flag, NULL);
|
374 |
|
|
gtk_quit_add (gtk_main_level (), clear_running_flag, NULL);
|
375 |
|
|
|
376 |
|
|
gtk_main ();
|
377 |
|
|
|
378 |
|
|
gdk_threads_leave();
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
JNIEXPORT void JNICALL
|
382 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkQuit
|
383 |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
|
384 |
|
|
{
|
385 |
|
|
gdk_threads_enter ();
|
386 |
|
|
|
387 |
|
|
gtk_main_quit ();
|
388 |
|
|
|
389 |
|
|
gdk_threads_leave ();
|
390 |
|
|
}
|
391 |
|
|
|
392 |
|
|
|
393 |
|
|
static jint gdk_color_to_java_color (GdkColor color);
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
JNIEXPORT void JNICALL
|
397 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_beep
|
398 |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
|
399 |
|
|
{
|
400 |
|
|
gdk_threads_enter ();
|
401 |
|
|
|
402 |
|
|
gdk_beep ();
|
403 |
|
|
|
404 |
|
|
gdk_threads_leave ();
|
405 |
|
|
}
|
406 |
|
|
|
407 |
|
|
JNIEXPORT void JNICALL
|
408 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_sync
|
409 |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
|
410 |
|
|
{
|
411 |
|
|
gdk_threads_enter ();
|
412 |
|
|
|
413 |
|
|
gdk_flush ();
|
414 |
|
|
|
415 |
|
|
gdk_threads_leave ();
|
416 |
|
|
}
|
417 |
|
|
|
418 |
|
|
JNIEXPORT void JNICALL
|
419 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenSizeDimensions
|
420 |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
|
421 |
|
|
jintArray jdims)
|
422 |
|
|
{
|
423 |
|
|
jint *dims = (*env)->GetIntArrayElements (env, jdims, 0);
|
424 |
|
|
|
425 |
|
|
gdk_threads_enter ();
|
426 |
|
|
|
427 |
|
|
dims[0] = gdk_screen_width ();
|
428 |
|
|
dims[1] = gdk_screen_height ();
|
429 |
|
|
|
430 |
|
|
gdk_threads_leave ();
|
431 |
|
|
|
432 |
|
|
(*env)->ReleaseIntArrayElements(env, jdims, dims, 0);
|
433 |
|
|
}
|
434 |
|
|
|
435 |
|
|
JNIEXPORT jint JNICALL
|
436 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenResolution
|
437 |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
|
438 |
|
|
{
|
439 |
|
|
jint res;
|
440 |
|
|
|
441 |
|
|
gdk_threads_enter ();
|
442 |
|
|
|
443 |
|
|
res = gdk_screen_width () / (gdk_screen_width_mm () / 25.4);
|
444 |
|
|
|
445 |
|
|
gdk_threads_leave ();
|
446 |
|
|
|
447 |
|
|
return res;
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
/**
|
451 |
|
|
* Report the number of mouse buttons
|
452 |
|
|
* Returns the number of buttons of the first mouse found, or -1 if no mouse
|
453 |
|
|
* seems to be connected.
|
454 |
|
|
*/
|
455 |
|
|
JNIEXPORT jint JNICALL
|
456 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_getMouseNumberOfButtons
|
457 |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
|
458 |
|
|
{
|
459 |
|
|
jint res = -1;
|
460 |
|
|
GList *devices;
|
461 |
|
|
GdkDevice *d;
|
462 |
|
|
|
463 |
|
|
gdk_threads_enter ();
|
464 |
|
|
|
465 |
|
|
/* FIXME: Why doesn't this return the correct number? */
|
466 |
|
|
devices = gdk_devices_list();
|
467 |
|
|
|
468 |
|
|
while( res == -1 && devices != NULL )
|
469 |
|
|
{
|
470 |
|
|
d = GDK_DEVICE( devices->data );
|
471 |
|
|
if( d->source == GDK_SOURCE_MOUSE )
|
472 |
|
|
res = d->num_keys;
|
473 |
|
|
devices = devices->next;
|
474 |
|
|
}
|
475 |
|
|
|
476 |
|
|
gdk_threads_leave ();
|
477 |
|
|
|
478 |
|
|
return res;
|
479 |
|
|
}
|
480 |
|
|
|
481 |
|
|
#define CONVERT(type, state) \
|
482 |
|
|
gdk_color_to_java_color (style->type[GTK_STATE_ ## state])
|
483 |
|
|
|
484 |
|
|
JNIEXPORT void JNICALL
|
485 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_loadSystemColors
|
486 |
|
|
(JNIEnv *env, jobject obj __attribute__((unused)),
|
487 |
|
|
jintArray jcolors)
|
488 |
|
|
{
|
489 |
|
|
jint *colors;
|
490 |
|
|
GtkStyle *style;
|
491 |
|
|
|
492 |
|
|
/* FIXME: this was deadlocking so assume it is thread-safe for now;
|
493 |
|
|
we need to replace this call with a .properties file anyway. */
|
494 |
|
|
#if 0
|
495 |
|
|
gdk_threads_enter ();
|
496 |
|
|
#endif
|
497 |
|
|
|
498 |
|
|
colors = (*env)->GetIntArrayElements (env, jcolors, 0);
|
499 |
|
|
|
500 |
|
|
style = gtk_widget_get_default_style ();
|
501 |
|
|
|
502 |
|
|
colors[AWT_DESKTOP] = CONVERT (bg, SELECTED);
|
503 |
|
|
colors[AWT_ACTIVE_CAPTION] = CONVERT (bg, SELECTED);
|
504 |
|
|
colors[AWT_ACTIVE_CAPTION_TEXT] = CONVERT (text, SELECTED);
|
505 |
|
|
colors[AWT_ACTIVE_CAPTION_BORDER] = CONVERT (fg, NORMAL);
|
506 |
|
|
colors[AWT_INACTIVE_CAPTION] = CONVERT (base, INSENSITIVE);
|
507 |
|
|
colors[AWT_INACTIVE_CAPTION_TEXT] = CONVERT (fg, INSENSITIVE);
|
508 |
|
|
colors[AWT_INACTIVE_CAPTION_BORDER] = CONVERT (fg, INSENSITIVE);
|
509 |
|
|
colors[AWT_WINDOW] = CONVERT (bg, NORMAL);
|
510 |
|
|
colors[AWT_WINDOW_BORDER] = CONVERT (fg, NORMAL);
|
511 |
|
|
colors[AWT_WINDOW_TEXT] = CONVERT (fg, NORMAL);
|
512 |
|
|
colors[AWT_MENU] = CONVERT (bg, NORMAL);
|
513 |
|
|
colors[AWT_MENU_TEXT] = CONVERT (fg, NORMAL);
|
514 |
|
|
colors[AWT_TEXT] = CONVERT (bg, NORMAL);
|
515 |
|
|
colors[AWT_TEXT_TEXT] = CONVERT (fg, NORMAL);
|
516 |
|
|
colors[AWT_TEXT_HIGHLIGHT] = CONVERT (bg, SELECTED);
|
517 |
|
|
colors[AWT_TEXT_HIGHLIGHT_TEXT] = CONVERT (fg, SELECTED);
|
518 |
|
|
colors[AWT_TEXT_INACTIVE_TEXT] = CONVERT (bg, INSENSITIVE);
|
519 |
|
|
colors[AWT_CONTROL] = CONVERT (bg, NORMAL);
|
520 |
|
|
colors[AWT_CONTROL_TEXT] = CONVERT (fg, NORMAL);
|
521 |
|
|
colors[AWT_CONTROL_HIGHLIGHT] = CONVERT (base, ACTIVE);
|
522 |
|
|
colors[AWT_CONTROL_LT_HIGHLIGHT] = CONVERT (bg, PRELIGHT);
|
523 |
|
|
colors[AWT_CONTROL_SHADOW] = CONVERT (bg, ACTIVE);
|
524 |
|
|
colors[AWT_CONTROL_DK_SHADOW] = CONVERT (fg, INSENSITIVE);
|
525 |
|
|
colors[AWT_SCROLLBAR] = CONVERT (base, INSENSITIVE);
|
526 |
|
|
colors[AWT_INFO] = CONVERT (bg, NORMAL);
|
527 |
|
|
colors[AWT_INFO_TEXT] = CONVERT (fg, NORMAL);
|
528 |
|
|
|
529 |
|
|
(*env)->ReleaseIntArrayElements(env, jcolors, colors, 0);
|
530 |
|
|
|
531 |
|
|
#if 0
|
532 |
|
|
gdk_threads_leave ();
|
533 |
|
|
#endif
|
534 |
|
|
}
|
535 |
|
|
|
536 |
|
|
#undef CONVERT
|
537 |
|
|
|
538 |
|
|
static jint
|
539 |
|
|
gdk_color_to_java_color (GdkColor gdk_color)
|
540 |
|
|
{
|
541 |
|
|
guchar red;
|
542 |
|
|
guchar green;
|
543 |
|
|
guchar blue;
|
544 |
|
|
float factor;
|
545 |
|
|
|
546 |
|
|
factor = 255.0 / 65535.0;
|
547 |
|
|
|
548 |
|
|
red = (float) gdk_color.red * factor;
|
549 |
|
|
green = (float) gdk_color.green * factor;
|
550 |
|
|
blue = (float) gdk_color.blue * factor;
|
551 |
|
|
|
552 |
|
|
return (jint) (0xff000000 | (red << 16) | (green << 8) | blue);
|
553 |
|
|
}
|
554 |
|
|
|
555 |
|
|
JNIEXPORT jint JNICALL
|
556 |
|
|
Java_gnu_java_awt_peer_gtk_GtkToolkit_getLockState
|
557 |
|
|
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
|
558 |
|
|
jint key)
|
559 |
|
|
{
|
560 |
|
|
gint coord;
|
561 |
|
|
GdkModifierType state, mask;
|
562 |
|
|
GdkWindow *root_window;
|
563 |
|
|
|
564 |
|
|
gdk_threads_enter ();
|
565 |
|
|
|
566 |
|
|
root_window = gdk_get_default_root_window ();
|
567 |
|
|
gdk_window_get_pointer (root_window, &coord, &coord, &state);
|
568 |
|
|
|
569 |
|
|
switch (key)
|
570 |
|
|
{
|
571 |
|
|
case VK_SHIFT:
|
572 |
|
|
mask = GDK_SHIFT_MASK;
|
573 |
|
|
break;
|
574 |
|
|
case VK_CONTROL:
|
575 |
|
|
mask = GDK_CONTROL_MASK;
|
576 |
|
|
break;
|
577 |
|
|
case VK_ALT:
|
578 |
|
|
/* This is dubious, since MOD1 could have been mapped to something
|
579 |
|
|
other than ALT. */
|
580 |
|
|
mask = GDK_MOD1_MASK;
|
581 |
|
|
break;
|
582 |
|
|
#if GTK_CHECK_VERSION(2, 10, 0)
|
583 |
|
|
case VK_META:
|
584 |
|
|
mask = GDK_META_MASK;
|
585 |
|
|
break;
|
586 |
|
|
#endif
|
587 |
|
|
case VK_CAPS_LOCK:
|
588 |
|
|
mask = GDK_LOCK_MASK;
|
589 |
|
|
break;
|
590 |
|
|
default:
|
591 |
|
|
mask = 0;
|
592 |
|
|
}
|
593 |
|
|
|
594 |
|
|
gdk_threads_leave ();
|
595 |
|
|
|
596 |
|
|
if (mask == 0)
|
597 |
|
|
return -1;
|
598 |
|
|
|
599 |
|
|
return state & mask ? 1 : 0;
|
600 |
|
|
}
|
601 |
|
|
|
602 |
|
|
static gboolean
|
603 |
|
|
post_set_running_flag (gpointer data __attribute__((unused)))
|
604 |
|
|
{
|
605 |
|
|
g_idle_add (set_running_flag, NULL);
|
606 |
|
|
return FALSE;
|
607 |
|
|
}
|
608 |
|
|
|
609 |
|
|
static gboolean
|
610 |
|
|
set_running_flag (gpointer data __attribute__((unused)))
|
611 |
|
|
{
|
612 |
|
|
(*cp_gtk_gdk_env ())->CallStaticVoidMethod (cp_gtk_gdk_env (),
|
613 |
|
|
gtktoolkit,
|
614 |
|
|
setRunningID, TRUE);
|
615 |
|
|
return FALSE;
|
616 |
|
|
}
|
617 |
|
|
|
618 |
|
|
static gboolean
|
619 |
|
|
clear_running_flag (gpointer data __attribute__((unused)))
|
620 |
|
|
{
|
621 |
|
|
(*cp_gtk_gdk_env ())->CallStaticVoidMethod (cp_gtk_gdk_env (),
|
622 |
|
|
gtktoolkit,
|
623 |
|
|
setRunningID, FALSE);
|
624 |
|
|
return FALSE;
|
625 |
|
|
}
|
626 |
|
|
|