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