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