data_out function to dynamically allocate return value.
[pspp-builds.git] / src / ui / gui / psppire-data-editor.c
index 861191917e4160e524ed3927e30a1f3389aac42b..b48ad2338b6ccb8e49ca1e8726383885aab1e17d 100644 (file)
@@ -23,8 +23,9 @@
 
 #include <language/syntax-string-source.h>
 #include "psppire-data-store.h"
-#include <ui/gui/sheet/psppire-axis-impl.h>
-#include "helper.h"
+#include <libpspp/i18n.h>
+#include <ui/gui/sheet/psppire-axis.h>
+#include "executor.h"
 
 #include <gtk-contrib/gtkxpaned.h>
 #include <gettext.h>
@@ -220,8 +221,8 @@ new_data_callback (PsppireDataStore *ds, gpointer data)
 
   for (i = 0; i < 2; ++i)
     {
-      psppire_axis_impl_clear (de->vaxis[i]);
-      psppire_axis_impl_append_n (de->vaxis[i], n_cases, DEFAULT_ROW_HEIGHT);
+      psppire_axis_clear (de->vaxis[i]);
+      psppire_axis_append_n (de->vaxis[i], n_cases, DEFAULT_ROW_HEIGHT);
     }
 }
 
@@ -232,7 +233,7 @@ case_inserted_callback (PsppireDataStore *ds, gint before, gpointer data)
   PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
 
   for (i = 0; i < 2; ++i)
-    psppire_axis_impl_insert (de->vaxis[i], before, DEFAULT_ROW_HEIGHT);
+    psppire_axis_insert (de->vaxis[i], before, DEFAULT_ROW_HEIGHT);
 }
 
 
@@ -243,7 +244,7 @@ cases_deleted_callback (PsppireDataStore *ds, gint first, gint n_cases, gpointer
   PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
 
   for (i = 0; i < 2; ++i)
-    psppire_axis_impl_delete (de->vaxis[0], first, n_cases);
+    psppire_axis_delete (de->vaxis[0], first, n_cases);
 }
 
 
@@ -288,22 +289,22 @@ new_variables_callback (PsppireDict *dict, gpointer data)
   PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
   gint m_width = width_of_m (GTK_WIDGET (de));
 
-  PsppireAxisImpl *vaxis;
+  PsppireAxis *vaxis;
   g_object_get (de->var_sheet, "vertical-axis", &vaxis, NULL);
 
-  psppire_axis_impl_clear (vaxis);
-  psppire_axis_impl_append_n (vaxis, 1 + psppire_dict_get_var_cnt (dict), DEFAULT_ROW_HEIGHT);
+  psppire_axis_clear (vaxis);
+  psppire_axis_append_n (vaxis, 1 + psppire_dict_get_var_cnt (dict), DEFAULT_ROW_HEIGHT);
 
   g_signal_connect_swapped (de->haxis, "resize-unit",
                            G_CALLBACK (rewidth_variable), de);
 
-  psppire_axis_impl_clear (de->haxis);
+  psppire_axis_clear (de->haxis);
 
   for (v = 0 ; v < psppire_dict_get_var_cnt (dict); ++v)
     {
       const struct variable *var = psppire_dict_get_variable (dict, v);
 
-      psppire_axis_impl_append (de->haxis, m_width * var_get_display_width (var));
+      psppire_axis_append (de->haxis, m_width * var_get_display_width (var));
     }
 }
 
@@ -314,16 +315,16 @@ insert_variable_callback (PsppireDict *dict, gint x, gpointer data)
 
   gint m_width  = width_of_m (GTK_WIDGET (de));
 
-  PsppireAxisImpl *var_vaxis;
+  PsppireAxis *var_vaxis;
 
   const struct variable *var = psppire_dict_get_variable (dict, x);
 
   g_object_get (de->var_sheet, "vertical-axis", &var_vaxis, NULL);
 
