X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-dict.c;h=640598e716a3533c38ff41f5e589348133364404;hb=d90a738745006b2696994bec344c160fca1f755b;hp=3bc39e40959c61a6f9db9d1d895d84d9a2d479d7;hpb=656e46ed80e20bf34312f01607a7bebdd2d8d622;p=pspp diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 3bc39e4095..640598e716 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -55,6 +55,9 @@ enum { WEIGHT_CHANGED, FILTER_CHANGED, SPLIT_CHANGED, + + RESIZE_ITEM, + n_SIGNALS }; @@ -99,6 +102,24 @@ gi (GListModel *list, guint id) gtk_button_set_label (GTK_BUTTON (button), var_get_name (v)); gtk_widget_set_tooltip_text (button, var_get_label (v)); + + { + 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, + -1); + } } return button; @@ -179,6 +200,18 @@ psppire_dict_class_init (PsppireDictClass *class) object_class->dispose = psppire_dict_dispose; + signals [RESIZE_ITEM] = + g_signal_new ("resize-item", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + psppire_marshal_BOOLEAN__INT_INT, + G_TYPE_BOOLEAN, + 2, + G_TYPE_INT, + G_TYPE_INT); + signals [VARIABLE_CHANGED] = g_signal_new ("variable-changed", G_TYPE_FROM_CLASS (class), @@ -190,10 +223,7 @@ psppire_dict_class_init (PsppireDictClass *class) 3, G_TYPE_INT, G_TYPE_UINT, - G_TYPE_POINTER - ); - - + G_TYPE_POINTER); signals [VARIABLE_INSERTED] = g_signal_new ("variable-inserted", @@ -206,7 +236,6 @@ psppire_dict_class_init (PsppireDictClass *class) 1, G_TYPE_INT); - signals [VARIABLE_DELETED] = g_signal_new ("variable-deleted", G_TYPE_FROM_CLASS (class), @@ -220,7 +249,6 @@ psppire_dict_class_init (PsppireDictClass *class) G_TYPE_INT, G_TYPE_INT); - signals [WEIGHT_CHANGED] = g_signal_new ("weight-changed", G_TYPE_FROM_CLASS (class), @@ -232,7 +260,6 @@ psppire_dict_class_init (PsppireDictClass *class) 1, G_TYPE_INT); - signals [FILTER_CHANGED] = g_signal_new ("filter-changed", G_TYPE_FROM_CLASS (class), @@ -244,7 +271,6 @@ psppire_dict_class_init (PsppireDictClass *class) 1, G_TYPE_INT); - signals [SPLIT_CHANGED] = g_signal_new ("split-changed", G_TYPE_FROM_CLASS (class), @@ -262,6 +288,7 @@ psppire_dict_dispose (GObject *object) PsppireDict *d = PSPPIRE_DICT (object); dict_set_callbacks (d->dict, NULL, NULL); + dict_unref (d->dict); G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -273,7 +300,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); @@ -341,7 +368,7 @@ PsppireDict* psppire_dict_new_from_dict (struct dictionary *d) { PsppireDict *new_dict = g_object_new (PSPPIRE_TYPE_DICT, NULL); - new_dict->dict = d; + new_dict->dict = dict_ref (d); dict_set_callbacks (new_dict->dict, &gui_callbacks, new_dict); @@ -352,12 +379,15 @@ 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; guint old_n = dict_get_var_cnt (dict->dict); guint new_n = dict_get_var_cnt (d); - dict->dict = d; + dict->dict = dict_ref (d); + dict_unref (old_dict); weight_changed_callback (d, var ? var_get_dict_index (var) : -1, dict); @@ -403,7 +433,8 @@ psppire_dict_generate_name (const PsppireDict *dict, char *name, size_t size) /* Insert a new variable at posn IDX, with the name NAME, and return the new variable. - If NAME is null, then a name will be automatically assigned. + IDX may take the special value -1, which will be treated the same as + zero. If NAME is null, then a name will be automatically assigned. */ struct variable * psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name) @@ -411,7 +442,8 @@ psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name) struct variable *var; char tmpname[64]; - g_return_val_if_fail (idx >= 0, NULL); + if (idx == -1) /* Note bug #56392. */ + idx = 0; g_return_val_if_fail (d, NULL); g_return_val_if_fail (PSPPIRE_IS_DICT (d), NULL); @@ -445,18 +477,13 @@ psppire_dict_delete_variables (PsppireDict *d, gint first, gint n) 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); } @@ -467,10 +494,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); @@ -496,7 +523,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); @@ -569,12 +596,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; } @@ -727,7 +754,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; @@ -752,7 +779,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); @@ -761,7 +788,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; @@ -884,16 +911,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; @@ -904,11 +931,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); @@ -946,8 +973,6 @@ psppire_dict_dump (const PsppireDict *dict) #endif - - const gchar * psppire_dict_encoding (const PsppireDict *dict) {