#include "var-display.h"
-#define TRAILING_ROWS 40
+enum
+ {
+ PSPPIRE_VAR_STORE_TRAILING_ROWS = 1,
+ PSPPIRE_VAR_STORE_FORMAT_TYPE
+ };
static void psppire_var_store_init (PsppireVarStore *var_store);
static void psppire_var_store_class_init (PsppireVarStoreClass *class);
const gchar *text, glong row, glong column);
static glong psppire_var_store_get_row_count (const GSheetModel * model);
+static glong psppire_var_store_get_column_count (const GSheetModel * model);
static gchar *text_for_column (const struct variable *pv, gint c, GError **err);
static GObjectClass *parent_class = NULL;
+GType
+psppire_var_store_format_type_get_type (void)
+{
+ static GType etype = 0;
+ if (etype == 0)
+ {
+ static const GEnumValue values[] =
+ {
+ { PSPPIRE_VAR_STORE_INPUT_FORMATS,
+ "PSPPIRE_VAR_STORE_INPUT_FORMATS",
+ "input" },
+ { PSPPIRE_VAR_STORE_OUTPUT_FORMATS,
+ "PSPPIRE_VAR_STORE_OUTPUT_FORMATS",
+ "output" },
+ { 0, NULL, NULL }
+ };
+
+ etype = g_enum_register_static
+ (g_intern_static_string ("PsppireVarStoreFormatType"), values);
+
+ }
+ return etype;
+}
+
GType
psppire_var_store_get_type (void)
{
return var_store_type;
}
+static void
+psppire_var_store_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireVarStore *self = (PsppireVarStore *) object;
+
+ switch (property_id)
+ {
+ case PSPPIRE_VAR_STORE_TRAILING_ROWS:
+ self->trailing_rows = g_value_get_int (value);
+ break;
+
+ case PSPPIRE_VAR_STORE_FORMAT_TYPE:
+ self->format_type = g_value_get_enum (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+psppire_var_store_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PsppireVarStore *self = (PsppireVarStore *) object;
+
+ switch (property_id)
+ {
+ case PSPPIRE_VAR_STORE_TRAILING_ROWS:
+ g_value_set_int (value, self->trailing_rows);
+ break;
+
+ case PSPPIRE_VAR_STORE_FORMAT_TYPE:
+ g_value_set_enum (value, self->format_type);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+}
+
+
static void
psppire_var_store_class_init (PsppireVarStoreClass *class)
{
GObjectClass *object_class;
+ GParamSpec *pspec;
parent_class = g_type_class_peek_parent (class);
object_class = (GObjectClass*) class;
object_class->finalize = psppire_var_store_finalize;
+ object_class->set_property = psppire_var_store_set_property;
+ object_class->get_property = psppire_var_store_get_property;
+
+ /* The minimum value for trailing-rows is 1 to prevent the
+ var-store from ever having 0 rows, which breaks invariants
+ in gtksheet. */
+ pspec = g_param_spec_int ("trailing-rows",
+ "Trailing rows",
+ "Number of rows displayed after last variable",
+ 1 /* minimum value */,
+ 100 /* maximum value */,
+ 40 /* default value */,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class,
+ PSPPIRE_VAR_STORE_TRAILING_ROWS,
+ pspec);
+
+ pspec = g_param_spec_enum ("format-type",
+ "Variable format type",
+ ("Whether variables have input or output "
+ "formats"),
+ G_TYPE_PSPPIRE_VAR_STORE_FORMAT_TYPE,
+ PSPPIRE_VAR_STORE_OUTPUT_FORMATS,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class,
+ PSPPIRE_VAR_STORE_FORMAT_TYPE,
+ pspec);
}
-
static void
psppire_var_store_init (PsppireVarStore *var_store)
{
gdk_colormap_alloc_color (colormap, &var_store->disabled, FALSE, TRUE);
var_store->dict = 0;
+ var_store->trailing_rows = 40;
+ var_store->format_type = PSPPIRE_VAR_STORE_OUTPUT_FORMATS;
}
static gboolean
+
static void
psppire_var_store_sheet_model_init (GSheetModelIface *iface)
{
iface->get_row_count = psppire_var_store_get_row_count;
+ iface->get_column_count = psppire_var_store_get_column_count;
iface->free_strings = TRUE;
iface->get_string = psppire_var_store_get_string;
iface->set_string = psppire_var_store_set_string;
g_sheet_model_rows_inserted (model, row, 1);
}
+static void
+refresh (PsppireDict *d, gpointer data)
+{
+ PsppireVarStore *vs = data;
+ g_sheet_model_range_changed (G_SHEET_MODEL (vs), -1, -1, -1, -1);
+}
/**
* psppire_var_store_replace_set_dictionary:
g_signal_connect (dict, "variable-deleted", G_CALLBACK (var_delete_callback),
var_store);
- g_signal_connect (dict, "variable-inserted", G_CALLBACK (var_insert_callback),
- var_store);
+ g_signal_connect (dict, "variable-inserted",
+ G_CALLBACK (var_insert_callback), var_store);
+ g_signal_connect (dict, "backend-changed", G_CALLBACK (refresh),
+ var_store);
/* The entire model has changed */
g_sheet_model_range_changed (G_SHEET_MODEL (var_store), -1, -1, -1, -1);
var_set_width (pv, width);
else
{
+ bool for_input
+ = var_store->format_type == PSPPIRE_VAR_STORE_INPUT_FORMATS;
struct fmt_spec fmt ;
fmt = *var_get_write_format (pv);
- if ( width < fmt_min_output_width (fmt.type)
+ if ( width < fmt_min_width (fmt.type, for_input)
||
- width > fmt_max_output_width (fmt.type))
+ width > fmt_max_width (fmt.type, for_input))
return FALSE;
fmt.w = width;
- fmt.d = MIN (fmt_max_output_decimals (fmt.type, width), fmt.d);
+ fmt.d = MIN (fmt_max_decimals (fmt.type, width, for_input), fmt.d);
var_set_both_formats (pv, &fmt);
}
break;
case COL_DECIMALS:
{
+ bool for_input
+ = var_store->format_type == PSPPIRE_VAR_STORE_INPUT_FORMATS;
int decimals;
struct fmt_spec fmt;
if ( ! text) return FALSE;
decimals = atoi (text);
fmt = *var_get_write_format (pv);
if ( decimals >
- fmt_max_output_decimals (fmt.type,
- fmt.w
- ))
+ fmt_max_decimals (fmt.type,
+ fmt.w,
+ for_input
+ ))
return FALSE;
fmt.d = decimals;
return rows ;
}
+static glong
+psppire_var_store_get_column_count (const GSheetModel * model)
+{
+ return n_COLS ;
+}
+
+
/* Row related funcs */
static glong
if (vs->dict)
rows = psppire_dict_get_var_cnt (vs->dict);
- return rows + TRAILING_ROWS;
+ return rows + vs->trailing_rows;
}
static gchar *
geometry_get_button_label (const GSheetRow *geom, glong unit, gpointer data)
{
- gchar *label = g_strdup_printf (_("%ld"), unit);
+ gchar *label = g_strdup_printf (_("%ld"), unit + 1);
return label;
}