From af0537bce12ac6d01a3655f29b5e16836bdde6a9 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Mon, 21 Nov 2011 14:07:06 +0100 Subject: [PATCH] prop-editor: Implement property editing for GdkRGBA properties Bug #664467. --- tests/prop-editor.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/prop-editor.c b/tests/prop-editor.c index de996fd575..8e91cccccc 100644 --- a/tests/prop-editor.c +++ b/tests/prop-editor.c @@ -660,6 +660,50 @@ object_properties (GtkWidget *button, create_prop_editor (obj, 0); } +static void +rgba_modified (GtkColorButton *cb, gpointer data) +{ + ObjectProperty *p = data; + GdkRGBA color; + + gtk_color_button_get_rgba (cb, &color); + + if (is_child_property (p->spec)) + { + GtkWidget *widget = GTK_WIDGET (p->obj); + GtkWidget *parent = gtk_widget_get_parent (widget); + + gtk_container_child_set (GTK_CONTAINER (parent), + widget, p->spec->name, &color, NULL); + } + else + g_object_set (p->obj, p->spec->name, &color, NULL); +} + +static void +rgba_changed (GObject *object, GParamSpec *pspec, gpointer data) +{ + GtkColorButton *cb = GTK_COLOR_BUTTON (data); + GValue val = G_VALUE_INIT; + GdkRGBA *color; + GdkRGBA cb_color; + + g_value_init (&val, GDK_TYPE_RGBA); + get_property_value (object, pspec, &val); + + color = g_value_get_boxed (&val); + gtk_color_button_get_rgba (cb, &cb_color); + + if (color != NULL && !gdk_rgba_equal (color, &cb_color)) + { + block_controller (G_OBJECT (cb)); + gtk_color_button_set_rgba (cb, color); + unblock_controller (G_OBJECT (cb)); + } + + g_value_unset (&val); +} + static void color_modified (GtkColorButton *cb, gpointer data) { @@ -967,6 +1011,20 @@ property_widget (GObject *object, /* The Properties button is not really modifying, anyway */ can_modify = TRUE; } + else if (type == G_TYPE_PARAM_BOXED && + G_PARAM_SPEC_VALUE_TYPE (spec) == GDK_TYPE_RGBA) + { + prop_edit = gtk_color_button_new (); + gtk_color_button_set_use_alpha (GTK_COLOR_BUTTON (prop_edit), TRUE); + + g_object_connect_property (object, spec, + G_CALLBACK (rgba_changed), + prop_edit, G_OBJECT (prop_edit)); + + if (can_modify) + connect_controller (G_OBJECT (prop_edit), "color-set", + object, spec, G_CALLBACK (rgba_modified)); + } else if (type == G_TYPE_PARAM_BOXED && G_PARAM_SPEC_VALUE_TYPE (spec) == GDK_TYPE_COLOR) {