38 #include "radio_helper.h"
40 static GtkRadioButton *rh_get_radio_from_value(GtkWidget *radio_button, gint value);
42 GtkWidget *rh_append_radio_to_vbox(GtkWidget *radio_button,
const gchar *text,
43 gint value,
void (*callback)(GtkToggleButton *, gpointer), gpointer callback_data,
46 GtkWidget *new_radio_button =
47 gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio_button), text);
48 gtk_box_pack_start(GTK_BOX(vbox), new_radio_button, FALSE, FALSE, 0);
52 g_signal_connect(GTK_TOGGLE_BUTTON(new_radio_button),
"toggled", G_CALLBACK(callback),
56 g_object_set_data(G_OBJECT(new_radio_button),
"value", GINT_TO_POINTER(value));
58 return new_radio_button;
61 gint rh_get_active_value(GtkWidget *radio_button)
63 gint active_value = -1;
64 GSList *radio_button_list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button));
67 for(i = 0; i < g_slist_length(radio_button_list);i++)
69 GtkRadioButton *current_radio = (GtkRadioButton *) g_slist_nth_data(radio_button_list, i);
70 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(current_radio)))
72 active_value = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(current_radio),
"value"));
80 void rh_set_radio_value(GtkWidget *radio_button, gint key_value, gboolean value)
82 GtkRadioButton *radio = rh_get_radio_from_value(radio_button, key_value);
83 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), value);
86 static GtkRadioButton *rh_get_radio_from_value(GtkWidget *radio_button, gint value)
88 GSList *radio_button_list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button));
91 gint list_length = g_slist_length(radio_button_list);
92 for(i = 0; i < list_length;i++)
94 GtkRadioButton *current_radio = (GtkRadioButton *) g_slist_nth_data(radio_button_list, i);
95 gint current_value = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(current_radio),
"value"));
96 if (current_value == value)