From 1641c5707278765ec595bda341378aa7c6bec152 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 22 Jun 2013 09:37:11 +0200 Subject: [PATCH] dictionary.c: Remove the var_resized and var_display_width_changed callbacks Remove the resized and display width changed callbacks, and transfer their actions to the variable_changed callback. --- src/data/dictionary.c | 38 --------------------- src/data/dictionary.h | 2 -- src/data/vardict.h | 2 -- src/data/variable.c | 2 -- src/ui/gui/psppire-data-sheet.c | 8 +++-- src/ui/gui/psppire-data-store.c | 58 ++++++++++++------------------- src/ui/gui/psppire-data-store.h | 1 - src/ui/gui/psppire-dict.c | 60 +-------------------------------- src/ui/gui/psppire-dict.h | 4 --- 9 files changed, 27 insertions(+), 148 deletions(-) diff --git a/src/data/dictionary.c b/src/data/dictionary.c index ff0587553f..79952b5814 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1619,44 +1619,6 @@ dict_var_changed (const struct variable *v, unsigned int what, struct variable * } -/* Called from variable.c to notify the dictionary that the variable's width - has changed */ -void -dict_var_resized (const struct variable *v, int old_width) -{ - if ( var_has_vardict (v)) - { - const struct vardict_info *vardict = var_get_vardict (v); - struct dictionary *d; - - d = vardict->dict; - - if (d->changed) d->changed (d, d->changed_data); - - invalidate_proto (d); - if ( d->callbacks && d->callbacks->var_resized ) - d->callbacks->var_resized (d, var_get_dict_index (v), old_width, - d->cb_data); - } -} - -/* Called from variable.c to notify the dictionary that the variable's display width - has changed */ -void -dict_var_display_width_changed (const struct variable *v) -{ - if ( var_has_vardict (v)) - { - const struct vardict_info *vardict = var_get_vardict (v); - struct dictionary *d; - - d = vardict->dict; - - if (d->changed) d->changed (d, d->changed_data); - if ( d->callbacks && d->callbacks->var_display_width_changed ) - d->callbacks->var_display_width_changed (d, var_get_dict_index (v), d->cb_data); - } -} /* Dictionary used to contain "internal variables". */ static struct dictionary *internal_dict; diff --git a/src/data/dictionary.h b/src/data/dictionary.h index fdc28611f6..66542469e3 100644 --- a/src/data/dictionary.h +++ b/src/data/dictionary.h @@ -182,11 +182,9 @@ struct dict_callbacks void (*var_deleted) (struct dictionary *, const struct variable *, int dict_index, int case_index, void *); void (*var_changed) (struct dictionary *, int, unsigned int, const struct variable *, void *); - void (*var_resized) (struct dictionary *, int, int, void *); void (*weight_changed) (struct dictionary *, int, void *); void (*filter_changed) (struct dictionary *, int, void *); void (*split_changed) (struct dictionary *, void *); - void (*var_display_width_changed) (struct dictionary *, int, void *); }; void dict_set_callbacks (struct dictionary *, const struct dict_callbacks *, diff --git a/src/data/vardict.h b/src/data/vardict.h index 76e1c05c8a..ecef88274b 100644 --- a/src/data/vardict.h +++ b/src/data/vardict.h @@ -40,8 +40,6 @@ void var_clear_vardict (struct variable *); /* Called by variable.c, defined in dictionary.c. */ void dict_var_changed (const struct variable *v, unsigned int what, struct variable *ov); -void dict_var_resized (const struct variable *v, int old_width); -void dict_var_display_width_changed (const struct variable *v); int vardict_get_dict_index (const struct vardict_info *); diff --git a/src/data/variable.c b/src/data/variable.c index 6affaec6e8..16c655b9ba 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -278,7 +278,6 @@ var_set_width (struct variable *v, int new_width) fmt_resize (&v->write, new_width); v->width = new_width; - dict_var_resized (v, old_width); dict_var_changed (v, VAR_TRAIT_WIDTH, ov); } @@ -835,7 +834,6 @@ var_set_display_width_quiet (struct variable *v, int new_width) if (v->display_width != new_width) { v->display_width = new_width; - dict_var_display_width_changed (v); } } diff --git a/src/ui/gui/psppire-data-sheet.c b/src/ui/gui/psppire-data-sheet.c index 746494eeeb..55b8d884d4 100644 --- a/src/ui/gui/psppire-data-sheet.c +++ b/src/ui/gui/psppire-data-sheet.c @@ -1922,11 +1922,16 @@ on_variable_changed (PsppireDict *dict, int dict_index, g_return_if_fail (data_sheet->data_store != NULL); g_return_if_fail (dict == data_sheet->data_store->dict); + + if (what & VAR_TRAIT_DISPLAY_WIDTH) + on_variable_display_width_changed (dict, dict_index, data_sheet); + column = psppire_data_sheet_find_column_for_variable (data_sheet, dict_index); if (column == NULL) return; + var = psppire_dict_get_variable (data_store->dict, dict_index); g_return_if_fail (var != NULL); @@ -2046,9 +2051,6 @@ psppire_data_sheet_set_data_store (PsppireDataSheet *data_sheet, g_signal_connect (data_store->dict, "variable-changed", G_CALLBACK (on_variable_changed), data_sheet); - g_signal_connect (data_store->dict, "variable-display-width-changed", - G_CALLBACK (on_variable_display_width_changed), - data_sheet); g_signal_connect (data_store->dict, "variable-inserted", G_CALLBACK (on_variable_inserted), data_sheet); g_signal_connect (data_store->dict, "variable-deleted", diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 7104d3a30a..f3543f13f1 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -210,35 +210,13 @@ delete_variable_callback (GObject *obj, const struct variable *var UNUSED, datasheet_insert_column (store->datasheet, NULL, -1, case_index); } -static void -variable_changed_callback (GObject *obj, gint var_num, guint what, const struct variable *oldvar, gpointer data) -{ -} - -static void -insert_variable_callback (GObject *obj, gint var_num, gpointer data) -{ - struct variable *variable; - PsppireDataStore *store; - gint posn; - - g_return_if_fail (data); - - store = PSPPIRE_DATA_STORE (data); - - variable = psppire_dict_get_variable (store->dict, var_num); - posn = var_get_case_index (variable); - psppire_data_store_insert_value (store, var_get_width (variable), posn); -} - struct resize_datum_aux { int old_width; int new_width; }; - -void +static void resize_datum (const union value *old, union value *new, void *aux_) { struct resize_datum_aux *aux = aux_; @@ -258,27 +236,38 @@ resize_datum (const union value *old, union value *new, void *aux_) } static void -dict_size_change_callback (GObject *obj, - gint var_num, gint old_width, gpointer data) +variable_changed_callback (GObject *obj, gint var_num, guint what, const struct variable *oldvar, + gpointer data) { PsppireDataStore *store = PSPPIRE_DATA_STORE (data); - struct variable *variable; - int posn; - - variable = psppire_dict_get_variable (store->dict, var_num); - posn = var_get_case_index (variable); + struct variable *variable = psppire_dict_get_variable (store->dict, var_num); - if (old_width != var_get_width (variable)) + if (what & VAR_TRAIT_WIDTH) { + int posn = var_get_case_index (variable); struct resize_datum_aux aux; - aux.old_width = old_width; + aux.old_width = var_get_width (oldvar); aux.new_width = var_get_width (variable); datasheet_resize_column (store->datasheet, posn, aux.new_width, resize_datum, &aux); } } +static void +insert_variable_callback (GObject *obj, gint var_num, gpointer data) +{ + struct variable *variable; + PsppireDataStore *store; + gint posn; + g_return_if_fail (data); + + store = PSPPIRE_DATA_STORE (data); + + variable = psppire_dict_get_variable (store->dict, var_num); + posn = var_get_case_index (variable); + psppire_data_store_insert_value (store, var_get_width (variable), posn); +} /** * psppire_data_store_new: @@ -364,11 +353,6 @@ psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *di g_signal_connect (dict, "variable-changed", G_CALLBACK (variable_changed_callback), data_store); - - data_store->dict_handler_id [SIZE_CHANGED] = - g_signal_connect (dict, "dict-size-changed", - G_CALLBACK (dict_size_change_callback), - data_store); } diff --git a/src/ui/gui/psppire-data-store.h b/src/ui/gui/psppire-data-store.h index 8096962ad7..47ce5e5e72 100644 --- a/src/ui/gui/psppire-data-store.h +++ b/src/ui/gui/psppire-data-store.h @@ -57,7 +57,6 @@ enum dict_signal_handler { VARIABLE_INSERTED, VARIABLE_CHANGED, VARIABLE_DELETED, - SIZE_CHANGED, n_dict_signals }; diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 60ccda5200..5e95550efb 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -41,10 +41,8 @@ enum { BACKEND_CHANGED, VARIABLE_CHANGED, - VARIABLE_RESIZED, VARIABLE_INSERTED, VARIABLE_DELETED, - VARIABLE_DISPLAY_WIDTH_CHANGED, WEIGHT_CHANGED, FILTER_CHANGED, @@ -170,30 +168,6 @@ psppire_dict_class_init (PsppireDictClass *class) G_TYPE_INT); - signals [VARIABLE_RESIZED] = - g_signal_new ("dict-size-changed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - psppire_marshal_VOID__INT_INT, - G_TYPE_NONE, - 2, - G_TYPE_INT, - G_TYPE_INT); - - signals [VARIABLE_DISPLAY_WIDTH_CHANGED] = - g_signal_new ("variable-display-width-changed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, - 1, - G_TYPE_INT); - - signals [WEIGHT_CHANGED] = g_signal_new ("weight-changed", G_TYPE_FROM_CLASS (class), @@ -264,12 +238,6 @@ mutcb (struct dictionary *d, int idx, unsigned int what, const struct variable * g_signal_emit (pd, signals [VARIABLE_CHANGED], 0, idx, what, oldvar); } -static void -resize_cb (struct dictionary *d, int idx, int old_width, void *pd) -{ - g_signal_emit (pd, signals [VARIABLE_RESIZED], 0, idx, old_width); -} - static void weight_changed_callback (struct dictionary *d, int idx, void *pd) { @@ -288,24 +256,14 @@ split_changed_callback (struct dictionary *d, void *pd) g_signal_emit (pd, signals [SPLIT_CHANGED], 0); } -static void -variable_display_width_callback (struct dictionary *d, int idx, void *pd) -{ - g_signal_emit (pd, signals [VARIABLE_DISPLAY_WIDTH_CHANGED], 0, idx); -} - - - static const struct dict_callbacks gui_callbacks = { addcb, delcb, mutcb, - resize_cb, weight_changed_callback, filter_changed_callback, - split_changed_callback, - variable_display_width_callback + split_changed_callback }; static void @@ -570,22 +528,6 @@ psppire_dict_get_next_value_idx (const PsppireDict *dict) } -void -psppire_dict_resize_variable (PsppireDict *d, const struct variable *pv, - gint old_size, gint new_size) -{ - g_return_if_fail (d); - g_return_if_fail (d->dict); - - if ( old_size == new_size ) - return ; - - g_signal_emit (d, signals [VARIABLE_RESIZED], 0, - var_get_dict_index (pv), - new_size - old_size ); -} - - /* Tree Model Stuff */ static GtkTreeModelFlags tree_model_get_flags (GtkTreeModel *model); diff --git a/src/ui/gui/psppire-dict.h b/src/ui/gui/psppire-dict.h index 4deabcaf8f..ecd5de063f 100644 --- a/src/ui/gui/psppire-dict.h +++ b/src/ui/gui/psppire-dict.h @@ -93,10 +93,6 @@ void psppire_dict_delete_variables (PsppireDict *d, gint first, gint n); struct variable *psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name); -void psppire_dict_resize_variable (PsppireDict *, - const struct variable *, - gint, gint ); - gboolean psppire_dict_check_name (const PsppireDict *dict, const gchar *name, gboolean report); -- 2.30.2