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)
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
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
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. */
41 #include "gnu_java_awt_peer_gtk_GtkCheckboxPeer.h"
42 #include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
44 static jmethodID postItemEventID
;
45 static GtkWidget
*combobox_get_widget (GtkWidget
*widget
);
48 cp_gtk_checkbox_init_jni (void)
50 jclass gtkcheckboxpeer
;
52 gtkcheckboxpeer
= (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
53 "gnu/java/awt/peer/gtk/GtkCheckboxPeer");
55 postItemEventID
= (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(), gtkcheckboxpeer
,
57 "(Ljava/lang/Object;Z)V");
60 static void item_toggled_cb (GtkToggleButton
*item
, jobject peer
);
62 JNIEXPORT
void JNICALL
63 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_create
64 (JNIEnv
*env
, jobject obj
, jobject group
)
71 NSA_SET_GLOBAL_REF (env
, obj
);
72 eventbox
= gtk_event_box_new ();
76 button
= gtk_check_button_new_with_label ("");
77 gtk_container_add (GTK_CONTAINER (eventbox
), button
);
78 gtk_widget_show (button
);
82 void *native_group
= NSA_GET_PTR (env
, group
);
83 button
= gtk_radio_button_new_with_label_from_widget (native_group
, "");
84 gtk_container_add (GTK_CONTAINER (eventbox
), button
);
85 gtk_widget_show (button
);
87 if (native_group
== NULL
)
89 /* Set the native group so we can use the correct value the
90 next time around. FIXME: this doesn't work! */
91 NSA_SET_PTR (env
, group
, button
);
95 NSA_SET_PTR (env
, obj
, eventbox
);
100 JNIEXPORT
void JNICALL
101 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectSignals
102 (JNIEnv
*env
, jobject obj
)
105 jobject
*gref
= NULL
;
108 gdk_threads_enter ();
110 ptr
= NSA_GET_PTR (env
, obj
);
111 gref
= NSA_GET_GLOBAL_REF (env
, obj
);
112 bin
= combobox_get_widget (GTK_WIDGET (ptr
));
114 /* Checkbox signals */
115 g_signal_connect (G_OBJECT (bin
), "toggled",
116 G_CALLBACK (item_toggled_cb
), *gref
);
118 /* Component signals */
119 cp_gtk_component_connect_signals (G_OBJECT (bin
), gref
);
121 gdk_threads_leave ();
124 JNIEXPORT
void JNICALL
125 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeSetCheckboxGroup
126 (JNIEnv
*env
, jobject obj
, jobject group
)
128 GtkRadioButton
*button
;
129 void *native_group
, *ptr
;
132 gdk_threads_enter ();
134 ptr
= NSA_GET_PTR (env
, obj
);
135 bin
= combobox_get_widget (GTK_WIDGET (ptr
));
137 /* FIXME: we can't yet switch between a checkbutton and a
138 radiobutton. However, AWT requires this. For now we just
141 button
= GTK_RADIO_BUTTON (bin
);
143 native_group
= NSA_GET_PTR (env
, group
);
144 if (native_group
== NULL
)
145 gtk_radio_button_set_group (button
, NULL
);
147 gtk_radio_button_set_group (button
,
148 gtk_radio_button_get_group
149 (GTK_RADIO_BUTTON (native_group
)));
151 /* If the native group wasn't set on the new CheckboxGroup, then set
152 it now so that the right thing will happen with the next
153 radiobutton. The native state for a CheckboxGroup is a pointer
154 to one of the widgets in the group. We are careful to keep this
155 always pointing at a live widget; whenever a widget is destroyed
156 (or otherwise removed from the group), the CheckboxGroup peer is
158 if (native_group
== NULL
)
159 NSA_SET_PTR (env
, group
, native_group
);
161 gdk_threads_leave ();
164 JNIEXPORT
void JNICALL
165 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkToggleButtonSetActive
166 (JNIEnv
*env
, jobject obj
, jboolean is_active
)
171 gdk_threads_enter ();
173 ptr
= NSA_GET_PTR (env
, obj
);
174 bin
= combobox_get_widget (GTK_WIDGET (ptr
));
176 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bin
), is_active
);
178 gdk_threads_leave ();
181 JNIEXPORT
void JNICALL
182 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkWidgetModifyFont
183 (JNIEnv
*env
, jobject obj
, jstring name
, jint style
, jint size
)
185 const char *font_name
;
189 PangoFontDescription
*font_desc
;
193 ptr
= NSA_GET_PTR (env
, obj
);
195 button
= combobox_get_widget (GTK_WIDGET (ptr
));
196 label
= gtk_bin_get_child (GTK_BIN(button
));
201 font_name
= (*env
)->GetStringUTFChars (env
, name
, NULL
);
203 font_desc
= pango_font_description_from_string (font_name
);
204 pango_font_description_set_size (font_desc
,
205 size
* cp_gtk_dpi_conversion_factor
);
207 if (style
& AWT_STYLE_BOLD
)
208 pango_font_description_set_weight (font_desc
, PANGO_WEIGHT_BOLD
);
210 if (style
& AWT_STYLE_ITALIC
)
211 pango_font_description_set_style (font_desc
, PANGO_STYLE_OBLIQUE
);
213 gtk_widget_modify_font (GTK_WIDGET(label
), font_desc
);
215 pango_font_description_free (font_desc
);
217 (*env
)->ReleaseStringUTFChars (env
, name
, font_name
);
222 JNIEXPORT
void JNICALL
223 Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkButtonSetLabel
224 (JNIEnv
*env
, jobject obj
, jstring label
)
227 GtkWidget
*label_widget
;
230 gdk_threads_enter ();
232 ptr
= NSA_GET_PTR (env
, obj
);
234 c_label
= (*env
)->GetStringUTFChars (env
, label
, NULL
);
236 label_widget
= gtk_bin_get_child (GTK_BIN (combobox_get_widget (GTK_WIDGET (ptr
))));
237 gtk_label_set_text (GTK_LABEL (label_widget
), c_label
);
239 (*env
)->ReleaseStringUTFChars (env
, label
, c_label
);
241 gdk_threads_leave ();
245 item_toggled_cb (GtkToggleButton
*item
, jobject peer
)
247 (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer
,
254 combobox_get_widget (GtkWidget
*widget
)
258 g_assert (GTK_IS_EVENT_BOX (widget
));
259 wid
= gtk_bin_get_child (GTK_BIN(widget
));