[glib] value: Allow automatic transforms to/from interfaces
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] value: Allow automatic transforms to/from interfaces
- Date: Mon, 25 Nov 2019 19:07:37 +0000 (UTC)
commit 5899c61ed2b4be3f02d0382d6fb0d1fc1bb7bc98
Author: Benjamin Otte <otte redhat com>
Date: Mon Nov 25 19:58:59 2019 +0100
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.
gobject/gvalue.c | 13 +++++++++++--
1 file 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]