-  psppire_axis_impl_insert (var_vaxis, x, DEFAULT_ROW_HEIGHT);
+  psppire_axis_insert (var_vaxis, x, DEFAULT_ROW_HEIGHT);
 
 
-  psppire_axis_impl_insert (de->haxis, x, m_width * var_get_display_width (var));
+  psppire_axis_insert (de->haxis, x, m_width * var_get_display_width (var));
 }
 
 
@@ -333,12 +334,12 @@ delete_variable_callback (PsppireDict *dict, gint posn,
 {
   PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
 
-  PsppireAxisImpl *var_vaxis;
+  PsppireAxis *var_vaxis;
   g_object_get (de->var_sheet, "vertical-axis", &var_vaxis, NULL);
 
-  psppire_axis_impl_delete (var_vaxis, posn, 1);
+  psppire_axis_delete (var_vaxis, posn, 1);
 
-  psppire_axis_impl_delete (de->haxis, posn, 1);
+  psppire_axis_delete (de->haxis, posn, 1);
 }
 
 
@@ -356,7 +357,7 @@ rewidth_variable_callback (PsppireDict *dict, gint posn, gpointer data)
   if ( var_width < 1 )
     var_width = 1;
 
-  psppire_axis_impl_resize (de->haxis, posn, m_width * var_width);
+  psppire_axis_resize (de->haxis, posn, m_width * var_width);
 }
 
 
