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
47 PsppireDataStore *data_store =
48 PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
51 g_assert (data_store);
53 n_vars = psppire_dict_get_var_cnt (data_store->dict);
55 if ( *new_column >= n_vars )
58 case_count = psppire_case_file_get_case_count (data_store->case_file);
60 if ( *new_row >= case_count )
64 for ( i = case_count ; i <= *new_row; ++i )
65 psppire_data_store_insert_new_case (data_store, i);
73 extern PsppireDataStore *the_data_store ;
76 /* Return the width that an 'M' character would occupy when typeset in WIDGET */
78 calc_m_width (GtkWidget *widget, const PangoFontDescription *font_desc)
82 PangoContext * context;
84 context = gtk_widget_create_pango_context (widget);
86 layout = pango_layout_new (context);
89 pango_layout_set_text (layout, "M", 1);
91 pango_layout_set_font_description (layout, font_desc);
93 pango_layout_get_extents (layout, NULL, &rect);
95 g_object_unref (G_OBJECT (layout));
96 g_object_unref (G_OBJECT (context));
98 return PANGO_PIXELS (rect.width);
104 font_change_callback (GObject *obj, gpointer data)
106 GtkWidget *sheet = data;
107 PsppireDataStore *ds = PSPPIRE_DATA_STORE (obj);
109 ds->width_of_m = calc_m_width (sheet, ds->font_desc);
114 G_MODULE_EXPORT GtkWidget*
115 psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2,
116 gint int1, gint int2)
120 sheet = gtk_sheet_new (G_SHEET_ROW (the_data_store),
121 G_SHEET_COLUMN (the_data_store), "data sheet", 0);
123 the_data_store->width_of_m = calc_m_width (sheet, the_data_store->font_desc);
125 g_signal_connect (G_OBJECT (sheet), "traverse",
126 G_CALLBACK (traverse_callback), 0);
129 g_signal_connect (G_OBJECT (the_data_store), "font-changed",
130 G_CALLBACK (font_change_callback), sheet);
132 gtk_sheet_set_active_cell (GTK_SHEET (sheet), -1, -1);
134 gtk_sheet_set_model (GTK_SHEET (sheet), G_SHEET_MODEL (the_data_store));
136 gtk_sheet_set_autoscroll (GTK_SHEET (sheet), FALSE);
138 gtk_widget_show (sheet);