1use 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 #[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
72pub trait RelationExt: IsA<Relation> + 'static {
78 #[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 #[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 #[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 #[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 {}