Written a proper implementation of psppire_axis_impl_delete
[pspp-builds.git] / src / ui / gui / psppire-data-editor.c
index c68133df2cacab89941e8c58433b16f0714bb6ed..cab0f755bc5a20f8a1eeee9162ff1b4f6ff60d9f 100644 (file)
@@ -23,8 +23,7 @@
 
 #include <language/syntax-string-source.h>
 #include "psppire-data-store.h"
-#include <gtksheet/psppire-axis-hetero.h>
-#include <gtksheet/psppire-axis-uniform.h>
+#include <gtksheet/psppire-axis-impl.h>
 #include "helper.h"
 
 #include <gtksheet/gtkxpaned.h>
@@ -218,12 +217,13 @@ new_data_callback (PsppireDataStore *ds, gpointer data)
   gint i;
   for (i = 0 ; i < 4 ; ++i)
     {
-      PsppireAxisUniform *vaxis;
+      PsppireAxisImpl *vaxis;
       casenumber n_cases =  psppire_data_store_get_case_count (ds);
 
       g_object_get (de->data_sheet[i], "vertical-axis", &vaxis, NULL);
 
-      psppire_axis_uniform_set_count (vaxis, n_cases);
+      psppire_axis_impl_clear (vaxis);
+      psppire_axis_impl_append_n (vaxis, n_cases, DEFAULT_ROW_HEIGHT);
     }
 }
 
@@ -236,12 +236,11 @@ case_inserted_callback (PsppireDataStore *ds, gint before, gpointer data)
 
   for (i = 0 ; i < 4 ; ++i)
     {
-      PsppireAxisUniform *vaxis;
-      casenumber n_cases =  psppire_data_store_get_case_count (ds);
+      PsppireAxisImpl *vaxis;
 
       g_object_get (de->data_sheet[i], "vertical-axis", &vaxis, NULL);
 
-      psppire_axis_uniform_set_count (vaxis, n_cases + 1);
+      psppire_axis_impl_insert (vaxis, before, DEFAULT_ROW_HEIGHT);
     }
 }
 
@@ -255,12 +254,11 @@ cases_deleted_callback (PsppireDataStore *ds, gint first, gint n_cases, gpointer
 
   for (i = 0 ; i < 4 ; ++i)
     {
-      PsppireAxisUniform *vaxis;
-      casenumber case_count =  psppire_data_store_get_case_count (ds);
+      PsppireAxisImpl *vaxis;
 
       g_object_get (de->data_sheet[i], "vertical-axis", &vaxis, NULL);
 
-      psppire_axis_uniform_set_count (vaxis, case_count - n_cases);
+      psppire_axis_impl_delete (vaxis, first, n_cases);
     }
 }
 
@@ -282,6 +280,18 @@ width_of_m (GtkWidget *w)
   return rect.width;
 }
 
+/* Callback for the axis' resize signal.
+   Changes the variable's display width */
+static void
+rewidth_variable (PsppireDataEditor *de, gint unit, glong size)
+{
+  const PsppireDict *dict = de->data_store->dict;
+  struct variable *var = psppire_dict_get_variable (dict, unit);
+
+  var_set_display_width (var, size / (float) width_of_m (de));
+}
+
+
 static void
 new_variables_callback (PsppireDict *dict, gpointer data)
 {
@@ -289,26 +299,27 @@ new_variables_callback (PsppireDict *dict, gpointer data)
   PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
   gint m_width = width_of_m (GTK_WIDGET (de));
 
-  PsppireAxisHetero *vaxis;
+  PsppireAxisImpl *vaxis;
   g_object_get (de->var_sheet, "vertical-axis", &vaxis, NULL);
 
-  psppire_axis_hetero_clear (vaxis);
-
-  for (v = 0 ; v < psppire_dict_get_var_cnt (dict); ++v)
-    psppire_axis_hetero_append (vaxis, DEFAULT_ROW_HEIGHT);
+  psppire_axis_impl_clear (vaxis);
+  psppire_axis_impl_append_n (vaxis, 1 + psppire_dict_get_var_cnt (dict), DEFAULT_ROW_HEIGHT);
 
   for (i = 0 ; i < 4 ; ++i)
     {
-      PsppireAxisHetero *haxis;
+      PsppireAxisImpl *haxis;
       g_object_get (de->data_sheet[i], "horizontal-axis", &haxis, NULL);
 
-      psppire_axis_hetero_clear (haxis);
+      g_signal_connect_swapped (haxis, "resize-unit",
+                               G_CALLBACK (rewidth_variable), de);
+
+      psppire_axis_impl_clear (haxis);
 
       for (v = 0 ; v < psppire_dict_get_var_cnt (dict); ++v)
        {
          const struct variable *var = psppire_dict_get_variable (dict, v);
 
-         psppire_axis_hetero_append (haxis, m_width * var_get_display_width (var));
+         psppire_axis_impl_append (haxis, m_width * var_get_display_width (var));
        }
     }
 }
@@ -322,18 +333,18 @@ insert_variable_callback (PsppireDict *dict, gint x, gpointer data)
 
   gint m_width  = width_of_m (GTK_WIDGET (de));
 
-  PsppireAxisHetero *var_vaxis;
+  PsppireAxisImpl *var_vaxis;
   g_object_get (de->var_sheet, "vertical-axis", &var_vaxis, NULL);
 
