Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / native / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkCheckboxPeer.c
blobb74b0a265e0a984ab3b103956a583ed7b7ab5049
1 /* gtkcheckboxpeer.c -- Native implementation of GtkCheckboxPeer
2 Copyright (C) 1998, 1999, 2002, 2003, 2004 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)
9 any later version.
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
19 02110-1301 USA.
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
24 combination.
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. */
39 #include "gtkpeer.h"
40 #include "gnu_java_awt_peer_gtk_GtkCheckboxPeer.h"
41 #include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
43 static jmethodID postItemEventID;
45 void
46 cp_gtk_checkbox_init_jni (void)
48 jclass gtkcheckboxpeer;
50 gtkcheckboxpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
51 "gnu/java/awt/peer/gtk/GtkCheckboxPeer");
53 postItemEventID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcheckboxpeer,
54 "postItemEvent",
55 "(Ljava/lang/Object;I)V");
58 static void item_toggled_cb (GtkToggleButton *item, jobject peer);
60 JNIEXPORT void JNICALL
61 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_create
62 (JNIEnv *env, jobject obj, jobject group)
64 GtkWidget *button;
66 gdk_threads_enter ();
68 NSA_SET_GLOBAL_REF (env, obj);
70 if (group == NULL)
71 button = gtk_check_button_new_with_label ("");
72 else
74 void *native_group = NSA_GET_PTR (env, group);
75 button = gtk_radio_button_new_with_label_from_widget (native_group, "");
76 if (native_group == NULL)
78 /* Set the native group so we can use the correct value the
79 next time around. FIXME: this doesn't work! */
80 NSA_SET_PTR (env, group, button);
84 NSA_SET_PTR (env, obj, button);
86 gdk_threads_leave ();
89 JNIEXPORT void JNICALL
90 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectSignals
91 (JNIEnv *env, jobject obj)
93 void *ptr = NULL;
94 jobject *gref = NULL;
96 gdk_threads_enter ();
98 ptr = NSA_GET_PTR (env, obj);
99 gref = NSA_GET_GLOBAL_REF (env, obj);
101 /* Checkbox signals */
102 g_signal_connect (G_OBJECT (ptr), "toggled",
103 G_CALLBACK (item_toggled_cb), *gref);
105 /* Component signals */
106 cp_gtk_component_connect_signals (G_OBJECT (ptr), gref);
108 gdk_threads_leave ();
111 JNIEXPORT void JNICALL
112 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeSetCheckboxGroup
113 (JNIEnv *env, jobject obj, jobject group)
115 GtkRadioButton *button;
116 void *native_group, *ptr;
118 gdk_threads_enter ();
120 ptr = NSA_GET_PTR (env, obj);
122 /* FIXME: we can't yet switch between a checkbutton and a
123 radiobutton. However, AWT requires this. For now we just
124 crash. */
126 button = GTK_RADIO_BUTTON (ptr);
128 native_group = NSA_GET_PTR (env, group);
129 if (native_group == NULL)
130 gtk_radio_button_set_group (button, NULL);
131 else
132 gtk_radio_button_set_group (button,
133 gtk_radio_button_get_group
134 (GTK_RADIO_BUTTON (native_group)));
136 /* If the native group wasn't set on the new CheckboxGroup, then set
137 it now so that the right thing will happen with the next
138 radiobutton. The native state for a CheckboxGroup is a pointer
139 to one of the widgets in the group. We are careful to keep this
140 always pointing at a live widget; whenever a widget is destroyed
141 (or otherwise removed from the group), the CheckboxGroup peer is
142 notified. */
143 if (native_group == NULL)
144 NSA_SET_PTR (env, group, native_group);
146 gdk_threads_leave ();
149 JNIEXPORT void JNICALL
150 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkToggleButtonSetActive
151 (JNIEnv *env, jobject obj, jboolean is_active)
153 void *ptr;
155 gdk_threads_enter ();
157 ptr = NSA_GET_PTR (env, obj);
159 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ptr), is_active);
161 gdk_threads_leave ();
164 JNIEXPORT void JNICALL
165 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkWidgetModifyFont
166 (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
168 const char *font_name;
169 void *ptr;
170 GtkWidget *button;
171 GtkWidget *label;
172 PangoFontDescription *font_desc;
174 gdk_threads_enter();
176 ptr = NSA_GET_PTR (env, obj);
178 button = GTK_WIDGET (ptr);
179 label = gtk_bin_get_child (GTK_BIN(button));
181 if (!label)
182 return;
184 font_name = (*env)->GetStringUTFChars (env, name, NULL);
186 font_desc = pango_font_description_from_string (font_name);
187 pango_font_description_set_size (font_desc,
188 size * cp_gtk_dpi_conversion_factor);
190 if (style & AWT_STYLE_BOLD)
191 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
193 if (style & AWT_STYLE_ITALIC)
194 pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
196 gtk_widget_modify_font (GTK_WIDGET(label), font_desc);
198 pango_font_description_free (font_desc);
200 (*env)->ReleaseStringUTFChars (env, name, font_name);
202 gdk_threads_leave();
205 JNIEXPORT void JNICALL
206 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkButtonSetLabel
207 (JNIEnv *env, jobject obj, jstring label)
209 const char *c_label;
210 GtkWidget *label_widget;
211 void *ptr;
213 gdk_threads_enter ();
215 ptr = NSA_GET_PTR (env, obj);
217 c_label = (*env)->GetStringUTFChars (env, label, NULL);
219 label_widget = gtk_bin_get_child (GTK_BIN (ptr));
220 gtk_label_set_text (GTK_LABEL (label_widget), c_label);
222 (*env)->ReleaseStringUTFChars (env, label, c_label);
224 gdk_threads_leave ();
227 static void
228 item_toggled_cb (GtkToggleButton *item, jobject peer)
230 (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer,
231 postItemEventID,
232 peer,
233 item->active ?
234 (jint) AWT_ITEM_SELECTED :
235 (jint) AWT_ITEM_DESELECTED);