X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fvar-sheet.c;h=b65c6e89ddf8cd0482091d97444588ff56132928;hb=4f2f805c653f0dc901924944ea4c55309ff14d32;hp=e04d48955d571f3edec16d54e858b6c11f8fca23;hpb=573068f2bdcd3f8796e9646668fed910a90f890b;p=pspp-builds.git diff --git a/src/ui/gui/var-sheet.c b/src/ui/gui/var-sheet.c index e04d4895..b65c6e89 100644 --- a/src/ui/gui/var-sheet.c +++ b/src/ui/gui/var-sheet.c @@ -1,7 +1,6 @@ /* PSPPIRE --- A Graphical User Interface for PSPP Copyright (C) 2004, 2005, 2006 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 @@ -22,6 +21,11 @@ /* This module creates the Variable Sheet used for inputing the variables in the dictonary */ +#include +#include +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + #include #include @@ -29,8 +33,9 @@ #include #include +#include -#define min(A,B) ((A < B)?A:B) +#include #include #include @@ -40,7 +45,6 @@ #include "helper.h" #include "menu-actions.h" #include "psppire-dict.h" -#include "psppire-variable.h" #include "var-type-dialog.h" #include "var-sheet.h" #include "customentry.h" @@ -48,8 +52,6 @@ #include "val-labs-dialog.h" #include "missing-val-dialog.h" -#define _(A) A -#define N_(A) A static const gint n_initial_rows = 40; @@ -64,16 +66,16 @@ struct column_parameters }; static const struct column_parameters column_def[] = { - {N_("Name"), 80}, - {N_("Type"), 100}, - {N_("Width"), 57}, - {N_("Decimals"),91}, - {N_("Label"), 95}, - {N_("Values"), 103}, - {N_("Missing"), 95}, - {N_("Columns"), 80}, - {N_("Align"), 69}, - {N_("Measure"), 99}, + { N_("Name"), 80}, + { N_("Type"), 100}, + { N_("Width"), 57}, + { N_("Decimals"),91}, + { N_("Label"), 95}, + { N_("Values"), 103}, + { N_("Missing"), 95}, + { N_("Columns"), 80}, + { N_("Align"), 69}, + { N_("Measure"), 99}, }; @@ -95,17 +97,17 @@ click2row(GtkWidget *w, gint row, gpointer data) -const gchar *alignments[]={ - _("Left"), - _("Right"), - _("Centre"), +const gchar *alignments[n_ALIGNMENTS + 1]={ + N_("Left"), + N_("Right"), + N_("Centre"), 0 }; -const gchar *measures[]={ - _("Nominal"), - _("Ordinal"), - _("Scale"), +const gchar *measures[n_MEASURES + 1]={ + N_("Nominal"), + N_("Ordinal"), + N_("Scale"), 0 }; @@ -124,7 +126,7 @@ create_label_list(const gchar **labels) { gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, - 0, s, + 0, gettext(s), -1); } @@ -137,28 +139,28 @@ static void change_alignment(GtkComboBox *cb, gpointer user_data) { - struct PsppireVariable *pv = user_data; + struct variable *pv = user_data; gint active_item = gtk_combo_box_get_active(cb); if ( active_item < 0 ) return ; - psppire_variable_set_alignment(pv, active_item); + var_set_alignment (pv, active_item); } /* Callback for when the measure combo box item is selected */ -static void +static void change_measure(GtkComboBox *cb, gpointer user_data) { - struct PsppireVariable *pv = user_data; + struct variable *pv = user_data; gint active_item = gtk_combo_box_get_active(cb); if ( active_item < 0 ) return ; - psppire_variable_set_measure(pv, active_item); + var_set_measure (pv, active_item); } @@ -188,13 +190,15 @@ traverse_cell_callback (GtkSheet * sheet, } /* If the destination cell is outside the current variables, then - accept the destination only as the name column of the first blank row + automatically create variables for the new rows. */ - if ( *new_row > n_vars) - return FALSE; - - if ( *new_row >= n_vars && *new_column != COL_NAME) - return FALSE; + if ( (*new_row > n_vars) || + (*new_row == n_vars && *new_column != COL_NAME) ) + { + gint i; + for ( i = n_vars ; i <= *new_row; ++i ) + psppire_dict_insert_variable(var_store->dict, i, NULL); + } return TRUE; } @@ -209,7 +213,7 @@ var_sheet_cell_change_entry (GtkSheet * sheet, gint row, gint column, { GtkSheetCellAttr attributes; PsppireVarStore *var_store ; - struct PsppireVariable *pv ; + struct variable *pv ; g_return_val_if_fail(sheet != NULL, FALSE); @@ -227,7 +231,7 @@ var_sheet_cell_change_entry (GtkSheet * sheet, gint row, gint column, gtk_sheet_get_attributes(sheet, row, column, &attributes); - pv = psppire_var_store_get_variable(var_store, row); + pv = psppire_var_store_get_var (var_store, row); switch (column) { @@ -261,15 +265,15 @@ var_sheet_cell_change_entry (GtkSheet * sheet, gint row, gint column, GTK_COMBO_BOX_ENTRY(gtk_sheet_get_entry(sheet)->parent); - if ( ! list_store) list_store = create_label_list(measures); + if ( ! list_store) list_store = create_label_list (measures); gtk_combo_box_set_model(GTK_COMBO_BOX(cbe), GTK_TREE_MODEL(list_store)); gtk_combo_box_entry_set_text_column (cbe, 0); - g_signal_connect(G_OBJECT(cbe),"changed", - G_CALLBACK(change_measure), pv); + g_signal_connect (G_OBJECT(cbe),"changed", + G_CALLBACK (change_measure), pv); } break; @@ -309,7 +313,7 @@ var_sheet_cell_change_entry (GtkSheet * sheet, gint row, gint column, if (!missing_val_dialog ) missing_val_dialog = missing_val_dialog_create(xml); - missing_val_dialog->pv = psppire_var_store_get_variable(var_store, row); + missing_val_dialog->pv = psppire_var_store_get_var (var_store, row); g_signal_connect_swapped(GTK_OBJECT(customEntry), "clicked", @@ -361,16 +365,16 @@ var_sheet_cell_change_entry (GtkSheet * sheet, gint row, gint column, const gint current_value = atoi(s); GtkObject *adj ; - const struct fmt_spec *fmt = psppire_variable_get_write_spec(pv); + const struct fmt_spec *fmt = var_get_write_format (pv); switch (column) { case COL_WIDTH: - r_min = fmt->d + 1; - r_max = (psppire_variable_get_type(pv) == ALPHA) ? 255 : 40; + r_min = MAX (fmt->d + 1, fmt_min_output_width (fmt->type)); + r_max = fmt_max_output_width (fmt->type); break; case COL_DECIMALS: r_min = 0 ; - r_max = min(fmt->w - 1, 16); + r_max = fmt_max_output_decimals (fmt->type, fmt->w); break; case COL_COLUMNS: r_min = 1; @@ -406,6 +410,8 @@ var_sheet_cell_change_entry (GtkSheet * sheet, gint row, gint column, } +extern PsppireVarStore *var_store; + /* Create the var sheet */ GtkWidget* @@ -414,15 +420,13 @@ psppire_variable_sheet_create (gchar *widget_name, gchar *string2, gint int1, gint int2) { + gchar *codeset; gint i; GtkWidget *sheet; GObject *geo = g_sheet_hetero_column_new(75, n_COLS); - GObject *row_geometry = g_sheet_uniform_row_new(25, n_initial_rows); - - - sheet = gtk_sheet_new(G_SHEET_ROW(row_geometry), + sheet = gtk_sheet_new(G_SHEET_ROW(var_store), G_SHEET_COLUMN(geo), "variable sheet", 0); @@ -442,14 +446,19 @@ psppire_variable_sheet_create (gchar *widget_name, GTK_SIGNAL_FUNC (click2row), sheet); + /* Since this happens inside glade_xml_new, we must prevent strings from + * being re-encoded twice */ + codeset = bind_textdomain_codeset(PACKAGE, 0); + bind_textdomain_codeset(PACKAGE, nl_langinfo(CODESET)); for (i = 0 ; i < n_COLS ; ++i ) { g_sheet_hetero_column_set_button_label(G_SHEET_HETERO_COLUMN(geo), i, - column_def[i].label); - + gettext(column_def[i].label)); + g_sheet_hetero_column_set_width(G_SHEET_HETERO_COLUMN(geo), i, column_def[i].width); } + bind_textdomain_codeset(PACKAGE, codeset); gtk_widget_show(sheet);