@@ -380,9 +381,15 @@ psppire_data_editor_set_property (GObject         *object,
       g_object_ref (de->data_store);
 
       for (i = 0 ; i < 4 ; ++i )
-       g_object_set (de->data_sheet[i],
-                     "model", de->data_store,
-                     NULL);
+       {
+         g_object_set (de->data_sheet[i],
+                       "model", de->data_store,
+                       NULL);
+
+         g_signal_connect_swapped (de->data_store->dict, "filter-changed",
+                                   G_CALLBACK (gtk_widget_queue_draw),
+                                   de->data_sheet[i]);
+       }
 
       g_signal_connect (de->data_store->dict, "backend-changed",
                        G_CALLBACK (new_variables_callback), de);
@@ -737,13 +744,10 @@ update_data_ref_entry (const PsppireSheet *sheet,
          gchar *text = g_strdup_printf ("%d: %s", row + FIRST_CASE_NUMBER,
                                         var_get_name (var));
 
-         gchar *s = pspp_locale_to_utf8 (text, -1, 0);
 
-         g_free (text);
-
-         gtk_entry_set_text (GTK_ENTRY (de->cell_ref_entry), s);
+         gtk_entry_set_text (GTK_ENTRY (de->cell_ref_entry), text);
 
-         g_free (s);
+         g_free (text);
        }
       else
        goto blank_entry;
@@ -816,8 +820,8 @@ on_map (GtkWidget *w)
 static void
 init_sheet (PsppireDataEditor *de, int i,
            GtkAdjustment *hadj, GtkAdjustment *vadj,
-           PsppireAxisImpl *vaxis,
-           PsppireAxisImpl *haxis
+           PsppireAxis *vaxis,
+           PsppireAxis *haxis
            )
 {
   de->sheet_bin[i] = gtk_scrolled_window_new (hadj, vadj);
@@ -853,13 +857,12 @@ init_data_sheet (PsppireDataEditor *de)
   GtkAdjustment *vadj1, *hadj1;
   GtkWidget *sheet ;
 
-  de->vaxis[0] = psppire_axis_impl_new ();
-  de->vaxis[1] = psppire_axis_impl_new ();
+  de->vaxis[0] = psppire_axis_new ();
+  de->vaxis[1] = psppire_axis_new ();
 
-  /* Txoxovhere's only one horizontal axis, since the
+  /* There's only one horizontal axis, since the
      column widths are parameters of the variables */
-  de->haxis = psppire_axis_impl_new ();
-
+  de->haxis = psppire_axis_new ();
 
   de->split = TRUE;
   de->paned = gtk_xpaned_new ();
@@ -1296,13 +1299,15 @@ psppire_data_editor_insert_variable (PsppireDataEditor *de)
   switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (de)))
     {
     case PSPPIRE_DATA_EDITOR_DATA_VIEW:
-      if ( de->data_sheet[0]->state == PSPPIRE_SHEET_COLUMN_SELECTED )
+      if ( PSPPIRE_SHEET (de->data_sheet[0])->select_status
+          == PSPPIRE_SHEET_COLUMN_SELECTED )
        posn = PSPPIRE_SHEET (de->data_sheet[0])->range.col0;
       else
        posn = PSPPIRE_SHEET (de->data_sheet[0])->active_cell.col;
       break;
     case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
-      if ( de->var_sheet->state == PSPPIRE_SHEET_ROW_SELECTED )
+      if ( PSPPIRE_SHEET (de->var_sheet)->select_status
+          == PSPPIRE_SHEET_ROW_SELECTED )
        posn = PSPPIRE_SHEET (de->var_sheet)->range.row0;
       else
        posn = PSPPIRE_SHEET (de->var_sheet)->active_cell.row;
@@ -1321,10 +1326,14 @@ psppire_data_editor_insert_case (PsppireDataEditor *de)
 {
   glong posn = -1;
 
-  if ( de->data_sheet[0]->state == PSPPIRE_SHEET_ROW_SELECTED )
-    posn = PSPPIRE_SHEET (de->data_sheet[0])->range.row0;
+  if ( PSPPIRE_SHEET (de->data_sheet[0])->select_status == PSPPIRE_SHEET_ROW_SELECTED )
+    {
+      posn = PSPPIRE_SHEET (de->data_sheet[0])->range.row0;
+    }
   else
-    posn = PSPPIRE_SHEET (de->data_sheet[0])->active_cell.row;
+    {
+      posn = PSPPIRE_SHEET (de->data_sheet[0])->active_cell.row;
+    }
 
   if ( posn == -1 ) posn = 0;
 
@@ -1612,7 +1621,7 @@ data_sheet_set_clip (PsppireSheet *sheet)
 
   /* Construct clip data. */
   map = case_map_by_name (ds->dict->dict, clip_dict);
-  writer = autopaging_writer_create (dict_get_next_value_idx (clip_dict));
+  writer = autopaging_writer_create (dict_get_proto (clip_dict));
   for (i = range.row0; i <= range.rowi ; ++i )
     {
       struct ccase *old = psppire_data_store_get_case (ds, i);
@@ -1640,17 +1649,14 @@ static void
 data_out_g_string (GString *string, const struct variable *v,
                   const struct ccase *cc)
 {
-  char *buf ;
-
   const struct fmt_spec *fs = var_get_print_format (v);
   const union value *val = case_data (cc, v);
-  buf = xzalloc (fs->w);
 
-  data_out (val, fs, buf);
+  char *s = data_out (val, fs);
 
-  g_string_append_len (string, buf, fs->w);
+  g_string_append_len (string, s, fs->w);
 
-  g_free (buf);
+  g_free (s);
 }
 
 static GString *
@@ -1659,7 +1665,7 @@ clip_to_text (void)
   casenumber r;
   GString *string;
 
-  const size_t val_cnt = casereader_get_value_cnt (clip_datasheet);
+  const size_t val_cnt = caseproto_get_n_widths (casereader_get_proto (clip_datasheet));
   const casenumber case_cnt = casereader_get_case_cnt (clip_datasheet);
   const size_t var_cnt = dict_get_var_cnt (clip_dict);
 
@@ -1701,7 +1707,7 @@ clip_to_html (void)
   casenumber r;
   GString *string;
 
-  const size_t val_cnt = casereader_get_value_cnt (clip_datasheet);
+  const size_t val_cnt = caseproto_get_n_widths (casereader_get_proto (clip_datasheet));
   const casenumber case_cnt = casereader_get_case_cnt (clip_datasheet);
   const size_t var_cnt = dict_get_var_cnt (clip_dict);