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
23 #include <glade/glade.h>
27 #include <gtksheet/gtksheet.h>
29 #include <gtksheet/gsheet-uniform-row.h>
31 #include "psppire-dict.h"
32 #include "psppire-variable.h"
33 #include "psppire-data-store.h"
36 #include <data/value-labels.h>
37 #include <data/case.h>
38 #include <data/data-in.h>
40 #include "menu-actions.h"
41 #include "data-sheet.h"
48 traverse_callback (GtkSheet * sheet,
50 gint *new_row, gint *new_column
54 PsppireDataStore *data_store = PSPPIRE_DATA_STORE(gtk_sheet_get_model(sheet));
55 const gint n_vars = psppire_dict_get_var_cnt(data_store->dict);
57 if ( *new_column >= n_vars )
60 case_count = psppire_case_file_get_case_count(data_store->case_file);
62 if ( *new_row >= case_count )
66 for ( i = case_count ; i <= *new_row; ++i )
67 psppire_data_store_insert_new_case (data_store, i);
77 /* Callback which occurs when the column title is double clicked */
79 click2column(GtkWidget *w, gint col, gpointer data)
81 gint current_row, current_column;
82 GtkWidget *var_sheet = get_widget_assert(xml, "variable_sheet");
84 select_sheet(PAGE_VAR_SHEET);
86 gtk_sheet_get_active_cell(GTK_SHEET(var_sheet),
87 ¤t_row, ¤t_column);
89 gtk_sheet_set_active_cell(GTK_SHEET(var_sheet), col, current_column);
95 /* Update the data_ref_entry with the reference of the active cell */
97 update_data_ref_entry(const GtkSheet *sheet, gint row, gint col)
100 /* The entry where the reference to the current cell is displayed */
101 GtkEntry *cell_ref_entry;
103 PsppireDataStore *data_store = PSPPIRE_DATA_STORE(gtk_sheet_get_model(sheet));
106 const struct PsppireVariable *pv =
107 psppire_dict_get_variable(data_store->dict, col);
115 text = g_strdup_printf("%d: %s", row,
116 pv ? psppire_variable_get_name(pv) : "");
118 cell_ref_entry = GTK_ENTRY(get_widget_assert(xml, "cell_ref_entry"));
120 s = pspp_locale_to_utf8(text, -1, 0);
124 gtk_entry_set_text(cell_ref_entry, s);
132 extern PsppireDataStore *data_store ;
135 /* Return the width that an 'M' character would occupy when typeset in WIDGET */
137 calc_m_width(GtkWidget *widget, const PangoFontDescription *font_desc)
140 PangoLayout *layout ;
141 PangoContext * context;
143 context = gtk_widget_create_pango_context (widget);
145 layout = pango_layout_new (context);
148 pango_layout_set_text (layout, "M", 1);
150 pango_layout_set_font_description (layout, font_desc);
152 pango_layout_get_extents (layout, NULL, &rect);
154 g_object_unref(G_OBJECT(layout));
155 g_object_unref(G_OBJECT(context));
157 return PANGO_PIXELS(rect.width);
163 font_change_callback(GObject *obj, gpointer data)
165 GtkWidget *sheet = data;
166 PsppireDataStore *ds = PSPPIRE_DATA_STORE(obj);
168 ds->width_of_m = calc_m_width(sheet, ds->font_desc);
172 psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2,
173 gint int1, gint int2)
177 sheet = gtk_sheet_new(G_SHEET_ROW(data_store),
178 G_SHEET_COLUMN(data_store), "data sheet", 0);
180 data_store->width_of_m = calc_m_width(sheet, data_store->font_desc);
182 g_signal_connect (G_OBJECT (sheet), "activate",
183 G_CALLBACK (update_data_ref_entry),
186 g_signal_connect (G_OBJECT (sheet), "traverse",
187 G_CALLBACK (traverse_callback), 0);
190 g_signal_connect (G_OBJECT (sheet), "double-click-column",
191 G_CALLBACK (click2column),
194 g_signal_connect (G_OBJECT (data_store), "font-changed",
195 G_CALLBACK (font_change_callback), sheet);
197 gtk_sheet_set_active_cell(GTK_SHEET(sheet), -1, -1);
198 gtk_widget_show(sheet);