Skip to main content

atk/auto/
relation.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, RelationType};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14    /// An object used to describe a relation between a
15    ///  object and one or more other objects.
16    ///
17    /// An AtkRelation describes a relation between an object and one or
18    /// more other objects. The actual relations that an object has with
19    /// other objects are defined as an AtkRelationSet, which is a set of
20    /// AtkRelations.
21    ///
22    /// ## Properties
23    ///
24    ///
25    /// #### `relation-type`
26    ///  Readable | Writeable
27    ///
28    ///
29    /// #### `target`
30    ///  Readable | Writeable
31    ///
32    /// # Implements
33    ///
34    /// [`RelationExt`][trait@crate::prelude::RelationExt], [`trait@glib::ObjectExt`]
35    #[doc(alias = "AtkRelation")]
36    pub struct Relation(Object<ffi::AtkRelation, ffi::AtkRelationClass>);
37
38    match fn {
39        type_ => || ffi::atk_relation_get_type(),
40    }
41}
42
43impl Relation {
44    pub const NONE: Option<&'static Relation> = None;
45
46    /// Create a new relation for the specified key and the specified list
47    /// of targets. See also [`AtkObjectExt::add_relationship()`][crate::prelude::AtkObjectExt::add_relationship()].
48    /// ## `targets`
49    /// an array of pointers to
50    ///  `AtkObjects`
51    /// ## `relationship`
52    /// an [`RelationType`][crate::RelationType] with which to create the new
53    ///  [`Relation`][crate::Relation]
54    ///
55    /// # Returns
56    ///
57    /// a pointer to a new [`Relation`][crate::Relation]
58    #[doc(alias = "atk_relation_new")]
59    pub fn new(targets: &[Object], relationship: RelationType) -> Relation {
60        assert_initialized_main_thread!();
61        let n_targets = targets.len() as _;
62        unsafe {
63            from_glib_full(ffi::atk_relation_new(
64                targets.to_glib_none().0,
65                n_targets,
66                relationship.into_glib(),
67            ))
68        }
69    }
70}
71
72mod sealed {
73    pub trait Sealed {}
74    impl<T: super::IsA<super::Relation>> Sealed for T {}
75}
76
77/// Trait containing all [`struct@Relation`] methods.
78///
79/// # Implementors
80///
81/// [`Relation`][struct@crate::Relation]
82pub trait RelationExt: IsA<Relation> + sealed::Sealed + 'static {
83    /// Adds the specified AtkObject to the target for the relation, if it is
84    /// not already present. See also [`AtkObjectExt::add_relationship()`][crate::prelude::AtkObjectExt::add_relationship()].
85    /// ## `target`
86    /// an [`Object`][crate::Object]
87    #[doc(alias = "atk_relation_add_target")]
88    fn add_target(&self, target: &impl IsA<Object>) {
89        unsafe {
90            ffi::atk_relation_add_target(
91                self.as_ref().to_glib_none().0,
92                target.as_ref().to_glib_none().0,
93            );
94        }
95    }
96
97    /// Gets the type of `self`
98    ///
99    /// # Returns
100    ///
101    /// the type of `self`
102    #[doc(alias = "atk_relation_get_relation_type")]
103    #[doc(alias = "get_relation_type")]
104    fn relation_type(&self) -> RelationType {
105        unsafe {
106            from_glib(ffi::atk_relation_get_relation_type(
107                self.as_ref().to_glib_none().0,
108            ))
109        }
110    }
111
112    /// Gets the target list of `self`
113    ///
114    /// # Returns
115    ///
116    /// the target list of `self`
117    #[doc(alias = "atk_relation_get_target")]
118    #[doc(alias = "get_target")]
119    fn target(&self) -> Vec<Object> {
120        unsafe {
121            FromGlibPtrContainer::from_glib_none(ffi::atk_relation_get_target(
122                self.as_ref().to_glib_none().0,
123            ))
124        }
125    }
126
127    /// Remove the specified AtkObject from the target for the relation.
128    /// ## `target`
129    /// an [`Object`][crate::Object]
130    ///
131    /// # Returns
132    ///
133    /// TRUE if the removal is successful.
134    #[doc(alias = "atk_relation_remove_target")]
135    fn remove_target(&self, target: &impl IsA<Object>) -> bool {
136        unsafe {
137            from_glib(ffi::atk_relation_remove_target(
138                self.as_ref().to_glib_none().0,
139                target.as_ref().to_glib_none().0,
140            ))
141        }
142    }
143
144    #[doc(alias = "relation-type")]
145    fn set_relation_type(&self, relation_type: RelationType) {
146        ObjectExt::set_property(self.as_ref(), "relation-type", relation_type)
147    }
148
149    fn set_target(&self, target: Option<&glib::ValueArray>) {
150        ObjectExt::set_property(self.as_ref(), "target", target)
151    }
152
153    #[doc(alias = "relation-type")]
154    fn connect_relation_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
155        unsafe extern "C" fn notify_relation_type_trampoline<
156            P: IsA<Relation>,
157            F: Fn(&P) + 'static,
158        >(
159            this: *mut ffi::AtkRelation,
160            _param_spec: glib::ffi::gpointer,
161            f: glib::ffi::gpointer,
162        ) {
163            let f: &F = &*(f as *const F);
164            f(Relation::from_glib_borrow(this).unsafe_cast_ref())
165        }
166        unsafe {
167            let f: Box_<F> = Box_::new(f);
168            connect_raw(
169                self.as_ptr() as *mut _,
170                b"notify::relation-type\0".as_ptr() as *const _,
171                Some(transmute::<_, unsafe extern "C" fn()>(
172                    notify_relation_type_trampoline::<Self, F> as *const (),
173                )),
174                Box_::into_raw(f),
175            )
176        }
177    }
178
179    #[doc(alias = "target")]
180    fn connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
181        unsafe extern "C" fn notify_target_trampoline<P: IsA<Relation>, F: Fn(&P) + 'static>(
182            this: *mut ffi::AtkRelation,
183            _param_spec: glib::ffi::gpointer,
184            f: glib::ffi::gpointer,
185        ) {
186            let f: &F = &*(f as *const F);
187            f(Relation::from_glib_borrow(this).unsafe_cast_ref())
188        }
189        unsafe {
190            let f: Box_<F> = Box_::new(f);
191            connect_raw(
192                self.as_ptr() as *mut _,
193                b"notify::target\0".as_ptr() as *const _,
194                Some(transmute::<_, unsafe extern "C" fn()>(
195                    notify_target_trampoline::<Self, F> as *const (),
196                )),
197                Box_::into_raw(f),
198            )
199        }
200    }
201}
202
203impl<O: IsA<Relation>> RelationExt for O {}
204
205impl fmt::Display for Relation {
206    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
207        f.write_str("Relation")
208    }
209}