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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Adjustment;
use crate::Border;
use crate::ScrollablePolicy;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    /// [`Scrollable`][crate::Scrollable] is an interface for widgets with native scrolling ability.
    ///
    /// To implement this interface you should override the
    /// `property::Scrollable::hadjustment` and
    /// `property::Scrollable::vadjustment` properties.
    ///
    /// ## Creating a scrollable widget
    ///
    /// All scrollable widgets should do the following.
    ///
    /// - When a parent widget sets the scrollable child widget’s adjustments,
    ///   the widget should connect to the `signal::Adjustment::value-changed`
    ///   signal. The child widget should then populate the adjustments’ properties
    ///   as soon as possible, which usually means queueing an allocation right away
    ///   and populating the properties in the `vfunc::Gtk::Widget::size_allocate`
    ///   implementation.
    ///
    /// - Because its preferred size is the size for a fully expanded widget,
    ///   the scrollable widget must be able to cope with underallocations.
    ///   This means that it must accept any value passed to its
    ///   `vfunc::Gtk::Widget::size_allocate` implementation.
    ///
    /// - When the parent allocates space to the scrollable child widget,
    ///   the widget must ensure the adjustments’ property values are correct and up
    ///   to date, for example using [`AdjustmentExt::configure()`][crate::prelude::AdjustmentExt::configure()].
    ///
    /// - When any of the adjustments emits the `signal::Adjustment::value-changed`
    ///   signal, the scrollable widget should scroll its contents.
    ///
    /// # Implements
    ///
    /// [`ScrollableExt`][trait@crate::prelude::ScrollableExt]
    #[doc(alias = "GtkScrollable")]
    pub struct Scrollable(Interface<ffi::GtkScrollable, ffi::GtkScrollableInterface>);

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

impl Scrollable {
    pub const NONE: Option<&'static Scrollable> = None;
}

