pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] psppire ./TODO ./psppire.glade src/ChangeLog sr...


From: John Darrington
Subject: [Pspp-cvs] psppire ./TODO ./psppire.glade src/ChangeLog sr...
Date: Wed, 14 Dec 2005 11:39:12 +0000

CVSROOT:        /sources/pspp
Module name:    psppire
Branch:         
Changes by:     John Darrington <address@hidden>        05/12/14 11:39:12

Modified files:
        .              : TODO psppire.glade 
        src            : ChangeLog val_labs_dialog.c var_sheet.c 
                         var_type_dialog.c var_type_dialog.h 

Log message:
        Fixed some outstanding problems with dollar and date formats

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/psppire/TODO.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/psppire/psppire.glade.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/psppire/src/ChangeLog.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/psppire/src/val_labs_dialog.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/psppire/src/var_sheet.c.diff?tr1=1.28&tr2=1.29&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/psppire/src/var_type_dialog.c.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/psppire/src/var_type_dialog.h.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: psppire/TODO
diff -u psppire/TODO:1.15 psppire/TODO:1.16
--- psppire/TODO:1.15   Sun Dec 11 10:14:39 2005
+++ psppire/TODO        Wed Dec 14 11:39:12 2005
@@ -39,12 +39,12 @@
 
 Phase 1 Issues
 --------------
-* When switching between data/variables sheets by double-clicking title 
buttons,
-  we need to scroll the sheet to the right position.
+* When switching between data/variables sheets by double-clicking title 
+  buttons, we need to scroll the sheet to the right position.
 
-* Value labels currently don't work properly for Date, Dot, Comma variables.
+* Implement Custom Currency sub type in Variable Type dialog.
 
-* Implement sub types of Dollar and Custom Currency in Variable Type dialog.
+* Value labels currently don't work properly for Date, Dot, Comma variables.
 
 * Implement mechanism for handling errors (use GError ?). 
 
Index: psppire/psppire.glade
diff -u psppire/psppire.glade:1.14 psppire/psppire.glade:1.15
--- psppire/psppire.glade:1.14  Sun Dec 11 10:14:39 2005
+++ psppire/psppire.glade       Wed Dec 14 11:39:12 2005
@@ -975,7 +975,8 @@
              <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
 
              <child>
-               <widget class="GtkTreeView" id="treeview3">
+               <widget class="GtkTreeView" id="dollar_treeview">
+                 <property name="visible">True</property>
                  <property name="can_focus">True</property>
                  <property name="headers_visible">False</property>
                  <property name="rules_hint">False</property>
Index: psppire/src/ChangeLog
diff -u psppire/src/ChangeLog:1.9 psppire/src/ChangeLog:1.10
--- psppire/src/ChangeLog:1.9   Mon Dec 12 07:52:51 2005
+++ psppire/src/ChangeLog       Wed Dec 14 11:39:12 2005
@@ -1,3 +1,12 @@
+Wed Dec 14 19:37:01 WST 2005 John Darrington <address@hidden>
+
+       * val_labs_dialog.c: When entering value, treeview item is now 
+         automatically selected.
+
+       * var_type_dialog.c: Implemented the actions for the dollar format.
+         Also, date and dollar treeviews are automatically selected even
+         when no valid format is present.
+
 Mon Dec 12 15:50:47 WST 2005 John Darrington <address@hidden>
 
        * val_labs_dialog.[ch]: Fixed problem with value labels on non numeric
Index: psppire/src/val_labs_dialog.c
diff -u psppire/src/val_labs_dialog.c:1.4 psppire/src/val_labs_dialog.c:1.5
--- psppire/src/val_labs_dialog.c:1.4   Mon Dec 12 07:52:51 2005
+++ psppire/src/val_labs_dialog.c       Wed Dec 14 11:39:12 2005
@@ -51,9 +51,48 @@
       gtk_widget_set_sensitive(dialog->change_button, FALSE);     
       gtk_widget_set_sensitive(dialog->add_button, TRUE);       
     }
