/* PSPPIRE --- A Graphical User Interface for PSPP Copyright (C) 2005 Free Software Foundation Written by John Darrington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* This module describes the behaviour of the Variable Type dialog box used for inputing the variable type in the var sheet */ #include #include #include "var_type_dialog.h" #include "var.h" /* callback for when any of thie radio buttons are toggled */ static void on_toggle(GtkToggleButton *togglebutton, gpointer user_data) { gint i; struct var_type_dialog *dialog = user_data; if ( gtk_toggle_button_get_active(togglebutton) == FALSE) return ; for(i = 0; i < num_BUTTONS; ++i ) { if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dialog->radioButton[i])) ) { switch (i) { case BUTTON_STRING: gtk_widget_hide(dialog->label_decimals); gtk_widget_hide(dialog->entry_decimals); break; default: gtk_widget_show(dialog->label_decimals); gtk_widget_show(dialog->entry_decimals); break; } break; } } } /* Create the structure from the XML definitions */ struct var_type_dialog * var_type_dialog_create(GladeXML *xml) { gint i; g_assert(xml); struct var_type_dialog *dialog = g_malloc(sizeof(struct var_type_dialog)); dialog->window = glade_xml_get_widget(xml,"var_type_dialog"); dialog->radioButton[BUTTON_NUMERIC] = glade_xml_get_widget(xml,"radiobutton1"); dialog->radioButton[BUTTON_COMMA] = glade_xml_get_widget(xml,"radiobutton2"); dialog->radioButton[BUTTON_DOT] = glade_xml_get_widget(xml,"radiobutton3"); dialog->radioButton[BUTTON_SCIENTIFIC] = glade_xml_get_widget(xml,"radiobutton4"); dialog->radioButton[BUTTON_DATE] = glade_xml_get_widget(xml,"radiobutton5"); dialog->radioButton[BUTTON_DOLLAR] = glade_xml_get_widget(xml,"radiobutton6"); dialog->radioButton[BUTTON_CUSTOM] = glade_xml_get_widget(xml,"radiobutton7"); dialog->radioButton[BUTTON_STRING] = glade_xml_get_widget(xml,"radiobutton8"); dialog->label_decimals = glade_xml_get_widget(xml,"label3"); dialog->entry_decimals = glade_xml_get_widget(xml,"entry2"); dialog->entry_width = glade_xml_get_widget(xml,"entry1"); dialog->ok = glade_xml_get_widget(xml,"var_type_ok"); for (i = 0 ; i < num_BUTTONS; ++i ) { g_signal_connect(dialog->radioButton[i], "toggled", G_CALLBACK(on_toggle), dialog); } return dialog; } /* Set up the state of the dialog box to match the variable VAR */ void var_type_dialog_set_state(struct var_type_dialog *dialog, const struct variable *var) { /* Populate width and decimals */ const struct fmt_spec write_spec = var->write; g_assert(dialog); GString *str = g_string_new(""); g_string_printf(str,"%d",write_spec.d); gtk_entry_set_text(GTK_ENTRY(dialog->entry_decimals), str->str); g_string_printf(str,"%d",write_spec.w); gtk_entry_set_text(GTK_ENTRY(dialog->entry_width), str->str); g_string_free(str,TRUE); /* Populate the radio button states */ switch (write_spec.type) { case FMT_A: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radioButton[BUTTON_STRING]), TRUE); gtk_widget_hide(dialog->label_decimals); gtk_widget_hide(dialog->entry_decimals); break; case FMT_COMMA: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radioButton[BUTTON_COMMA]), TRUE); gtk_widget_show(dialog->label_decimals); gtk_widget_show(dialog->entry_decimals); break; case FMT_DOT: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radioButton[BUTTON_DOT]), TRUE); gtk_widget_show(dialog->label_decimals); gtk_widget_show(dialog->entry_decimals); break; case FMT_DOLLAR: gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radioButton[BUTTON_DOLLAR]), TRUE); gtk_widget_show(dialog->label_decimals); gtk_widget_show(dialog->entry_decimals); break; default: gtk_widget_show(dialog->label_decimals); gtk_widget_show(dialog->entry_decimals); break; } } /* Popup the dialog box */ void var_type_dialog_show(struct var_type_dialog *dialog) { gtk_widget_show(dialog->window); } /* Callbacks for the Variable Type Dialog Box */ gint on_var_type_ok_clicked (GtkWidget *w, gint idx, gpointer data) { g_print("OK\n"); gtk_widget_hide(w); return FALSE; } gint on_var_type_cancel_clicked (GtkWidget *w, gint idx, gpointer data) { gtk_widget_hide(w); return FALSE; }