2 PSPPIRE --- A Graphical User Interface for PSPP
3 Copyright (C) 2004, 2005, 2006 Free Software Foundation
4 Written by John Darrington
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 /* This module creates the Variable Sheet used for inputing the
23 variables in the dictonary */
27 #define _(msgid) gettext (msgid)
28 #define N_(msgid) msgid
30 #include <data/value-labels.h>
32 #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 "psppire-variable.h"
49 #include "var-type-dialog.h"
50 #include "var-sheet.h"
51 #include "customentry.h"
53 #include "val-labs-dialog.h"
54 #include "missing-val-dialog.h"
58 static const gint n_initial_rows = 40;
63 struct column_parameters
69 static const struct column_parameters column_def[] = {
84 click2row(GtkWidget *w, gint row, gpointer data)
86 gint current_row, current_column;
87 GtkWidget *data_sheet = get_widget_assert(xml, "data_sheet");
89 select_sheet(PAGE_DATA_SHEET);
91 gtk_sheet_get_active_cell(GTK_SHEET(data_sheet),
92 ¤t_row, ¤t_column);
94 gtk_sheet_set_active_cell(GTK_SHEET(data_sheet), current_row, row);
101 const gchar *alignments[]={
108 const gchar *measures[]={
115 static GtkListStore *
116 create_label_list(const gchar **labels)
122 GtkListStore *list_store;
123 list_store = gtk_list_store_new (1, G_TYPE_STRING);
126 while ( (s = labels[i++]))
128 gtk_list_store_append (list_store, &iter);
129 gtk_list_store_set (list_store, &iter,
137 /* Callback for when the alignment combo box
140 change_alignment(GtkComboBox *cb,
143 struct PsppireVariable *pv = user_data;
144 gint active_item = gtk_combo_box_get_active(cb);
146 if ( active_item < 0 ) return ;
148 psppire_variable_set_alignment(pv, active_item);
153 /* Callback for when the measure combo box
156 change_measure(GtkComboBox *cb,
159 struct PsppireVariable *pv = user_data;
160 gint active_item = gtk_combo_box_get_active(cb);
162 if ( active_item < 0 ) return ;
164 psppire_variable_set_measure(pv, active_item);
170 traverse_cell_callback (GtkSheet * sheet,
171 gint row, gint column,
172 gint *new_row, gint *new_column
175 PsppireVarStore *var_store = PSPPIRE_VAR_STORE(gtk_sheet_get_model(sheet));
177 gint n_vars = psppire_var_store_get_var_cnt(var_store);
179 if ( row == n_vars && *new_row >= n_vars)
181 GtkEntry *entry = GTK_ENTRY(gtk_sheet_get_entry(sheet));
183 const gchar *name = gtk_entry_get_text(entry);
185 if (! psppire_dict_check_name(var_store->dict, name, TRUE))
188 psppire_dict_insert_variable(var_store->dict, row, name);
193 /* If the destination cell is outside the current variables, then
194 accept the destination only as the name column of the first blank row
196 if ( *new_row > n_vars)
199 if ( *new_row >= n_vars && *new_column != COL_NAME)
206 /* Callback whenever the cell on the var sheet is entered or left.
207 It sets the entry box type appropriately.
210 var_sheet_cell_change_entry (GtkSheet * sheet, gint row, gint column,
213 GtkSheetCellAttr attributes;
214 PsppireVarStore *var_store ;
215 struct PsppireVariable *pv ;
217 g_return_val_if_fail(sheet != NULL, FALSE);
219 var_store = PSPPIRE_VAR_STORE(gtk_sheet_get_model(sheet));
221 if ( row >= psppire_var_store_get_var_cnt(var_store))
226 gtk_sheet_change_entry(sheet, GTK_TYPE_ENTRY);
231 gtk_sheet_get_attributes(sheet, row, column, &attributes);
233 pv = psppire_var_store_get_variable(var_store, row);
239 static GtkListStore *list_store = 0;
240 GtkComboBoxEntry *cbe;
241 gtk_sheet_change_entry(sheet, GTK_TYPE_COMBO_BOX_ENTRY);
243 GTK_COMBO_BOX_ENTRY(gtk_sheet_get_entry(sheet)->parent);
246 if ( ! list_store) list_store = create_label_list(alignments);
248 gtk_combo_box_set_model(GTK_COMBO_BOX(cbe),
249 GTK_TREE_MODEL(list_store));
251 gtk_combo_box_entry_set_text_column (cbe, 0);
254 g_signal_connect(G_OBJECT(cbe),"changed",
255 G_CALLBACK(change_alignment), pv);
260 static GtkListStore *list_store = 0;
261 GtkComboBoxEntry *cbe;
262 gtk_sheet_change_entry(sheet, GTK_TYPE_COMBO_BOX_ENTRY);
264 GTK_COMBO_BOX_ENTRY(gtk_sheet_get_entry(sheet)->parent);
267 if ( ! list_store) list_store = create_label_list(measures);
269 gtk_combo_box_set_model(GTK_COMBO_BOX(cbe),
270 GTK_TREE_MODEL(list_store));
272 gtk_combo_box_entry_set_text_column (cbe, 0);
274 g_signal_connect(G_OBJECT(cbe),"changed",
275 G_CALLBACK(change_measure), pv);
281 static struct val_labs_dialog *val_labs_dialog = 0;
283 PsppireCustomEntry *customEntry;
285 gtk_sheet_change_entry(sheet, PSPPIRE_CUSTOM_ENTRY_TYPE);
288 PSPPIRE_CUSTOM_ENTRY(gtk_sheet_get_entry(sheet));
291 if (!val_labs_dialog )
292 val_labs_dialog = val_labs_dialog_create(xml);
294 val_labs_dialog->pv = pv;
296 g_signal_connect_swapped(GTK_OBJECT(customEntry),
298 GTK_SIGNAL_FUNC(val_labs_dialog_show),
304 static struct missing_val_dialog *missing_val_dialog = 0;
305 PsppireCustomEntry *customEntry;
307 gtk_sheet_change_entry(sheet, PSPPIRE_CUSTOM_ENTRY_TYPE);
310 PSPPIRE_CUSTOM_ENTRY(gtk_sheet_get_entry(sheet));
312 if (!missing_val_dialog )
313 missing_val_dialog = missing_val_dialog_create(xml);
315 missing_val_dialog->pv = psppire_var_store_get_variable(var_store, row);
317 g_signal_connect_swapped(GTK_OBJECT(customEntry),
319 GTK_SIGNAL_FUNC(missing_val_dialog_show),
326 static struct var_type_dialog *var_type_dialog = 0;
328 PsppireCustomEntry *customEntry;
330 gtk_sheet_change_entry(sheet, PSPPIRE_CUSTOM_ENTRY_TYPE);
333 PSPPIRE_CUSTOM_ENTRY(gtk_sheet_get_entry(sheet));
336 /* Popup the Variable Type dialog box */
337 if (!var_type_dialog )
338 var_type_dialog = var_type_dialog_create(xml);
341 var_type_dialog->pv = pv;
343 g_signal_connect_swapped(GTK_OBJECT(customEntry),
345 GTK_SIGNAL_FUNC(var_type_dialog_show),
353 if ( attributes.is_editable)
357 const gchar *s = gtk_sheet_cell_get_text(sheet, row, column);
363 GtkSpinButton *spinButton ;
364 const gint current_value = atoi(s);
367 const struct fmt_spec *fmt = psppire_variable_get_write_spec(pv);
372 r_max = (psppire_variable_get_type(pv) == ALPHA) ? MAX_STRING : 40;
376 r_max = MIN(fmt->w - 1, 16);
380 r_max = 255 ; /* Is this a sensible value ? */
383 g_assert_not_reached();
386 adj = gtk_adjustment_new(current_value,
388 1.0, 1.0, 1.0 /* steps */
391 gtk_sheet_change_entry(sheet, GTK_TYPE_SPIN_BUTTON);
394 GTK_SPIN_BUTTON(gtk_sheet_get_entry(sheet));
396 gtk_spin_button_set_adjustment(spinButton, GTK_ADJUSTMENT(adj));
397 gtk_spin_button_set_digits(spinButton, 0);
404 gtk_sheet_change_entry(sheet, GTK_TYPE_ENTRY);
413 /* Create the var sheet */
415 psppire_variable_sheet_create (gchar *widget_name,
418 gint int1, gint int2)
423 GObject *geo = g_sheet_hetero_column_new(75, n_COLS);
424 GObject *row_geometry = g_sheet_uniform_row_new(25, n_initial_rows);
428 sheet = gtk_sheet_new(G_SHEET_ROW(row_geometry),
430 "variable sheet", 0);
432 g_signal_connect (GTK_OBJECT (sheet), "activate",
433 GTK_SIGNAL_FUNC (var_sheet_cell_change_entry),
436 g_signal_connect (GTK_OBJECT (sheet), "deactivate",
437 GTK_SIGNAL_FUNC (var_sheet_cell_change_entry),
440 g_signal_connect (GTK_OBJECT (sheet), "traverse",
441 GTK_SIGNAL_FUNC (traverse_cell_callback), 0);
444 g_signal_connect (GTK_OBJECT (sheet), "double-click-row",
445 GTK_SIGNAL_FUNC (click2row),
448 for (i = 0 ; i < n_COLS ; ++i )
450 g_sheet_hetero_column_set_button_label(G_SHEET_HETERO_COLUMN(geo), i,
451 gettext(column_def[i].label));
453 g_sheet_hetero_column_set_width(G_SHEET_HETERO_COLUMN(geo), i,
454 column_def[i].width);
457 gtk_widget_show(sheet);