atk/auto/relation_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::{Object, Relation, RelationType, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// A set of AtkRelations, normally the set of
10 /// AtkRelations which an AtkObject has.
11 ///
12 /// The AtkRelationSet held by an object establishes its relationships
13 /// with objects beyond the normal "parent/child" hierarchical
14 /// relationships that all user interface objects have.
15 /// AtkRelationSets establish whether objects are labelled or
16 /// controlled by other components, share group membership with other
17 /// components (for instance within a radio-button group), or share
18 /// content which "flows" between them, among other types of possible
19 /// relationships.
20 ///
21 /// # Implements
22 ///
23 /// [`RelationSetExt`][trait@crate::prelude::RelationSetExt], [`trait@glib::ObjectExt`]
24 #[doc(alias = "AtkRelationSet")]
25 pub struct RelationSet(Object<ffi::AtkRelationSet, ffi::AtkRelationSetClass>);
26
27 match fn {
28 type_ => || ffi::atk_relation_set_get_type(),
29 }
30}
31
32impl RelationSet {
33 pub const NONE: Option<&'static RelationSet> = None;
34
35 /// Creates a new empty relation set.
36 ///
37 /// # Returns
38 ///
39 /// a new [`RelationSet`][crate::RelationSet]
40 #[doc(alias = "atk_relation_set_new")]
41 pub fn new() -> RelationSet {
42 assert_initialized_main_thread!();
43 unsafe { from_glib_full(ffi::atk_relation_set_new()) }
44 }
45}
46
47impl Default for RelationSet {
48 fn default() -> Self {
49 Self::new()
50 }
51}
52
53/// Trait containing all [`struct@RelationSet`] methods.
54///
55/// # Implementors
56///
57/// [`RelationSet`][struct@crate::RelationSet]
58pub trait RelationSetExt: IsA<RelationSet> + 'static {
59 /// Add a new relation to the current relation set if it is not already
60 /// present.
61 /// This function ref's the AtkRelation so the caller of this function
62 /// should unref it to ensure that it will be destroyed when the AtkRelationSet
63 /// is destroyed.
64 /// ## `relation`
65 /// an [`Relation`][crate::Relation]
66 #[doc(alias = "atk_relation_set_add")]
67 fn add(&self, relation: &impl IsA<Relation>) {
68 unsafe {
69 ffi::atk_relation_set_add(
70 self.as_ref().to_glib_none().0,
71 relation.as_ref().to_glib_none().0,
72 );
73 }
74 }
75
76 /// Add a new relation of the specified type with the specified target to
77 /// the current relation set if the relation set does not contain a relation
78 /// of that type. If it is does contain a relation of that typea the target
79 /// is added to the relation.
80 /// ## `relationship`
81 /// an [`RelationType`][crate::RelationType]
82 /// ## `target`
83 /// an [`Object`][crate::Object]
84 #[doc(alias = "atk_relation_set_add_relation_by_type")]
85 fn add_relation_by_type(&self, relationship: RelationType, target: &impl IsA<Object>) {
86 unsafe {
87 ffi::atk_relation_set_add_relation_by_type(
88 self.as_ref().to_glib_none().0,
89 relationship.into_glib(),
90 target.as_ref().to_glib_none().0,
91 );
92 }
93 }
94
95 /// Determines whether the relation set contains a relation that matches the
96 /// specified type.
97 /// ## `relationship`
98 /// an [`RelationType`][crate::RelationType]
99 ///
100 /// # Returns
101 ///
102 /// [`true`] if `relationship` is the relationship type of a relation
103 /// in `self`, [`false`] otherwise
104 #[doc(alias = "atk_relation_set_contains")]
105 fn contains(&self, relationship: RelationType) -> bool {
106 unsafe {
107 from_glib(ffi::atk_relation_set_contains(
108 self.as_ref().to_glib_none().0,
109 relationship.into_glib(),
110 ))
111 }
112 }
113
114 /// Determines whether the relation set contains a relation that
115 /// matches the specified pair formed by type `relationship` and object
116 /// `target`.
117 /// ## `relationship`
118 /// an [`RelationType`][crate::RelationType]
119 /// ## `target`
120 /// an [`Object`][crate::Object]
121 ///
122 /// # Returns
123 ///
124 /// [`true`] if `self` contains a relation with the relationship
125 /// type `relationship` with an object `target`, [`false`] otherwise
126 #[doc(alias = "atk_relation_set_contains_target")]
127 fn contains_target(&self, relationship: RelationType, target: &impl IsA<Object>) -> bool {
128 unsafe {
129 from_glib(ffi::atk_relation_set_contains_target(
130 self.as_ref().to_glib_none().0,
131 relationship.into_glib(),
132 target.as_ref().to_glib_none().0,
133 ))
134 }
135 }
136
137 /// Determines the number of relations in a relation set.
138 ///
139 /// # Returns
140 ///
141 /// an integer representing the number of relations in the set.
142 #[doc(alias = "atk_relation_set_get_n_relations")]
143 #[doc(alias = "get_n_relations")]
144 fn n_relations(&self) -> i32 {
145 unsafe { ffi::atk_relation_set_get_n_relations(self.as_ref().to_glib_none().0) }
146 }
147
148 /// Determines the relation at the specified position in the relation set.
149 /// ## `i`
150 /// a gint representing a position in the set, starting from 0.
151 ///
152 /// # Returns
153 ///
154 /// a [`Relation`][crate::Relation], which is the relation at
155 /// position i in the set.
156 #[doc(alias = "atk_relation_set_get_relation")]
157 #[doc(alias = "get_relation")]
158 fn relation(&self, i: i32) -> Option<Relation> {
159 unsafe {
160 from_glib_none(ffi::atk_relation_set_get_relation(
161 self.as_ref().to_glib_none().0,
162 i,
163 ))
164 }
165 }
166
167 /// Finds a relation that matches the specified type.
168 /// ## `relationship`
169 /// an [`RelationType`][crate::RelationType]
170 ///
171 /// # Returns
172 ///
173 /// an [`Relation`][crate::Relation], which is a relation matching the
174 /// specified type.
175 #[doc(alias = "atk_relation_set_get_relation_by_type")]
176 #[doc(alias = "get_relation_by_type")]
177 fn relation_by_type(&self, relationship: RelationType) -> Option<Relation> {
178 unsafe {
179 from_glib_none(ffi::atk_relation_set_get_relation_by_type(
180 self.as_ref().to_glib_none().0,
181 relationship.into_glib(),
182 ))
183 }
184 }
185
186 /// Removes a relation from the relation set.
187 /// This function unref's the [`Relation`][crate::Relation] so it will be deleted unless there
188 /// is another reference to it.
189 /// ## `relation`
190 /// an [`Relation`][crate::Relation]
191 #[doc(alias = "atk_relation_set_remove")]
192 fn remove(&self, relation: &impl IsA<Relation>) {
193 unsafe {
194 ffi::atk_relation_set_remove(
195 self.as_ref().to_glib_none().0,
196 relation.as_ref().to_glib_none().0,
197 );
198 }
199 }
200}
201
202impl<O: IsA<RelationSet>> RelationSetExt for O {}