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
// 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::Object;
use crate::Relation;
use crate::RelationType;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// The AtkRelationSet held by an object establishes its relationships
    /// with objects beyond the normal "parent/child" hierarchical
    /// relationships that all user interface objects have.
    /// AtkRelationSets establish whether objects are labelled or
    /// controlled by other components, share group membership with other
    /// components (for instance within a radio-button group), or share
    /// content which "flows" between them, among other types of possible
    /// relationships.
    ///
    /// # Implements
    ///
    /// [`RelationSetExt`][trait@crate::prelude::RelationSetExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "AtkRelationSet")]
    pub struct RelationSet(Object<ffi::AtkRelationSet, ffi::AtkRelationSetClass>);

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

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

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

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

/// Trait containing all [`struct@RelationSet`] methods.
///
/// # Implementors
///
/// [`RelationSet`][struct@crate::RelationSet]
pub trait RelationSetExt: 'static {
    /// Add a new relation to the current relation set if it is not already
    /// present.
    /// This function ref's the AtkRelation so the caller of this function
    /// should unref it to ensure that it will be destroyed when the AtkRelationSet
    /// is destroyed.
    /// ## `relation`
    /// an [`Relation`][crate::Relation]
    #[doc(alias = "atk_relation_set_add")]
    fn add(&self, relation: &impl IsA<Relation>);

    /// Add a new relation of the specified type with the specified target to
    /// the current relation set if the relation set does not contain a relation
    /// of that type. If it is does contain a relation of that typea the target
    /// is added to the relation.
    /// ## `relationship`
    /// an [`RelationType`][crate::RelationType]
    /// ## `target`
    /// an [`Object`][crate::Object]
    #[doc(alias = "atk_relation_set_add_relation_by_type")]
    fn add_relation_by_type(&self, relationship: RelationType, target: &impl IsA<Object>);

    /// Determines whether the relation set contains a relation that matches the
    /// specified type.
    /// ## `relationship`
    /// an [`RelationType`][crate::RelationType]
    ///
    /// # Returns
    ///
    /// [`true`] if `relationship` is the relationship type of a relation
    /// in `self`, [`false`] otherwise
    #[doc(alias = "atk_relation_set_contains")]
    fn contains(&self, relationship: RelationType) -> bool;

    /// Determines whether the relation set contains a relation that
    /// matches the specified pair formed by type `relationship` and object
    /// `target`.
    /// ## `relationship`
    /// an [`RelationType`][crate::RelationType]
    /// ## `target`
    /// an [`Object`][crate::Object]
    ///
    /// # Returns
    ///
    /// [`true`] if `self` contains a relation with the relationship
    /// type `relationship` with an object `target`, [`false`] otherwise
    #[doc(alias = "atk_relation_set_contains_target")]
    fn contains_target(&self, relationship: RelationType, target: &impl IsA<Object>) -> bool;

    /// Determines the number of relations in a relation set.
    ///
    /// # Returns
    ///
    /// an integer representing the number of relations in the set.
    #[doc(alias = "atk_relation_set_get_n_relations")]
    #[doc(alias = "get_n_relations")]
    fn n_relations(&self) -> i32;

    /// Determines the relation at the specified position in the relation set.
    /// ## `i`
    /// a gint representing a position in the set, starting from 0.
    ///
    /// # Returns
    ///
    /// a [`Relation`][crate::Relation], which is the relation at
    /// position i in the set.
    #[doc(alias = "atk_relation_set_get_relation")]
    #[doc(alias = "get_relation")]
    fn relation(&self, i: i32) -> Option<Relation>;

    /// Finds a relation that matches the specified type.
    /// ## `relationship`
    /// an [`RelationType`][crate::RelationType]
    ///
    /// # Returns
    ///
    /// an [`Relation`][crate::Relation], which is a relation matching the
    /// specified type.
    #[doc(alias = "atk_relation_set_get_relation_by_type")]
    #[doc(alias = "get_relation_by_type")]
    fn relation_by_type(&self, relationship: RelationType) -> Option<Relation>;

    /// Removes a relation from the relation set.
    /// This function unref's the [`Relation`][crate::Relation] so it will be deleted unless there
    /// is another reference to it.
    /// ## `relation`
    /// an [`Relation`][crate::Relation]
    #[doc(alias = "atk_relation_set_remove")]
    fn remove(&self, relation: &impl IsA<Relation>);
}

impl<O: IsA<RelationSet>> RelationSetExt for O {
    fn add(&self, relation: &impl IsA<Relation>) {
        unsafe {
            ffi::atk_relation_set_add(
                self.as_ref().to_glib_none().0,
                relation.as_ref().to_glib_none().0,
            );
        }
    }

    fn add_relation_by_type(&self, relationship: RelationType, target: &impl IsA<Object>) {
        unsafe {
            ffi::atk_relation_set_add_relation_by_type(
                self.as_ref().to_glib_none().0,
                relationship.into_glib(),
                target.as_ref().to_glib_none().0,
            );
        }
    }

    fn contains(&self, relationship: RelationType) -> bool {
        unsafe {
            from_glib(ffi::atk_relation_set_contains(
                self.as_ref().to_glib_none().0,
                relationship.into_glib(),
            ))
        }
    }

    fn contains_target(&self, relationship: RelationType, target: &impl IsA<Object>) -> bool {
        unsafe {
            from_glib(ffi::atk_relation_set_contains_target(
                self.as_ref().to_glib_none().0,
                relationship.into_glib(),
                target.as_ref().to_glib_none().0,
            ))
        }
    }

    fn n_relations(&self) -> i32 {
        unsafe { ffi::atk_relation_set_get_n_relations(self.as_ref().to_glib_none().0) }
    }

    fn relation(&self, i: i32) -> Option<Relation> {
        unsafe {
            from_glib_none(ffi::atk_relation_set_get_relation(
                self.as_ref().to_glib_none().0,
                i,
            ))
        }
    }

    fn relation_by_type(&self, relationship: RelationType) -> Option<Relation> {
        unsafe {
            from_glib_none(ffi::atk_relation_set_get_relation_by_type(
                self.as_ref().to_glib_none().0,
                relationship.into_glib(),
            ))
        }
    }

    fn remove(&self, relation: &impl IsA<Relation>) {
        unsafe {
            ffi::atk_relation_set_remove(
                self.as_ref().to_glib_none().0,
                relation.as_ref().to_glib_none().0,
            );
        }
    }
}

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