1 /* gbinding.h: Binding for object properties
3 * Copyright (C) 2010 Intel Corp.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Emmanuele Bassi <ebassi@linux.intel.com>
23 #ifndef __G_BINDING_H__
24 #define __G_BINDING_H__
26 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
27 #error "Only <glib-object.h> can be included directly."
31 #include <gobject/gobject.h>
35 #define G_TYPE_BINDING_FLAGS (g_binding_flags_get_type ())
37 #define G_TYPE_BINDING (g_binding_get_type ())
38 #define G_BINDING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_BINDING, GBinding))
39 #define G_IS_BINDING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_BINDING))
44 * <structname>GBinding</structname> is an opaque structure whose members
45 * cannot be accessed directly.
49 typedef struct _GBinding GBinding
;
52 * GBindingTransformFunc:
53 * @binding: a #GBinding
54 * @from_value: the #GValue containing the value to transform
55 * @to_value: the #GValue in which to store the transformed value
56 * @user_data: data passed to the transform function
58 * A function to be called to transform @from_value to @to_value. If
59 * this is the @transform_to function of a binding, then @from_value
60 * is the @source_property on the @source object, and @to_value is the
61 * @target_property on the @target object. If this is the
62 * @transform_from function of a %G_BINDING_BIDIRECTIONAL binding,
63 * then those roles are reversed.
65 * Return value: %TRUE if the transformation was successful, and %FALSE
70 typedef gboolean (* GBindingTransformFunc
) (GBinding
*binding
,
71 const GValue
*from_value
,
77 * @G_BINDING_DEFAULT: The default binding; if the source property
78 * changes, the target property is updated with its value.
79 * @G_BINDING_BIDIRECTIONAL: Bidirectional binding; if either the
80 * property of the source or the property of the target changes,
81 * the other is updated.
82 * @G_BINDING_SYNC_CREATE: Synchronize the values of the source and
83 * target properties when creating the binding; the direction of
84 * the synchronization is always from the source to the target.
85 * @G_BINDING_INVERT_BOOLEAN: If the two properties being bound are
86 * booleans, setting one to %TRUE will result in the other being
87 * set to %FALSE and vice versa. This flag will only work for
88 * boolean properties, and cannot be used when passing custom
89 * transformation functions to g_object_bind_property_full().
91 * Flags to be passed to g_object_bind_property() or
92 * g_object_bind_property_full().
94 * This enumeration can be extended at later date.
98 typedef enum { /*< prefix=G_BINDING >*/
99 G_BINDING_DEFAULT
= 0,
101 G_BINDING_BIDIRECTIONAL
= 1 << 0,
102 G_BINDING_SYNC_CREATE
= 1 << 1,
103 G_BINDING_INVERT_BOOLEAN
= 1 << 2
106 GLIB_AVAILABLE_IN_ALL
107 GType
g_binding_flags_get_type (void) G_GNUC_CONST
;
108 GLIB_AVAILABLE_IN_ALL
109 GType
g_binding_get_type (void) G_GNUC_CONST
;
111 GLIB_AVAILABLE_IN_ALL
112 GBindingFlags
g_binding_get_flags (GBinding
*binding
);
113 GLIB_AVAILABLE_IN_ALL
114 GObject
* g_binding_get_source (GBinding
*binding
);
115 GLIB_AVAILABLE_IN_ALL
116 GObject
* g_binding_get_target (GBinding
*binding
);
117 GLIB_AVAILABLE_IN_ALL
118 const gchar
* g_binding_get_source_property (GBinding
*binding
);
119 GLIB_AVAILABLE_IN_ALL
120 const gchar
* g_binding_get_target_property (GBinding
*binding
);
121 GLIB_AVAILABLE_IN_2_38
122 void g_binding_unbind (GBinding
*binding
);
124 GLIB_AVAILABLE_IN_ALL
125 GBinding
*g_object_bind_property (gpointer source
,
126 const gchar
*source_property
,
128 const gchar
*target_property
,
129 GBindingFlags flags
);
130 GLIB_AVAILABLE_IN_ALL
131 GBinding
*g_object_bind_property_full (gpointer source
,
132 const gchar
*source_property
,
134 const gchar
*target_property
,
136 GBindingTransformFunc transform_to
,
137 GBindingTransformFunc transform_from
,
139 GDestroyNotify notify
);
140 GLIB_AVAILABLE_IN_ALL
141 GBinding
*g_object_bind_property_with_closures (gpointer source
,
142 const gchar
*source_property
,
144 const gchar
*target_property
,
146 GClosure
*transform_to
,
147 GClosure
*transform_from
);
151 #endif /* __G_BINDING_H__ */