+}
+
+
+/* Set the TREEVIEW list cursor to the item which has the value VAL */
+static void
+select_treeview_from_value(GtkTreeView *treeview, union value *val)
+{
+  /*
+    We do this with a linear search through the model --- hardly 
+    efficient, but the list is short ... */
+  GtkTreeIter iter;
+
+  GtkTreeModel * model  = gtk_tree_view_get_model(treeview);
+
+  gboolean success;
+  for (success = gtk_tree_model_get_iter_first(model, &iter);
+       success;
+       success = gtk_tree_model_iter_next(model, &iter))
+    {
+      GValue gvalue = {0};
+
+      gtk_tree_model_get_value(model, &iter, 1, &gvalue);
+         
+      union value v;
+      v.f = g_value_get_double(&gvalue);
+
+      if ( 0 == memcmp(&v, val, sizeof (union value)))
+       {
+         break;
+       }
+    }
+       
+  GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
+  if ( path ) 
+    {
+      gtk_tree_view_set_cursor(treeview, path, 0, 0);
+      gtk_tree_path_free(path);
+    }
 
 }
 
+
 /* This callback occurs when the text in the value entry box is
    changed */
 static void
@@ -78,6 +117,7 @@
       gtk_entry_set_text(GTK_ENTRY(dialog->label_entry), s);
       gtk_widget_set_sensitive(dialog->add_button, FALSE);
       gtk_widget_set_sensitive(dialog->remove_button, TRUE);
