1use 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 #[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 #[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
77pub trait RelationExt: IsA<Relation> + sealed::Sealed + 'static {
83 #[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 #[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 #[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 #[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}