mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-14 14:27:14 +01:00
binding: Add a default marshaller for the closure API
The g_object_bind_property_with_closures() function should set a marshaller if the two GClosures don't have one already. This simplifies the caller code and avoids duplication. We need to add a new marshaller to the gmarshal.list matching the signature of the GBindingTransformFunc function.
This commit is contained in:
parent
f5cd8ddeaa
commit
4bc9654c63
@ -105,6 +105,7 @@
|
|||||||
|
|
||||||
#include "gbinding.h"
|
#include "gbinding.h"
|
||||||
#include "genums.h"
|
#include "genums.h"
|
||||||
|
#include "gmarshal.h"
|
||||||
#include "gobject.h"
|
#include "gobject.h"
|
||||||
#include "gsignal.h"
|
#include "gsignal.h"
|
||||||
#include "gparamspecs.h"
|
#include "gparamspecs.h"
|
||||||
@ -1161,12 +1162,18 @@ g_object_bind_property_with_closures (gpointer source,
|
|||||||
|
|
||||||
if (transform_to != NULL)
|
if (transform_to != NULL)
|
||||||
{
|
{
|
||||||
|
if (G_CLOSURE_NEEDS_MARSHAL (transform_to))
|
||||||
|
g_closure_set_marshal (transform_to, g_cclosure_marshal_BOOLEAN__BOXED_BOXED);
|
||||||
|
|
||||||
data->transform_to_closure = g_closure_ref (transform_to);
|
data->transform_to_closure = g_closure_ref (transform_to);
|
||||||
g_closure_sink (data->transform_to_closure);
|
g_closure_sink (data->transform_to_closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transform_from != NULL)
|
if (transform_from != NULL)
|
||||||
{
|
{
|
||||||
|
if (G_CLOSURE_NEEDS_MARSHAL (transform_from))
|
||||||
|
g_closure_set_marshal (transform_from, g_cclosure_marshal_BOOLEAN__BOXED_BOXED);
|
||||||
|
|
||||||
data->transform_from_closure = g_closure_ref (transform_from);
|
data->transform_from_closure = g_closure_ref (transform_from);
|
||||||
g_closure_sink (data->transform_from_closure);
|
g_closure_sink (data->transform_from_closure);
|
||||||
}
|
}
|
||||||
|
@ -1236,3 +1236,18 @@ g_signal_type_cclosure_new (GType itype,
|
|||||||
* A marshaller for a #GCClosure with a callback of type
|
* A marshaller for a #GCClosure with a callback of type
|
||||||
* <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
|
* <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>.
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED:
|
||||||
|
* @closure: the #GClosure to which the marshaller belongs
|
||||||
|
* @return_value: a #GValue, which can store the returned string
|
||||||
|
* @n_param_values: 3
|
||||||
|
* @param_values: a #GValue array holding instance, arg1 and arg2
|
||||||
|
* @invocation_hint: the invocation hint given as the last argument
|
||||||
|
* to g_closure_invoke()
|
||||||
|
* @marshal_data: additional data specified when registering the marshaller
|
||||||
|
*
|
||||||
|
* A marshaller for a #GCClosure with a callback of type
|
||||||
|
* <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>.
|
||||||
|
*
|
||||||
|
* Since: 2.26
|
||||||
|
*/
|
||||||
|
@ -47,3 +47,4 @@ VOID:VARIANT
|
|||||||
VOID:UINT,POINTER
|
VOID:UINT,POINTER
|
||||||
BOOL:FLAGS
|
BOOL:FLAGS
|
||||||
STRING:OBJECT,POINTER
|
STRING:OBJECT,POINTER
|
||||||
|
BOOL:BOXED,BOXED
|
||||||
|
@ -58,6 +58,7 @@ g_variant_get_gtype G_GNUC_CONST
|
|||||||
#if IN_HEADER(__G_MARSHAL_H__)
|
#if IN_HEADER(__G_MARSHAL_H__)
|
||||||
#if IN_FILE(__G_SIGNAL_C__)
|
#if IN_FILE(__G_SIGNAL_C__)
|
||||||
g_cclosure_marshal_BOOLEAN__FLAGS
|
g_cclosure_marshal_BOOLEAN__FLAGS
|
||||||
|
g_cclosure_marshal_BOOLEAN__BOXED_BOXED
|
||||||
g_cclosure_marshal_STRING__OBJECT_POINTER
|
g_cclosure_marshal_STRING__OBJECT_POINTER
|
||||||
g_cclosure_marshal_VOID__BOOLEAN
|
g_cclosure_marshal_VOID__BOOLEAN
|
||||||
g_cclosure_marshal_VOID__BOXED
|
g_cclosure_marshal_VOID__BOXED
|
||||||
|
@ -355,43 +355,6 @@ binding_transform (void)
|
|||||||
g_assert (unused_data);
|
g_assert (unused_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
binding_transform_marshal (GClosure *closure,
|
|
||||||
GValue *return_value,
|
|
||||||
guint n_param_values,
|
|
||||||
const GValue *param_values,
|
|
||||||
gpointer invocation_hint G_GNUC_UNUSED,
|
|
||||||
gpointer marshal_data)
|
|
||||||
{
|
|
||||||
typedef gboolean (* GMarshalFunc_BOOLEAN__VALUE_VALUE) (gpointer data1,
|
|
||||||
gpointer arg_2,
|
|
||||||
gpointer arg_3,
|
|
||||||
gpointer data2);
|
|
||||||
register GMarshalFunc_BOOLEAN__VALUE_VALUE callback;
|
|
||||||
register GCClosure *cc = (GCClosure *) closure;
|
|
||||||
register gpointer data1, data2;
|
|
||||||
gboolean v_return;
|
|
||||||
|
|
||||||
if (G_CCLOSURE_SWAP_DATA (closure))
|
|
||||||
{
|
|
||||||
data1 = closure->data;
|
|
||||||
data2 = g_value_peek_pointer (param_values + 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data1 = g_value_peek_pointer (param_values + 0);
|
|
||||||
data2 = closure->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback = (GMarshalFunc_BOOLEAN__VALUE_VALUE) (marshal_data ? marshal_data : cc->callback);
|
|
||||||
v_return = callback (data1,
|
|
||||||
g_value_get_boxed (param_values + 1),
|
|
||||||
g_value_get_boxed (param_values + 2),
|
|
||||||
data2);
|
|
||||||
|
|
||||||
g_value_set_boolean (return_value, v_return);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
binding_transform_closure (void)
|
binding_transform_closure (void)
|
||||||
{
|
{
|
||||||
@ -402,10 +365,8 @@ binding_transform_closure (void)
|
|||||||
GClosure *c2f_clos, *f2c_clos;
|
GClosure *c2f_clos, *f2c_clos;
|
||||||
|
|
||||||
c2f_clos = g_cclosure_new (G_CALLBACK (celsius_to_fahrenheit), &unused_data_1, (GClosureNotify) data_free);
|
c2f_clos = g_cclosure_new (G_CALLBACK (celsius_to_fahrenheit), &unused_data_1, (GClosureNotify) data_free);
|
||||||
g_closure_set_marshal (c2f_clos, binding_transform_marshal);
|
|
||||||
|
|
||||||
f2c_clos = g_cclosure_new (G_CALLBACK (fahrenheit_to_celsius), &unused_data_2, (GClosureNotify) data_free);
|
f2c_clos = g_cclosure_new (G_CALLBACK (fahrenheit_to_celsius), &unused_data_2, (GClosureNotify) data_free);
|
||||||
g_closure_set_marshal (f2c_clos, binding_transform_marshal);
|
|
||||||
|
|
||||||
binding = g_object_bind_property_with_closures (source, "value",
|
binding = g_object_bind_property_with_closures (source, "value",
|
||||||
target, "value",
|
target, "value",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user