1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute};

glib::wrapper! {
    /// [`BindingGroup`][crate::BindingGroup] manages to simplify the process of binding
    /// many properties from a [`glib::Object`][crate::glib::Object] as a group. As such there is no API
    /// to unbind a property from the group.
    ///
    /// In particular, this allows you to change the source instance for the
    /// bindings. This automatically causes the unbinding of the properties
    /// from the old instance and binding to the new instance.
    ///
    /// This should not be confused with `GtkBindingGroup`.
    ///
    /// ## Properties
    ///
    ///
    /// #### `source`
    ///  The source object used for binding properties.
    ///
    /// Readable | Writeable
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`]
    #[doc(alias = "DzlBindingGroup")]
    pub struct BindingGroup(Object<ffi::DzlBindingGroup, ffi::DzlBindingGroupClass>);

    match fn {
        type_ => || ffi::dzl_binding_group_get_type(),
    }
}

impl BindingGroup {
    /// Creates a new [`BindingGroup`][crate::BindingGroup].
    ///
    /// # Returns
    ///
    /// a new [`BindingGroup`][crate::BindingGroup]
    #[doc(alias = "dzl_binding_group_new")]
    pub fn new() -> BindingGroup {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::dzl_binding_group_new()) }
    }

    /// Creates a binding between `source_property` on the source object
    /// and `target_property` on `target`. Whenever the `source_property`
    /// is changed the `target_property` is updated using the same value.
    /// The binding flags [`glib::BindingFlags::SYNC_CREATE`][crate::glib::BindingFlags::SYNC_CREATE] is automatically specified.
    ///
    /// See: [`ObjectExt::bind_property()`][crate::glib::prelude::ObjectExt::bind_property()].
    /// ## `source_property`
    /// the property on the source to bind
    /// ## `target`
    /// the target [`glib::Object`][crate::glib::Object]
    /// ## `target_property`
    /// the property on `target` to bind
    /// ## `flags`
    /// the flags used to create the [`glib::Binding`][crate::glib::Binding]
    #[doc(alias = "dzl_binding_group_bind")]
    pub fn bind(
        &self,
        source_property: &str,
        target: &impl IsA<glib::Object>,
        target_property: &str,
        flags: glib::BindingFlags,
    ) {
        unsafe {
            ffi::dzl_binding_group_bind(
                self.to_glib_none().0,
                source_property.to_glib_none().0,
                target.as_ref().to_glib_none().0,
                target_property.to_glib_none().0,
                flags.into_glib(),
            );
        }
    }

    //#[doc(alias = "dzl_binding_group_bind_full")]
    //pub fn bind_full(&self, source_property: &str, target: &impl IsA<glib::Object>, target_property: &str, flags: glib::BindingFlags, transform_to: Option<Box_<dyn Fn(&glib::Binding, &glib::Value, &glib::Value) -> bool + 'static>>, transform_from: Option<Box_<dyn Fn(&glib::Binding, &glib::Value, &glib::Value) -> bool + 'static>>) {
    //    unsafe { TODO: call ffi:dzl_binding_group_bind_full() }
    //}

    /// Creates a binding between `source_property` on the source object and
    /// `target_property` on `target`, allowing you to set the transformation
    /// functions to be used by the binding. The binding flags
    /// [`glib::BindingFlags::SYNC_CREATE`][crate::glib::BindingFlags::SYNC_CREATE] is automatically specified.
    ///
    /// This function is the language bindings friendly version of
    /// `dzl_binding_group_bind_property_full()`, using `GClosures`
    /// instead of function pointers.
    ///
    /// See: [`ObjectExt::bind_property_with_closures()`][crate::glib::prelude::ObjectExt::bind_property_with_closures()].
    /// ## `source_property`
    /// the property on the source to bind
    /// ## `target`
    /// the target [`glib::Object`][crate::glib::Object]
    /// ## `target_property`
    /// the property on `target` to bind
    /// ## `flags`
    /// the flags used to create the [`glib::Binding`][crate::glib::Binding]
    /// ## `transform_to`
    /// a [`glib::Closure`][crate::glib::Closure] wrapping the
    ///  transformation function from the source object to the `target`,
    ///  or [`None`] to use the default
    /// ## `transform_from`
    /// a [`glib::Closure`][crate::glib::Closure] wrapping the
    ///  transformation function from the `target` to the source object,
    ///  or [`None`] to use the default
    #[doc(alias = "dzl_binding_group_bind_with_closures")]
    pub fn bind_with_closures(
        &self,
        source_property: &str,
        target: &impl IsA<glib::Object>,
        target_property: &str,
        flags: glib::BindingFlags,
        transform_to: Option<&glib::Closure>,
        transform_from: Option<&glib::Closure>,
    ) {
        unsafe {
            ffi::dzl_binding_group_bind_with_closures(
                self.to_glib_none().0,
                source_property.to_glib_none().0,
                target.as_ref().to_glib_none().0,
                target_property.to_glib_none().0,
                flags.into_glib(),
                transform_to.to_glib_none().0,
                transform_from.to_glib_none().0,
            );
        }
    }

    /// Gets the source object used for binding properties.
    ///
    /// # Returns
    ///
    /// the source object.
    #[doc(alias = "dzl_binding_group_get_source")]
    #[doc(alias = "get_source")]
    pub fn source(&self) -> Option<glib::Object> {
        unsafe { from_glib_none(ffi::dzl_binding_group_get_source(self.to_glib_none().0)) }
    }

    /// Sets `source` as the source object used for creating property
    /// bindings. If there is already a source object all bindings from it
    /// will be removed.
    ///
    /// Note: All properties that have been bound must exist on `source`.
    /// ## `source`
    /// the source [`glib::Object`][crate::glib::Object]
    #[doc(alias = "dzl_binding_group_set_source")]
    pub fn set_source(&self, source: Option<&impl IsA<glib::Object>>) {
        unsafe {
            ffi::dzl_binding_group_set_source(
                self.to_glib_none().0,
                source.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    #[doc(alias = "source")]
    pub fn connect_source_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_source_trampoline<F: Fn(&BindingGroup) + 'static>(
            this: *mut ffi::DzlBindingGroup,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::source\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_source_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for BindingGroup {
    fn default() -> Self {
        Self::new()
    }
}

impl fmt::Display for BindingGroup {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("BindingGroup")
    }
}