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
// 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::StateType;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// An AtkStateSet contains the states of an object.
    ///
    /// An AtkStateSet is a read-only representation of the full set of `AtkStates`
    /// that apply to an object at a given time. This set is not meant to be
    /// modified, but rather created when [`AtkObjectExt::ref_state_set()`][crate::prelude::AtkObjectExt::ref_state_set()] is called.
    ///
    /// # Implements
    ///
    /// [`StateSetExt`][trait@crate::prelude::StateSetExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "AtkStateSet")]
    pub struct StateSet(Object<ffi::AtkStateSet, ffi::AtkStateSetClass>);

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

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

    /// Creates a new empty state set.
    ///
    /// # Returns
    ///
    /// a new [`StateSet`][crate::StateSet]
    #[doc(alias = "atk_state_set_new")]
    pub fn new() -> StateSet {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::atk_state_set_new()) }
    }
}

impl Default for StateSet {
    fn default() -> Self {
        Self::new()
    }
}

/// Trait containing all [`struct@StateSet`] methods.
///
/// # Implementors
///
/// [`StateSet`][struct@crate::StateSet]
pub trait StateSetExt: 'static {
    /// Adds the state of the specified type to the state set if it is not already
    /// present.
    ///
    /// Note that because an [`StateSet`][crate::StateSet] is a read-only object, this method should
    /// be used to add a state to a newly-created set which will then be returned by
    /// `atk_object_ref_state_set`. It should not be used to modify the existing state
    /// of an object. See also `atk_object_notify_state_change`.
    /// ## `type_`
    /// an [`StateType`][crate::StateType]
    ///
    /// # Returns
    ///
    /// [`true`] if the state for `type_` is not already in `self`.
    #[doc(alias = "atk_state_set_add_state")]
    fn add_state(&self, type_: StateType) -> bool;

    //#[doc(alias = "atk_state_set_add_states")]
    //fn add_states(&self, types: /*Unimplemented*/&CArray TypeId { ns_id: 1, id: 68 });

    /// Constructs the intersection of the two sets, returning [`None`] if the
    /// intersection is empty.
    /// ## `compare_set`
    /// another [`StateSet`][crate::StateSet]
    ///
    /// # Returns
    ///
    /// a new [`StateSet`][crate::StateSet] which is the intersection of
    /// the two sets.
    #[doc(alias = "atk_state_set_and_sets")]
    #[must_use]
    fn and_sets(&self, compare_set: &impl IsA<StateSet>) -> Option<StateSet>;

    /// Removes all states from the state set.
    #[doc(alias = "atk_state_set_clear_states")]
    fn clear_states(&self);

    /// Checks whether the state for the specified type is in the specified set.
    /// ## `type_`
    /// an [`StateType`][crate::StateType]
    ///
    /// # Returns
    ///
    /// [`true`] if `type_` is the state type is in `self`.
    #[doc(alias = "atk_state_set_contains_state")]
    fn contains_state(&self, type_: StateType) -> bool;

    //#[doc(alias = "atk_state_set_contains_states")]
    //fn contains_states(&self, types: /*Unimplemented*/&CArray TypeId { ns_id: 1, id: 68 }) -> bool;

    /// Checks whether the state set is empty, i.e. has no states set.
    ///
    /// # Returns
    ///
    /// [`true`] if `self` has no states set, otherwise [`false`]
    #[doc(alias = "atk_state_set_is_empty")]
    fn is_empty(&self) -> bool;

    /// Constructs the union of the two sets.
    /// ## `compare_set`
    /// another [`StateSet`][crate::StateSet]
    ///
    /// # Returns
    ///
    /// a new [`StateSet`][crate::StateSet] which is
    /// the union of the two sets, returning [`None`] is empty.
    #[doc(alias = "atk_state_set_or_sets")]
    #[must_use]
    fn or_sets(&self, compare_set: &impl IsA<StateSet>) -> Option<StateSet>;

    /// Removes the state for the specified type from the state set.
    ///
    /// Note that because an [`StateSet`][crate::StateSet] is a read-only object, this method should
    /// be used to remove a state to a newly-created set which will then be returned
    /// by `atk_object_ref_state_set`. It should not be used to modify the existing
    /// state of an object. See also `atk_object_notify_state_change`.
    /// ## `type_`
    /// an `AtkType`
    ///
    /// # Returns
    ///
    /// [`true`] if `type_` was the state type is in `self`.
    #[doc(alias = "atk_state_set_remove_state")]
    fn remove_state(&self, type_: StateType) -> bool;

    /// Constructs the exclusive-or of the two sets, returning [`None`] is empty.
    /// The set returned by this operation contains the states in exactly
    /// one of the two sets.
    /// ## `compare_set`
    /// another [`StateSet`][crate::StateSet]
    ///
    /// # Returns
    ///
    /// a new [`StateSet`][crate::StateSet] which contains the states
    /// which are in exactly one of the two sets.
    #[doc(alias = "atk_state_set_xor_sets")]
    #[must_use]
    fn xor_sets(&self, compare_set: &impl IsA<StateSet>) -> Option<StateSet>;
}

impl<O: IsA<StateSet>> StateSetExt for O {
    fn add_state(&self, type_: StateType) -> bool {
        unsafe {
            from_glib(ffi::atk_state_set_add_state(
                self.as_ref().to_glib_none().0,
                type_.into_glib(),
            ))
        }
    }

    //fn add_states(&self, types: /*Unimplemented*/&CArray TypeId { ns_id: 1, id: 68 }) {
    //    unsafe { TODO: call ffi:atk_state_set_add_states() }
    //}

    fn and_sets(&self, compare_set: &impl IsA<StateSet>) -> Option<StateSet> {
        unsafe {
            from_glib_full(ffi::atk_state_set_and_sets(
                self.as_ref().to_glib_none().0,
                compare_set.as_ref().to_glib_none().0,
            ))
        }
    }

    fn clear_states(&self) {
        unsafe {
            ffi::atk_state_set_clear_states(self.as_ref().to_glib_none().0);
        }
    }

    fn contains_state(&self, type_: StateType) -> bool {
        unsafe {
            from_glib(ffi::atk_state_set_contains_state(
                self.as_ref().to_glib_none().0,
                type_.into_glib(),
            ))
        }
    }

    //fn contains_states(&self, types: /*Unimplemented*/&CArray TypeId { ns_id: 1, id: 68 }) -> bool {
    //    unsafe { TODO: call ffi:atk_state_set_contains_states() }
    //}

    fn is_empty(&self) -> bool {
        unsafe { from_glib(ffi::atk_state_set_is_empty(self.as_ref().to_glib_none().0)) }
    }

    fn or_sets(&self, compare_set: &impl IsA<StateSet>) -> Option<StateSet> {
        unsafe {
            from_glib_full(ffi::atk_state_set_or_sets(
                self.as_ref().to_glib_none().0,
                compare_set.as_ref().to_glib_none().0,
            ))
        }
    }

    fn remove_state(&self, type_: StateType) -> bool {
        unsafe {
            from_glib(ffi::atk_state_set_remove_state(
                self.as_ref().to_glib_none().0,
                type_.into_glib(),
            ))
        }
    }

    fn xor_sets(&self, compare_set: &impl IsA<StateSet>) -> Option<StateSet> {
        unsafe {
            from_glib_full(ffi::atk_state_set_xor_sets(
                self.as_ref().to_glib_none().0,
                compare_set.as_ref().to_glib_none().0,
            ))
        }
    }
}

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