1 // Generated by gmmproc 2.64.2 -- DO NOT MODIFY!
2
3
4 #include <glibmm.h>
5
6 #include <glibmm/binding.h>
7 #include <glibmm/private/binding_p.h>
8
9
10 /* Copyright (C) 2014 The glibmm Development Team
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26 #include <glibmm/binding.h>
27 #include <glib.h>
28
29 namespace
30 {
31 struct BindingTransformSlots
32 {
BindingTransformSlots__anon271949d10111::BindingTransformSlots33 BindingTransformSlots(const Glib::Binding::SlotTransform& transform_to,
34 const Glib::Binding::SlotTransform& transform_from)
35 : from_source_to_target(transform_to), from_target_to_source(transform_from)
36 {
37 }
38
39 Glib::Binding::SlotTransform from_source_to_target;
40 Glib::Binding::SlotTransform from_target_to_source;
41 };
42
43 gboolean
Binding_transform_callback_common(const GValue * from_value,GValue * to_value,Glib::Binding::SlotTransform & the_slot)44 Binding_transform_callback_common(
45 const GValue* from_value, GValue* to_value, Glib::Binding::SlotTransform& the_slot)
46 {
47 bool result = false;
48 try
49 {
50 result = the_slot(from_value, to_value);
51 }
52 catch (...)
53 {
54 Glib::exception_handlers_invoke();
55 }
56 return result;
57 }
58
59 gboolean
Binding_transform_to_callback(GBinding *,const GValue * from_value,GValue * to_value,gpointer user_data)60 Binding_transform_to_callback(
61 GBinding*, const GValue* from_value, GValue* to_value, gpointer user_data)
62 {
63 Glib::Binding::SlotTransform& the_slot =
64 static_cast<BindingTransformSlots*>(user_data)->from_source_to_target;
65
66 return Binding_transform_callback_common(from_value, to_value, the_slot);
67 }
68
69 gboolean
Binding_transform_from_callback(GBinding *,const GValue * from_value,GValue * to_value,gpointer user_data)70 Binding_transform_from_callback(
71 GBinding*, const GValue* from_value, GValue* to_value, gpointer user_data)
72 {
73 Glib::Binding::SlotTransform& the_slot =
74 static_cast<BindingTransformSlots*>(user_data)->from_target_to_source;
75
76 return Binding_transform_callback_common(from_value, to_value, the_slot);
77 }
78
79 void
Binding_transform_callback_destroy(gpointer user_data)80 Binding_transform_callback_destroy(gpointer user_data)
81 {
82 delete static_cast<BindingTransformSlots*>(user_data);
83 }
84
85 } // anonymous namespace
86
87 namespace Glib
88 {
89 // static
90 Glib::RefPtr<Binding>
bind_property_value(const PropertyProxy_Base & source_property,const PropertyProxy_Base & target_property,BindingFlags flags,const SlotTransform & transform_to,const SlotTransform & transform_from)91 Binding::bind_property_value(const PropertyProxy_Base& source_property,
92 const PropertyProxy_Base& target_property, BindingFlags flags, const SlotTransform& transform_to,
93 const SlotTransform& transform_from)
94 {
95 GBinding* binding = nullptr;
96 if (transform_to.empty() && transform_from.empty())
97 {
98 // No user-supplied transformations.
99 binding =
100 g_object_bind_property(source_property.get_object()->gobj(), source_property.get_name(),
101 target_property.get_object()->gobj(), target_property.get_name(), (GBindingFlags)flags);
102 }
103 else
104 {
105 // Create copies of the slots. A pointer to this will be passed
106 // through the callback's data parameter. It will be deleted
107 // when Binding_transform_callback_destroy() is called.
108 BindingTransformSlots* slots_copy = new BindingTransformSlots(transform_to, transform_from);
109
110 binding = g_object_bind_property_full(source_property.get_object()->gobj(),
111 source_property.get_name(), target_property.get_object()->gobj(), target_property.get_name(),
112 (GBindingFlags)flags, transform_to.empty() ? nullptr : &Binding_transform_to_callback,
113 transform_from.empty() ? nullptr : &Binding_transform_from_callback, slots_copy,
114 &Binding_transform_callback_destroy);
115 }
116
117 if (!binding)
118 return Glib::RefPtr<Binding>();
119
120 // Take an extra ref. GBinding uses one ref itself, and drops it if
121 // either the source object or the target object is finalized.
122 // The GBinding object must not be destroyed while there are RefPtrs around.
123 g_object_ref(binding);
124 return Glib::RefPtr<Binding>(new Binding(binding));
125 }
126
127 void
unbind()128 Binding::unbind()
129 {
130 // Call g_binding_unbind() only once. It always calls g_object_unref().
131 if (g_binding_get_source(gobj()))
132 g_binding_unbind(gobj());
133 }
134
135 // Override unreference() from ObjectBase.
136 //
137 // Why is this necessary? Because GBinding is an unusual kind of GObject.
138 // It calls g_object_unref() itself, if either the source object or the
139 // target object is finalized, almost like g_binding_unbind().
140 // But the GBinding object shall be destroyed when and only when the last
141 // reference from a Glib::RefPtr is dropped.
142 void
unreference() const143 Binding::unreference() const
144 {
145 GBinding* const binding = const_cast<GBinding*>(gobj());
146
147 // If the last Glib::RefPtr is being deleted, and the binding has not been unbound,
148 // then drop the extra reference that was added by bind_property_value().
149 if (gobject_->ref_count == 2 && g_binding_get_source(binding))
150 g_object_unref(binding);
151
152 Object::unreference();
153 }
154
155 } // namespace Glib
156
157 namespace
158 {
159 } // anonymous namespace
160
161 // static
value_type()162 GType Glib::Value<Glib::BindingFlags>::value_type()
163 {
164 return g_binding_flags_get_type();
165 }
166
167
168 namespace Glib
169 {
170
wrap(GBinding * object,bool take_copy)171 Glib::RefPtr<Glib::Binding> wrap(GBinding* object, bool take_copy)
172 {
173 return Glib::RefPtr<Glib::Binding>( dynamic_cast<Glib::Binding*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
174 //We use dynamic_cast<> in case of multiple inheritance.
175 }
176
177 } /* namespace Glib */
178
179
180 namespace Glib
181 {
182
183
184 /* The *_Class implementation: */
185
init()186 const Glib::Class& Binding_Class::init()
187 {
188 if(!gtype_) // create the GType if necessary
189 {
190 // Glib::Class has to know the class init function to clone custom types.
191 class_init_func_ = &Binding_Class::class_init_function;
192
193 // This is actually just optimized away, apparently with no harm.
194 // Make sure that the parent type has been created.
195 //CppClassParent::CppObjectType::get_type();
196
197 // Create the wrapper type, with the same class/instance size as the base type.
198 register_derived_type(g_binding_get_type());
199
200 // Add derived versions of interfaces, if the C type implements any interfaces:
201
202 }
203
204 return *this;
205 }
206
207
class_init_function(void * g_class,void * class_data)208 void Binding_Class::class_init_function(void* g_class, void* class_data)
209 {
210 const auto klass = static_cast<BaseClassType*>(g_class);
211 CppClassParent::class_init_function(klass, class_data);
212
213
214 }
215
216
wrap_new(GObject * object)217 Glib::ObjectBase* Binding_Class::wrap_new(GObject* object)
218 {
219 return new Binding((GBinding*)object);
220 }
221
222
223 /* The implementation: */
224
gobj_copy()225 GBinding* Binding::gobj_copy()
226 {
227 reference();
228 return gobj();
229 }
230
Binding(const Glib::ConstructParams & construct_params)231 Binding::Binding(const Glib::ConstructParams& construct_params)
232 :
233 Glib::Object(construct_params)
234 {
235
236 }
237
Binding(GBinding * castitem)238 Binding::Binding(GBinding* castitem)
239 :
240 Glib::Object((GObject*)(castitem))
241 {}
242
243
Binding(Binding && src)244 Binding::Binding(Binding&& src) noexcept
245 : Glib::Object(std::move(src))
246 {}
247
operator =(Binding && src)248 Binding& Binding::operator=(Binding&& src) noexcept
249 {
250 Glib::Object::operator=(std::move(src));
251 return *this;
252 }
253
254
~Binding()255 Binding::~Binding() noexcept
256 {}
257
258
259 Binding::CppClassType Binding::binding_class_; // initialize static member
260
get_type()261 GType Binding::get_type()
262 {
263 return binding_class_.init().get_type();
264 }
265
266
get_base_type()267 GType Binding::get_base_type()
268 {
269 return g_binding_get_type();
270 }
271
272
get_source()273 Glib::RefPtr<Glib::ObjectBase> Binding::get_source()
274 {
275 Glib::RefPtr<Glib::ObjectBase> retvalue = Glib::wrap(g_binding_get_source(gobj()));
276 if(retvalue)
277 retvalue->reference(); //The function does not do a ref for us.
278 return retvalue;
279 }
280
get_source() const281 Glib::RefPtr<const Glib::ObjectBase> Binding::get_source() const
282 {
283 return const_cast<Binding*>(this)->get_source();
284 }
285
get_source_property() const286 Glib::ustring Binding::get_source_property() const
287 {
288 return Glib::convert_const_gchar_ptr_to_ustring(g_binding_get_source_property(const_cast<GBinding*>(gobj())));
289 }
290
get_target()291 Glib::RefPtr<Glib::ObjectBase> Binding::get_target()
292 {
293 Glib::RefPtr<Glib::ObjectBase> retvalue = Glib::wrap(g_binding_get_target(gobj()));
294 if(retvalue)
295 retvalue->reference(); //The function does not do a ref for us.
296 return retvalue;
297 }
298
get_target() const299 Glib::RefPtr<const Glib::ObjectBase> Binding::get_target() const
300 {
301 return const_cast<Binding*>(this)->get_target();
302 }
303
get_target_property() const304 Glib::ustring Binding::get_target_property() const
305 {
306 return Glib::convert_const_gchar_ptr_to_ustring(g_binding_get_target_property(const_cast<GBinding*>(gobj())));
307 }
308
get_flags() const309 BindingFlags Binding::get_flags() const
310 {
311 return ((BindingFlags)(g_binding_get_flags(const_cast<GBinding*>(gobj()))));
312 }
313
314
property_flags() const315 Glib::PropertyProxy_ReadOnly< Glib::BindingFlags > Binding::property_flags() const
316 {
317 return Glib::PropertyProxy_ReadOnly< Glib::BindingFlags >(this, "flags");
318 }
319
property_source() const320 Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Glib::ObjectBase> > Binding::property_source() const
321 {
322 return Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Glib::ObjectBase> >(this, "source");
323 }
324
property_source_property() const325 Glib::PropertyProxy_ReadOnly< Glib::ustring > Binding::property_source_property() const
326 {
327 return Glib::PropertyProxy_ReadOnly< Glib::ustring >(this, "source-property");
328 }
329
property_target() const330 Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Glib::ObjectBase> > Binding::property_target() const
331 {
332 return Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Glib::ObjectBase> >(this, "target");
333 }
334
property_target_property() const335 Glib::PropertyProxy_ReadOnly< Glib::ustring > Binding::property_target_property() const
336 {
337 return Glib::PropertyProxy_ReadOnly< Glib::ustring >(this, "target-property");
338 }
339
340
341 } // namespace Glib
342
343
344