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
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::{Accessible, AccessibleProperty, AccessibleRelation, AccessibleState};
use glib::translate::*;
use glib::{IsA, ToValue};

pub trait AccessibleExtManual {
    /// Updates an array of accessible properties.
    ///
    /// This function should be called by [`Widget`][crate::Widget] types whenever an accessible
    /// property change must be communicated to assistive technologies.
    ///
    /// This function is meant to be used by language bindings.
    /// ## `properties`
    /// an array of [`AccessibleProperty`][crate::AccessibleProperty]
    /// ## `values`
    /// an array of `GValues`, one for each property
    #[doc(alias = "gtk_accessible_update_property")]
    #[doc(alias = "gtk_accessible_update_property_value")]
    fn update_property(&self, properties: &[(AccessibleProperty, &dyn ToValue)]);

    /// Updates an array of accessible relations.
    ///
    /// This function should be called by [`Widget`][crate::Widget] types whenever an accessible
    /// relation change must be communicated to assistive technologies.
    ///
    /// This function is meant to be used by language bindings.
    /// ## `relations`
    /// an array of [`AccessibleRelation`][crate::AccessibleRelation]
    /// ## `values`
    /// an array of `GValues`, one for each relation
    #[doc(alias = "gtk_accessible_update_relation")]
    #[doc(alias = "gtk_accessible_update_relation_value")]
    fn update_relation(&self, relations: &[(AccessibleRelation, &dyn ToValue)]);

    /// Updates an array of accessible states.
    ///
    /// This function should be called by [`Widget`][crate::Widget] types whenever an accessible
    /// state change must be communicated to assistive technologies.
    ///
    /// This function is meant to be used by language bindings.
    /// ## `states`
    /// an array of [`AccessibleState`][crate::AccessibleState]
    /// ## `values`
    /// an array of `GValues`, one for each state
    #[doc(alias = "gtk_accessible_update_state")]
    #[doc(alias = "gtk_accessible_update_state_value")]
    fn update_state(&self, states: &[(AccessibleState, &dyn ToValue)]);
}

impl<O: IsA<Accessible>> AccessibleExtManual for O {
    fn update_property(&self, properties: &[(AccessibleProperty, &dyn ToValue)]) {
        unsafe {
            let properties_ptr: Vec<ffi::GtkAccessibleProperty> =
                properties.iter().map(|(k, _)| k.into_glib()).collect();
            let values: Vec<glib::gobject_ffi::GValue> = properties
                .iter()
                .map(|(_, v)| *v.to_value().to_glib_none().0)
                .collect();

            ffi::gtk_accessible_update_property_value(
                self.as_ref().to_glib_none().0,
                properties.len() as i32,
                mut_override(properties_ptr.as_ptr()),
                values.as_ptr(),
            )
        }
    }

    fn update_relation(&self, relations: &[(AccessibleRelation, &dyn ToValue)]) {
        unsafe {
            let relations_ptr: Vec<ffi::GtkAccessibleRelation> =
                relations.iter().map(|(k, _)| k.into_glib()).collect();
            let values: Vec<glib::gobject_ffi::GValue> = relations
                .iter()
                .map(|(_, v)| *v.to_value().to_glib_none().0)
                .collect();

            ffi::gtk_accessible_update_relation_value(
                self.as_ref().to_glib_none().0,
                relations.len() as i32,
                mut_override(relations_ptr.as_ptr()),
                values.as_ptr(),
            )
        }
    }

    fn update_state(&self, states: &[(AccessibleState, &dyn ToValue)]) {
        unsafe {
            let values: Vec<glib::gobject_ffi::GValue> = states
                .iter()
                .map(|(_, v)| *v.to_value().to_glib_none().0)
                .collect();
            let states_ptr: Vec<ffi::GtkAccessibleState> =
                states.iter().map(|(k, _)| k.into_glib()).collect();

            ffi::gtk_accessible_update_state_value(
                self.as_ref().to_glib_none().0,
                states.len() as i32,
                mut_override(states_ptr.as_ptr()),
                values.as_ptr(),
            )
        }
    }
}