+      select_treeview_from_value(dialog->treeview, &v);
     }
   else
     {
@@ -153,10 +193,14 @@
 on_change(GtkWidget *w, gpointer data)
 {
   struct val_labs_dialog *dialog = data;
+  
+  const gchar *val_text = gtk_entry_get_text(GTK_ENTRY(dialog->value_entry));
+  
+  union value v;
+  
+  text_to_value(val_text, &v, dialog->var->write);
 
-  struct val_lab *vl = get_selected_tuple(dialog);
-
-  val_labs_replace (dialog->labs, vl->value, 
+  val_labs_replace (dialog->labs, v,
                    gtk_entry_get_text(GTK_ENTRY(dialog->label_entry)));
 
   gtk_widget_set_sensitive(dialog->change_button, FALSE);
@@ -196,7 +240,6 @@
 {
   struct val_labs_dialog *dialog = data;
 
-
   struct val_lab *vl = get_selected_tuple(dialog);
 
   val_labs_remove (dialog->labs, vl->value);
Index: psppire/src/var_sheet.c
diff -u psppire/src/var_sheet.c:1.28 psppire/src/var_sheet.c:1.29
--- psppire/src/var_sheet.c:1.28        Mon Dec 12 07:52:51 2005
+++ psppire/src/var_sheet.c     Wed Dec 14 11:39:12 2005
@@ -695,7 +695,7 @@
 
              g_assert(vl);
 
-             const gchar *vstr = value_to_text(vl->value, var->write);
+             gchar *const vstr = value_to_text(vl->value, var->write);
              gchar *const text = 
                g_strdup_printf("{%s,\"%s\"}_", vstr, vl->label);
 
Index: psppire/src/var_type_dialog.c
diff -u psppire/src/var_type_dialog.c:1.6 psppire/src/var_type_dialog.c:1.7
--- psppire/src/var_type_dialog.c:1.6   Sun Dec 11 10:14:39 2005
+++ psppire/src/var_type_dialog.c       Wed Dec 14 11:39:12 2005
@@ -37,6 +37,54 @@
 };
 
 
+struct format_opt {
+  gchar desc[18];
+  struct fmt_spec spec;
+};
+
+static struct format_opt format_option[] =
+  {
+    { "dd-mmm-yyyy", {FMT_DATE,  11, 0} },
+    { "dd-mmm-yy",   {FMT_DATE,   9, 0} },
+    { "mm/dd/yyyy",  {FMT_ADATE, 10, 0} },
+    { "mm/dd/yy",    {FMT_ADATE, 8, 0} },
+    { "dd.mm.yyyy",  {FMT_EDATE, 10, 0} },
+    { "dd.mm.yy",    {FMT_EDATE, 8, 0} },
+    { "yyyy/mm/dd",  {FMT_SDATE, 10, 0} },
+    { "yy/mm/dd",    {FMT_SDATE, 8, 0} },
+    { "yyddd",       {FMT_JDATE, 5, 0} },
+    { "yyyyddd",     {FMT_JDATE, 7, 0} },
+    { "q Q yyyy",    {FMT_QYR, 8, 0} },
+    { "q Q yy",      {FMT_QYR, 6, 0} },
+    { "mmm yyyy",    {FMT_MOYR, 8, 0} },
+    { "mmm yy",      {FMT_MOYR, 6, 0} },
+    { "dd WK yyyy",  {FMT_WKYR, 10, 0} },
+    { "dd WK yy",    {FMT_WKYR, 8, 0} },
+    { "dd-mmm-yyyy HH:MM", {FMT_DATETIME, 17, 0}}
+  };
+
+
+static 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}
+  };
+
+
+static void select_treeview_from_format
+      (GtkTreeView *treeview, const struct fmt_spec *fmt);
+
+
 /* callback for when any of the radio buttons are toggled */
 static void        
 on_toggle_1(GtkToggleButton *togglebutton, gpointer user_data)
@@ -84,10 +132,14 @@
       gtk_widget_hide(dialog->entry_decimals);
       break;
     case BUTTON_DATE:
+      select_treeview_from_format(dialog->date_format_treeview,
+                                 &format_option[0].spec);
       gtk_widget_hide(dialog->width_decimals);
       gtk_widget_show(dialog->date_format_list);
       break;
     case BUTTON_DOLLAR:
+      select_treeview_from_format(dialog->dollar_treeview,
+                                 &dollar_format[0]);
       gtk_widget_show(dialog->dollar_window);
       gtk_widget_show_all(dialog->width_decimals);
       break;
@@ -105,32 +157,42 @@
 
 static gint on_var_type_ok_clicked(GtkWidget *w, gpointer data);
 
+#define LEN 20
 
-struct format_opt {
-  gchar desc[18];
-  struct fmt_spec spec;
-};
+/* return a string of the form "$#,###.##" according to FMT. 
+   FMT must be of type FMT_DOLLAR
+ */
+static const gchar *
+dollar_format_template(const struct fmt_spec *fmt)
+{
+  static gchar buf[LEN];
+  g_assert( fmt->type == FMT_DOLLAR);
 
-static struct format_opt format_option[] =
-  {
-    { "dd-mmm-yyyy", {FMT_DATE,  11, 0} },
-    { "dd-mmm-yy",   {FMT_DATE,   9, 0} },
-    { "mm/dd/yyyy",  {FMT_ADATE, 10, 0} },
-    { "mm/dd/yy",    {FMT_ADATE, 8, 0} },
-    { "dd.mm.yyyy",  {FMT_EDATE, 10, 0} },
-    { "dd.mm.yy",    {FMT_EDATE, 8, 0} },
-    { "yyyy/mm/dd",  {FMT_SDATE, 10, 0} },
-    { "yy/mm/dd",    {FMT_SDATE, 8, 0} },
-    { "yyddd",       {FMT_JDATE, 5, 0} },
-    { "yyyyddd",     {FMT_JDATE, 7, 0} },
-    { "q Q yyyy",    {FMT_QYR, 8, 0} },
-    { "q Q yy",      {FMT_QYR, 6, 0} },
-    { "mmm yyyy",    {FMT_MOYR, 8, 0} },
-    { "mmm yy",      {FMT_MOYR, 6, 0} },
-    { "dd WK yyyy",  {FMT_WKYR, 10, 0} },
-    { "dd WK yy",    {FMT_WKYR, 8, 0} },
-    { "dd-mmm-yyyy HH:MM", {FMT_DATETIME, 17, 0}}
-  };
+  gint int_part = fmt->w - fmt->d;
+  if ( fmt->d > 0 ) --int_part;
+  g_assert(int_part > 0);
+
+  g_strlcpy(buf, "$", LEN);
+
+  gint c = int_part - 1;
+  while(c > 0)
+    {
+      g_strlcat(buf, "#", LEN);
+      if(--c % 4 == 0 && c > 0 ) 
+      {
+       g_strlcat(buf, ",", LEN);
+       --c;
+      }
+    }
+  if ( fmt->d > 0 ) 
+    {
+      g_strlcat(buf, ".", LEN);
+      for ( c = 0 ; c < fmt->d ; ++c ) 
+       g_strlcat(buf, "#", LEN);
+    }
+
+  return buf;
+}
 
 static void
 add_to_group(GtkWidget *w, gpointer data)
@@ -140,11 +202,27 @@
   gtk_size_group_add_widget(sg, w);
 }
 
+/* Callback for when a treeview row is changed.
+   It sets the fmt_spec to reflect the selected format */
+static void
+update_width_decimals(GtkTreeView *treeview, gpointer data)
+{
+  struct var_type_dialog *dialog = data;
+
+  gchar *text = g_strdup_printf("%d", dialog->fmt_spec->w);
+  gtk_entry_set_text(GTK_ENTRY(dialog->entry_width), text);
+  g_free(text);
+
+  text = g_strdup_printf("%d", dialog->fmt_spec->d);
+  gtk_entry_set_text(GTK_ENTRY(dialog->entry_decimals), text);
+  g_free(text);
+}
+
 
