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
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-data-store.h"
35 #include <data/value-labels.h>
36 #include <data/case.h>
37 #include <data/data-in.h>
39 #include "data-sheet.h"
43 traverse_callback (GtkSheet * sheet,
45 gint *new_row, gint *new_column
51 PsppireDataStore *data_store =
52 PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
55 g_assert (data_store);
57 n_vars = psppire_dict_get_var_cnt (data_store->dict);
59 if ( *new_column >= n_vars )
62 case_count = psppire_case_file_get_case_count (data_store->case_file);
64 if ( *new_row >= case_count )
68 for ( i = case_count ; i <= *new_row; ++i )
69 psppire_data_store_insert_new_case (data_store, i);
79 /* Update the data_ref_entry with the reference of the active cell */
81 update_data_ref_entry (const GtkSheet *sheet, gint row, gint col)
84 GladeXML *data_editor_xml = NULL; /* FIXME !!!! */
87 /* The entry where the reference to the current cell is displayed */
88 GtkEntry *cell_ref_entry;
90 PsppireDataStore *data_store = PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
93 const struct variable *pv =
94 psppire_dict_get_variable (data_store->dict, col);
99 if ( !data_editor_xml)
102 text = g_strdup_printf ("%d: %s", row,
103 pv ? var_get_name (pv) : "");
105 cell_ref_entry = GTK_ENTRY (get_widget_assert (data_editor_xml,
108 s = pspp_locale_to_utf8 (text, -1, 0);
112 gtk_entry_set_text (cell_ref_entry, s);
120 extern PsppireDataStore *the_data_store ;
123 /* Return the width that an 'M' character would occupy when typeset in WIDGET */
125 calc_m_width (GtkWidget *widget, const PangoFontDescription *font_desc)
128 PangoLayout *layout ;
129 PangoContext * context;
131 context = gtk_widget_create_pango_context (widget);
133 layout = pango_layout_new (context);
136 pango_layout_set_text (layout, "M", 1);
138 pango_layout_set_font_description (layout, font_desc);
140 pango_layout_get_extents (layout, NULL, &rect);
142 g_object_unref (G_OBJECT (layout));
143 g_object_unref (G_OBJECT (context));
145 return PANGO_PIXELS (rect.width);
151 font_change_callback (GObject *obj, gpointer data)
153 GtkWidget *sheet = data;
154 PsppireDataStore *ds = PSPPIRE_DATA_STORE (obj);
156 ds->width_of_m = calc_m_width (sheet, ds->font_desc);
161 G_MODULE_EXPORT GtkWidget*
162 psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2,
163 gint int1, gint int2)
167 sheet = gtk_sheet_new (G_SHEET_ROW (the_data_store),
168 G_SHEET_COLUMN (the_data_store), "data sheet", 0);
170 the_data_store->width_of_m = calc_m_width (sheet, the_data_store->font_desc);
172 g_signal_connect (G_OBJECT (sheet), "activate",
173 G_CALLBACK (update_data_ref_entry),
176 g_signal_connect (G_OBJECT (sheet), "traverse",
177 G_CALLBACK (traverse_callback), 0);
180 g_signal_connect (G_OBJECT (the_data_store), "font-changed",
181 G_CALLBACK (font_change_callback), sheet);
183 gtk_sheet_set_active_cell (GTK_SHEET (sheet), -1, -1);
185 gtk_sheet_set_model (GTK_SHEET (sheet), G_SHEET_MODEL (the_data_store));
187 gtk_widget_show (sheet);