Set variable display width when datasheet's columns are resized.
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 7 Dec 2008 02:14:16 +0000 (11:14 +0900)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 7 Dec 2008 02:14:16 +0000 (11:14 +0900)
lib/gtksheet/marshaller-list
lib/gtksheet/psppire-axis.c
src/ui/gui/psppire-data-editor.c

index df5ac6ceda1ea0800a96f9cb072fb522fb32bbc4..cb7c9113afe67df6cb514b702a2db820f5231603 100644 (file)
@@ -6,6 +6,7 @@ BOOLEAN:BOXED,POINTER
 BOOLEAN:VOID
 VOID:BOXED,BOXED
 VOID:INT,INT
+VOID:INT,LONG
 VOID:INT,INT,INT
 VOID:INT,INT,INT,INT
 VOID:INT,POINTER
index 8a4eb568545a9c4725afa61c3eaede17ea037e33..b30005a20b93a14687330da0a21385bcde287b9e 100644 (file)
 #include <libpspp/pool.h>
 #include <libpspp/misc.h>
 #include "psppire-axis.h"
+#include "psppire-marshal.h"
 #include <gtk/gtk.h>
 
 
+
+/* Signals */
+enum
+  {
+    RESIZE_UNIT,
+    n_signals
+  };
+
+static guint signals[n_signals] ;
+
+
 #define PSPPIRE_AXIS_GET_IFACE(obj) \
   (G_TYPE_INSTANCE_GET_INTERFACE ((obj), PSPPIRE_TYPE_AXIS_IFACE, PsppireAxisIface))
 
@@ -163,6 +175,20 @@ psppire_axis_class_init (PsppireAxisClass *class)
   parent_class = g_type_class_peek_parent (class);
 
   object_class->finalize = psppire_axis_finalize;
+
+
+  signals[RESIZE_UNIT] =
+    g_signal_new ("resize-unit",
+                 G_TYPE_FROM_CLASS (object_class),
+                 G_SIGNAL_RUN_LAST,
+                 0,
+                 NULL, NULL,
+                 psppire_marshal_VOID__INT_LONG,
+                 G_TYPE_NONE,
+                 2,
+                 G_TYPE_INT,
+                 G_TYPE_LONG
+                 );
 }
 
 
@@ -265,6 +291,9 @@ psppire_axis_resize (PsppireAxis *a, gint unit, glong size)
 
   if (PSPPIRE_AXIS_GET_IFACE (a)->resize)
     PSPPIRE_AXIS_GET_IFACE (a)->resize (a, unit, size);
+
+
+  g_signal_emit (a, signals [RESIZE_UNIT], 0, unit, size);
 }
 
 
index 74660f12e37caa2b96bee61f976986496a9b0974..dcc2cdf8e7ba58be3571b20628ce5d7f9dc2b053 100644 (file)
@@ -280,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)
 {
@@ -298,6 +310,9 @@ new_variables_callback (PsppireDict *dict, gpointer data)
       PsppireAxisImpl *haxis;
       g_object_get (de->data_sheet[i], "horizontal-axis", &haxis, NULL);
 
+      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)