2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2004, 2005, 2006 Free Software Foundation
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 /* This module creates the Variable Sheet used for inputing the
22 variables in the dictonary */
26 #define _(msgid) gettext (msgid)
27 #define N_(msgid) msgid
29 #include <data/value-labels.h>
31 #include <glade/glade.h>
38 #include <data/value.h>
40 #include <gtksheet/gtksheet.h>
41 #include <gtksheet/gsheet-hetero-column.h>
42 #include <gtksheet/gsheet-uniform-row.h>
44 #include "psppire-var-store.h"
46 #include "menu-actions.h"
47 #include "psppire-dict.h"
48 #include "var-type-dialog.h"
49 #include "var-sheet.h"
50 #include "customentry.h"
52 #include "val-labs-dialog.h"
53 #include "missing-val-dialog.h"
57 static const gint n_initial_rows = 40;
62 struct column_parameters
68 static const struct column_parameters column_def[] = {
83 click2row(GtkWidget *w, gint row, gpointer data)
85 gint current_row, current_column;
86 GtkWidget *data_sheet = get_widget_assert(xml, "data_sheet");
88 select_sheet(PAGE_DATA_SHEET);
90 gtk_sheet_get_active_cell(GTK_SHEET(data_sheet),
91 ¤t_row, ¤t_column);
93 gtk_sheet_set_active_cell(GTK_SHEET(data_sheet), current_row, row);
100 const gchar *alignments[n_ALIGNMENTS + 1]={
107 const gchar *measures[n_MEASURES + 1]={
114 static GtkListStore *
115 create_label_list(const gchar **labels)
121 GtkListStore *list_store;
122 list_store = gtk_list_store_new (1, G_TYPE_STRING);
125 while ( (s = labels[i++]))
127 gtk_list_store_append (list_store, &iter);
128 gtk_list_store_set (list_store, &iter,
136 /* Callback for when the alignment combo box
139 change_alignment(GtkComboBox *cb,
142 struct variable *pv = user_data;
143 gint active_item = gtk_combo_box_get_active(cb);
145 if ( active_item < 0 ) return ;
147 var_set_alignment (pv, active_item);
152 /* Callback for when the measure combo box
155 change_measure(GtkComboBox *cb,
158 struct variable *pv = user_data;
159 gint active_item = gtk_combo_box_get_active(cb);
161 if ( active_item < 0 ) return ;
163 var_set_measure (pv, active_item);
169 traverse_cell_callback (GtkSheet * sheet,
170 gint row, gint column,
171 gint *new_row, gint *new_column
174 PsppireVarStore *var_store = PSPPIRE_VAR_STORE(gtk_sheet_get_model(sheet));
176 gint n_vars = psppire_var_store_get_var_cnt(var_store);
178 if ( row == n_vars && *new_row >= n_vars)
180 GtkEntry *entry = GTK_ENTRY(gtk_sheet_get_entry(sheet));
182 const gchar *name = gtk_entry_get_text(entry);
184 if (! psppire_dict_check_name(var_store->dict, name, TRUE))
187 psppire_dict_insert_variable(var_store->dict, row, name);
192 /* If the destination cell is outside the current variables, then
193 automatically create variables for the new rows.
195 if ( (*new_row > n_vars) ||
196 (*new_row == n_vars && *new_column != COL_NAME) )
199 for ( i = n_vars ; i <= *new_row; ++i )
200 psppire_dict_insert_variable(var_store->dict, i, NULL);
207 /* Callback whenever the cell on the var sheet is entered or left.
208 It sets the entry box type appropriately.
211 var_sheet_cell_change_entry (GtkSheet * sheet, gint row, gint column,
214 GtkSheetCellAttr attributes;
215 PsppireVarStore *var_store ;
216 struct variable *pv ;
218 g_return_val_if_fail(sheet != NULL, FALSE);
220 var_store = PSPPIRE_VAR_STORE(gtk_sheet_get_model(sheet));
222 if ( row >= psppire_var_store_get_var_cnt(var_store))
227 gtk_sheet_change_entry(sheet, GTK_TYPE_ENTRY);
232 gtk_sheet_get_attributes(sheet, row, column, &attributes);
234 pv = psppire_var_store_get_var (var_store, row);
240 static GtkListStore *list_store = 0;
241 GtkComboBoxEntry *cbe;
242 gtk_sheet_change_entry(sheet, GTK_TYPE_COMBO_BOX_ENTRY);
244 GTK_COMBO_BOX_ENTRY(gtk_sheet_get_entry(sheet)->parent);
247 if ( ! list_store) list_store = create_label_list(alignments);
249 gtk_combo_box_set_model(GTK_COMBO_BOX(cbe),
250 GTK_TREE_MODEL(list_store));
252 gtk_combo_box_entry_set_text_column (cbe, 0);
255 g_signal_connect(G_OBJECT(cbe),"changed",
256 G_CALLBACK(change_alignment), pv);
261 static GtkListStore *list_store = 0;
262 GtkComboBoxEntry *cbe;
263 gtk_sheet_change_entry(sheet, GTK_TYPE_COMBO_BOX_ENTRY);
265 GTK_COMBO_BOX_ENTRY(gtk_sheet_get_entry(sheet)->parent);
268 if ( ! list_store) list_store = create_label_list (measures);
270 gtk_combo_box_set_model(GTK_COMBO_BOX(cbe),
271 GTK_TREE_MODEL(list_store));
273 gtk_combo_box_entry_set_text_column (cbe, 0);
275 g_signal_connect (G_OBJECT(cbe),"changed",
276 G_CALLBACK (change_measure), pv);
282 static struct val_labs_dialog *val_labs_dialog = 0;
284 PsppireCustomEntry *customEntry;
286 gtk_sheet_change_entry(sheet, PSPPIRE_CUSTOM_ENTRY_TYPE);
289 PSPPIRE_CUSTOM_ENTRY(gtk_sheet_get_entry(sheet));
292 if (!val_labs_dialog )
293 val_labs_dialog = val_labs_dialog_create(xml);
295 val_labs_dialog->pv = pv;
297 g_signal_connect_swapped(GTK_OBJECT(customEntry),
299 GTK_SIGNAL_FUNC(val_labs_dialog_show),
305 static struct missing_val_dialog *missing_val_dialog = 0;
306 PsppireCustomEntry *customEntry;
308 gtk_sheet_change_entry(sheet, PSPPIRE_CUSTOM_ENTRY_TYPE);
311 PSPPIRE_CUSTOM_ENTRY(gtk_sheet_get_entry(sheet));
313 if (!missing_val_dialog )
314 missing_val_dialog = missing_val_dialog_create(xml);
316 missing_val_dialog->pv = psppire_var_store_get_var (var_store, row);
318 g_signal_connect_swapped(GTK_OBJECT(customEntry),
320 GTK_SIGNAL_FUNC(missing_val_dialog_show),
327 static struct var_type_dialog *var_type_dialog = 0;
329 PsppireCustomEntry *customEntry;
331 gtk_sheet_change_entry(sheet, PSPPIRE_CUSTOM_ENTRY_TYPE);
334 PSPPIRE_CUSTOM_ENTRY(gtk_sheet_get_entry(sheet));
337 /* Popup the Variable Type dialog box */
338 if (!var_type_dialog )
339 var_type_dialog = var_type_dialog_create(xml);
342 var_type_dialog->pv = pv;
344 g_signal_connect_swapped(GTK_OBJECT(customEntry),
346 GTK_SIGNAL_FUNC(var_type_dialog_show),
354 if ( attributes.is_editable)
358 const gchar *s = gtk_sheet_cell_get_text(sheet, row, column);
364 GtkSpinButton *spinButton ;
365 const gint current_value = atoi(s);
368 const struct fmt_spec *fmt = var_get_write_format (pv);
372 r_min = MAX (fmt->d + 1, fmt_min_output_width (fmt->type));
373 r_max = fmt_max_output_width (fmt->type);
377 r_max = fmt_max_output_decimals (fmt->type, fmt->w);
381 r_max = 255 ; /* Is this a sensible value ? */
384 g_assert_not_reached();
387 adj = gtk_adjustment_new(current_value,
389 1.0, 1.0, 1.0 /* steps */
392 gtk_sheet_change_entry(sheet, GTK_TYPE_SPIN_BUTTON);
395 GTK_SPIN_BUTTON(gtk_sheet_get_entry(sheet));
397 gtk_spin_button_set_adjustment(spinButton, GTK_ADJUSTMENT(adj));
398 gtk_spin_button_set_digits(spinButton, 0);
405 gtk_sheet_change_entry(sheet, GTK_TYPE_ENTRY);
413 extern PsppireVarStore *var_store;
416 /* Create the var sheet */
418 psppire_variable_sheet_create (gchar *widget_name,
421 gint int1, gint int2)
427 GObject *geo = g_sheet_hetero_column_new(75, n_COLS);
429 sheet = gtk_sheet_new(G_SHEET_ROW(var_store),
431 "variable sheet", 0);
433 g_signal_connect (GTK_OBJECT (sheet), "activate",
434 GTK_SIGNAL_FUNC (var_sheet_cell_change_entry),
437 g_signal_connect (GTK_OBJECT (sheet), "deactivate",
438 GTK_SIGNAL_FUNC (var_sheet_cell_change_entry),
441 g_signal_connect (GTK_OBJECT (sheet), "traverse",
442 GTK_SIGNAL_FUNC (traverse_cell_callback), 0);
445 g_signal_connect (GTK_OBJECT (sheet), "double-click-row",
446 GTK_SIGNAL_FUNC (click2row),
449 /* Since this happens inside glade_xml_new, we must prevent strings from
450 * being re-encoded twice */
451 codeset = bind_textdomain_codeset(PACKAGE, 0);
452 bind_textdomain_codeset(PACKAGE, nl_langinfo(CODESET));
453 for (i = 0 ; i < n_COLS ; ++i )
455 g_sheet_hetero_column_set_button_label(G_SHEET_HETERO_COLUMN(geo), i,
456 gettext(column_def[i].label));
458 g_sheet_hetero_column_set_width(G_SHEET_HETERO_COLUMN(geo), i,
459 column_def[i].width);
461 bind_textdomain_codeset(PACKAGE, codeset);
463 gtk_widget_show(sheet);