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