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 gobject.ObjectG;
29 private import gobject.c.functions;
30 public  import gobject.c.types;
31 public  import gtkc.gobjecttypes;
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 	protected override void setStruct(GObject* obj)
135 	{
136 		gBinding = cast(GBinding*)obj;
137 		super.setStruct(obj);
138 	}
139 
140 	/**
141 	 * Sets our main struct and passes it to the parent class.
142 	 */
143 	public this (GBinding* gBinding, bool ownedRef = false)
144 	{
145 		this.gBinding = gBinding;
146 		super(cast(GObject*)gBinding, ownedRef);
147 	}
148 
149 
150 	/** */
151 	public static GType getType()
152 	{
153 		return g_binding_get_type();
154 	}
155 
156 	/**
157 	 * Retrieves the flags passed when constructing the #GBinding.
158 	 *
159 	 * Returns: the #GBindingFlags used by the #GBinding
160 	 *
161 	 * Since: 2.26
162 	 */
163 	public GBindingFlags getFlags()
164 	{
165 		return g_binding_get_flags(gBinding);
166 	}
167 
168 	/**
169 	 * Retrieves the #GObject instance used as the source of the binding.
170 	 *
171 	 * Returns: the source #GObject
172 	 *
173 	 * Since: 2.26
174 	 */
175 	public ObjectG getSource()
176 	{
177 		auto p = g_binding_get_source(gBinding);
178 
179 		if(p is null)
180 		{
181 			return null;
182 		}
183 
184 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p);
185 	}
186 
187 	/**
188 	 * Retrieves the name of the property of #GBinding:source used as the source
189 	 * of the binding.
190 	 *
191 	 * Returns: the name of the source property
192 	 *
193 	 * Since: 2.26
194 	 */
195 	public string getSourceProperty()
196 	{
197 		return Str.toString(g_binding_get_source_property(gBinding));
198 	}
199 
200 	/**
201 	 * Retrieves the #GObject instance used as the target of the binding.
202 	 *
203 	 * Returns: the target #GObject
204 	 *
205 	 * Since: 2.26
206 	 */
207 	public ObjectG getTarget()
208 	{
209 		auto p = g_binding_get_target(gBinding);
210 
211 		if(p is null)
212 		{
213 			return null;
214 		}
215 
216 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p);
217 	}
218 
219 	/**
220 	 * Retrieves the name of the property of #GBinding:target used as the target
221 	 * of the binding.
222 	 *
223 	 * Returns: the name of the target property
224 	 *
225 	 * Since: 2.26
226 	 */
227 	public string getTargetProperty()
228 	{
229 		return Str.toString(g_binding_get_target_property(gBinding));
230 	}
231 
232 	/**
233 	 * Explicitly releases the binding between the source and the target
234 	 * property expressed by @binding.
235 	 *
236 	 * This function will release the reference that is being held on
237 	 * the @binding instance; if you want to hold on to the #GBinding instance
238 	 * after calling g_binding_unbind(), you will need to hold a reference
239 	 * to it.
240 	 *
241 	 * Since: 2.38
242 	 */
243 	public void unbind()
244 	{
245 		g_binding_unbind(gBinding);
246 	}
247 }