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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Scriptable
use super::{Animatable, Interval, Timeline};
use glib::{
    object::{Cast, IsA},
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;
use std::{fmt, mem::transmute};

// TODO: @implements Scriptable
glib_wrapper! {
    pub struct Transition(Object<ffi::ClutterTransition, ffi::ClutterTransitionClass, TransitionClass>) @extends Timeline;

    match fn {
        get_type => || ffi::clutter_transition_get_type(),
    }
}

/// Trait containing all `Transition` methods.
///
/// # Implementors
///
/// [`PropertyTransition`](struct.PropertyTransition.html), [`TransitionGroup`](struct.TransitionGroup.html), [`Transition`](struct.Transition.html)
pub trait TransitionExt: 'static {
    /// Retrieves the `Animatable` set using `TransitionExt::set_animatable`.
    ///
    /// # Returns
    ///
    /// a `Animatable`, or `None`; the returned
    ///  animatable is owned by the `Transition`, and it should not be freed
    ///  directly.
    fn get_animatable(&self) -> Option<Animatable>;

    /// Retrieves the interval set using `TransitionExt::set_interval`
    ///
    /// # Returns
    ///
    /// a `Interval`, or `None`; the returned
    ///  interval is owned by the `Transition` and it should not be freed
    ///  directly
    fn get_interval(&self) -> Option<Interval>;

    /// Retrieves the value of the `Transition:remove-on-complete` property.
    ///
    /// # Returns
    ///
    /// `true` if the `self` should be detached when complete,
    ///  and `false` otherwise
    fn get_remove_on_complete(&self) -> bool;

    /// Sets the `Transition:animatable` property.
    ///
    /// The `self` will acquire a reference to the `animatable` instance,
    /// and will call the `TransitionClass.attached`() virtual function.
    ///
    /// If an existing `Animatable` is attached to `self`, the
    /// reference will be released, and the `TransitionClass.detached`()
    /// virtual function will be called.
    /// ## `animatable`
    /// a `Animatable`, or `None`
    fn set_animatable<P: IsA<Animatable>>(&self, animatable: Option<&P>);

    //fn set_from(&self, value_type: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Sets the initial value of the transition.
    ///
    /// This is a convenience function that will either create the
    /// `Interval` used by `self`, or will update it if
    /// the `Transition:interval` is already set.
    ///
    /// This function will copy the contents of `value`, so it is
    /// safe to call `gobject::Value::unset` after it returns.
    ///
    /// If `self` already has a `Transition:interval` set,
    /// then `value` must hold the same type, or a transformable type,
    /// as the interval's `Interval:value-type` property.
    ///
    /// This function is meant to be used by language bindings.
    /// ## `value`
    /// a `gobject::Value` with the initial value of the transition
    fn set_from_value(&self, value: &glib::Value);

    /// Sets the `Transition:interval` property using `interval`.
    ///
    /// The `self` will acquire a reference on the `interval`, sinking
    /// the floating flag on it if necessary.
    /// ## `interval`
    /// a `Interval`, or `None`
    fn set_interval<P: IsA<Interval>>(&self, interval: Option<&P>);

    /// Sets whether `self` should be detached from the `Animatable`
    /// set using `TransitionExt::set_animatable` when the
    /// `Timeline::completed` signal is emitted.
    /// ## `remove_complete`
    /// whether to detach `self` when complete
    fn set_remove_on_complete(&self, remove_complete: bool);

    //fn set_to(&self, value_type: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Sets the final value of the transition.
    ///
    /// This is a convenience function that will either create the
    /// `Interval` used by `self`, or will update it if
    /// the `Transition:interval` is already set.
    ///
    /// This function will copy the contents of `value`, so it is
    /// safe to call `gobject::Value::unset` after it returns.
    ///
    /// If `self` already has a `Transition:interval` set,
    /// then `value` must hold the same type, or a transformable type,
    /// as the interval's `Interval:value-type` property.
    ///
    /// This function is meant to be used by language bindings.
    /// ## `value`
    /// a `gobject::Value` with the final value of the transition
    fn set_to_value(&self, value: &glib::Value);

    fn connect_property_animatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_interval_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_remove_on_complete_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;
}

impl<O: IsA<Transition>> TransitionExt for O {
    fn get_animatable(&self) -> Option<Animatable> {
        unsafe {
            from_glib_none(ffi::clutter_transition_get_animatable(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_interval(&self) -> Option<Interval> {
        unsafe {
            from_glib_none(ffi::clutter_transition_get_interval(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_remove_on_complete(&self) -> bool {
        unsafe {
            from_glib(ffi::clutter_transition_get_remove_on_complete(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_animatable<P: IsA<Animatable>>(&self, animatable: Option<&P>) {
        unsafe {
            ffi::clutter_transition_set_animatable(
                self.as_ref().to_glib_none().0,
                animatable.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    //fn set_from(&self, value_type: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call clutter_sys:clutter_transition_set_from() }
    //}

    fn set_from_value(&self, value: &glib::Value) {
        unsafe {
            ffi::clutter_transition_set_from_value(
                self.as_ref().to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    fn set_interval<P: IsA<Interval>>(&self, interval: Option<&P>) {
        unsafe {
            ffi::clutter_transition_set_interval(
                self.as_ref().to_glib_none().0,
                interval.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    fn set_remove_on_complete(&self, remove_complete: bool) {
        unsafe {
            ffi::clutter_transition_set_remove_on_complete(
                self.as_ref().to_glib_none().0,
                remove_complete.to_glib(),
            );
        }
    }

    //fn set_to(&self, value_type: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call clutter_sys:clutter_transition_set_to() }
    //}

    fn set_to_value(&self, value: &glib::Value) {
        unsafe {
            ffi::clutter_transition_set_to_value(
                self.as_ref().to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    fn connect_property_animatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_animatable_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ffi::ClutterTransition,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Transition>,
        {
            let f: &F = &*(f as *const F);
            f(&Transition::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::animatable\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_animatable_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_interval_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_interval_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ffi::ClutterTransition,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Transition>,
        {
            let f: &F = &*(f as *const F);
            f(&Transition::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::interval\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_interval_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_remove_on_complete_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_remove_on_complete_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ffi::ClutterTransition,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Transition>,
        {
            let f: &F = &*(f as *const F);
            f(&Transition::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::remove-on-complete\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_remove_on_complete_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Transition {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Transition")
    }
}