1/* gbinding.h: Binding for object properties
2 *
3 * Copyright (C) 2010 Intel Corp.
4 *
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.1 of the License, or (at your option) any later version.
9 *
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.
14 *
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author: Emmanuele Bassi <ebassi@linux.intel.com>
19 */
20
21#ifndef __G_BINDING_H__
22#define __G_BINDING_H__
23
24#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
25#error "Only <glib-object.h> can be included directly."
26#endif
27
28#include <glib.h>
29#include <gobject/gobject.h>
30
31G_BEGIN_DECLS
32
33#define G_TYPE_BINDING_FLAGS (g_binding_flags_get_type ())
34
35#define G_TYPE_BINDING (g_binding_get_type ())
36#define G_BINDING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_BINDING, GBinding))
37#define G_IS_BINDING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_BINDING))
38
39/**
40 * GBinding:
41 *
42 * GBinding is an opaque structure whose members
43 * cannot be accessed directly.
44 *
45 * Since: 2.26
46 */
47typedef struct _GBinding GBinding;
48
49/**
50 * GBindingTransformFunc:
51 * @binding: a #GBinding
52 * @from_value: the #GValue containing the value to transform
53 * @to_value: the #GValue in which to store the transformed value
54 * @user_data: data passed to the transform function
55 *
56 * A function to be called to transform @from_value to @to_value. If
57 * this is the @transform_to function of a binding, then @from_value
58 * is the @source_property on the @source object, and @to_value is the
59 * @target_property on the @target object. If this is the
60 * @transform_from function of a %G_BINDING_BIDIRECTIONAL binding,
61 * then those roles are reversed.
62 *
63 * Returns: %TRUE if the transformation was successful, and %FALSE
64 * otherwise
65 *
66 * Since: 2.26
67 */
68typedef gboolean (* GBindingTransformFunc) (GBinding *binding,
69 const GValue *from_value,
70 GValue *to_value,
71 gpointer user_data);
72
73/**
74 * GBindingFlags:
75 * @G_BINDING_DEFAULT: The default binding; if the source property
76 * changes, the target property is updated with its value.
77 * @G_BINDING_BIDIRECTIONAL: Bidirectional binding; if either the
78 * property of the source or the property of the target changes,
79 * the other is updated.
80 * @G_BINDING_SYNC_CREATE: Synchronize the values of the source and
81 * target properties when creating the binding; the direction of
82 * the synchronization is always from the source to the target.
83 * @G_BINDING_INVERT_BOOLEAN: If the two properties being bound are
84 * booleans, setting one to %TRUE will result in the other being
85 * set to %FALSE and vice versa. This flag will only work for
86 * boolean properties, and cannot be used when passing custom
87 * transformation functions to g_object_bind_property_full().
88 *
89 * Flags to be passed to g_object_bind_property() or
90 * g_object_bind_property_full().
91 *
92 * This enumeration can be extended at later date.
93 *
94 * Since: 2.26
95 */
96typedef enum { /*< prefix=G_BINDING >*/
97 G_BINDING_DEFAULT = 0,
98
99 G_BINDING_BIDIRECTIONAL = 1 << 0,
100 G_BINDING_SYNC_CREATE = 1 << 1,
101 G_BINDING_INVERT_BOOLEAN = 1 << 2
102} GBindingFlags;
103
104GLIB_AVAILABLE_IN_ALL
105GType g_binding_flags_get_type (void) G_GNUC_CONST;
106GLIB_AVAILABLE_IN_ALL
107GType g_binding_get_type (void) G_GNUC_CONST;
108
109GLIB_AVAILABLE_IN_ALL
110GBindingFlags g_binding_get_flags (GBinding *binding);
111GLIB_DEPRECATED_IN_2_68_FOR(g_binding_dup_source)
112GObject * g_binding_get_source (GBinding *binding);
113GLIB_AVAILABLE_IN_2_68
114GObject * g_binding_dup_source (GBinding *binding);
115GLIB_DEPRECATED_IN_2_68_FOR(g_binding_dup_target)
116GObject * g_binding_get_target (GBinding *binding);
117GLIB_AVAILABLE_IN_2_68
118GObject * g_binding_dup_target (GBinding *binding);
119GLIB_AVAILABLE_IN_ALL
120const gchar * g_binding_get_source_property (GBinding *binding);
121GLIB_AVAILABLE_IN_ALL
122const gchar * g_binding_get_target_property (GBinding *binding);
123GLIB_AVAILABLE_IN_2_38
124void g_binding_unbind (GBinding *binding);
125
126GLIB_AVAILABLE_IN_ALL
127GBinding *g_object_bind_property (gpointer source,
128 const gchar *source_property,
129 gpointer target,
130 const gchar *target_property,
131 GBindingFlags flags);
132GLIB_AVAILABLE_IN_ALL
133GBinding *g_object_bind_property_full (gpointer source,
134 const gchar *source_property,
135 gpointer target,
136 const gchar *target_property,
137 GBindingFlags flags,
138 GBindingTransformFunc transform_to,
139 GBindingTransformFunc transform_from,
140 gpointer user_data,
141 GDestroyNotify notify);
142GLIB_AVAILABLE_IN_ALL
143GBinding *g_object_bind_property_with_closures (gpointer source,
144 const gchar *source_property,
145 gpointer target,
146 const gchar *target_property,
147 GBindingFlags flags,
148 GClosure *transform_to,
149 GClosure *transform_from);
150
151G_END_DECLS
152
153#endif /* __G_BINDING_H__ */
154

source code of gtk/subprojects/glib/gobject/gbinding.h