-  psppire_axis_hetero_insert (var_vaxis, DEFAULT_ROW_HEIGHT, x);
+  psppire_axis_impl_insert (var_vaxis, x, DEFAULT_ROW_HEIGHT);
 
   for (i = 0 ; i < 4 ; ++i)
     {
       const struct variable *var = psppire_dict_get_variable (dict, x);
-      PsppireAxisHetero *haxis;
+      PsppireAxisImpl *haxis;
       g_object_get (de->data_sheet[i], "horizontal-axis", &haxis, NULL);
 
-      psppire_axis_hetero_insert (haxis, m_width * var_get_display_width (var), x);
+      psppire_axis_impl_insert (haxis, x, m_width * var_get_display_width (var));
     }
 }
 
@@ -345,18 +356,18 @@ delete_variable_callback (PsppireDict *dict, gint posn,
   gint i;
   PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
 
-  PsppireAxisHetero *var_vaxis;
+  PsppireAxisImpl *var_vaxis;
   g_object_get (de->var_sheet, "vertical-axis", &var_vaxis, NULL);
 
-  psppire_axis_hetero_remove (var_vaxis, posn);
+  psppire_axis_impl_delete (var_vaxis, posn, 1);
 
-  for (i = 0 ; i < 4 ; ++i)
-    {
-      PsppireAxisHetero *haxis;
-      g_object_get (de->data_sheet[i], "horizontal-axis", &haxis, NULL);
 
-      psppire_axis_hetero_remove (haxis, posn);
-    }
+  {
+    PsppireAxisImpl *haxis;
+    g_object_get (de->data_sheet[0], "horizontal-axis", &haxis, NULL);
+
+    psppire_axis_impl_delete (haxis, posn, 1);
+  }
 }
 
 
@@ -370,12 +381,11 @@ rewidth_variable_callback (PsppireDict *dict, gint posn, gpointer data)
   for (i = 0 ; i < 4 ; ++i)
     {
       const struct variable *var = psppire_dict_get_variable (dict, posn);
-      PsppireAxisHetero *haxis;
+      PsppireAxisImpl *haxis;
       g_object_get (de->data_sheet[i], "horizontal-axis", &haxis, NULL);
 
-      psppire_axis_hetero_resize_unit (haxis,
-                                      m_width *
-                                      var_get_display_width (var), posn);
+      psppire_axis_impl_resize (haxis, posn, m_width *
+                                 var_get_display_width (var));
     }
 }
 
@@ -833,10 +843,11 @@ on_map (GtkWidget *w)
 
 static void
 init_sheet (PsppireDataEditor *de, int i,
-           GtkAdjustment *hadj, GtkAdjustment *vadj)
+           GtkAdjustment *hadj, GtkAdjustment *vadj,
+           PsppireAxisImpl *vaxis,
+           PsppireAxisImpl *haxis
+           )
 {
-  PsppireAxisHetero *haxis = psppire_axis_hetero_new ();
-  PsppireAxisUniform *vaxis = psppire_axis_uniform_new ();
   de->sheet_bin[i] = gtk_scrolled_window_new (hadj, vadj);
 
   de->data_sheet[i] = gtk_sheet_new (NULL);
@@ -866,38 +877,46 @@ init_sheet (PsppireDataEditor *de, int i,
 static void
 init_data_sheet (PsppireDataEditor *de)
 {
-  GtkAdjustment *va0, *ha0;
-  GtkAdjustment *va1, *ha1;
+  GtkAdjustment *vadj0, *hadj0;
+  GtkAdjustment *vadj1, *hadj1;
   GtkWidget *sheet ;
 
+  PsppireAxisImpl *vaxis0 = psppire_axis_impl_new ();
+  PsppireAxisImpl *vaxis1 = psppire_axis_impl_new ();
+
+  /* There's only one horizontal axis, since the
+     column widths are parameters of the variables */
+  PsppireAxisImpl *haxis = psppire_axis_impl_new ();
+
+
   de->split = TRUE;
   de->paned = gtk_xpaned_new ();
 
-  init_sheet (de, 0, NULL, NULL);
+  init_sheet (de, 0, NULL, NULL, vaxis0, haxis);
   gtk_widget_show (de->sheet_bin[0]);
-  va0 = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[0]));
-  ha0 = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[0]));
+  vadj0 = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[0]));
+  hadj0 = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[0]));
 
   g_object_set (de->sheet_bin[0], "vscrollbar-policy", GTK_POLICY_NEVER, NULL);
   g_object_set (de->sheet_bin[0], "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
 
-  init_sheet (de, 1, NULL, va0);
+  init_sheet (de, 1, NULL, vadj0, vaxis0, haxis);
   gtk_widget_show (de->sheet_bin[1]);
   sheet = gtk_bin_get_child (GTK_BIN (de->sheet_bin[1]));
   gtk_sheet_hide_row_titles (GTK_SHEET (sheet));
-  ha1 = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[1]));
+  hadj1 = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[1]));
   g_object_set (de->sheet_bin[1], "vscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
   g_object_set (de->sheet_bin[1], "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
 
-  init_sheet (de, 2, ha0, NULL);
+  init_sheet (de, 2, hadj0, NULL, vaxis1, haxis);
   gtk_widget_show (de->sheet_bin[2]);
   sheet = gtk_bin_get_child (GTK_BIN (de->sheet_bin[2]));
   gtk_sheet_hide_column_titles (GTK_SHEET (sheet));
   g_object_set (de->sheet_bin[2], "vscrollbar-policy", GTK_POLICY_NEVER, NULL);
   g_object_set (de->sheet_bin[2], "hscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
-  va1 = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[2]));
+  vadj1 = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[2]));
 
-  init_sheet (de, 3, ha1, va1);
+  init_sheet (de, 3, hadj1, vadj1, vaxis1, haxis);
   gtk_widget_show (de->sheet_bin[3]);
   sheet = gtk_bin_get_child (GTK_BIN (de->sheet_bin[3]));
   gtk_sheet_hide_column_titles (GTK_SHEET (sheet));