diff --git a/demos/constraint-editor/constraint-editor-window.c b/demos/constraint-editor/constraint-editor-window.c index debbd7da51..bd9fd3e171 100644 --- a/demos/constraint-editor/constraint-editor-window.c +++ b/demos/constraint-editor/constraint-editor-window.c @@ -95,8 +95,9 @@ add_guide (ConstraintEditorWindow *win) guide_counter++; name = g_strdup_printf ("Guide %d", guide_counter); - guide = g_object_new (GTK_TYPE_CONSTRAINT_GUIDE, NULL); - g_object_set_data_full (G_OBJECT (guide), "name", name, g_free); + guide = gtk_constraint_guide_new (); + gtk_constraint_guide_set_name (guide, name); + g_free (name); constraint_view_add_guide (CONSTRAINT_VIEW (win->view), guide); } @@ -158,7 +159,6 @@ guide_editor_done (GuideEditor *editor, GtkConstraintGuide *guide, ConstraintEditorWindow *win) { - constraint_view_guide_changed (CONSTRAINT_VIEW (win->view), guide); gtk_widget_destroy (gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW)); } @@ -295,19 +295,23 @@ create_widget_func (gpointer item, ConstraintEditorWindow *win = user_data; const char *name; GtkWidget *row, *box, *label, *button; - char *str; - name = (const char *)g_object_get_data (G_OBJECT (item), "name"); + if (GTK_IS_WIDGET (item)) + name = gtk_widget_get_name (GTK_WIDGET (item)); + else if (GTK_IS_CONSTRAINT_GUIDE (item)) + name = gtk_constraint_guide_get_name (GTK_CONSTRAINT_GUIDE (item)); + else + name = (const char *)g_object_get_data (G_OBJECT (item), "name"); row = gtk_list_box_row_new (); g_object_set_data_full (G_OBJECT (row), "item", g_object_ref (item), g_object_unref); box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - str = g_strdup_printf ("%s %p", name, item); - label = gtk_label_new (str); - g_free (str); - g_object_set (label, - "margin", 10, - NULL); + label = gtk_label_new (name); + if (GTK_IS_WIDGET (item) || GTK_IS_CONSTRAINT_GUIDE (item)) + g_object_bind_property (item, "name", + label, "label", + G_BINDING_DEFAULT); + g_object_set (label, "margin", 10, NULL); gtk_label_set_xalign (GTK_LABEL (label), 0.0); gtk_widget_set_hexpand (label, TRUE); gtk_container_add (GTK_CONTAINER (row), box); diff --git a/demos/constraint-editor/constraint-editor.c b/demos/constraint-editor/constraint-editor.c index 95d854ee9c..e871b6a6c8 100644 --- a/demos/constraint-editor/constraint-editor.c +++ b/demos/constraint-editor/constraint-editor.c @@ -66,8 +66,12 @@ get_target_name (GtkConstraintTarget *target) { if (target == NULL) return "super"; + else if (GTK_IS_WIDGET (target)) + return gtk_widget_get_name (GTK_WIDGET (target)); + else if (GTK_IS_CONSTRAINT_GUIDE (target)) + return gtk_constraint_guide_get_name (GTK_CONSTRAINT_GUIDE (target)); else - return (const char *)g_object_get_data (G_OBJECT (target), "name"); + return ""; } static void @@ -145,13 +149,19 @@ get_target (GListModel *model, for (i = 0; i < g_list_model_get_n_items (model); i++) { GObject *item = g_list_model_get_object (model, i); - const char *name; + g_object_unref (item); if (GTK_IS_CONSTRAINT (item)) continue; - name = (const char *)g_object_get_data (item, "name"); - g_object_unref (item); - if (strcmp (name, id) == 0) - return item; + else if (GTK_IS_WIDGET (item)) + { + if (strcmp (id, gtk_widget_get_name (GTK_WIDGET (item))) == 0) + return item; + } + else if (GTK_IS_CONSTRAINT_GUIDE (item)) + { + if (strcmp (id, gtk_constraint_guide_get_name (GTK_CONSTRAINT_GUIDE (item))) == 0) + return item; + } } return NULL; diff --git a/demos/constraint-editor/constraint-view.c b/demos/constraint-editor/constraint-view.c index 8a050dbf8b..982338c93d 100644 --- a/demos/constraint-editor/constraint-view.c +++ b/demos/constraint-editor/constraint-view.c @@ -215,7 +215,7 @@ constraint_view_add_child (ConstraintView *view, label = gtk_label_new (name); frame = gtk_frame_new (NULL); gtk_style_context_add_class (gtk_widget_get_style_context (frame), "child"); - g_object_set_data_full (G_OBJECT (frame), "name", g_strdup (name), g_free); + gtk_widget_set_name (frame, name); gtk_container_add (GTK_CONTAINER (frame), label); gtk_widget_set_parent (frame, GTK_WIDGET (view)); @@ -250,9 +250,12 @@ constraint_view_add_guide (ConstraintView *view, }; int i; - name = (const char *)g_object_get_data (G_OBJECT (guide), "name"); - + name = gtk_constraint_guide_get_name (guide); label = gtk_label_new (name); + g_object_bind_property (guide, "name", + label, "label", + G_BINDING_DEFAULT); + frame = gtk_frame_new (NULL); gtk_style_context_add_class (gtk_widget_get_style_context (frame), "guide"); g_object_set_data (G_OBJECT (frame), "internal", "yes"); @@ -260,7 +263,6 @@ constraint_view_add_guide (ConstraintView *view, gtk_widget_insert_after (frame, GTK_WIDGET (view), NULL); g_object_set_data (G_OBJECT (guide), "frame", frame); - g_object_set_data (G_OBJECT (guide), "label", label); layout = GTK_CONSTRAINT_LAYOUT (gtk_widget_get_layout_manager (GTK_WIDGET (view))); gtk_constraint_layout_add_guide (layout, g_object_ref (guide)); @@ -282,27 +284,6 @@ constraint_view_add_guide (ConstraintView *view, update_weak_position (view, frame, 150, 150); } -void -constraint_view_guide_changed (ConstraintView *view, - GtkConstraintGuide *guide) -{ - GtkWidget *label; - const char *name; - int i; - - name = (const char *)g_object_get_data (G_OBJECT (guide), "name"); - label = (GtkWidget *)g_object_get_data (G_OBJECT (guide), "label"); - gtk_label_set_label (GTK_LABEL (label), name); - for (i = 0; i < g_list_model_get_n_items (view->model); i++) - { - if (g_list_model_get_item (view->model, i) == (GObject*)guide) - { - g_list_model_items_changed (view->model, i, 1, 1); - break; - } - } -} - void constraint_view_remove_guide (ConstraintView *view, GtkConstraintGuide *guide) diff --git a/demos/constraint-editor/guide-editor.c b/demos/constraint-editor/guide-editor.c index 947274f2ad..663697337c 100644 --- a/demos/constraint-editor/guide-editor.c +++ b/demos/constraint-editor/guide-editor.c @@ -105,7 +105,7 @@ create_guide (GtkButton *button, guide = gtk_constraint_guide_new (); name = gtk_editable_get_text (GTK_EDITABLE (editor->name)); - g_object_set_data_full (G_OBJECT (guide), "name", g_strdup (name), g_free); + gtk_constraint_guide_set_name (guide, name); w = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->min_width)); h = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editor->min_height)); @@ -238,7 +238,7 @@ guide_editor_constructed (GObject *object) const char *nick; int w, h; - nick = (char *)g_object_get_data (G_OBJECT (editor->guide), "name"); + nick = gtk_constraint_guide_get_name (editor->guide); if (nick) gtk_editable_set_text (GTK_EDITABLE (editor->name), nick);