X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Fui%2Fgui%2Fpsppire-dict.c;h=e381e5dab7a40050df1a47f89e33564ded7341f6;hb=2d45d41b2bae93062d76d0dc48a025b348631801;hp=84a89527e807dced67884c924745b9c9e10ddb60;hpb=91ced0102521c876f1ac4602977fd15c73b25697;p=pspp diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 84a89527e8..e381e5dab7 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -107,14 +107,14 @@ gi (GListModel *list, guint id) PangoContext *context = gtk_widget_create_pango_context (button); PangoLayout *layout = pango_layout_new (context); PangoRectangle rect; - + pango_layout_set_text (layout, "M", 1); - + pango_layout_get_extents (layout, NULL, &rect); - + g_object_unref (G_OBJECT (layout)); g_object_unref (G_OBJECT (context)); - + gtk_widget_set_size_request (button, (0.25 + var_get_display_width (v)) * rect.width / PANGO_SCALE, @@ -287,6 +287,11 @@ psppire_dict_dispose (GObject *object) { PsppireDict *d = PSPPIRE_DICT (object); + if (!d->dispose_has_run) + return; + + d->dispose_has_run = TRUE; + dict_set_callbacks (d->dict, NULL, NULL); dict_unref (d->dict); @@ -300,7 +305,7 @@ addcb (struct dictionary *d, int idx, void *pd) { PsppireDict *dict = PSPPIRE_DICT (pd); - if ( ! dict->disable_insert_signal) + if (! dict->disable_insert_signal) { g_signal_emit (dict, signals [VARIABLE_INSERTED], 0, idx); g_signal_emit_by_name (dict, "items-changed", idx, 1, 1); @@ -352,10 +357,12 @@ static const struct dict_callbacks gui_callbacks = }; static void -psppire_dict_init (PsppireDict *psppire_dict) +psppire_dict_init (PsppireDict *d) { - psppire_dict->stamp = g_random_int (); - psppire_dict->disable_insert_signal = FALSE; + d->dispose_has_run = FALSE; + + d->stamp = g_random_int (); + d->disable_insert_signal = FALSE; } /** @@ -379,7 +386,7 @@ psppire_dict_new_from_dict (struct dictionary *d) void psppire_dict_replace_dictionary (PsppireDict *dict, struct dictionary *d) { - struct variable *var = dict_get_weight (d); + const struct variable *var = dict_get_weight (d); struct dictionary *old_dict = dict->dict; @@ -473,22 +480,16 @@ psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name) void psppire_dict_delete_variables (PsppireDict *d, gint first, gint n) { - gint idx; g_return_if_fail (d); g_return_if_fail (d->dict); g_return_if_fail (PSPPIRE_IS_DICT (d)); + size_t varcnt = dict_get_var_cnt (d->dict); + g_return_if_fail (first < varcnt); + g_return_if_fail (first >= 0); + g_return_if_fail (n > 0); + g_return_if_fail (first + n <= varcnt); - for (idx = 0 ; idx < n ; ++idx ) - { - struct variable *var; - - /* Do nothing if it's out of bounds */ - if ( first >= dict_get_var_cnt (d->dict)) - break; - - var = dict_get_var (d->dict, first); - dict_delete_var (d->dict, var); - } + dict_delete_consecutive_vars (d->dict, first, n); } @@ -499,10 +500,10 @@ psppire_dict_set_name (PsppireDict* d, gint idx, const gchar *name) g_assert (d); g_assert (PSPPIRE_IS_DICT (d)); - if ( ! dict_id_is_valid (d->dict, name, false)) + if (! dict_id_is_valid (d->dict, name, false)) return FALSE; - if ( idx < dict_get_var_cnt (d->dict)) + if (idx < dict_get_var_cnt (d->dict)) { /* This is an existing variable? */ var = dict_get_var (d->dict, idx); @@ -528,7 +529,7 @@ psppire_dict_get_variable (const PsppireDict *d, gint idx) g_return_val_if_fail (d, NULL); g_return_val_if_fail (d->dict, NULL); - if ( dict_get_var_cnt (d->dict) <= idx ) + if (dict_get_var_cnt (d->dict) <= idx) return NULL; return dict_get_var (d->dict, idx); @@ -601,12 +602,12 @@ gboolean psppire_dict_check_name (const PsppireDict *dict, const gchar *name, gboolean report) { - if ( ! dict_id_is_valid (dict->dict, name, report ) ) + if (! dict_id_is_valid (dict->dict, name, report)) return FALSE; if (psppire_dict_lookup_var (dict, name)) { - if ( report ) + if (report) msg (ME, _("Duplicate variable name.")); return FALSE; } @@ -759,7 +760,7 @@ tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path) n = indices [0]; - if ( n < 0 || n >= psppire_dict_get_var_cnt (dict)) + if (n < 0 || n >= psppire_dict_get_var_cnt (dict)) { iter->stamp = 0; iter->user_data = NULL; @@ -784,7 +785,7 @@ tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter) struct variable *var; gint idx; - if ( iter == NULL || iter->user_data == NULL) + if (iter == NULL || iter->user_data == NULL) return FALSE; g_return_val_if_fail (iter->stamp == dict->stamp, FALSE); @@ -793,7 +794,7 @@ tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter) idx = var_get_dict_index (var); - if ( idx + 1 >= psppire_dict_get_var_cnt (dict)) + if (idx + 1 >= psppire_dict_get_var_cnt (dict)) { iter->user_data = NULL; iter->stamp = 0; @@ -916,16 +917,16 @@ tree_model_nth_child (GtkTreeModel *model, GtkTreeIter *iter, dict = PSPPIRE_DICT (model); - if ( parent ) + if (parent) return FALSE; - if ( n >= psppire_dict_get_var_cnt (dict) ) + if (n >= psppire_dict_get_var_cnt (dict)) return FALSE; iter->stamp = dict->stamp; iter->user_data = psppire_dict_get_variable (dict, n); - if ( !iter->user_data) + if (!iter->user_data) return FALSE; return TRUE; @@ -936,11 +937,11 @@ gboolean psppire_dict_rename_var (PsppireDict *dict, struct variable *v, const gchar *name) { - if ( ! dict_id_is_valid (dict->dict, name, false)) + if (! dict_id_is_valid (dict->dict, name, false)) return FALSE; /* Make sure no other variable has this name */ - if ( NULL != psppire_dict_lookup_var (dict, name)) + if (NULL != psppire_dict_lookup_var (dict, name)) return FALSE; dict_rename_var (dict->dict, v, name);