diff options
author | Benjamin Otte <otte@redhat.com> | 2019-11-25 19:58:59 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2019-11-25 20:06:49 +0100 |
commit | 5899c61ed2b4be3f02d0382d6fb0d1fc1bb7bc98 (patch) | |
tree | 6f86a61cb38672db6620f52545a755e59e286999 | |
parent | e994d4535270b233c4ed5c62e0055fe20c9ab1c6 (diff) | |
download | glib-5899c61ed2b4be3f02d0382d6fb0d1fc1bb7bc98.tar.gz |
value: Allow automatic transforms to/from interfaces
Use the new g_type_interface_instantiable_prerequisite() to check
compatibility for transform functions.
In particular, this allows interfaces (in my case GDK_TYPE_PAINTABLE) to
be transformed to/from any GObject type (in my case G_TYPE_OBJECT) using
the transform function registered to tranform between any 2 objects
(g_value_object_transform_value() does a type check and uses NULL if the
types don't match).
And this in turn allows be to g_object_bind_property() a gobject-typed
generic property (GtkListItem::item) to a GtkImage::paintable.
-rw-r--r-- | gobject/gvalue.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/gobject/gvalue.c b/gobject/gvalue.c index c30501a6b..df7b4ee11 100644 --- a/gobject/gvalue.c +++ b/gobject/gvalue.c @@ -448,6 +448,15 @@ g_value_init_from_instance (GValue *value, } } +static GType +tranform_lookup_get_parent_type (GType type) +{ + if (g_type_fundamental (type) == G_TYPE_INTERFACE) + return g_type_interface_instantiable_prerequisite (type); + + return g_type_parent (type); +} + static GValueTransform transform_func_lookup (GType src_type, GType dest_type) @@ -470,11 +479,11 @@ transform_func_lookup (GType src_type, g_type_value_table_peek (entry.src_type) == g_type_value_table_peek (src_type)) return e->func; } - entry.dest_type = g_type_parent (entry.dest_type); + entry.dest_type = tranform_lookup_get_parent_type (entry.dest_type); } while (entry.dest_type); - entry.src_type = g_type_parent (entry.src_type); + entry.src_type = tranform_lookup_get_parent_type (entry.src_type); } while (entry.src_type); |