Made everything except gtkitementry.c multi-head safe
[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 #define DISABLED_COLOR "pink"
243 static void
244 psppire_var_store_init (PsppireVarStore *var_store)
245 {
246   if ( ! gdk_color_parse (DISABLED_COLOR, &var_store->disabled))
247         g_critical ("Could not parse color \"%s\"", DISABLED_COLOR);
248
249   var_store->dict = 0;
250   var_store->trailing_rows = 40;
251   var_store->format_type = PSPPIRE_VAR_STORE_OUTPUT_FORMATS;
252 }
253
254 static gboolean
255 psppire_var_store_item_editable (PsppireVarStore *var_store, glong row, glong column)
256 {
257   const struct fmt_spec *write_spec ;
258
259   struct variable *pv = psppire_var_store_get_var (var_store, row);
260
261   if ( !pv )
262     return TRUE;
263
264   if ( var_is_alpha (pv) && column == PSPPIRE_VAR_STORE_COL_DECIMALS )
265     return FALSE;
266
267   write_spec = var_get_print_format (pv);
268
269   switch ( write_spec->type )
270     {
271     case FMT_DATE:
272     case FMT_EDATE:
273     case FMT_SDATE:
274     case FMT_ADATE:
275     case FMT_JDATE:
276     case FMT_QYR:
277     case FMT_MOYR:
278     case FMT_WKYR:
279     case FMT_DATETIME:
280     case FMT_TIME:
281     case FMT_DTIME:
282     case FMT_WKDAY:
283     case FMT_MONTH:
284       if ( column == PSPPIRE_VAR_STORE_COL_DECIMALS || column == PSPPIRE_VAR_STORE_COL_WIDTH)
285         return FALSE;
286       break;
287     default:
288       break;
289     }
290
291   return TRUE;
292 }
293
294
295 struct variable *
296 psppire_var_store_get_var (PsppireVarStore *store, glong row)
297 {
298   return psppire_dict_get_variable (store->dict, row);
299 }
300
301 static gboolean
302 psppire_var_store_is_editable (const GSheetModel *model, glong row, glong column)
303 {
304   PsppireVarStore *store = PSPPIRE_VAR_STORE (model);
305   return psppire_var_store_item_editable (store, row, column);
306 }
307
308
309 static const GdkColor *
310 psppire_var_store_get_foreground (const GSheetModel *model, glong row, glong column)
311 {
312   PsppireVarStore *store = PSPPIRE_VAR_STORE (model);
313
314   if ( ! psppire_var_store_item_editable (store, row, column) )
315     return &store->disabled;
316
317   return NULL;
318 }
319
320
321 const PangoFontDescription *
322 psppire_var_store_get_font_desc (const GSheetModel *model,
323                               glong row, glong column)
324 {
325   PsppireVarStore *store = PSPPIRE_VAR_STORE (model);
326
327   return store->font_desc;
328 }
329
330
331
332
333 static void
334 psppire_var_store_sheet_model_init (GSheetModelIface *iface)
335 {
336   iface->get_row_count = psppire_var_store_get_row_count;
337   iface->get_column_count = psppire_var_store_get_column_count;
338   iface->free_strings = TRUE;
339   iface->get_string = psppire_var_store_get_string;
340   iface->set_string = psppire_var_store_set_string;
341   iface->clear_datum = psppire_var_store_clear;
342   iface->is_editable = psppire_var_store_is_editable;
343   iface->is_visible = NULL;
344   iface->get_foreground = psppire_var_store_get_foreground;
345   iface->get_background = NULL;
346   iface->get_font_desc = psppire_var_store_get_font_desc;
347   iface->get_cell_border = NULL;
348 }
349
350
351
352 /**
353  * psppire_var_store_new:
354  * @dict: The dictionary for this var_store.
355  *
356  *
357  * Return value: a new #PsppireVarStore
358  **/
359 PsppireVarStore *
360 psppire_var_store_new (PsppireDict *dict)
361 {
362   PsppireVarStore *retval;
363
364   retval = g_object_new (GTK_TYPE_VAR_STORE, NULL);
365
366   psppire_var_store_set_dictionary (retval, dict);
367
368   return retval;
369 }
370
371 static void
372 var_change_callback (GtkWidget *w, gint n, gpointer data)
373 {
374   GSheetModel *model = G_SHEET_MODEL (data);
375
376   g_sheet_model_range_changed (model,
377                                  n, 0, n, PSPPIRE_VAR_STORE_n_COLS);
378 }
379
380
381 static void
382 var_delete_callback (GtkWidget *w, gint dict_idx, gint case_idx, gint val_cnt, gpointer data)
383 {
384   GSheetModel *model = G_SHEET_MODEL (data);
385
386   g_sheet_model_rows_deleted (model, dict_idx, 1);
387 }
388
389
390
391 static void
392 var_insert_callback (GtkWidget *w, glong row, gpointer data)
393 {
394   GSheetModel *model = G_SHEET_MODEL (data);
395
396   g_sheet_model_rows_inserted (model, row, 1);
397 }
398
399 static void
400 refresh (PsppireDict  *d, gpointer data)
401 {
402   PsppireVarStore *vs = data;
403
404   g_sheet_model_range_changed (G_SHEET_MODEL (vs), -1, -1, -1, -1);
405 }
406
407 /**
408  * psppire_var_store_replace_set_dictionary:
409  * @var_store: The variable store
410  * @dict: The dictionary to set
411  *
412  * If a dictionary is already associated with the var-store, then it will be
413  * destroyed.
414  **/
415 void
416 psppire_var_store_set_dictionary (PsppireVarStore *var_store, PsppireDict *dict)
417 {
418   if ( var_store->dict ) g_object_unref (var_store->dict);
419
420   var_store->dict = dict;
421
422   g_signal_connect (dict, "variable-changed", G_CALLBACK (var_change_callback),
423                    var_store);
424
425   g_signal_connect (dict, "variable-deleted", G_CALLBACK (var_delete_callback),
426                    var_store);
427
428   g_signal_connect (dict, "variable-inserted",
429                     G_CALLBACK (var_insert_callback), var_store);
430
431   g_signal_connect (dict, "backend-changed", G_CALLBACK (refresh),
432                     var_store);
433
434   /* The entire model has changed */
435   g_sheet_model_range_changed (G_SHEET_MODEL (var_store), -1, -1, -1, -1);
436 }
437
438 static void
439 psppire_var_store_finalize (GObject *object)
440 {
441   /* must chain up */
442   (* parent_class->finalize) (object);
443 }
444
445 static gchar *
446 psppire_var_store_get_string (const GSheetModel *model, glong row, glong column)
447 {
448   PsppireVarStore *store = PSPPIRE_VAR_STORE (model);
449
450   struct variable *pv;
451
452   if ( row >= psppire_dict_get_var_cnt (store->dict))
453     return 0;
454
455   pv = psppire_dict_get_variable (store->dict, row);
456
457   return text_for_column (pv, column, 0);
458 }
459
460
461 /* Clears that part of the variable store, if possible, which corresponds
462    to ROW, COL.
463    Returns true if anything was updated, false otherwise.
464 */
465 static gboolean
466 psppire_var_store_clear (GSheetModel *model,  glong row, glong col)
467 {
468   struct variable *pv ;
469
470   PsppireVarStore *var_store = PSPPIRE_VAR_STORE (model);
471
472   if ( row >= psppire_dict_get_var_cnt (var_store->dict))
473       return FALSE;
474
475   pv = psppire_var_store_get_var (var_store, row);
476
477   if ( !pv )
478     return FALSE;
479
480   switch (col)
481     {
482     case PSPPIRE_VAR_STORE_COL_LABEL:
483       var_set_label (pv, 0);
484       return TRUE;
485       break;
486     }
487
488   return FALSE;
489 }
490
491 /* Attempts to update that part of the variable store which corresponds
492    to ROW, COL with  the value TEXT.
493    Returns true if anything was updated, false otherwise.
494 */
495 static gboolean
496 psppire_var_store_set_string (GSheetModel *model,
497                           const gchar *text, glong row, glong col)
498 {
499   struct variable *pv ;
500
501   PsppireVarStore *var_store = PSPPIRE_VAR_STORE (model);
502
503   if ( row >= psppire_dict_get_var_cnt (var_store->dict))
504       return FALSE;
505
506   pv = psppire_var_store_get_var (var_store, row);
507
508   if ( !pv )
509     return FALSE;
510
511   switch (col)
512     {
513     case PSPPIRE_VAR_STORE_COL_NAME:
514       return psppire_dict_rename_var (var_store->dict, pv, text);
515       break;
516     case PSPPIRE_VAR_STORE_COL_COLUMNS:
517       if ( ! text) return FALSE;
518       var_set_display_width (pv, atoi (text));
519       return TRUE;
520       break;
521     case PSPPIRE_VAR_STORE_COL_WIDTH:
522       {
523         int width = atoi (text);
524         if ( ! text) return FALSE;
525         if ( var_is_alpha (pv))
526             var_set_width (pv, width);
527         else
528           {
529             bool for_input
530               = var_store->format_type == PSPPIRE_VAR_STORE_INPUT_FORMATS;
531             struct fmt_spec fmt ;
532             fmt = *var_get_write_format (pv);
533             if ( width < fmt_min_width (fmt.type, for_input)
534                  ||
535                  width > fmt_max_width (fmt.type, for_input))
536               return FALSE;
537
538             fmt.w = width;
539             fmt.d = MIN (fmt_max_decimals (fmt.type, width, for_input), fmt.d);
540
541             var_set_both_formats (pv, &fmt);
542           }
543
544         return TRUE;
545       }
546       break;
547     case PSPPIRE_VAR_STORE_COL_DECIMALS:
548       {
549         bool for_input
550           = var_store->format_type == PSPPIRE_VAR_STORE_INPUT_FORMATS;
551         int decimals;
552         struct fmt_spec fmt;
553         if ( ! text) return FALSE;
554         decimals = atoi (text);
555         fmt = *var_get_write_format (pv);
556         if ( decimals >
557              fmt_max_decimals (fmt.type,
558                                fmt.w,
559                                for_input
560                                ))
561           return FALSE;
562
563         fmt.d = decimals;
564         var_set_both_formats (pv, &fmt);
565         return TRUE;
566       }
567       break;
568     case PSPPIRE_VAR_STORE_COL_LABEL:
569       var_set_label (pv, text);
570       return TRUE;
571       break;
572     case PSPPIRE_VAR_STORE_COL_TYPE:
573     case PSPPIRE_VAR_STORE_COL_VALUES:
574     case PSPPIRE_VAR_STORE_COL_MISSING:
575     case PSPPIRE_VAR_STORE_COL_ALIGN:
576     case PSPPIRE_VAR_STORE_COL_MEASURE:
577       /* These can be modified only by their respective dialog boxes */
578       return FALSE;
579       break;
580     default:
581       g_assert_not_reached ();
582       return FALSE;
583     }
584
585   return TRUE;
586 }
587
588
589 const static gchar none[] = N_("None");
590
591 static  gchar *
592 text_for_column (const struct variable *pv, gint c, GError **err)
593 {
594   static const gchar *const type_label[] =
595     {
596       N_("Numeric"),
597       N_("Comma"),
598       N_("Dot"),
599       N_("Scientific"),
600       N_("Date"),
601       N_("Dollar"),
602       N_("Custom"),
603       N_("String")
604     };
605   enum {VT_NUMERIC, VT_COMMA, VT_DOT, VT_SCIENTIFIC, VT_DATE, VT_DOLLAR,
606         VT_CUSTOM, VT_STRING};
607
608   const struct fmt_spec *write_spec = var_get_write_format (pv);
609
610   switch (c)
611     {
612     case PSPPIRE_VAR_STORE_COL_NAME:
613       return pspp_locale_to_utf8 ( var_get_name (pv), -1, err);
614       break;
615     case PSPPIRE_VAR_STORE_COL_TYPE:
616       {
617         switch ( write_spec->type )
618           {
619           case FMT_F:
620             return g_locale_to_utf8 (gettext (type_label[VT_NUMERIC]), -1, 0, 0, err);
621             break;
622           case FMT_COMMA:
623             return g_locale_to_utf8 (gettext (type_label[VT_COMMA]), -1, 0, 0, err);
624             break;
625           case FMT_DOT:
626             return g_locale_to_utf8 (gettext (type_label[VT_DOT]), -1, 0, 0, err);
627             break;
628           case FMT_E:
629             return g_locale_to_utf8 (gettext (type_label[VT_SCIENTIFIC]), -1, 0, 0, err);
630             break;
631           case FMT_DATE:
632           case FMT_EDATE:
633           case FMT_SDATE:
634           case FMT_ADATE:
635           case FMT_JDATE:
636           case FMT_QYR:
637           case FMT_MOYR:
638           case FMT_WKYR:
639           case FMT_DATETIME:
640           case FMT_TIME:
641           case FMT_DTIME:
642           case FMT_WKDAY:
643           case FMT_MONTH:
644             return g_locale_to_utf8 (type_label[VT_DATE], -1, 0, 0, err);
645             break;
646           case FMT_DOLLAR:
647             return g_locale_to_utf8 (type_label[VT_DOLLAR], -1, 0, 0, err);
648             break;
649           case FMT_CCA:
650           case FMT_CCB:
651           case FMT_CCC:
652           case FMT_CCD:
653           case FMT_CCE:
654             return g_locale_to_utf8 (gettext (type_label[VT_CUSTOM]), -1, 0, 0, err);
655             break;
656           case FMT_A:
657             return g_locale_to_utf8 (gettext (type_label[VT_STRING]), -1, 0, 0, err);
658             break;
659           default:
660             {
661               char str[FMT_STRING_LEN_MAX + 1];
662               g_warning ("Unknown format: \"%s\"\n",
663                         fmt_to_string (write_spec, str));
664             }
665             break;
666           }
667       }
668       break;
669     case PSPPIRE_VAR_STORE_COL_WIDTH:
670       {
671         gchar *s;
672         GString *gstr = g_string_sized_new (10);
673         g_string_printf (gstr, _("%d"), write_spec->w);
674         s = g_locale_to_utf8 (gstr->str, gstr->len, 0, 0, err);
675         g_string_free (gstr, TRUE);
676         return s;
677       }
678       break;
679     case PSPPIRE_VAR_STORE_COL_DECIMALS:
680       {
681         gchar *s;
682         GString *gstr = g_string_sized_new (10);
683         g_string_printf (gstr, _("%d"), write_spec->d);
684         s = g_locale_to_utf8 (gstr->str, gstr->len, 0, 0, err);
685         g_string_free (gstr, TRUE);
686         return s;
687       }
688       break;
689     case PSPPIRE_VAR_STORE_COL_COLUMNS:
690       {
691         gchar *s;
692         GString *gstr = g_string_sized_new (10);
693         g_string_printf (gstr, _("%d"), var_get_display_width (pv));
694         s = g_locale_to_utf8 (gstr->str, gstr->len, 0, 0, err);
695         g_string_free (gstr, TRUE);
696         return s;
697       }
698       break;
699     case PSPPIRE_VAR_STORE_COL_LABEL:
700       return pspp_locale_to_utf8 (var_get_label (pv), -1, err);
701       break;
702
703     case PSPPIRE_VAR_STORE_COL_MISSING:
704       {
705         return missing_values_to_string (pv, err);
706       }
707       break;
708     case PSPPIRE_VAR_STORE_COL_VALUES:
709       {
710         if ( ! var_has_value_labels (pv))
711           return g_locale_to_utf8 (gettext (none), -1, 0, 0, err);
712         else
713           {
714             gchar *ss;
715             GString *gstr = g_string_sized_new (10);
716             const struct val_labs *vls = var_get_value_labels (pv);
717             struct val_labs_iterator *ip = 0;
718             struct val_lab *vl = val_labs_first_sorted (vls, &ip);
719
720             g_assert (vl);
721
722             {
723               gchar *const vstr = value_to_text (vl->value, *write_spec);
724
725               g_string_printf (gstr, "{%s,\"%s\"}_", vstr, vl->label);
726               g_free (vstr);
727             }
728
729             val_labs_done (&ip);
730
731             ss = pspp_locale_to_utf8 (gstr->str, gstr->len, err);
732             g_string_free (gstr, TRUE);
733             return ss;
734           }
735       }
736       break;
737     case PSPPIRE_VAR_STORE_COL_ALIGN:
738       {
739         const gint align = var_get_alignment (pv);
740
741         g_assert (align < n_ALIGNMENTS);
742         return g_locale_to_utf8 (gettext (alignments[align]), -1, 0, 0, err);
743       }
744       break;
745     case PSPPIRE_VAR_STORE_COL_MEASURE:
746       {
747         return measure_to_string (pv, err);
748       }
749       break;
750     }
751   return 0;
752 }
753
754
755
756 /* Return the number of variables */
757 gint
758 psppire_var_store_get_var_cnt (PsppireVarStore  *store)
759 {
760   return psppire_dict_get_var_cnt (store->dict);
761 }
762
763
764 void
765 psppire_var_store_set_font (PsppireVarStore *store, const PangoFontDescription *fd)
766 {
767   g_return_if_fail (store);
768   g_return_if_fail (PSPPIRE_IS_VAR_STORE (store));
769
770   store->font_desc = fd;
771
772   g_sheet_model_range_changed (G_SHEET_MODEL (store), -1, -1, -1, -1);
773 }
774
775
776 static glong
777 psppire_var_store_get_row_count (const GSheetModel * model)
778 {
779   gint rows = 0;
780   PsppireVarStore *vs = PSPPIRE_VAR_STORE (model);
781
782   if (vs->dict)
783     rows =  psppire_dict_get_var_cnt (vs->dict);
784
785   return rows ;
786 }
787
788 static glong
789 psppire_var_store_get_column_count (const GSheetModel * model)
790 {
791   return PSPPIRE_VAR_STORE_n_COLS ;
792 }
793
794
795 /* Row related funcs */
796
797 static glong
798 geometry_get_row_count (const GSheetRow *geom)
799 {
800   gint rows = 0;
801   PsppireVarStore *vs = PSPPIRE_VAR_STORE (geom);
802
803   if (vs->dict)
804     rows =  psppire_dict_get_var_cnt (vs->dict);
805
806   return rows + vs->trailing_rows;
807 }
808
809
810 static gint
811 geometry_get_height (const GSheetRow *geom, glong row)
812 {
813   return 25;
814 }
815
816
817 static gboolean
818 geometry_is_sensitive (const GSheetRow *geom, glong row)
819 {
820   PsppireVarStore *vs = PSPPIRE_VAR_STORE (geom);
821
822   if ( ! vs->dict)
823     return FALSE;
824
825   return  row < psppire_dict_get_var_cnt (vs->dict);
826 }
827
828 static gchar *
829 geometry_get_button_label (const GSheetRow *geom, glong unit)
830 {
831   gchar *label = g_strdup_printf (_("%ld"), unit + 1);
832
833   return label;
834 }
835
836 static void
837 psppire_var_store_sheet_row_init (GSheetRowIface *iface)
838 {
839   iface->get_row_count =     geometry_get_row_count;
840   iface->get_height =        geometry_get_height;
841   iface->set_height =        NULL;
842   iface->get_sensitivity =   geometry_is_sensitive;
843
844   iface->get_button_label = geometry_get_button_label;
845 }
846
847
848