include format.h only where necessary.
[pspp-builds.git] / src / ui / gui / psppire-var-store.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2006  Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <gettext.h>
21 #define _(msgid) gettext (msgid)
22 #define N_(msgid) msgid
23
24
25
26 #include <gobject/gvaluecollector.h>
27
28 #include <gtksheet/gsheetmodel.h>
29
30 #include "psppire-var-store.h"
31 #include <gtksheet/gsheet-row-iface.h>
32 #include "helper.h"
33
34 #include <data/dictionary.h>
35 #include <data/variable.h>
36 #include <data/format.h>
37 #include <data/missing-values.h>
38
39 #include "val-labs-dialog.h"
40 #include "missing-val-dialog.h"
41 #include <data/value-labels.h>
42
43 #include "var-display.h"
44
45 enum
46   {
47     PSPPIRE_VAR_STORE_TRAILING_ROWS = 1,
48     PSPPIRE_VAR_STORE_FORMAT_TYPE
49   };
50
51 static void         psppire_var_store_init            (PsppireVarStore      *var_store);
52 static void         psppire_var_store_class_init      (PsppireVarStoreClass *class);
53 static void         psppire_var_store_sheet_model_init (GSheetModelIface *iface);
54 static void         psppire_var_store_finalize        (GObject           *object);
55
56
57 gchar * missing_values_to_string (const struct variable *pv, GError **err);
58
59
60 static gchar *psppire_var_store_get_string (const GSheetModel *sheet_model, glong row, glong column);
61
62 static gboolean  psppire_var_store_clear (GSheetModel *model,  glong row, glong col);
63
64
65 static gboolean psppire_var_store_set_string (GSheetModel *model,
66                                           const gchar *text, glong row, glong column);
67
68 static glong psppire_var_store_get_row_count (const GSheetModel * model);
69 static glong psppire_var_store_get_column_count (const GSheetModel * model);
70
71 static gchar *text_for_column (const struct variable *pv, gint c, GError **err);
72
73
74 static void psppire_var_store_sheet_row_init (GSheetRowIface *iface);
75
76
77
78 static GObjectClass *parent_class = NULL;
79
80 GType
81 psppire_var_store_format_type_get_type (void)
82 {
83   static GType etype = 0;
84   if (etype == 0)
85     {
86       static const GEnumValue values[] =
87         {
88           { PSPPIRE_VAR_STORE_INPUT_FORMATS,
89             "PSPPIRE_VAR_STORE_INPUT_FORMATS",
90             "input" },
91           { PSPPIRE_VAR_STORE_OUTPUT_FORMATS,
92             "PSPPIRE_VAR_STORE_OUTPUT_FORMATS",
93             "output" },
94           { 0, NULL, NULL }
95         };
96
97       etype = g_enum_register_static
98         (g_intern_static_string ("PsppireVarStoreFormatType"), values);
99
100     }
101   return etype;
102 }
103
104 GType
105 psppire_var_store_get_type (void)
106 {
107   static GType var_store_type = 0;
108
109   if (!var_store_type)
110     {
111       static const GTypeInfo var_store_info =
112       {
113         sizeof (PsppireVarStoreClass),
114         NULL,           /* base_init */
115         NULL,           /* base_finalize */
116         (GClassInitFunc) psppire_var_store_class_init,
117         NULL,           /* class_finalize */
118         NULL,           /* class_data */
119         sizeof (PsppireVarStore),
120         0,
121         (GInstanceInitFunc) psppire_var_store_init,
122       };
123
124       static const GInterfaceInfo sheet_model_info =
125       {
126         (GInterfaceInitFunc) psppire_var_store_sheet_model_init,
127         NULL,
128         NULL
129       };
130
131       static const GInterfaceInfo sheet_row_info =
132       {
133         (GInterfaceInitFunc) psppire_var_store_sheet_row_init,
134         NULL,
135         NULL
136       };
137
138       var_store_type = g_type_register_static (G_TYPE_OBJECT, "PsppireVarStore", &var_store_info, 0);
139
140       g_type_add_interface_static (var_store_type,
141                                    G_TYPE_SHEET_MODEL,
142                                    &sheet_model_info);
143
144       g_type_add_interface_static (var_store_type,
145                                    G_TYPE_SHEET_ROW,
146                                    &sheet_row_info);
147
148
149     }
150
151   return var_store_type;
152 }
153
154 static void
155 psppire_var_store_set_property (GObject      *object,
156                                 guint         property_id,
157                                 const GValue *value,
158                                 GParamSpec   *pspec)
159 {
160   PsppireVarStore *self = (PsppireVarStore *) object;
161
162   switch (property_id)
163     {
164     case PSPPIRE_VAR_STORE_TRAILING_ROWS:
165       self->trailing_rows = g_value_get_int (value);
166       break;
167
168     case PSPPIRE_VAR_STORE_FORMAT_TYPE:
169       self->format_type = g_value_get_enum (value);
170       break;
171
172     default:
173       G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
174       break;
175     }
176 }
177
178 static void
179 psppire_var_store_get_property (GObject      *object,
180                         guint         property_id,
181                         GValue       *value,
182                         GParamSpec   *pspec)
183 {
184   PsppireVarStore *self = (PsppireVarStore *) object;
185
186   switch (property_id)
187     {
188     case PSPPIRE_VAR_STORE_TRAILING_ROWS:
189       g_value_set_int (value, self->trailing_rows);
190       break;
191
192     case PSPPIRE_VAR_STORE_FORMAT_TYPE:
193       g_value_set_enum (value, self->format_type);
194       break;
195
196     default:
197       G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
198       break;
199     }
200 }
201
202
203 static void
204 psppire_var_store_class_init (PsppireVarStoreClass *class)
205 {
206   GObjectClass *object_class;
207   GParamSpec *pspec;
208
209   parent_class = g_type_class_peek_parent (class);
210   object_class = (GObjectClass*) class;
211
212   object_class->finalize = psppire_var_store_finalize;
213   object_class->set_property = psppire_var_store_set_property;
214   object_class->get_property = psppire_var_store_get_property;
215
216   /* The minimum value for trailing-rows is 1 to prevent the
217      var-store from ever having 0 rows, which breaks invariants
218      in gtksheet. */
219   pspec = g_param_spec_int ("trailing-rows",
220                             "Trailing rows",
221                             "Number of rows displayed after last variable",
222                             1  /* minimum value */,
223                             100 /* maximum value */,
224                             40  /* default value */,
225                             G_PARAM_READWRITE);
226   g_object_class_install_property (object_class,
227                                    PSPPIRE_VAR_STORE_TRAILING_ROWS,
228                                    pspec);
229
230   pspec = g_param_spec_enum ("format-type",
231                              "Variable format type",
232                              ("Whether variables have input or output "
233                               "formats"),
234                              G_TYPE_PSPPIRE_VAR_STORE_FORMAT_TYPE,
235                              PSPPIRE_VAR_STORE_OUTPUT_FORMATS,
236                              G_PARAM_READWRITE);
237   g_object_class_install_property (object_class,
238                                    PSPPIRE_VAR_STORE_FORMAT_TYPE,
239                                    pspec);
240 }
241
242 static void
243 psppire_var_store_init (PsppireVarStore *var_store)
244 {
245   GdkColormap *colormap = gdk_colormap_get_system ();
246
247   g_assert (gdk_color_parse ("gray", &var_store->disabled));
248
249   gdk_colormap_alloc_color (colormap, &var_store->disabled, FALSE, TRUE);
250
251   var_store->dict = 0;
252   var_store->trailing_rows = 40;
253   var_store->format_type = PSPPIRE_VAR_STORE_OUTPUT_FORMATS;
254 }
255
256 static gboolean
257 psppire_var_store_item_editable (PsppireVarStore *var_store, glong row, glong column)
258 {
259   const struct fmt_spec *write_spec ;
260
261   struct variable *pv = psppire_var_store_get_var (var_store, row);
262
263   if ( !pv )
264     return TRUE;
265
266   if ( var_is_alpha (pv) && column == PSPPIRE_VAR_STORE_COL_DECIMALS )
267     return FALSE;
268
269   write_spec = var_get_print_format (pv);
270
271   switch ( write_spec->type )
272     {
273     case FMT_DATE:
274     case FMT_EDATE:
275     case FMT_SDATE:
276     case FMT_ADATE:
277     case FMT_JDATE:
278     case FMT_QYR:
279     case FMT_MOYR:
280     case FMT_WKYR:
281     case FMT_DATETIME:
282     case FMT_TIME:
283     case FMT_DTIME:
284     case FMT_WKDAY:
285     case FMT_MONTH:
286       if ( column == PSPPIRE_VAR_STORE_COL_DECIMALS || column == PSPPIRE_VAR_STORE_COL_WIDTH)
287         return FALSE;
288       break;
289     default:
290       break;
291     }
292
293   return TRUE;
294 }
295
296
297 struct variable *
298 psppire_var_store_get_var (PsppireVarStore *store, glong row)
299 {
300   return psppire_dict_get_variable (store->dict, row);
301 }
302
303 static gboolean
304 psppire_var_store_is_editable (const GSheetModel *model, glong row, glong column)
305 {
306   PsppireVarStore *store = PSPPIRE_VAR_STORE (model);
307   return psppire_var_store_item_editable (store, row, column);
308 }
309
310
311 static const GdkColor *
312 psppire_var_store_get_foreground (const GSheetModel *model, glong row, glong column)
313 {
314   PsppireVarStore *store = PSPPIRE_VAR_STORE (model);
315
316   if ( ! psppire_var_store_item_editable (store, row, column) )
317     return &store->disabled;
318
319   return NULL;
320 }
321
322
323 const PangoFontDescription *
324 psppire_var_store_get_font_desc (const GSheetModel *model,
325                               glong row, glong column)
326 {
327   PsppireVarStore *store = PSPPIRE_VAR_STORE (model);
328
329   return store->font_desc;
330 }
331
332
333
334
335 static void
336 psppire_var_store_sheet_model_init (GSheetModelIface *iface)
337 {
338   iface->get_row_count = psppire_var_store_get_row_count;
339   iface->get_column_count = psppire_var_store_get_column_count;
340   iface->free_strings = TRUE;
341   iface->get_string = psppire_var_store_get_string;
342   iface->set_string = psppire_var_store_set_string;
343   iface->clear_datum = psppire_var_store_clear;
344   iface->is_editable = psppire_var_store_is_editable;
345   iface->is_visible = NULL;
346   iface->get_foreground = psppire_var_store_get_foreground;
347   iface->get_background = NULL;
348   iface->get_font_desc = psppire_var_store_get_font_desc;
349   iface->get_cell_border = NULL;
350 }
351
352
353
354 /**
355  * psppire_var_store_new:
356  * @dict: The dictionary for this var_store.
357  *
358  *
359  * Return value: a new #PsppireVarStore
360  **/
361 PsppireVarStore *
362 psppire_var_store_new (PsppireDict *dict)
363 {
364   PsppireVarStore *retval;
365
366   retval = g_object_new (GTK_TYPE_VAR_STORE, NULL);
367
368   psppire_var_store_set_dictionary (retval, dict);
369
370   return retval;
371 }
372
373 static void
374 var_change_callback (GtkWidget *w, gint n, gpointer data)
375 {
376   GSheetModel *model = G_SHEET_MODEL (data);
377
378   g_sheet_model_range_changed (model,
379                                  n, 0, n, PSPPIRE_VAR_STORE_n_COLS);
380 }
381
382
383 static void
384 var_delete_callback (GtkWidget *w, gint dict_idx, gint case_idx, gint val_cnt, gpointer data)
385 {
386   GSheetModel *model = G_SHEET_MODEL (data);
387
388   g_sheet_model_rows_deleted (model, dict_idx, 1);
389 }
390
391
392
393 static void
394 var_insert_callback (GtkWidget *w, glong row, gpointer data)
395 {
396   GSheetModel *model = G_SHEET_MODEL (data);
397
398   g_sheet_model_rows_inserted (model, row, 1);
399 }
400
401 static void
402 refresh (PsppireDict  *d, gpointer data)
403 {
404   PsppireVarStore *vs = data;
405
406   g_sheet_model_range_changed (G_SHEET_MODEL (vs), -1, -1, -1, -1);
407 }
408
409 /**
410  * psppire_var_store_replace_set_dictionary:
411  * @var_store: The variable store
412  * @dict: The dictionary to set
413  *
414  * If a dictionary is already associated with the var-store, then it will be
415  * destroyed.
416  **/
417 void
418 psppire_var_store_set_dictionary (PsppireVarStore *var_store, PsppireDict *dict)
419 {
420   if ( var_store->dict ) g_object_unref (var_store->dict);
421
422   var_store->dict = dict;
423
424   g_signal_connect (dict, "variable-changed", G_CALLBACK (var_change_callback),
425                    var_store);
426
427   g_signal_connect (dict, "variable-deleted", G_CALLBACK (var_delete_callback),
428                    var_store);
429
430   g_signal_connect (dict, "variable-inserted",
431                     G_CALLBACK (var_insert_callback), var_store);
432
433   g_signal_connect (dict, "backend-changed", G_CALLBACK (refresh),
434                     var_store);
435
436   /* The entire model has changed */
437   g_sheet_model_range_changed (G_SHEET_MODEL (var_store), -1, -1, -1, -1);
438 }
439
440 static void
441 psppire_var_store_finalize (GObject *object)
442 {
443   /* must chain up */
444   (* parent_class->finalize) (object);
445 }
446
447 static gchar *
448 psppire_var_store_get_string (const GSheetModel *model, glong row, glong column)
449 {
450   PsppireVarStore *store = PSPPIRE_VAR_STORE (model);
451
452   struct variable *pv;
453
454   if ( row >= psppire_dict_get_var_cnt (store->dict))
455     return 0;
456
457   pv = psppire_dict_get_variable (store->dict, row);
458
459   return text_for_column (pv, column, 0);
460 }
461
462
463 /* Clears that part of the variable store, if possible, which corresponds
464    to ROW, COL.
465    Returns true if anything was updated, false otherwise.
466 */
467 static gboolean
468 psppire_var_store_clear (GSheetModel *model,  glong row, glong col)
469 {
470   struct variable *pv ;
471
472   PsppireVarStore *var_store = PSPPIRE_VAR_STORE (model);
473
474   if ( row >= psppire_dict_get_var_cnt (var_store->dict))
475       return FALSE;
476
477   pv = psppire_var_store_get_var (var_store, row);
478
479   if ( !pv )
480     return FALSE;
481
482   switch (col)
483     {
484     case PSPPIRE_VAR_STORE_COL_LABEL:
485       var_set_label (pv, 0);
486       return TRUE;
487       break;
488     }
489
490   return FALSE;
491 }
492
493 /* Attempts to update that part of the variable store which corresponds
494    to ROW, COL with  the value TEXT.
495    Returns true if anything was updated, false otherwise.
496 */
497 static gboolean
498 psppire_var_store_set_string (GSheetModel *model,
499                           const gchar *text, glong row, glong col)
500 {
501   struct variable *pv ;
502
503   PsppireVarStore *var_store = PSPPIRE_VAR_STORE (model);
504
505   if ( row >= psppire_dict_get_var_cnt (var_store->dict))
506       return FALSE;
507
508   pv = psppire_var_store_get_var (var_store, row);
509
510   if ( !pv )
511     return FALSE;
512
513   switch (col)
514     {
515     case PSPPIRE_VAR_STORE_COL_NAME:
516       return psppire_dict_rename_var (var_store->dict, pv, text);
517       break;
518     case PSPPIRE_VAR_STORE_COL_COLUMNS:
519       if ( ! text) return FALSE;
520       var_set_display_width (pv, atoi (text));
521       return TRUE;
522       break;
523     case PSPPIRE_VAR_STORE_COL_WIDTH:
524       {
525         int width = atoi (text);
526         if ( ! text) return FALSE;
527         if ( var_is_alpha (pv))
528             var_set_width (pv, width);
529         else
530           {
531             bool for_input
532               = var_store->format_type == PSPPIRE_VAR_STORE_INPUT_FORMATS;
533             struct fmt_spec fmt ;
534             fmt = *var_get_write_format (pv);
535             if ( width < fmt_min_width (fmt.type, for_input)
536                  ||
537                  width > fmt_max_width (fmt.type, for_input))
538               return FALSE;
539
540             fmt.w = width;
541             fmt.d = MIN (fmt_max_decimals (fmt.type, width, for_input), fmt.d);
542
543             var_set_both_formats (pv, &fmt);
544           }
545
546         return TRUE;
547       }
548       break;
549     case PSPPIRE_VAR_STORE_COL_DECIMALS:
550       {
551         bool for_input
552           = var_store->format_type == PSPPIRE_VAR_STORE_INPUT_FORMATS;
553         int decimals;
554         struct fmt_spec fmt;
555         if ( ! text) return FALSE;
556         decimals = atoi (text);
557         fmt = *var_get_write_format (pv);
558         if ( decimals >
559              fmt_max_decimals (fmt.type,
560                                fmt.w,
561                                for_input
562                                ))
563           return FALSE;
564
565         fmt.d = decimals;
566         var_set_both_formats (pv, &fmt);
567         return TRUE;
568       }
569       break;
570     case PSPPIRE_VAR_STORE_COL_LABEL:
571       var_set_label (pv, text);
572       return TRUE;
573       break;
574     case PSPPIRE_VAR_STORE_COL_TYPE:
575     case PSPPIRE_VAR_STORE_COL_VALUES:
576     case PSPPIRE_VAR_STORE_COL_MISSING:
577     case PSPPIRE_VAR_STORE_COL_ALIGN:
578     case PSPPIRE_VAR_STORE_COL_MEASURE:
579       /* These can be modified only by their respective dialog boxes */
580       return FALSE;
581       break;
582     default:
583       g_assert_not_reached ();
584       return FALSE;
585     }
586
587   return TRUE;
588 }
589
590
591 const static gchar none[] = N_("None");
592
593 static  gchar *
594 text_for_column (const struct variable *pv, gint c, GError **err)
595 {
596   static const gchar *const type_label[] =
597     {
598       N_("Numeric"),
599       N_("Comma"),
600       N_("Dot"),
601       N_("Scientific"),
602       N_("Date"),
603       N_("Dollar"),
604       N_("Custom"),
605       N_("String")
606     };
607   enum {VT_NUMERIC, VT_COMMA, VT_DOT, VT_SCIENTIFIC, VT_DATE, VT_DOLLAR,
608         VT_CUSTOM, VT_STRING};
609
610   const struct fmt_spec *write_spec = var_get_write_format (pv);
611
612   switch (c)
613     {
614     case PSPPIRE_VAR_STORE_COL_NAME:
615       return pspp_locale_to_utf8 ( var_get_name (pv), -1, err);
616       break;
617     case PSPPIRE_VAR_STORE_COL_TYPE:
618       {
619         switch ( write_spec->type )
620           {
621           case FMT_F:
622             return g_locale_to_utf8 (gettext (type_label[VT_NUMERIC]), -1, 0, 0, err);
623             break;
624           case FMT_COMMA:
625             return g_locale_to_utf8 (gettext (type_label[VT_COMMA]), -1, 0, 0, err);
626             break;
627           case FMT_DOT:
628             return g_locale_to_utf8 (gettext (type_label[VT_DOT]), -1, 0, 0, err);
629             break;
630           case FMT_E:
631             return g_locale_to_utf8 (gettext (type_label[VT_SCIENTIFIC]), -1, 0, 0, err);
632             break;
633           case FMT_DATE:
634           case FMT_EDATE:
635           case FMT_SDATE:
636           case FMT_ADATE:
637           case FMT_JDATE:
638           case FMT_QYR:
639           case FMT_MOYR:
640           case FMT_WKYR:
641           case FMT_DATETIME:
642           case FMT_TIME:
643           case FMT_DTIME:
644           case FMT_WKDAY:
645           case FMT_MONTH:
646             return g_locale_to_utf8 (type_label[VT_DATE], -1, 0, 0, err);
647             break;
648           case FMT_DOLLAR:
649             return g_locale_to_utf8 (type_label[VT_DOLLAR], -1, 0, 0, err);
650             break;
651           case FMT_CCA:
652           case FMT_CCB:
653           case FMT_CCC:
654           case FMT_CCD:
655           case FMT_CCE:
656             return g_locale_to_utf8 (gettext (type_label[VT_CUSTOM]), -1, 0, 0, err);
657             break;
658           case FMT_A:
659             return g_locale_to_utf8 (gettext (type_label[VT_STRING]), -1, 0, 0, err);
660             break;
661           default:
662             {
663               char str[FMT_STRING_LEN_MAX + 1];
664               g_warning ("Unknown format: \"%s\"\n",
665                         fmt_to_string (write_spec, str));
666             }
667             break;
668           }
669       }
670       break;
671     case PSPPIRE_VAR_STORE_COL_WIDTH:
672       {
673         gchar *s;
674         GString *gstr = g_string_sized_new (10);
675         g_string_printf (gstr, _("%d"), write_spec->w);
676         s = g_locale_to_utf8 (gstr->str, gstr->len, 0, 0, err);
677         g_string_free (gstr, TRUE);
678         return s;
679       }
680       break;
681     case PSPPIRE_VAR_STORE_COL_DECIMALS:
682       {
683         gchar *s;
684         GString *gstr = g_string_sized_new (10);
685         g_string_printf (gstr, _("%d"), write_spec->d);
686         s = g_locale_to_utf8 (gstr->str, gstr->len, 0, 0, err);
687         g_string_free (gstr, TRUE);
688         return s;
689       }
690       break;
691     case PSPPIRE_VAR_STORE_COL_COLUMNS:
692       {
693         gchar *s;
694         GString *gstr = g_string_sized_new (10);
695         g_string_printf (gstr, _("%d"), var_get_display_width (pv));
696         s = g_locale_to_utf8 (gstr->str, gstr->len, 0, 0, err);
697         g_string_free (gstr, TRUE);
698         return s;
699       }
700       break;
701     case PSPPIRE_VAR_STORE_COL_LABEL:
702       return pspp_locale_to_utf8 (var_get_label (pv), -1, err);
703       break;
704
705     case PSPPIRE_VAR_STORE_COL_MISSING:
706       {
707         return missing_values_to_string (pv, err);
708       }
709       break;
710     case PSPPIRE_VAR_STORE_COL_VALUES:
711       {
712         if ( ! var_has_value_labels (pv))
713           return g_locale_to_utf8 (gettext (none), -1, 0, 0, err);
714         else
715           {
716             gchar *ss;
717             GString *gstr = g_string_sized_new (10);
718             const struct val_labs *vls = var_get_value_labels (pv);
719             struct val_labs_iterator *ip = 0;
720             struct val_lab *vl = val_labs_first_sorted (vls, &ip);
721
722             g_assert (vl);
723
724             {
725               gchar *const vstr = value_to_text (vl->value, *write_spec);
726
727               g_string_printf (gstr, "{%s,\"%s\"}_", vstr, vl->label);
728               g_free (vstr);
729             }
730
731             val_labs_done (&ip);
732
733             ss = pspp_locale_to_utf8 (gstr->str, gstr->len, err);
734             g_string_free (gstr, TRUE);
735             return ss;
736           }
737       }
738       break;
739     case PSPPIRE_VAR_STORE_COL_ALIGN:
740       {
741         const gint align = var_get_alignment (pv);
742
743         g_assert (align < n_ALIGNMENTS);
744         return g_locale_to_utf8 (gettext (alignments[align]), -1, 0, 0, err);
745       }
746       break;
747     case PSPPIRE_VAR_STORE_COL_MEASURE:
748       {
749         return measure_to_string (pv, err);
750       }
751       break;
752     }
753   return 0;
754 }
755
756
757
758 /* Return the number of variables */
759 gint
760 psppire_var_store_get_var_cnt (PsppireVarStore  *store)
761 {
762   return psppire_dict_get_var_cnt (store->dict);
763 }
764
765
766 void
767 psppire_var_store_set_font (PsppireVarStore *store, const PangoFontDescription *fd)
768 {
769   g_return_if_fail (store);
770   g_return_if_fail (PSPPIRE_IS_VAR_STORE (store));
771
772   store->font_desc = fd;
773
774   g_sheet_model_range_changed (G_SHEET_MODEL (store), -1, -1, -1, -1);
775 }
776
777
778 static glong
779 psppire_var_store_get_row_count (const GSheetModel * model)
780 {
781   gint rows = 0;
782   PsppireVarStore *vs = PSPPIRE_VAR_STORE (model);
783
784   if (vs->dict)
785     rows =  psppire_dict_get_var_cnt (vs->dict);
786
787   return rows ;
788 }
789
790 static glong
791 psppire_var_store_get_column_count (const GSheetModel * model)
792 {
793   return PSPPIRE_VAR_STORE_n_COLS ;
794 }
795
796
797 /* Row related funcs */
798
799 static glong
800 geometry_get_row_count (const GSheetRow *geom)
801 {
802   gint rows = 0;
803   PsppireVarStore *vs = PSPPIRE_VAR_STORE (geom);
804
805   if (vs->dict)
806     rows =  psppire_dict_get_var_cnt (vs->dict);
807
808   return rows + vs->trailing_rows;
809 }
810
811
812 static gint
813 geometry_get_height (const GSheetRow *geom, glong row)
814 {
815   return 25;
816 }
817
818
819 static gboolean
820 geometry_is_sensitive (const GSheetRow *geom, glong row)
821 {
822   PsppireVarStore *vs = PSPPIRE_VAR_STORE (geom);
823
824   if ( ! vs->dict)
825     return FALSE;
826
827   return  row < psppire_dict_get_var_cnt (vs->dict);
828 }
829
830 static
831 gboolean always_true ()
832 {
833   return TRUE;
834 }
835
836
837 static gchar *
838 geometry_get_button_label (const GSheetRow *geom, glong unit)
839 {
840   gchar *label = g_strdup_printf (_("%ld"), unit + 1);
841
842   return label;
843 }
844
845 static void
846 psppire_var_store_sheet_row_init (GSheetRowIface *iface)
847 {
848   iface->get_row_count =     geometry_get_row_count;
849   iface->get_height =        geometry_get_height;
850   iface->set_height =        0;
851   iface->get_visibility =    always_true;
852   iface->get_sensitivity =   geometry_is_sensitive;
853
854   iface->get_button_label = geometry_get_button_label;
855 }
856
857
858