-/* Callback for when the date_format treeview row is changed.
-   It sets the fmt_spec to reflect the selected date format */
+/* Callback for when a treeview row is changed.
+   It sets the fmt_spec to reflect the selected format */
 static void
-set_date_format(GtkTreeView *treeview, gpointer data)
+set_format(GtkTreeView *treeview, gpointer data)
 {
   struct var_type_dialog *dialog = data;
   GtkTreeIter iter ;
@@ -161,6 +239,8 @@
   dialog->fmt_spec = g_value_get_pointer(&the_value);
 }
 
+
+
 /* Create the structure from the XML definitions */
 struct var_type_dialog *
 var_type_dialog_create(GladeXML *xml)
@@ -170,6 +250,8 @@
 
   struct var_type_dialog *dialog = g_malloc(sizeof(struct var_type_dialog));
 
+  dialog->fmt_spec = 0;
+
   dialog->window = get_widget_assert(xml,"var_type_dialog");
 
   gtk_window_set_transient_for(GTK_WINDOW(dialog->window), 
@@ -203,20 +285,22 @@
 
   dialog->custom_currency_hbox = get_widget_assert(xml,
                                                   "custom_currency_hbox");
-  dialog->dollar_window = get_widget_assert(xml, "dollar_window");
 
+  dialog->dollar_window = get_widget_assert(xml, "dollar_window");
+  dialog->dollar_treeview = 
+    GTK_TREE_VIEW(get_widget_assert(xml, "dollar_treeview"));
 
   dialog->ok = get_widget_assert(xml,"var_type_ok");
 
 
+  /* The "middle_box" is a vbox with serveral children.
+     However only one child is ever shown at a time.
+     We need to make sure that they all have the same width, to avoid
+     upleasant resizing effects */
   GtkSizeGroup *sizeGroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-
   gtk_container_foreach(get_widget_assert(xml, "middle_box"), 
                        add_to_group, sizeGroup);
-#if 0
-  gtk_size_group_add_widget(sizeGroup, dialog->date_format_list);
-  gtk_size_group_add_widget(sizeGroup, dialog->width_decimals);
-#endif
+
   
   static struct tgs tgs[num_BUTTONS];
   for (i = 0 ; i < num_BUTTONS; ++i ) 
@@ -231,7 +315,6 @@
     }
 
   /* Populate the date format tree view */
-
   dialog->date_format_treeview = GTK_TREE_VIEW(get_widget_assert(xml, 
                                              "date_format_list_view"));
 
@@ -268,8 +351,51 @@
   g_object_unref(list_store);
 
   g_signal_connect(GTK_OBJECT(dialog->date_format_treeview), "cursor-changed",
-                  GTK_SIGNAL_FUNC(set_date_format), dialog);
+                  GTK_SIGNAL_FUNC(set_format), dialog);
+
+
+  /* populate the dollar treeview */
+
+  renderer = gtk_cell_renderer_text_new();
+  
+  column = gtk_tree_view_column_new_with_attributes ("Title",
+                                                    renderer,
+                                                    "text",
+                                                    0,
+                                                    NULL);
+
+  gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->dollar_treeview), 
+                              column);
+
+
+  list_store = gtk_list_store_new (2, G_TYPE_STRING, 
+                                                G_TYPE_POINTER);
+
+  for ( i = 0 ; i < sizeof(dollar_format)/sizeof(dollar_format[0]) ; ++i ) 
+    {
+      gtk_list_store_append (list_store, &iter);
+      gtk_list_store_set (list_store, &iter,
+                          0, dollar_format_template(&dollar_format[i]),
+                         1, &dollar_format[i],
+                         -1);
+    }
+
+  gtk_tree_view_set_model(GTK_TREE_VIEW(dialog->dollar_treeview), 
+                         GTK_TREE_MODEL(list_store));
+
+  g_object_unref(list_store);
+
+  g_signal_connect(GTK_OBJECT(dialog->dollar_treeview), 
+                  "cursor-changed",
+                  GTK_SIGNAL_FUNC(set_format), dialog);
 
+  g_signal_connect(GTK_OBJECT(dialog->dollar_treeview), 
+                  "cursor-changed",
+                  GTK_SIGNAL_FUNC(update_width_decimals), dialog);
+
+
+
+  /* Connect the OK button */
   g_signal_connect(dialog->ok, "clicked", G_CALLBACK(on_var_type_ok_clicked), 
                   dialog);
 
