X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fvar-type-dialog.c;h=21d49669de6cc6c858b1b5ddebef7848ee9944fb;hb=deea66e1be0c3e783b159e1605a697d9e75861aa;hp=05ba5d3c9e748c61662bc8ee48914a521938490f;hpb=b40baf410822471fbdeeec553693619d60d7c7b6;p=pspp diff --git a/src/ui/gui/var-type-dialog.c b/src/ui/gui/var-type-dialog.c index 05ba5d3c9e..21d49669de 100644 --- a/src/ui/gui/var-type-dialog.c +++ b/src/ui/gui/var-type-dialog.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2005, 2006 Free Software Foundation + Copyright (C) 2005, 2006, 2010, 2011, 2012 Free Software Foundation 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 @@ -21,25 +21,15 @@ #include #include - #include #include -#include "var-type-dialog.h" - -#include "helper.h" - -#include -#include -#include - - -struct tgs -{ - struct var_type_dialog *dialog; - gint button; -}; - +#include "data/data-out.h" +#include "data/settings.h" +#include "data/variable.h" +#include "libpspp/message.h" +#include "ui/gui/builder-wrapper.h" +#include "ui/gui/var-type-dialog.h" struct format_opt { gchar desc[21]; @@ -105,14 +95,22 @@ static void select_treeview_from_format_type (GtkTreeView *treeview, /* callback for when any of the radio buttons are toggled */ static void -on_toggle_1 (GtkToggleButton *togglebutton, gpointer user_data) +on_toggle_1 (GtkToggleButton *togglebutton, gpointer dialog_) { - struct tgs *tgs = user_data; + GtkWidget *widget = GTK_WIDGET (togglebutton); + struct var_type_dialog *dialog = dialog_; + int i; if ( gtk_toggle_button_get_active (togglebutton) == FALSE) return ; - tgs->dialog->active_button = tgs->button; + for (i = 0; i < num_BUTTONS; i++) + if (widget == dialog->radioButton[i]) + { + dialog->active_button = i; + return; + } + g_return_if_reached (); } static void update_width_decimals (const struct var_type_dialog *dialog); @@ -125,7 +123,7 @@ static void update_width_decimals (const struct var_type_dialog *dialog); static void set_local_width_decimals (struct var_type_dialog *dialog) { - dialog->fmt_l = * var_get_write_format (dialog->pv); + dialog->fmt_l = * var_get_print_format (dialog->pv); switch (dialog->active_button) { @@ -262,12 +260,12 @@ preview_custom (GtkWidget *w, gpointer data) union value v; v.f = 1234.56; - sample_text = value_to_text (v, NULL, dialog->fmt_l); + sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l)); gtk_label_set_text (GTK_LABEL (dialog->label_psample), sample_text); g_free (sample_text); v.f = -v.f; - sample_text = value_to_text (v, NULL, dialog->fmt_l); + sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l)); gtk_label_set_text (GTK_LABEL (dialog->label_nsample), sample_text); g_free (sample_text); } @@ -315,12 +313,9 @@ set_format_type_from_treeview (GtkTreeView *treeview, gpointer data) dialog->fmt_l = custom_format; dialog->fmt_l.type = *(int*) g_value_get_pointer (&the_value); - } - - /* Create the structure */ struct var_type_dialog * var_type_dialog_create (GtkWindow *toplevel) @@ -328,7 +323,7 @@ var_type_dialog_create (GtkWindow *toplevel) gint i; struct var_type_dialog *dialog = g_malloc (sizeof (struct var_type_dialog)); - GtkBuilder *xml = builder_new ("var-sheet-dialogs.ui"); + GtkBuilder *xml = builder_new ("var-type-dialog.ui"); dialog->window = get_widget_assert (xml,"var_type_dialog"); dialog->active_button = -1; @@ -390,7 +385,6 @@ var_type_dialog_create (GtkWindow *toplevel) GtkTreeViewColumn *column; GtkCellRenderer *renderer ; - static struct tgs tgs[num_BUTTONS]; /* The "middle_box" is a vbox with serveral children. However only one child is ever shown at a time. We need to make sure that they all have the same width, to avoid @@ -403,10 +397,8 @@ var_type_dialog_create (GtkWindow *toplevel) for (i = 0 ; i < num_BUTTONS; ++i ) { - tgs[i].dialog = dialog; - tgs[i].button = i; g_signal_connect (dialog->radioButton[i], "toggled", - G_CALLBACK (on_toggle_1), &tgs[i]); + G_CALLBACK (on_toggle_1), dialog); g_signal_connect (dialog->radioButton[i], "toggled", G_CALLBACK (on_toggle_2), dialog); @@ -445,7 +437,7 @@ var_type_dialog_create (GtkWindow *toplevel) g_object_unref (list_store); g_signal_connect (dialog->date_format_treeview, "cursor-changed", - GTK_SIGNAL_FUNC (set_format_from_treeview), dialog); + G_CALLBACK (set_format_from_treeview), dialog); /* populate the dollar treeview */ @@ -483,11 +475,11 @@ var_type_dialog_create (GtkWindow *toplevel) g_signal_connect (dialog->dollar_treeview, "cursor-changed", - GTK_SIGNAL_FUNC (set_format_from_treeview), dialog); + G_CALLBACK (set_format_from_treeview), dialog); g_signal_connect_swapped (dialog->dollar_treeview, "cursor-changed", - GTK_SIGNAL_FUNC (update_width_decimals), dialog); + G_CALLBACK (update_width_decimals), dialog); /* populate the custom treeview */ @@ -527,22 +519,22 @@ var_type_dialog_create (GtkWindow *toplevel) g_signal_connect (dialog->custom_treeview, "cursor-changed", - GTK_SIGNAL_FUNC (set_format_type_from_treeview), dialog); + G_CALLBACK (set_format_type_from_treeview), dialog); g_signal_connect (dialog->custom_treeview, "cursor-changed", - GTK_SIGNAL_FUNC (preview_custom), dialog); + G_CALLBACK (preview_custom), dialog); g_signal_connect (dialog->entry_width, "changed", - GTK_SIGNAL_FUNC (preview_custom), dialog); + G_CALLBACK (preview_custom), dialog); g_signal_connect (dialog->entry_decimals, "changed", - GTK_SIGNAL_FUNC (preview_custom), dialog); + G_CALLBACK (preview_custom), dialog); /* Connect to the OK button */ @@ -665,21 +657,21 @@ select_treeview_from_format_type (GtkTreeView *treeview, static void var_type_dialog_set_state (struct var_type_dialog *dialog) { - const struct fmt_spec *write_spec ; + const struct fmt_spec *format ; GString *str = g_string_new (""); g_assert (dialog); g_assert (dialog->pv); /* Populate width and decimals */ - write_spec = var_get_write_format (dialog->pv); + format = var_get_print_format (dialog->pv); - g_string_printf (str, "%d", write_spec->d); + g_string_printf (str, "%d", format->d); gtk_entry_set_text (GTK_ENTRY (dialog->entry_decimals), str->str); - g_string_printf (str, "%d", write_spec->w); + g_string_printf (str, "%d", format->w); gtk_entry_set_text (GTK_ENTRY (dialog->entry_width), str->str); @@ -687,7 +679,7 @@ var_type_dialog_set_state (struct var_type_dialog *dialog) g_string_free (str, TRUE); /* Populate the radio button states */ - switch (write_spec->type) + switch (format->type) { case FMT_F: var_type_dialog_set_active_button (dialog, BUTTON_NUMERIC); @@ -710,7 +702,7 @@ var_type_dialog_set_state (struct var_type_dialog *dialog) var_type_dialog_set_active_button (dialog, BUTTON_DOLLAR); gtk_widget_show_all (dialog->width_decimals); - select_treeview_from_format (dialog->dollar_treeview, write_spec); + select_treeview_from_format (dialog->dollar_treeview, format); break; case FMT_DATE: case FMT_EDATE: @@ -728,7 +720,7 @@ var_type_dialog_set_state (struct var_type_dialog *dialog) var_type_dialog_set_active_button (dialog, BUTTON_DATE); gtk_widget_hide (dialog->width_decimals); gtk_widget_show (dialog->date_format_list); - select_treeview_from_format (dialog->date_format_treeview, write_spec); + select_treeview_from_format (dialog->date_format_treeview, format); break; case FMT_CCA: case FMT_CCB: @@ -737,7 +729,7 @@ var_type_dialog_set_state (struct var_type_dialog *dialog) case FMT_CCE: var_type_dialog_set_active_button (dialog, BUTTON_CUSTOM); select_treeview_from_format_type (dialog->custom_treeview, - write_spec->type); + format->type); gtk_widget_show_all (dialog->width_decimals); break; default: @@ -790,14 +782,12 @@ on_var_type_ok_clicked (GtkWidget *w, gpointer data) gint decimals = atoi (gtk_entry_get_text (GTK_ENTRY (dialog->entry_decimals))); - gint new_type = VAL_NUMERIC; gint new_width = 0; bool result = false; struct fmt_spec spec; switch (dialog->active_button) { case BUTTON_STRING: - new_type = VAL_STRING; new_width = width; result = make_output_format_try (&spec, FMT_A, width, 0); break; @@ -815,14 +805,16 @@ on_var_type_ok_clicked (GtkWidget *w, gpointer data) break; case BUTTON_DATE: case BUTTON_CUSTOM: - g_assert (fmt_check_output (&dialog->fmt_l)); - result = memcpy (&spec, &dialog->fmt_l, sizeof (struct fmt_spec)); + if (! fmt_check_output (&dialog->fmt_l)) + g_critical ("Invalid variable format"); + else + result = memcpy (&spec, &dialog->fmt_l, sizeof (struct fmt_spec)); break; case BUTTON_DOLLAR: result = make_output_format_try (&spec, FMT_DOLLAR, width, decimals); break; default: - g_print ("Unknown variable type: %d\n", dialog->active_button) ; + g_critical ("Unknown variable type: %d", dialog->active_button) ; result = false; break; }