diff options
author | Matthias Clasen <mclasen@redhat.com> | 2016-02-10 07:25:00 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2016-02-10 07:25:00 -0500 |
commit | 0175222353240f46aee5df4d7d8ebbf0526dc730 (patch) | |
tree | de4e8815621d27f701c49d7e1d853d1d73e834bb | |
parent | d70501d86589323e85ba81532521d852d36f29fe (diff) | |
download | glib-wip/multibinding.tar.gz |
Some more work-in-progresswip/multibinding
-rw-r--r-- | gobject/gmultibinding.c | 13 | ||||
-rw-r--r-- | gobject/gmultibinding.h | 21 | ||||
-rw-r--r-- | gobject/tests/multibinding.c | 2 |
3 files changed, 33 insertions, 3 deletions
diff --git a/gobject/gmultibinding.c b/gobject/gmultibinding.c index 9399f1b7e..52d9890ea 100644 --- a/gobject/gmultibinding.c +++ b/gobject/gmultibinding.c @@ -154,17 +154,24 @@ on_source_notify (GObject *gobject, GValue *to_values; gboolean res; gint i; + gint notified; if (binding->is_frozen) return; + notified = -1; from_values = g_new0 (GValue, binding->n_sources); for (i = 0; i < binding->n_sources; i++) { g_value_init (&from_values[i], G_PARAM_SPEC_VALUE_TYPE (binding->source_pspec[i])); g_object_get_property (binding->source[i], binding->source_pspec[i]->name, &from_values[i]); + + if (gobject == binding->source[i]) + notified = i; } + g_assert (0 <= notified && notified < binding->n_sources); + to_values = g_new0 (GValue, binding->n_targets); for (i = 0; i < binding->n_targets; i++) { @@ -172,7 +179,7 @@ on_source_notify (GObject *gobject, g_object_get_property (binding->target[i], binding->target_pspec[i]->name, &to_values[i]); } - res = binding->transform (binding, (const GValue *)from_values, to_values, binding->transform_data); + res = binding->transform (binding, notified, (const GValue *)from_values, to_values, binding->transform_data); if (res) { @@ -339,6 +346,7 @@ g_object_multi_bind_property_v (gint n_sources, gint n_targets, GObject *targets[], const gchar *target_properties[], + GMultiBindingFlags flags, GMultiBindingTransformFunc transform, gpointer user_data, GDestroyNotify notify) @@ -443,5 +451,8 @@ g_object_multi_bind_property_v (gint n_sources, } } + if (flags & G_MULTI_BINDING_SYNC_CREATE) + on_source_notify (binding->source[0], binding->source_pspec[0], binding); + return binding; } diff --git a/gobject/gmultibinding.h b/gobject/gmultibinding.h index 36c143068..948b9efac 100644 --- a/gobject/gmultibinding.h +++ b/gobject/gmultibinding.h @@ -34,6 +34,11 @@ G_BEGIN_DECLS #define G_MULTI_BINDING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_MULTI_BINDING, GMultiBinding)) #define G_IS_MULTI_BINDING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_MULTI_BINDING)) +typedef enum { /*< prefix=G_MULTI_BINDING >*/ + G_MULTI_BINDING_DEFAULT = 0, + G_MULTI_BINDING_SYNC_CREATE = 1 << 1 +} GMultiBindingFlags; + /** * GMultiBinding: * @@ -45,6 +50,7 @@ G_BEGIN_DECLS typedef struct _GMultiBinding GMultiBinding; typedef gboolean (* GMultiBindingTransformFunc) (GMultiBinding *binding, + gint notified, const GValue from_values[], GValue to_values[], gpointer user_data); @@ -74,15 +80,26 @@ GLIB_AVAILABLE_IN_ALL void g_multi_binding_unbind (GMultiBinding *binding); GLIB_AVAILABLE_IN_ALL -GMultiBinding *g_object_multi_bind_property_v (gint n_sources, +GMultiBinding *g_object_bind_properties_v (gint n_sources, GObject *sources[], const gchar *source_properties[], gint n_targets, GObject *targets[], const gchar *target_properties[], + GMultiBindingFlags flags, + GMultiBindingTransformFunc transform, + gpointer user_data, + GDestroyNotify notify); +GLIB_AVAILABLE_IN_ALL +GMultiBinding *g_object_bind_properties (GObject *source, + const gchar *property, + ... + GObject *target, + const gchar *property, + ... + GMultiBindingFlags flags, GMultiBindingTransformFunc transform, gpointer user_data, GDestroyNotify notify); - #endif /* __G_MULTI_BINDING_H__ */ diff --git a/gobject/tests/multibinding.c b/gobject/tests/multibinding.c index afff184b3..3305e768b 100644 --- a/gobject/tests/multibinding.c +++ b/gobject/tests/multibinding.c @@ -237,6 +237,7 @@ binding_target_init (BindingTarget *self) static gboolean munge_two_ints (GMultiBinding *binding, + gint notified, const GValue from_values[], GValue to_values[], gpointer user_data) @@ -273,6 +274,7 @@ multibinding_basic (void) target_props[1] = "bar"; binding = g_object_multi_bind_property_v (2, sources, source_props, 2, targets, target_props, + G_MULTI_BINDING_DEFAULT, munge_two_ints, NULL, NULL); g_object_add_weak_pointer (G_OBJECT (binding), (gpointer *) &binding); |