progress on ROWLABELS=LAYER
[pspp] / src / ui / gui / var-type-dialog.c
index 7b663383912c91b4f78ff6caac99b05b2be265da..a6d89cbf8a38508f8a6ead99b4434f7454f4d4a1 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-    Copyright (C) 2005, 2006, 2010, 2011, 2012  Free Software Foundation
+   Copyright (C) 2005, 2006, 2010, 2011, 2012, 2015, 2020  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include "ui/gui/psppire-format.h"
 #include "ui/gui/var-type-dialog.h"
 
+#include <gettext.h>
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
 static const struct fmt_spec date_format[] =
   {
-    {FMT_DATE,  11, 0},
-    {FMT_DATE,   9, 0},
-    {FMT_ADATE, 10, 0},
-    {FMT_ADATE, 8, 0},
-    {FMT_EDATE, 10, 0},
-    {FMT_EDATE, 8, 0},
-    {FMT_SDATE, 10, 0},
-    {FMT_SDATE, 8, 0},
-    {FMT_JDATE, 5, 0},
-    {FMT_JDATE, 7, 0},
-    {FMT_QYR, 8, 0},
-    {FMT_QYR, 6, 0},
-    {FMT_MOYR, 8, 0},
-    {FMT_MOYR, 6, 0},
-    {FMT_WKYR, 10, 0},
-    {FMT_WKYR, 8, 0},
-    {FMT_DATETIME, 17, 0},
-    {FMT_DATETIME, 20, 0}
+    { .type = FMT_DATE, .w = 11, .d = 0 },
+    { .type = FMT_DATE, .w = 9, .d = 0 },
+    { .type = FMT_ADATE, .w = 10, .d = 0 },
+    { .type = FMT_ADATE, .w = 8, .d = 0 },
+    { .type = FMT_EDATE, .w = 10, .d = 0 },
+    { .type = FMT_EDATE, .w = 8, .d = 0 },
+    { .type = FMT_SDATE, .w = 10, .d = 0 },
+    { .type = FMT_SDATE, .w = 8, .d = 0 },
+    { .type = FMT_JDATE, .w = 5, .d = 0 },
+    { .type = FMT_JDATE, .w = 7, .d = 0 },
+    { .type = FMT_QYR, .w = 8, .d = 0 },
+    { .type = FMT_QYR, .w = 6, .d = 0 },
+    { .type = FMT_MOYR, .w = 8, .d = 0 },
+    { .type = FMT_MOYR, .w = 6, .d = 0 },
+    { .type = FMT_WKYR, .w = 10, .d = 0 },
+    { .type = FMT_WKYR, .w = 8, .d = 0 },
+    { .type = FMT_DATETIME, .w = 17, .d = 0 },
+    { .type = FMT_DATETIME, .w = 20, .d = 0 },
+    { .type = FMT_YMDHMS, .w = 16, .d = 0 },
+    { .type = FMT_YMDHMS, .w = 20, .d = 0 }
   };
 
 
 static const struct fmt_spec dollar_format[] =
   {
-    {FMT_DOLLAR, 2, 0},
-    {FMT_DOLLAR, 3, 0},
-    {FMT_DOLLAR, 4, 0},
-    {FMT_DOLLAR, 7, 2},
-    {FMT_DOLLAR, 6, 0},
-    {FMT_DOLLAR, 9, 2},
-    {FMT_DOLLAR, 8, 0},
-    {FMT_DOLLAR, 11, 2},
-    {FMT_DOLLAR, 12, 0},
-    {FMT_DOLLAR, 15, 2},
-    {FMT_DOLLAR, 16, 0},
-    {FMT_DOLLAR, 19, 2}
+    { .type = FMT_DOLLAR, .w = 2, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 3, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 4, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 7, .d = 2 },
+    { .type = FMT_DOLLAR, .w = 6, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 9, .d = 2 },
+    { .type = FMT_DOLLAR, .w = 8, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 11, .d = 2 },
+    { .type = FMT_DOLLAR, .w = 12, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 15, .d = 2 },
+    { .type = FMT_DOLLAR, .w = 16, .d = 0 },
+    { .type = FMT_DOLLAR, .w = 19, .d = 2 }
   };
 
 static const int cc_format[] =
@@ -84,6 +90,9 @@ static GObject *psppire_var_type_dialog_constructor (GType type, guint,
                                                      GObjectConstructParam *);
 static void psppire_var_type_dialog_set_state (PsppireVarTypeDialog *);
 
