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