Skip to main content

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