1 /* gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c
2 Copyright (C) 2004, 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
42 #include "gdkdisplay.h"
43 #include "gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h"
45 struct state_table *cp_gtk_native_display_state_table;
47 jclass gdkGraphicsEnvironment_class;
49 JNIEXPORT void JNICALL
50 Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_initStaticState
51 (JNIEnv *env, jclass klazz __attribute__((unused)))
53 gdkGraphicsEnvironment_class = (*env)->NewGlobalRef
56 NSA_DISPLAY_INIT(env, gdkGraphicsEnvironment_class);
59 JNIEXPORT void JNICALL
60 Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeInitState
61 (JNIEnv *env, jobject obj)
63 GdkDisplay *defaultDisplay;
67 /* Retrieve the default display. */
68 defaultDisplay = gdk_display_get_default();
72 /* Store display pointer in GdkGraphicsEnvironment instance. */
73 NSA_SET_DISPLAY_PTR(env, obj, (void *) defaultDisplay);
77 cmp_families (const void *a, const void *b)
79 const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
80 const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
82 return g_utf8_collate (a_name, b_name);
85 JNIEXPORT void JNICALL
86 Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetFontFamilies
87 (JNIEnv *env, jobject self __attribute__((unused)), jobjectArray family_name)
89 PangoContext *context = NULL;
90 PangoFontFamily **families = NULL;
96 context = gdk_pango_context_get();
97 g_assert (context != NULL);
99 pango_context_list_families (context, &families, &n_families);
101 qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
103 for (idx = 0; idx < n_families; idx++)
105 const char *name_tmp = pango_font_family_get_name (families[idx]);
106 jstring name = (*env)->NewStringUTF (env, name_tmp);
107 (*env)->SetObjectArrayElement (env, family_name, idx, name);
108 (*env)->DeleteLocalRef(env, name);
112 gdk_threads_leave ();
115 JNIEXPORT jint JNICALL
116 Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetNumFontFamilies
117 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)))
119 PangoContext *context = NULL;
120 PangoFontFamily **families = NULL;
124 gdk_threads_enter ();
126 context = gdk_pango_context_get();
127 g_assert (context != NULL);
129 pango_context_list_families (context, &families, &n_families);
134 gdk_threads_leave ();
139 JNIEXPORT jobjectArray JNICALL
140 Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetScreenDevices
141 (JNIEnv *env, jobject obj)
143 jmethodID gdkScreenGraphicsDevice_ctor, gdkScreenGraphicsDevice_init;
144 jclass gdkScreenGraphicsDevice_class;
145 int numScreens = 0, i = 0;
150 gdkScreenGraphicsDevice_class = (*env)->FindClass
151 (env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice");
153 gdkScreenGraphicsDevice_ctor = (*env)->GetMethodID
154 (env, gdkScreenGraphicsDevice_class, "<init>",
155 "(Lgnu/java/awt/peer/gtk/GdkGraphicsEnvironment;)V");
157 gdkScreenGraphicsDevice_init = (*env)->GetMethodID
158 (env, gdkScreenGraphicsDevice_class, "init", "()V");
160 display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, obj);
164 numScreens = gdk_display_get_n_screens(display);
167 /* Create a suitably sized array. */
168 array = (*env)->NewObjectArray(env,
170 gdkScreenGraphicsDevice_class,
173 /* Create GdkScreenGraphicsDevice instances, store the native pointer to
174 * the GScreen object with them, run a 2nd initialization phase and
175 * put the new instance into the result array.
177 for ( ; i < numScreens ; i++)
179 instance = (*env)->NewObject (env,
180 gdkScreenGraphicsDevice_class,
181 gdkScreenGraphicsDevice_ctor,
184 NSA_SET_SCREEN_PTR(env,
186 gdk_display_get_screen(display, i));
189 (*env)->CallVoidMethod(env,
191 gdkScreenGraphicsDevice_init);
194 (*env)->SetObjectArrayElement(env, array, i, instance);
202 JNIEXPORT jobject JNICALL
203 Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_nativeGetDefaultScreenDevice
204 (JNIEnv *env, jobject obj)
206 jclass gdkScreenGraphicsDevice_class;
207 jmethodID gdkScreenGraphicsDevice_ctor, gdkScreenGraphicsDevice_init;
208 jobject defaultDevice;
209 GdkScreen *defaultScreen;
211 gdkScreenGraphicsDevice_class = (*env)->FindClass
212 (env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice");
214 gdkScreenGraphicsDevice_ctor = (*env)->GetMethodID
215 (env, gdkScreenGraphicsDevice_class, "<init>",
216 "(Lgnu/java/awt/peer/gtk/GdkGraphicsEnvironment;)V");
218 gdkScreenGraphicsDevice_init = (*env)->GetMethodID
219 (env, gdkScreenGraphicsDevice_class, "init", "()V");
221 /* Create the GdkScreenGraphicsDevice instance. */
222 defaultDevice = (*env)->NewObject (env,
223 gdkScreenGraphicsDevice_class,
224 gdkScreenGraphicsDevice_ctor,
229 defaultScreen = gdk_screen_get_default();
233 /* Class initialization will have set up the native_state storage
234 * mechanism for GdkScreenGraphicsDevice.
236 NSA_SET_SCREEN_PTR(env, defaultDevice, defaultScreen);
238 (*env)->CallVoidMethod(env,
240 gdkScreenGraphicsDevice_init);
242 return defaultDevice;
245 JNIEXPORT jintArray JNICALL
246 Java_gnu_java_awt_peer_gtk_GdkGraphicsEnvironment_getMouseCoordinates
247 (JNIEnv *env, jobject obj)
252 gint x, y, screenIndex;
255 display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, obj);
256 g_assert (display != NULL);
258 gdk_threads_enter ();
260 gdk_display_get_pointer (display, &screen, &x, &y, NULL);
261 screenIndex = gdk_screen_get_number( screen );
263 gdk_threads_leave ();
265 retArray = (*env)->NewIntArray (env, 3);
266 values = (*env)->GetIntArrayElements (env, retArray, NULL);
268 values[0] = screenIndex;
272 (*env)->ReleaseIntArrayElements (env, retArray, values, 0);