gtk4/subclass/
accessible_range.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3// rustdoc-stripper-ignore-next
4//! Traits intended for implementing the
5//! [`AccessibleRange`](crate::AccessibleRange) interface.
6
7use glib::translate::*;
8
9use crate::{ffi, prelude::*, subclass::prelude::*, AccessibleRange};
10
11pub trait AccessibleRangeImpl: WidgetImpl {
12    fn set_current_value(&self, value: f64) -> bool {
13        self.parent_set_current_value(value)
14    }
15}
16
17mod sealed {
18    pub trait Sealed {}
19    impl<T: super::AccessibleRangeImplExt> Sealed for T {}
20}
21
22pub trait AccessibleRangeImplExt: sealed::Sealed + ObjectSubclass {
23    // Returns true if the operation was performed, false otherwise
24    fn parent_set_current_value(&self, value: f64) -> bool {
25        unsafe {
26            let type_data = Self::type_data();
27            let parent_iface = type_data.as_ref().parent_interface::<AccessibleRange>()
28                as *const ffi::GtkAccessibleRangeInterface;
29
30            let func = (*parent_iface)
31                .set_current_value
32                .expect("no parent \"set_current_value\" implementation");
33
34            from_glib(func(
35                self.obj()
36                    .unsafe_cast_ref::<AccessibleRange>()
37                    .to_glib_none()
38                    .0,
39                value,
40            ))
41        }
42    }
43}
44
45impl<T: AccessibleRangeImpl> AccessibleRangeImplExt for T {}
46
47unsafe impl<T: AccessibleRangeImpl> IsImplementable<T> for AccessibleRange {
48    fn interface_init(iface: &mut glib::Interface<Self>) {
49        let iface = iface.as_mut();
50
51        iface.set_current_value = Some(accessible_range_set_current_value::<T>);
52    }
53}
54
55unsafe extern "C" fn accessible_range_set_current_value<T: AccessibleRangeImpl>(
56    accessible_range: *mut ffi::GtkAccessibleRange,
57    value: f64,
58) -> glib::ffi::gboolean {
59    let instance = &*(accessible_range as *mut T::Instance);
60    let imp = instance.imp();
61
62    imp.set_current_value(value).into_glib()
63}