+static void psppire_var_type_dialog_set_format (PsppireVarTypeDialog *dialog,
+                                               const struct fmt_spec *format);
+
 static int find_format (const struct fmt_spec *target,
                         const struct fmt_spec formats[], int n_formats);
 static int find_format_type (int target, const int types[], int n_types);
@@ -145,7 +154,7 @@ psppire_var_type_dialog_get_property (GObject      *object,
     }
 }
 
-void
+static void
 psppire_var_type_dialog_set_format (PsppireVarTypeDialog *dialog,
                                     const struct fmt_spec *format)
 {
@@ -153,7 +162,7 @@ psppire_var_type_dialog_set_format (PsppireVarTypeDialog *dialog,
   psppire_var_type_dialog_set_state (dialog);
 }
 
-const struct fmt_spec *
+static const struct fmt_spec *
 psppire_var_type_dialog_get_format (const PsppireVarTypeDialog *dialog)
 {
   return &dialog->fmt_l;
@@ -194,12 +203,11 @@ psppire_var_type_dialog_new (const struct fmt_spec *format)
 {
   return PSPPIRE_VAR_TYPE_DIALOG (
     g_object_new (PSPPIRE_TYPE_VAR_TYPE_DIALOG,
-                  "orientation", PSPPIRE_HORIZONTAL,
                   "format", format,
                   NULL));
 }
 
-void
+gint
 psppire_var_type_dialog_run (GtkWindow *parent_window,
                              struct fmt_spec *format)
 {
@@ -207,10 +215,16 @@ psppire_var_type_dialog_run (GtkWindow *parent_window,
 
   dialog = psppire_var_type_dialog_new (format);
   gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
+  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
   gtk_widget_show (GTK_WIDGET (dialog));
 
-  if (psppire_dialog_run (PSPPIRE_DIALOG (dialog)) == GTK_RESPONSE_OK)
+  gint result = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
+  if (result == GTK_RESPONSE_OK)
     *format = *psppire_var_type_dialog_get_format (dialog);
+
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+
+  return result;
 }
 
 
@@ -220,7 +234,7 @@ on_toggle (GtkToggleButton *togglebutton, gpointer dialog_)
 {
   PsppireVarTypeDialog *dialog = dialog_;
 
-  if ( gtk_toggle_button_get_active (togglebutton) == TRUE)
+  if (gtk_toggle_button_get_active (togglebutton) == TRUE)
     refresh_active_button (dialog);
 }
 
@@ -409,7 +423,7 @@ preview_custom (GtkWidget *w, gpointer data)
 
   PsppireVarTypeDialog *dialog = data;
 
-  if ( dialog->active_button != BUTTON_CUSTOM )
+  if (dialog->active_button != BUTTON_CUSTOM)
     return;
 
   text = gtk_entry_get_text (GTK_ENTRY (dialog->entry_decimals));
@@ -419,7 +433,7 @@ preview_custom (GtkWidget *w, gpointer data)
   dialog->fmt_l.w = atoi (text);
 
   msg_disable ();
-  if ( ! fmt_check_output (&dialog->fmt_l))
+  if (! fmt_check_output (&dialog->fmt_l))
     {
       gtk_label_set_text (GTK_LABEL (dialog->label_psample), "---");
       gtk_label_set_text (GTK_LABEL (dialog->label_nsample), "---");
@@ -430,12 +444,14 @@ preview_custom (GtkWidget *w, gpointer data)
       union value v;
       v.f = 1234.56;
 
-      sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l));
+      sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l,
+                                         settings_get_fmt_settings ()));
       gtk_label_set_text (GTK_LABEL (dialog->label_psample), sample_text);
       g_free (sample_text);
 
       v.f = -v.f;
-      sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l));
+      sample_text = g_strchug (data_out (&v, NULL, &dialog->fmt_l,
+                                         settings_get_fmt_settings ()));
       gtk_label_set_text (GTK_LABEL (dialog->label_nsample), sample_text);
       g_free (sample_text);
     }
@@ -451,6 +467,9 @@ get_index_from_treeview (GtkTreeView *treeview)
   GtkTreeIter iter;
   gint index;
 
+  if (selection == NULL)
+    return -1;
+
   gtk_tree_selection_get_selected (selection, &model, &iter);
   path = gtk_tree_model_get_path (model, &iter);
   if (!path || gtk_tree_path_get_depth (path) < 1)
