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, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
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 | Writable
27    ///
28    ///
29    /// #### `target`
30    ///  Readable | Writable
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
72/// Trait containing all [`struct@Relation`] methods.
73///
74/// # Implementors
75///
76/// [`Relation`][struct@crate::Relation]
77pub trait RelationExt: IsA<Relation> + 'static {
78    /// Adds the specified AtkObject to the target for the relation, if it is
79    /// not already present. See also [`AtkObjectExt::add_relationship()`][crate::prelude::AtkObjectExt::add_relationship()].
80    /// ## `target`
81    /// an [`Object`][crate::Object]
82    #[doc(alias = "atk_relation_add_target")]
83    fn add_target(&self, target: &impl IsA<Object>) {
84        unsafe {
85            ffi::atk_relation_add_target(
86                self.as_ref().to_glib_none().0,
87                target.as_ref().to_glib_none().0,
88            );
89        }
90    }
91
92    /// Gets the type of `self`
93    ///
94    /// # Returns
95    ///
96    /// the type of `self`
97    #[doc(alias = "atk_relation_get_relation_type")]
98    #[doc(alias = "get_relation_type")]
99    #[doc(alias = "relation-type")]
100    fn relation_type(&self) -> RelationType {
101        unsafe {
102            from_glib(ffi::atk_relation_get_relation_type(
103                self.as_ref().to_glib_none().0,
104            ))
105        }
106    }
107
108    /// Gets the target list of `self`
109    ///
110    /// # Returns
111    ///
112    /// the target list of `self`
113    #[doc(alias = "atk_relation_get_target")]
114    #[doc(alias = "get_target")]
115    fn target(&self) -> Vec<Object> {
116        unsafe {
117            FromGlibPtrContainer::from_glib_none(ffi::atk_relation_get_target(
118                self.as_ref().to_glib_none().0,
119            ))
120        }
121    }
122
123    /// Remove the specified AtkObject from the target for the relation.
124    /// ## `target`
125    /// an [`Object`][crate::Object]
126    ///
127    /// # Returns
128    ///
129    /// TRUE if the removal is successful.
130    #[doc(alias = "atk_relation_remove_target")]
131    fn remove_target(&self, target: &impl IsA<Object>) -> bool {
132        unsafe {
133            from_glib(ffi::atk_relation_remove_target(
134                self.as_ref().to_glib_none().0,
135                target.as_ref().to_glib_none().0,
136            ))
137        }
138    }
139
140    #[doc(alias = "relation-type")]
141    fn set_relation_type(&self, relation_type: RelationType) {
142        ObjectExt::set_property(self.as_ref(), "relation-type", relation_type)
143    }
144
145    fn set_target(&self, target: Option<&glib::ValueArray>) {
146        ObjectExt::set_property(self.as_ref(), "target", target)
147    }
148
149    #[doc(alias = "relation-type")]
150    fn connect_relation_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
151        unsafe extern "C" fn notify_relation_type_trampoline<
152            P: IsA<Relation>,
153            F: Fn(&P) + 'static,
154        >(
155            this: *mut ffi::AtkRelation,
156            _param_spec: glib::ffi::gpointer,
157            f: glib::ffi::gpointer,
158        ) {
159            unsafe {
160                let f: &F = &*(f as *const F);
161                f(Relation::from_glib_borrow(this).unsafe_cast_ref())
162            }
163        }
164        unsafe {
165            let f: Box_<F> = Box_::new(f);
166            connect_raw(
167                self.as_ptr() as *mut _,
168                c"notify::relation-type".as_ptr(),
169                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
170                    notify_relation_type_trampoline::<Self, F> as *const (),
171                )),
172                Box_::into_raw(f),
173            )
174        }
175    }
176
177    #[doc(alias = "target")]
178    fn connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
179        unsafe extern "C" fn notify_target_trampoline<P: IsA<Relation>, F: Fn(&P) + 'static>(
180            this: *mut ffi::AtkRelation,
181            _param_spec: glib::ffi::gpointer,
182            f: glib::ffi::gpointer,
183        ) {
184            unsafe {
185                let f: &F = &*(f as *const F);
186                f(Relation::from_glib_borrow(this).unsafe_cast_ref())
187            }
188        }
189        unsafe {
190            let f: Box_<F> = Box_::new(f);
191            connect_raw(
192                self.as_ptr() as *mut _,
193                c"notify::target".as_ptr(),
194                Some(std::mem::transmute::<*const (), 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 {}