From 3785800c7a660f059857b66ec36efec99af0d052 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 7 Dec 2008 11:14:16 +0900 Subject: [PATCH] Set variable display width when datasheet's columns are resized. --- lib/gtksheet/marshaller-list | 1 + lib/gtksheet/psppire-axis.c | 29 +++++++++++++++++++++++++++++ src/ui/gui/psppire-data-editor.c | 15 +++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/lib/gtksheet/marshaller-list b/lib/gtksheet/marshaller-list index df5ac6ce..cb7c9113 100644 --- a/lib/gtksheet/marshaller-list +++ b/lib/gtksheet/marshaller-list @@ -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 diff --git a/lib/gtksheet/psppire-axis.c b/lib/gtksheet/psppire-axis.c index 8a4eb568..b30005a2 100644 --- a/lib/gtksheet/psppire-axis.c +++ b/lib/gtksheet/psppire-axis.c @@ -22,9 +22,21 @@ #include #include #include "psppire-axis.h" +#include "psppire-marshal.h" #include + +/* 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); } diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 74660f12..dcc2cdf8 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -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) -- 2.30.2