/// Trait containing all [`struct@Scrollable`] methods.
///
/// # Implementors
///
/// [`ColumnView`][struct@crate::ColumnView], [`GridView`][struct@crate::GridView], [`IconView`][struct@crate::IconView], [`ListBase`][struct@crate::ListBase], [`ListView`][struct@crate::ListView], [`Scrollable`][struct@crate::Scrollable], [`TextView`][struct@crate::TextView], [`TreeView`][struct@crate::TreeView], [`Viewport`][struct@crate::Viewport]
pub trait ScrollableExt: 'static {
    /// Returns the size of a non-scrolling border around the
    /// outside of the scrollable.
    ///
    /// An example for this would be treeview headers. GTK can use
    /// this information to display overlaid graphics, like the
    /// overshoot indication, at the right position.
    ///
    /// # Returns
    ///
    /// [`true`] if @border has been set
    ///
    /// ## `border`
    /// return location for the results
    #[doc(alias = "gtk_scrollable_get_border")]
    #[doc(alias = "get_border")]
    fn border(&self) -> Option<Border>;

    /// Retrieves the [`Adjustment`][crate::Adjustment] used for horizontal scrolling.
    ///
    /// # Returns
    ///
    /// horizontal [`Adjustment`][crate::Adjustment].
    #[doc(alias = "gtk_scrollable_get_hadjustment")]
    #[doc(alias = "get_hadjustment")]
    fn hadjustment(&self) -> Option<Adjustment>;

    /// Gets the horizontal [`ScrollablePolicy`][crate::ScrollablePolicy].
    ///
    /// # Returns
    ///
    /// The horizontal [`ScrollablePolicy`][crate::ScrollablePolicy].
    #[doc(alias = "gtk_scrollable_get_hscroll_policy")]
    #[doc(alias = "get_hscroll_policy")]
    fn hscroll_policy(&self) -> ScrollablePolicy;

    /// Retrieves the [`Adjustment`][crate::Adjustment] used for vertical scrolling.
    ///
    /// # Returns
    ///
    /// vertical [`Adjustment`][crate::Adjustment].
    #[doc(alias = "gtk_scrollable_get_vadjustment")]
    #[doc(alias = "get_vadjustment")]
    fn vadjustment(&self) -> Option<Adjustment>;

    /// Gets the vertical [`ScrollablePolicy`][crate::ScrollablePolicy].
    ///
    /// # Returns
    ///
    /// The vertical [`ScrollablePolicy`][crate::ScrollablePolicy].
    #[doc(alias = "gtk_scrollable_get_vscroll_policy")]
    #[doc(alias = "get_vscroll_policy")]
    fn vscroll_policy(&self) -> ScrollablePolicy;

    /// Sets the horizontal adjustment of the [`Scrollable`][crate::Scrollable].
    /// ## `hadjustment`
    /// a [`Adjustment`][crate::Adjustment]
    #[doc(alias = "gtk_scrollable_set_hadjustment")]
    fn set_hadjustment(&self, hadjustment: Option<&impl IsA<Adjustment>>);

    /// Sets the [`ScrollablePolicy`][crate::ScrollablePolicy].
    ///
    /// The policy determines whether horizontal scrolling should start
    /// below the minimum width or below the natural width.
    /// ## `policy`
    /// the horizontal [`ScrollablePolicy`][crate::ScrollablePolicy]
    #[doc(alias = "gtk_scrollable_set_hscroll_policy")]
    fn set_hscroll_policy(&self, policy: ScrollablePolicy);

    /// Sets the vertical adjustment of the [`Scrollable`][crate::Scrollable].
    /// ## `vadjustment`
    /// a [`Adjustment`][crate::Adjustment]
    #[doc(alias = "gtk_scrollable_set_vadjustment")]
    fn set_vadjustment(&self, vadjustment: Option<&impl IsA<Adjustment>>);

    /// Sets the [`ScrollablePolicy`][crate::ScrollablePolicy].
    ///
    /// The policy determines whether vertical scrolling should start
    /// below the minimum height or below the natural height.
    /// ## `policy`
    /// the vertical [`ScrollablePolicy`][crate::ScrollablePolicy]
    #[doc(alias = "gtk_scrollable_set_vscroll_policy")]
    fn set_vscroll_policy(&self, policy: ScrollablePolicy);

    #[doc(alias = "hadjustment")]
    fn connect_hadjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "hscroll-policy")]
    fn connect_hscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "vadjustment")]
    fn connect_vadjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "vscroll-policy")]
    fn connect_vscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Scrollable>> ScrollableExt for O {
    fn border(&self) -> Option<Border> {
        unsafe {
            let mut border = Border::uninitialized();
            let ret = from_glib(ffi::gtk_scrollable_get_border(
                self.as_ref().to_glib_none().0,
                border.to_glib_none_mut().0,
            ));
            if ret {
                Some(border)
            } else {
                None
            }
        }
    }

    fn hadjustment(&self) -> Option<Adjustment> {
        unsafe {
            from_glib_none(ffi::gtk_scrollable_get_hadjustment(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn hscroll_policy(&self) -> ScrollablePolicy {
        unsafe {
            from_glib(ffi::gtk_scrollable_get_hscroll_policy(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn vadjustment(&self) -> Option<Adjustment> {
        unsafe {
            from_glib_none(ffi::gtk_scrollable_get_vadjustment(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn vscroll_policy(&self) -> ScrollablePolicy {
        unsafe {
            from_glib(ffi::gtk_scrollable_get_vscroll_policy(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_hadjustment(&self, hadjustment: Option<&impl IsA<Adjustment>>) {
        unsafe {
            ffi::gtk_scrollable_set_hadjustment(
                self.as_ref().to_glib_none().0,
                hadjustment.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    fn set_hscroll_policy(&self, policy: ScrollablePolicy) {
        unsafe {
            ffi::gtk_scrollable_set_hscroll_policy(
                self.as_ref().to_glib_none().0,
                policy.into_glib(),
            );
        }
    }

    fn set_vadjustment(&self, vadjustment: Option<&impl IsA<Adjustment>>) {
        unsafe {
            ffi::gtk_scrollable_set_vadjustment(
                self.as_ref().to_glib_none().0,
                vadjustment.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    fn set_vscroll_policy(&self, policy: ScrollablePolicy) {
        unsafe {
            ffi::gtk_scrollable_set_vscroll_policy(
                self.as_ref().to_glib_none().0,
                policy.into_glib(),
            );
        }
    }

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

    fn connect_hscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_hscroll_policy_trampoline<
            P: IsA<Scrollable>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkScrollable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::hscroll-policy\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_hscroll_policy_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

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

    fn connect_vscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_vscroll_policy_trampoline<
            P: IsA<Scrollable>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkScrollable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::vscroll-policy\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_vscroll_policy_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

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