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 atk_sys;
6use glib;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib::Value;
13use glib_sys;
14use gobject_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use Object;
19use RelationType;
20
21glib_wrapper! {
22    pub struct Relation(Object<atk_sys::AtkRelation, atk_sys::AtkRelationClass, RelationClass>);
23
24    match fn {
25        get_type => || atk_sys::atk_relation_get_type(),
26    }
27}
28
29impl Relation {
30    pub fn new(targets: &[Object], relationship: RelationType) -> Relation {
31        assert_initialized_main_thread!();
32        let n_targets = targets.len() as i32;
33        unsafe {
34            from_glib_full(atk_sys::atk_relation_new(
35                targets.to_glib_none().0,
36                n_targets,
37                relationship.to_glib(),
38            ))
39        }
40    }
41}
42
43pub const NONE_RELATION: Option<&Relation> = None;
44
45pub trait RelationExt: 'static {
46    fn add_target<P: IsA<Object>>(&self, target: &P);
47
48    fn get_relation_type(&self) -> RelationType;
49
50    //fn get_target(&self) -> /*Unknown conversion*//*Unimplemented*/PtrArray TypeId { ns_id: 1, id: 9 };
51
52    fn remove_target<P: IsA<Object>>(&self, target: &P) -> bool;
53
54    fn set_property_relation_type(&self, relation_type: RelationType);
55
56    fn set_property_target(&self, target: Option<&glib::ValueArray>);
57
58    fn connect_property_relation_type_notify<F: Fn(&Self) + 'static>(
59        &self,
60        f: F,
61    ) -> SignalHandlerId;
62
63    fn connect_property_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
64}
65
66impl<O: IsA<Relation>> RelationExt for O {
67    fn add_target<P: IsA<Object>>(&self, target: &P) {
68        unsafe {
69            atk_sys::atk_relation_add_target(
70                self.as_ref().to_glib_none().0,
71                target.as_ref().to_glib_none().0,
72            );
73        }
74    }
75
76    fn get_relation_type(&self) -> RelationType {
77        unsafe {
78            from_glib(atk_sys::atk_relation_get_relation_type(
79                self.as_ref().to_glib_none().0,
80            ))
81        }
82    }
83
84    //fn get_target(&self) -> /*Unknown conversion*//*Unimplemented*/PtrArray TypeId { ns_id: 1, id: 9 } {
85    //    unsafe { TODO: call atk_sys:atk_relation_get_target() }
86    //}
87
88    fn remove_target<P: IsA<Object>>(&self, target: &P) -> bool {
89        unsafe {
90            from_glib(atk_sys::atk_relation_remove_target(
91                self.as_ref().to_glib_none().0,
92                target.as_ref().to_glib_none().0,
93            ))
94        }
95    }
96
97    fn set_property_relation_type(&self, relation_type: RelationType) {
98        unsafe {
99            gobject_sys::g_object_set_property(
100                self.to_glib_none().0 as *mut gobject_sys::GObject,
101                b"relation-type\0".as_ptr() as *const _,
102                Value::from(&relation_type).to_glib_none().0,
103            );
104        }
105    }
106
107    fn set_property_target(&self, target: Option<&glib::ValueArray>) {
108        unsafe {
109            gobject_sys::g_object_set_property(
110                self.to_glib_none().0 as *mut gobject_sys::GObject,
111                b"target\0".as_ptr() as *const _,
112                Value::from(target).to_glib_none().0,
113            );
114        }
115    }
116
117    fn connect_property_relation_type_notify<F: Fn(&Self) + 'static>(
118        &self,
119        f: F,
120    ) -> SignalHandlerId {
121        unsafe extern "C" fn notify_relation_type_trampoline<P, F: Fn(&P) + 'static>(
122            this: *mut atk_sys::AtkRelation,
123            _param_spec: glib_sys::gpointer,
124            f: glib_sys::gpointer,
125        ) where
126            P: IsA<Relation>,
127        {
128            let f: &F = &*(f as *const F);
129            f(&Relation::from_glib_borrow(this).unsafe_cast())
130        }
131        unsafe {
132            let f: Box_<F> = Box_::new(f);
133            connect_raw(
134                self.as_ptr() as *mut _,
135                b"notify::relation-type\0".as_ptr() as *const _,
136                Some(transmute(
137                    notify_relation_type_trampoline::<Self, F> as usize,
138                )),
139                Box_::into_raw(f),
140            )
141        }
142    }
143
144    fn connect_property_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
145        unsafe extern "C" fn notify_target_trampoline<P, F: Fn(&P) + 'static>(
146            this: *mut atk_sys::AtkRelation,
147            _param_spec: glib_sys::gpointer,
148            f: glib_sys::gpointer,
149        ) where
150            P: IsA<Relation>,
151        {
152            let f: &F = &*(f as *const F);
153            f(&Relation::from_glib_borrow(this).unsafe_cast())
154        }
155        unsafe {
156            let f: Box_<F> = Box_::new(f);
157            connect_raw(
158                self.as_ptr() as *mut _,
159                b"notify::target\0".as_ptr() as *const _,
160                Some(transmute(notify_target_trampoline::<Self, F> as usize)),
161                Box_::into_raw(f),
162            )
163        }
164    }
165}
166
167impl fmt::Display for Relation {
168    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
169        write!(f, "Relation")
170    }
171}