1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gobject.Binding;
26 
27 private import glib.Str;
28 private import glib.c.functions;
29 private import gobject.ObjectG;
30 private import gobject.c.functions;
31 public  import gobject.c.types;
32 
33 
34 /**
35  * #GBinding is the representation of a binding between a property on a
36  * #GObject instance (or source) and another property on another #GObject
37  * instance (or target). Whenever the source property changes, the same
38  * value is applied to the target property; for instance, the following
39  * binding:
40  * 
41  * |[<!-- language="C" -->
42  * g_object_bind_property (object1, "property-a",
43  * object2, "property-b",
44  * G_BINDING_DEFAULT);
45  * ]|
46  * 
47  * will cause the property named "property-b" of @object2 to be updated
48  * every time g_object_set() or the specific accessor changes the value of
49  * the property "property-a" of @object1.
50  * 
51  * It is possible to create a bidirectional binding between two properties
52  * of two #GObject instances, so that if either property changes, the
53  * other is updated as well, for instance:
54  * 
55  * |[<!-- language="C" -->
56  * g_object_bind_property (object1, "property-a",
57  * object2, "property-b",
58  * G_BINDING_BIDIRECTIONAL);
59  * ]|
60  * 
61  * will keep the two properties in sync.
62  * 
63  * It is also possible to set a custom transformation function (in both
64  * directions, in case of a bidirectional binding) to apply a custom
65  * transformation from the source value to the target value before
66  * applying it; for instance, the following binding:
67  * 
68  * |[<!-- language="C" -->
69  * g_object_bind_property_full (adjustment1, "value",
70  * adjustment2, "value",
71  * G_BINDING_BIDIRECTIONAL,
72  * celsius_to_fahrenheit,
73  * fahrenheit_to_celsius,
74  * NULL, NULL);
75  * ]|
76  * 
77  * will keep the "value" property of the two adjustments in sync; the
78  * @celsius_to_fahrenheit function will be called whenever the "value"
79  * property of @adjustment1 changes and will transform the current value
80  * of the property before applying it to the "value" property of @adjustment2.
81  * 
82  * Vice versa, the @fahrenheit_to_celsius function will be called whenever
83  * the "value" property of @adjustment2 changes, and will transform the
84  * current value of the property before applying it to the "value" property
85  * of @adjustment1.
86  * 
87  * Note that #GBinding does not resolve cycles by itself; a cycle like
88  * 
89  * |[
90  * object1:propertyA -> object2:propertyB
91  * object2:propertyB -> object3:propertyC
92  * object3:propertyC -> object1:propertyA
93  * ]|
94  * 
95  * might lead to an infinite loop. The loop, in this particular case,
96  * can be avoided if the objects emit the #GObject::notify signal only
97  * if the value has effectively been changed. A binding is implemented
98  * using the #GObject::notify signal, so it is susceptible to all the
99  * various ways of blocking a signal emission, like g_signal_stop_emission()
100  * or g_signal_handler_block().
101  * 
102  * A binding will be severed, and the resources it allocates freed, whenever
103  * either one of the #GObject instances it refers to are finalized, or when
104  * the #GBinding instance loses its last reference.
105  * 
106  * Bindings for languages with garbage collection can use
107  * g_binding_unbind() to explicitly release a binding between the source
108  * and target properties, instead of relying on the last reference on the
109  * binding, source, and target instances to drop.
110  * 
111  * #GBinding is available since GObject 2.26
112  *
113  * Since: 2.26
114  */
115 public class Binding : ObjectG
116 {
117 	/** the main Gtk struct */
118 	protected GBinding* gBinding;
119 
120 	/** Get the main Gtk struct */
121 	public GBinding* getBindingStruct(bool transferOwnership = false)
122 	{
123 		if (transferOwnership)
124 			ownedRef = false;
125 		return gBinding;
126 	}
127 
128 	/** the main Gtk struct as a void* */
129 	protected override void* getStruct()
130 	{
131 		return cast(void*)gBinding;
132 	}
133 
134 	/**
135 	 * Sets our main struct and passes it to the parent class.
136 	 */
137 	public this (GBinding* gBinding, bool ownedRef = false)
138 	{
139 		this.gBinding = gBinding;
140 		super(cast(GObject*)gBinding, ownedRef);
141 	}
142 
143 
144 	/** */
145 	public static GType getType()
146 	{
147 		return g_binding_get_type();
148 	}
149 
150 	/**
151 	 * Retrieves the #GObject instance used as the source of the binding.
152 	 *
153 	 * A #GBinding can outlive the source #GObject as the binding does not hold a
154 	 * strong reference to the source. If the source is destroyed before the
155 	 * binding then this function will return %NULL.
156 	 *
157 	 * Returns: the source #GObject, or %NULL if the
158 	 *     source does not exist any more.
159 	 *
160 	 * Since: 2.68
161 	 */
162 	public ObjectG dupSource()
163 	{
164 		auto __p = g_binding_dup_source(gBinding);
165 
166 		if(__p is null)
167 		{
168 			return null;
169 		}
170 
171 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p, true);
172 	}
173 
174 	/**
175 	 * Retrieves the #GObject instance used as the target of the binding.
176 	 *
177 	 * A #GBinding can outlive the target #GObject as the binding does not hold a
178 	 * strong reference to the target. If the target is destroyed before the
179 	 * binding then this function will return %NULL.
180 	 *
181 	 * Returns: the target #GObject, or %NULL if the
182 	 *     target does not exist any more.
183 	 *
184 	 * Since: 2.68
185 	 */
186 	public ObjectG dupTarget()
187 	{
188 		auto __p = g_binding_dup_target(gBinding);
189 
190 		if(__p is null)
191 		{
192 			return null;
193 		}
194 
195 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p, true);
196 	}
197 
198 	/**
199 	 * Retrieves the flags passed when constructing the #GBinding.
200 	 *
201 	 * Returns: the #GBindingFlags used by the #GBinding
202 	 *
203 	 * Since: 2.26
204 	 */
205 	public GBindingFlags getFlags()
206 	{
207 		return g_binding_get_flags(gBinding);
208 	}
209 
210 	/**
211 	 * Retrieves the #GObject instance used as the source of the binding.
212 	 *
213 	 * A #GBinding can outlive the source #GObject as the binding does not hold a
214 	 * strong reference to the source. If the source is destroyed before the
215 	 * binding then this function will return %NULL.
216 	 *
217 	 * Use g_binding_dup_source() if the source or binding are used from different
218 	 * threads as otherwise the pointer returned from this function might become
219 	 * invalid if the source is finalized from another thread in the meantime.
220 	 *
221 	 * Deprecated: Use g_binding_dup_source() for a safer version of this
222 	 * function.
223 	 *
224 	 * Returns: the source #GObject, or %NULL if the
225 	 *     source does not exist any more.
226 	 *
227 	 * Since: 2.26
228 	 */
229 	public ObjectG getSource()
230 	{
231 		auto __p = g_binding_get_source(gBinding);
232 
233 		if(__p is null)
234 		{
235 			return null;
236 		}
237 
238 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p);
239 	}
240 
241 	/**
242 	 * Retrieves the name of the property of #GBinding:source used as the source
243 	 * of the binding.
244 	 *
245 	 * Returns: the name of the source property
246 	 *
247 	 * Since: 2.26
248 	 */
249 	public string getSourceProperty()
250 	{
251 		return Str.toString(g_binding_get_source_property(gBinding));
252 	}
253 
254 	/**
255 	 * Retrieves the #GObject instance used as the target of the binding.
256 	 *
257 	 * A #GBinding can outlive the target #GObject as the binding does not hold a
258 	 * strong reference to the target. If the target is destroyed before the
259 	 * binding then this function will return %NULL.
260 	 *
261 	 * Use g_binding_dup_target() if the target or binding are used from different
262 	 * threads as otherwise the pointer returned from this function might become
263 	 * invalid if the target is finalized from another thread in the meantime.
264 	 *
265 	 * Deprecated: Use g_binding_dup_target() for a safer version of this
266 	 * function.
267 	 *
268 	 * Returns: the target #GObject, or %NULL if the
269 	 *     target does not exist any more.
270 	 *
271 	 * Since: 2.26
272 	 */
273 	public ObjectG getTarget()
274 	{
275 		auto __p = g_binding_get_target(gBinding);
276 
277 		if(__p is null)
278 		{
279 			return null;
280 		}
281 
282 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p);
283 	}
284 
285 	/**
286 	 * Retrieves the name of the property of #GBinding:target used as the target
287 	 * of the binding.
288 	 *
289 	 * Returns: the name of the target property
290 	 *
291 	 * Since: 2.26
292 	 */
293 	public string getTargetProperty()
294 	{
295 		return Str.toString(g_binding_get_target_property(gBinding));
296 	}
297 
298 	/**
299 	 * Explicitly releases the binding between the source and the target
300 	 * property expressed by @binding.
301 	 *
302 	 * This function will release the reference that is being held on
303 	 * the @binding instance if the binding is still bound; if you want to hold on
304 	 * to the #GBinding instance after calling g_binding_unbind(), you will need
305 	 * to hold a reference to it.
306 	 *
307 	 * Note however that this function does not take ownership of @binding, it
308 	 * only unrefs the reference that was initially created by
309 	 * g_object_bind_property() and is owned by the binding.
310 	 *
311 	 * Since: 2.38
312 	 */
313 	public void unbind()
314 	{
315 		g_binding_unbind(gBinding);
316 	}
317 }