@@ -468,7 +487,11 @@ static void
 set_date_format_from_treeview (GtkTreeView *treeview,
                                PsppireVarTypeDialog *dialog)
 {
-  dialog->fmt_l = date_format[get_index_from_treeview (treeview)];
+  gint idx = get_index_from_treeview (treeview);
+  if (idx < 0)
+    return;
+
+  dialog->fmt_l = date_format[idx];
 }
 
 /* Callback for when a dollar treeview row is changed.
@@ -477,7 +500,11 @@ static void
 set_dollar_format_from_treeview (GtkTreeView *treeview,
                                  PsppireVarTypeDialog *dialog)
 {
-  dialog->fmt_l = dollar_format[get_index_from_treeview (treeview)];
+  gint idx = get_index_from_treeview (treeview);
+  if (idx < 0)
+    return;
+
+  dialog->fmt_l = dollar_format[idx];
 }
 
 /* Callback for when a treeview row is changed.
@@ -486,7 +513,11 @@ static void
 set_custom_format_from_treeview (GtkTreeView *treeview,
                                  PsppireVarTypeDialog *dialog)
 {
-  dialog->fmt_l.type = cc_format[get_index_from_treeview (treeview)];
+  gint idx = get_index_from_treeview (treeview);
+  if (idx < 0)
+    return;
+
+  dialog->fmt_l.type = cc_format[idx];
   update_adj_ranges (dialog);
   fmt_fix_output (&dialog->fmt_l);
   update_width_decimals (dialog);
@@ -508,9 +539,12 @@ psppire_var_type_dialog_constructor (GType                  type,
     type, n_properties, properties);
   dialog = PSPPIRE_VAR_TYPE_DIALOG (obj);
 
+  g_object_set (dialog, "help-page", "Input-and-Output-Formats",
+               "title", _("Variable Type and Format"), NULL);
+
   xml = builder_new ("var-type-dialog.ui");
 
-  content_area = GTK_CONTAINER (PSPPIRE_DIALOG (dialog)->box);
+  content_area = GTK_CONTAINER (PSPPIRE_DIALOG (dialog));
   gtk_container_add (GTK_CONTAINER (content_area),
                      get_widget_assert (xml, "var-type-dialog"));
 
@@ -580,7 +614,7 @@ psppire_var_type_dialog_constructor (GType                  type,
                        add_to_group, sizeGroup);
 
 
-  for (i = 0 ; i < num_BUTTONS; ++i )
+  for (i = 0 ; i < num_BUTTONS; ++i)
     g_signal_connect (dialog->radioButton[i], "toggled",
                       G_CALLBACK (on_toggle), dialog);
 
@@ -602,7 +636,7 @@ psppire_var_type_dialog_constructor (GType                  type,
 
   list_store = gtk_list_store_new (1, G_TYPE_STRING);
 
-  for ( i = 0 ; i < sizeof (date_format) / sizeof (date_format[0]) ; ++i )
+  for (i = 0 ; i < sizeof (date_format) / sizeof (date_format[0]) ; ++i)
     {
       const struct fmt_spec *f = &date_format[i];
       gtk_list_store_append (list_store, &iter);
@@ -636,7 +670,7 @@ psppire_var_type_dialog_constructor (GType                  type,
 
   list_store = gtk_list_store_new (1, G_TYPE_STRING);
 
-  for ( i = 0 ; i < sizeof (dollar_format)/sizeof (dollar_format[0]) ; ++i )
+  for (i = 0 ; i < sizeof (dollar_format)/sizeof (dollar_format[0]) ; ++i)
     {
       char *template = settings_dollar_template (&dollar_format[i]);
       gtk_list_store_append (list_store, &iter);
@@ -676,7 +710,7 @@ psppire_var_type_dialog_constructor (GType                  type,
 
   list_store = gtk_list_store_new (1, G_TYPE_STRING);
 
-  for ( i = 0 ; i < 5 ; ++i )
+  for (i = 0 ; i < 5 ; ++i)
     {
       enum fmt_type cc_fmts[5] = {FMT_CCA, FMT_CCB, FMT_CCC, FMT_CCD, FMT_CCE};
       gtk_list_store_append (list_store, &iter);
@@ -726,7 +760,7 @@ psppire_var_type_dialog_constructor (GType                  type,
 
 
 /* Set a particular button to be active */
-void
+static void
 var_type_dialog_set_active_button (PsppireVarTypeDialog *dialog, gint b)
 {
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->radioButton[b]),
@@ -806,6 +840,8 @@ psppire_var_type_dialog_set_state (PsppireVarTypeDialog *dialog)
     case FMT_MOYR:
     case FMT_WKYR:
     case FMT_DATETIME:
+    case FMT_YMDHMS:
+    case FMT_MTIME:
     case FMT_TIME:
     case FMT_DTIME:
     case FMT_WKDAY: