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