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