Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / native / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkCheckboxPeer.c
blob297b4f853da66b4460ed988f77afd9b2c06635bd
1 /* gtkcheckboxpeer.c -- Native implementation of GtkCheckboxPeer
2 Copyright (C) 1998, 1999, 2002, 2003, 2004, 2006
3 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
40 #include "gtkpeer.h"
41 #include "gnu_java_awt_peer_gtk_GtkCheckboxPeer.h"
42 #include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
44 static jmethodID postItemEventID;
46 void
47 cp_gtk_checkbox_init_jni (void)
49 jclass gtkcheckboxpeer;
51 gtkcheckboxpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
52 "gnu/java/awt/peer/gtk/GtkCheckboxPeer");
54 postItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcheckboxpeer,
55 "postItemEvent",
56 "(Ljava/lang/Object;Z)V");
59 static void item_toggled_cb (GtkToggleButton *item, jobject peer);
61 JNIEXPORT void JNICALL
62 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_create
63 (JNIEnv *env, jobject obj, jobject group)
65 GtkWidget *button;
67 gdk_threads_enter ();
69 NSA_SET_GLOBAL_REF (env, obj);
71 if (group == NULL)
72 button = gtk_check_button_new_with_label ("");
73 else
75 void *native_group = NSA_GET_PTR (env, group);
76 button = gtk_radio_button_new_with_label_from_widget (native_group, "");
77 if (native_group == NULL)
79 /* Set the native group so we can use the correct value the
80 next time around. FIXME: this doesn't work! */
81 NSA_SET_PTR (env, group, button);
85 NSA_SET_PTR (env, obj, button);
87 gdk_threads_leave ();
90 JNIEXPORT void JNICALL
91 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectSignals
92 (JNIEnv *env, jobject obj)
94 void *ptr = NULL;
95 jobject *gref = NULL;
97 gdk_threads_enter ();
99 ptr = NSA_GET_PTR (env, obj);
100 gref = NSA_GET_GLOBAL_REF (env, obj);
102 /* Checkbox signals */
103 g_signal_connect (G_OBJECT (ptr), "toggled",
104 G_CALLBACK (item_toggled_cb), *gref);
106 /* Component signals */
107 cp_gtk_component_connect_signals (G_OBJECT (ptr), gref);
109 gdk_threads_leave ();
112 JNIEXPORT void JNICALL
113 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeSetCheckboxGroup
114 (JNIEnv *env, jobject obj, jobject group)
116 GtkRadioButton *button;
117 void *native_group, *ptr;
119 gdk_threads_enter ();
121 ptr = NSA_GET_PTR (env, obj);
123 /* FIXME: we can't yet switch between a checkbutton and a
124 radiobutton. However, AWT requires this. For now we just
125 crash. */
127 button = GTK_RADIO_BUTTON (ptr);
129 native_group = NSA_GET_PTR (env, group);
130 if (native_group == NULL)
131 gtk_radio_button_set_group (button, NULL);
132 else
133 gtk_radio_button_set_group (button,
134 gtk_radio_button_get_group
135 (GTK_RADIO_BUTTON (native_group)));
137 /* If the native group wasn't set on the new CheckboxGroup, then set
138 it now so that the right thing will happen with the next
139 radiobutton. The native state for a CheckboxGroup is a pointer
140 to one of the widgets in the group. We are careful to keep this
141 always pointing at a live widget; whenever a widget is destroyed
142 (or otherwise removed from the group), the CheckboxGroup peer is
143 notified. */
144 if (native_group == NULL)
145 NSA_SET_PTR (env, group, native_group);
147 gdk_threads_leave ();
150 JNIEXPORT void JNICALL
151 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkToggleButtonSetActive
152 (JNIEnv *env, jobject obj, jboolean is_active)
154 void *ptr;
156 gdk_threads_enter ();
158 ptr = NSA_GET_PTR (env, obj);
160 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ptr), is_active);
162 gdk_threads_leave ();
165 JNIEXPORT void JNICALL
166 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkWidgetModifyFont
167 (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
169 const char *font_name;
170 void *ptr;
171 GtkWidget *button;
172 GtkWidget *label;
173 PangoFontDescription *font_desc;
175 gdk_threads_enter();
177 ptr = NSA_GET_PTR (env, obj);
179 button = GTK_WIDGET (ptr);
180 label = gtk_bin_get_child (GTK_BIN(button));
182 if (!label)
183 return;
185 font_name = (*env)->GetStringUTFChars (env, name, NULL);
187 font_desc = pango_font_description_from_string (font_name);
188 pango_font_description_set_size (font_desc,
189 size * cp_gtk_dpi_conversion_factor);
191 if (style & AWT_STYLE_BOLD)
192 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
194 if (style & AWT_STYLE_ITALIC)
195 pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
197 gtk_widget_modify_font (GTK_WIDGET(label), font_desc);
199 pango_font_description_free (font_desc);
201 (*env)->ReleaseStringUTFChars (env, name, font_name);
203 gdk_threads_leave();
206 JNIEXPORT void JNICALL
207 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkButtonSetLabel
208 (JNIEnv *env, jobject obj, jstring label)
210 const char *c_label;
211 GtkWidget *label_widget;
212 void *ptr;
214 gdk_threads_enter ();
216 ptr = NSA_GET_PTR (env, obj);
218 c_label = (*env)->GetStringUTFChars (env, label, NULL);
220 label_widget = gtk_bin_get_child (GTK_BIN (ptr));
221 gtk_label_set_text (GTK_LABEL (label_widget), c_label);
223 (*env)->ReleaseStringUTFChars (env, label, c_label);
225 gdk_threads_leave ();
228 static void
229 item_toggled_cb (GtkToggleButton *item, jobject peer)
231 (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
232 postItemEventID,
233 peer,
234 item->active);