1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2004, 2005, 2006 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include <glade/glade.h>
23 #include <gtksheet/gtksheet.h>
25 #include <gtksheet/gsheet-uniform-row.h>
27 #include "psppire-dict.h"
28 #include "psppire-data-store.h"
31 #include <data/value-labels.h>
32 #include <data/case.h>
33 #include <data/data-in.h>
35 #include "data-sheet.h"
39 traverse_callback (GtkSheet *sheet,
41 gint *new_row, gint *new_column
45 GtkWidget *entry = gtk_sheet_get_entry (sheet);
47 PsppireDataStore *data_store =
48 PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
50 g_assert (data_store);
52 n_vars = psppire_dict_get_var_cnt (data_store->dict);
54 n_cases = psppire_data_store_get_case_count (data_store);
56 g_object_set (entry, "editable", (*new_row < n_cases + 1), NULL);
58 if ( *new_column >= n_vars )
64 extern PsppireDataStore *the_data_store ;
67 /* Return the width that an 'M' character would occupy when typeset in WIDGET */
69 calc_m_width (GtkWidget *widget, const PangoFontDescription *font_desc)
73 PangoContext * context;
75 context = gtk_widget_create_pango_context (widget);
77 layout = pango_layout_new (context);
80 pango_layout_set_text (layout, "M", 1);
82 pango_layout_set_font_description (layout, font_desc);
84 pango_layout_get_extents (layout, NULL, &rect);
86 g_object_unref (G_OBJECT (layout));
87 g_object_unref (G_OBJECT (context));
89 return PANGO_PIXELS (rect.width);
95 font_change_callback (GObject *obj, gpointer data)
97 GtkWidget *sheet = data;
98 PsppireDataStore *ds = PSPPIRE_DATA_STORE (obj);
100 ds->width_of_m = calc_m_width (sheet, ds->font_desc);
105 G_MODULE_EXPORT GtkWidget*
106 psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2,
107 gint int1, gint int2)
111 sheet = gtk_sheet_new (G_SHEET_ROW (the_data_store),
112 G_SHEET_COLUMN (the_data_store), "data sheet", 0);
114 the_data_store->width_of_m = calc_m_width (sheet, the_data_store->font_desc);
116 g_signal_connect (G_OBJECT (sheet), "traverse",
117 G_CALLBACK (traverse_callback), 0);
120 g_signal_connect (G_OBJECT (the_data_store), "font-changed",
121 G_CALLBACK (font_change_callback), sheet);
123 gtk_sheet_set_active_cell (GTK_SHEET (sheet), -1, -1);
125 gtk_sheet_set_model (GTK_SHEET (sheet), G_SHEET_MODEL (the_data_store));
127 gtk_sheet_set_autoscroll (GTK_SHEET (sheet), TRUE);
129 gtk_widget_show (sheet);