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);
77 extern PsppireDataStore *the_data_store ;
80 /* Return the width that an 'M' character would occupy when typeset in WIDGET */
82 calc_m_width (GtkWidget *widget, const PangoFontDescription *font_desc)
86 PangoContext * context;
88 context = gtk_widget_create_pango_context (widget);
90 layout = pango_layout_new (context);
93 pango_layout_set_text (layout, "M", 1);
95 pango_layout_set_font_description (layout, font_desc);
97 pango_layout_get_extents (layout, NULL, &rect);
99 g_object_unref (G_OBJECT (layout));
100 g_object_unref (G_OBJECT (context));
102 return PANGO_PIXELS (rect.width);
108 font_change_callback (GObject *obj, gpointer data)
110 GtkWidget *sheet = data;
111 PsppireDataStore *ds = PSPPIRE_DATA_STORE (obj);
113 ds->width_of_m = calc_m_width (sheet, ds->font_desc);
118 G_MODULE_EXPORT GtkWidget*
119 psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2,
120 gint int1, gint int2)
124 sheet = gtk_sheet_new (G_SHEET_ROW (the_data_store),
125 G_SHEET_COLUMN (the_data_store), "data sheet", 0);
127 the_data_store->width_of_m = calc_m_width (sheet, the_data_store->font_desc);
129 g_signal_connect (G_OBJECT (sheet), "traverse",
130 G_CALLBACK (traverse_callback), 0);
133 g_signal_connect (G_OBJECT (the_data_store), "font-changed",
134 G_CALLBACK (font_change_callback), sheet);
136 gtk_sheet_set_active_cell (GTK_SHEET (sheet), -1, -1);
138 gtk_sheet_set_model (GTK_SHEET (sheet), G_SHEET_MODEL (the_data_store));
140 gtk_widget_show (sheet);