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 5 use crate::Object; 6 use crate::RelationType; 7 use glib::object::Cast; 8 use glib::object::IsA; 9 use glib::signal::connect_raw; 10 use glib::signal::SignalHandlerId; 11 use glib::translate::*; 12 use glib::ToValue; 13 use std::boxed::Box as Box_; 14 use std::fmt; 15 use std::mem::transmute; 16 17 glib::wrapper! { 18 #[doc(alias = "AtkRelation")] 19 pub struct Relation(Object<ffi::AtkRelation, ffi::AtkRelationClass>); 20 21 match fn { 22 type_ => || ffi::atk_relation_get_type(), 23 } 24 } 25 26 impl Relation { 27 #[doc(alias = "atk_relation_new")] new(targets: &[Object], relationship: RelationType) -> Relation28 pub fn new(targets: &[Object], relationship: RelationType) -> Relation { 29 assert_initialized_main_thread!(); 30 let n_targets = targets.len() as i32; 31 unsafe { 32 from_glib_full(ffi::atk_relation_new( 33 targets.to_glib_none().0, 34 n_targets, 35 relationship.into_glib(), 36 )) 37 } 38 } 39 } 40 41 pub const NONE_RELATION: Option<&Relation> = None; 42 43 pub trait RelationExt: 'static { 44 #[doc(alias = "atk_relation_add_target")] add_target<P: IsA<Object>>(&self, target: &P)45 fn add_target<P: IsA<Object>>(&self, target: &P); 46 47 #[doc(alias = "atk_relation_get_relation_type")] 48 #[doc(alias = "get_relation_type")] relation_type(&self) -> RelationType49 fn relation_type(&self) -> RelationType; 50 51 #[doc(alias = "atk_relation_get_target")] 52 #[doc(alias = "get_target")] target(&self) -> Vec<Object>53 fn target(&self) -> Vec<Object>; 54 55 #[doc(alias = "atk_relation_remove_target")] remove_target<P: IsA<Object>>(&self, target: &P) -> bool56 fn remove_target<P: IsA<Object>>(&self, target: &P) -> bool; 57 58 #[doc(alias = "relation-type")] set_relation_type(&self, relation_type: RelationType)59 fn set_relation_type(&self, relation_type: RelationType); 60 set_target(&self, target: Option<&glib::ValueArray>)61 fn set_target(&self, target: Option<&glib::ValueArray>); 62 63 #[doc(alias = "relation-type")] connect_relation_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId64 fn connect_relation_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 65 66 #[doc(alias = "target")] connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId67 fn connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 68 } 69 70 impl<O: IsA<Relation>> RelationExt for O { add_target<P: IsA<Object>>(&self, target: &P)71 fn add_target<P: IsA<Object>>(&self, target: &P) { 72 unsafe { 73 ffi::atk_relation_add_target( 74 self.as_ref().to_glib_none().0, 75 target.as_ref().to_glib_none().0, 76 ); 77 } 78 } 79 relation_type(&self) -> RelationType80 fn relation_type(&self) -> RelationType { 81 unsafe { 82 from_glib(ffi::atk_relation_get_relation_type( 83 self.as_ref().to_glib_none().0, 84 )) 85 } 86 } 87 target(&self) -> Vec<Object>88 fn target(&self) -> Vec<Object> { 89 unsafe { 90 FromGlibPtrContainer::from_glib_none(ffi::atk_relation_get_target( 91 self.as_ref().to_glib_none().0, 92 )) 93 } 94 } 95 remove_target<P: IsA<Object>>(&self, target: &P) -> bool96 fn remove_target<P: IsA<Object>>(&self, target: &P) -> bool { 97 unsafe { 98 from_glib(ffi::atk_relation_remove_target( 99 self.as_ref().to_glib_none().0, 100 target.as_ref().to_glib_none().0, 101 )) 102 } 103 } 104 set_relation_type(&self, relation_type: RelationType)105 fn set_relation_type(&self, relation_type: RelationType) { 106 unsafe { 107 glib::gobject_ffi::g_object_set_property( 108 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, 109 b"relation-type\0".as_ptr() as *const _, 110 relation_type.to_value().to_glib_none().0, 111 ); 112 } 113 } 114 set_target(&self, target: Option<&glib::ValueArray>)115 fn set_target(&self, target: Option<&glib::ValueArray>) { 116 unsafe { 117 glib::gobject_ffi::g_object_set_property( 118 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, 119 b"target\0".as_ptr() as *const _, 120 target.to_value().to_glib_none().0, 121 ); 122 } 123 } 124 connect_relation_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId125 fn connect_relation_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 126 unsafe extern "C" fn notify_relation_type_trampoline< 127 P: IsA<Relation>, 128 F: Fn(&P) + 'static, 129 >( 130 this: *mut ffi::AtkRelation, 131 _param_spec: glib::ffi::gpointer, 132 f: glib::ffi::gpointer, 133 ) { 134 let f: &F = &*(f as *const F); 135 f(Relation::from_glib_borrow(this).unsafe_cast_ref()) 136 } 137 unsafe { 138 let f: Box_<F> = Box_::new(f); 139 connect_raw( 140 self.as_ptr() as *mut _, 141 b"notify::relation-type\0".as_ptr() as *const _, 142 Some(transmute::<_, unsafe extern "C" fn()>( 143 notify_relation_type_trampoline::<Self, F> as *const (), 144 )), 145 Box_::into_raw(f), 146 ) 147 } 148 } 149 connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId150 fn connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 151 unsafe extern "C" fn notify_target_trampoline<P: IsA<Relation>, F: Fn(&P) + 'static>( 152 this: *mut ffi::AtkRelation, 153 _param_spec: glib::ffi::gpointer, 154 f: glib::ffi::gpointer, 155 ) { 156 let f: &F = &*(f as *const F); 157 f(Relation::from_glib_borrow(this).unsafe_cast_ref()) 158 } 159 unsafe { 160 let f: Box_<F> = Box_::new(f); 161 connect_raw( 162 self.as_ptr() as *mut _, 163 b"notify::target\0".as_ptr() as *const _, 164 Some(transmute::<_, unsafe extern "C" fn()>( 165 notify_target_trampoline::<Self, F> as *const (), 166 )), 167 Box_::into_raw(f), 168 ) 169 } 170 } 171 } 172 173 impl fmt::Display for Relation { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result174 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 175 f.write_str("Relation") 176 } 177 } 178