Skip to main content

atk/auto/
state_set.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{StateType, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// An AtkStateSet contains the states of an object.
10    ///
11    /// An AtkStateSet is a read-only representation of the full set of `AtkStates`
12    /// that apply to an object at a given time. This set is not meant to be
13    /// modified, but rather created when [`AtkObjectExt::ref_state_set()`][crate::prelude::AtkObjectExt::ref_state_set()] is called.
14    ///
15    /// # Implements
16    ///
17    /// [`StateSetExt`][trait@crate::prelude::StateSetExt], [`trait@glib::ObjectExt`]
18    #[doc(alias = "AtkStateSet")]
19    pub struct StateSet(Object<ffi::AtkStateSet, ffi::AtkStateSetClass>);
20
21    match fn {
22        type_ => || ffi::atk_state_set_get_type(),
23    }
24}
25
26impl StateSet {
27    pub const NONE: Option<&'static StateSet> = None;
28
29    /// Creates a new empty state set.
30    ///
31    /// # Returns
32    ///
33    /// a new [`StateSet`][crate::StateSet]
34    #[doc(alias = "atk_state_set_new")]
35    pub fn new() -> StateSet {
36        assert_initialized_main_thread!();
37        unsafe { from_glib_full(ffi::atk_state_set_new()) }
38    }
39}
40
41impl Default for StateSet {
42    fn default() -> Self {
43        Self::new()
44    }
45}
46
47/// Trait containing all [`struct@StateSet`] methods.
48///
49/// # Implementors
50///
51/// [`StateSet`][struct@crate::StateSet]
52pub trait StateSetExt: IsA<StateSet> + 'static {
53    /// Adds the state of the specified type to the state set if it is not already
54    /// present.
55    ///
56    /// Note that because an [`StateSet`][crate::StateSet] is a read-only object, this method should
57    /// be used to add a state to a newly-created set which will then be returned by
58    /// `atk_object_ref_state_set`. It should not be used to modify the existing state
59    /// of an object. See also `atk_object_notify_state_change`.
60    /// ## `type_`
61    /// an [`StateType`][crate::StateType]
62    ///
63    /// # Returns
64    ///
65    /// [`true`] if the state for `type_` is not already in `self`.
66    #[doc(alias = "atk_state_set_add_state")]
67    fn add_state(&self, type_: StateType) -> bool {
68        unsafe {
69            from_glib(ffi::atk_state_set_add_state(
70                self.as_ref().to_glib_none().0,
71                type_.into_glib(),
72            ))
73        }
74    }
75
76    //#[doc(alias = "atk_state_set_add_states")]
77    //fn add_states(&self, types: /*Unimplemented*/&CArray TypeId { ns_id: 1, id: 32 }) {
78    //    unsafe { TODO: call ffi:atk_state_set_add_states() }
79    //}
80
81    /// Constructs the intersection of the two sets, returning [`None`] if the
82    /// intersection is empty.
83    /// ## `compare_set`
84    /// another [`StateSet`][crate::StateSet]
85    ///
86    /// # Returns
87    ///
88    /// a new [`StateSet`][crate::StateSet] which is the intersection of
89    /// the two sets.
90    #[doc(alias = "atk_state_set_and_sets")]
91    #[must_use]
92    fn and_sets(&self, compare_set: &impl IsA<StateSet>) -> Option<StateSet> {
93        unsafe {
94            from_glib_full(ffi::atk_state_set_and_sets(
95                self.as_ref().to_glib_none().0,
96                compare_set.as_ref().to_glib_none().0,
97            ))
98        }
99    }
100
101    /// Removes all states from the state set.
102    #[doc(alias = "atk_state_set_clear_states")]
103    fn clear_states(&self) {
104        unsafe {
105            ffi::atk_state_set_clear_states(self.as_ref().to_glib_none().0);
106        }
107    }
108
109    /// Checks whether the state for the specified type is in the specified set.
110    /// ## `type_`
111    /// an [`StateType`][crate::StateType]
112    ///
113    /// # Returns
114    ///
115    /// [`true`] if `type_` is the state type is in `self`.
116    #[doc(alias = "atk_state_set_contains_state")]
117    fn contains_state(&self, type_: StateType) -> bool {
118        unsafe {
119            from_glib(ffi::atk_state_set_contains_state(
120                self.as_ref().to_glib_none().0,
121                type_.into_glib(),
122            ))
123        }
124    }
125
126    //#[doc(alias = "atk_state_set_contains_states")]
127    //fn contains_states(&self, types: /*Unimplemented*/&CArray TypeId { ns_id: 1, id: 32 }) -> bool {
128    //    unsafe { TODO: call ffi:atk_state_set_contains_states() }
129    //}
130
131    /// Checks whether the state set is empty, i.e. has no states set.
132    ///
133    /// # Returns
134    ///
135    /// [`true`] if `self` has no states set, otherwise [`false`]
136    #[doc(alias = "atk_state_set_is_empty")]
137    fn is_empty(&self) -> bool {
138        unsafe { from_glib(ffi::atk_state_set_is_empty(self.as_ref().to_glib_none().0)) }
139    }
140
141    /// Constructs the union of the two sets.
142    /// ## `compare_set`
143    /// another [`StateSet`][crate::StateSet]
144    ///
145    /// # Returns
146    ///
147    /// a new [`StateSet`][crate::StateSet] which is
148    /// the union of the two sets, returning [`None`] is empty.
149    #[doc(alias = "atk_state_set_or_sets")]
150    #[must_use]
151    fn or_sets(&self, compare_set: &impl IsA<StateSet>) -> Option<StateSet> {
152        unsafe {
153            from_glib_full(ffi::atk_state_set_or_sets(
154                self.as_ref().to_glib_none().0,
155                compare_set.as_ref().to_glib_none().0,
156            ))
157        }
158    }
159
160    /// Removes the state for the specified type from the state set.
161    ///
162    /// Note that because an [`StateSet`][crate::StateSet] is a read-only object, this method should
163    /// be used to remove a state to a newly-created set which will then be returned
164    /// by `atk_object_ref_state_set`. It should not be used to modify the existing
165    /// state of an object. See also `atk_object_notify_state_change`.
166    /// ## `type_`
167    /// an `AtkType`
168    ///
169    /// # Returns
170    ///
171    /// [`true`] if `type_` was the state type is in `self`.
172    #[doc(alias = "atk_state_set_remove_state")]
173    fn remove_state(&self, type_: StateType) -> bool {
174        unsafe {
175            from_glib(ffi::atk_state_set_remove_state(
176                self.as_ref().to_glib_none().0,
177                type_.into_glib(),
178            ))
179        }
180    }
181
182    /// Constructs the exclusive-or of the two sets, returning [`None`] is empty.
183    /// The set returned by this operation contains the states in exactly
184    /// one of the two sets.
185    /// ## `compare_set`
186    /// another [`StateSet`][crate::StateSet]
187    ///
188    /// # Returns
189    ///
190    /// a new [`StateSet`][crate::StateSet] which contains the states
191    /// which are in exactly one of the two sets.
192    #[doc(alias = "atk_state_set_xor_sets")]
193    #[must_use]
194    fn xor_sets(&self, compare_set: &impl IsA<StateSet>) -> Option<StateSet> {
195        unsafe {
196            from_glib_full(ffi::atk_state_set_xor_sets(
197                self.as_ref().to_glib_none().0,
198                compare_set.as_ref().to_glib_none().0,
199            ))
200        }
201    }
202}
203
204impl<O: IsA<StateSet>> StateSetExt for O {}