@@ -286,6 +412,49 @@
   dialog->active_button = b;
 }
 
+
+
+/* Set the TREEVIEW list cursor to the item described by FMT */
+static void
+select_treeview_from_format(GtkTreeView *treeview, const struct fmt_spec *fmt)
+{
+  /*
+    We do this with a linear search through the model --- hardly 
+    efficient, but the list is short ... */
+  GtkTreeIter iter;
+
+  GtkTreeModel * model  = gtk_tree_view_get_model(treeview);
+
+  gboolean success;
+  for (success = gtk_tree_model_get_iter_first(model, &iter);
+       success;
+       success = gtk_tree_model_iter_next(model, &iter))
+    {
+      GValue value = {0};
+
+      gtk_tree_model_get_value(model, &iter, 1, &value);
+         
+      const struct fmt_spec *spec = g_value_get_pointer(&value);
+
+      if ( 0 == memcmp(spec, fmt, sizeof (struct fmt_spec)))
+       {
+         break;
+       }
+    }
+       
+  GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
+  if ( path ) 
+    {
+      gtk_tree_view_set_cursor(treeview, path, 0, 0);
+      gtk_tree_path_free(path);
+    }
+  else
+    g_warning("Unusual date format: %s\n", fmt_to_string(fmt));
+
+}
+
+
+
 /* Set up the state of the dialog box to match the variable VAR */
 void
 var_type_dialog_set_state(struct var_type_dialog *dialog, 
@@ -336,6 +505,8 @@
     case FMT_DOLLAR:
       var_type_dialog_set_active_button(dialog, BUTTON_DOLLAR);
       gtk_widget_show_all(dialog->width_decimals);
+      
+      select_treeview_from_format(dialog->dollar_treeview, &var->write);
       break;
     case FMT_DATE:     
     case FMT_EDATE:    
@@ -353,42 +524,7 @@
       var_type_dialog_set_active_button(dialog, BUTTON_DATE);
       gtk_widget_hide(dialog->width_decimals);
       gtk_widget_show(dialog->date_format_list);
-      {
-       /* Set the tree view list cursor to the current format.
-          We do this with a linear search through the model --- hardly 
-          efficient, but the list is short ... */
-       GtkTreeIter iter;
-
-       GtkTreeModel * model  = 
-         gtk_tree_view_get_model(dialog->date_format_treeview);
-
-       gboolean success;
-       for (success = gtk_tree_model_get_iter_first(model, &iter);
-            success;
-            success = gtk_tree_model_iter_next(model, &iter))
-       {
-         GValue value = {0};
-
-         gtk_tree_model_get_value(model, &iter, 1, &value);
-         
-         const struct fmt_spec *spec = g_value_get_pointer(&value);
-
-         if ( 0 == memcmp(spec, &var->write, sizeof (struct fmt_spec)))
-           {
-             break;
-           }
-       }
-       
-       GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
-       if ( path ) 
-         {
-           gtk_tree_view_set_cursor(dialog->date_format_treeview, path, 0, 0);
-           gtk_tree_path_free(path);
-         }
-       else
-         g_warning("Unusual date format: %s\n", fmt_to_string(&var->write));
-
-      }
+      select_treeview_from_format(dialog->date_format_treeview, &var->write);
       break;
     default:
       gtk_widget_show_all(dialog->width_decimals);
@@ -464,6 +600,8 @@
       result = make_output_format_try(&spec, FMT_E, width, decimals);
       break;
     case BUTTON_DATE:
+      g_assert(dialog->fmt_spec);
+      g_assert(check_output_specifier(dialog->fmt_spec, TRUE));
       result = memcpy(&spec, dialog->fmt_spec, sizeof(struct fmt_spec));
       break;
     case BUTTON_DOLLAR:
Index: psppire/src/var_type_dialog.h
diff -u psppire/src/var_type_dialog.h:1.4 psppire/src/var_type_dialog.h:1.5
--- psppire/src/var_type_dialog.h:1.4   Sun Dec 11 10:14:39 2005
+++ psppire/src/var_type_dialog.h       Wed Dec 14 11:39:12 2005
@@ -67,8 +67,12 @@
   GtkWidget *date_format_list;
   GtkTreeView *date_format_treeview;
 
-  GtkWidget *custom_currency_hbox;
+  /* Dollar */
   GtkWidget *dollar_window;
+  GtkTreeView *dollar_treeview;
+
+  /* Custom Currency */
+  GtkWidget *custom_currency_hbox;
 
   /* Actions */
   GtkWidget *ok;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]