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::Buildable; 6 use crate::TextTag; 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 std::boxed::Box as Box_; 13 use std::fmt; 14 use std::mem::transmute; 15 16 glib::wrapper! { 17 #[doc(alias = "GtkTextTagTable")] 18 pub struct TextTagTable(Object<ffi::GtkTextTagTable, ffi::GtkTextTagTableClass>) @implements Buildable; 19 20 match fn { 21 type_ => || ffi::gtk_text_tag_table_get_type(), 22 } 23 } 24 25 impl TextTagTable { 26 #[doc(alias = "gtk_text_tag_table_new")] new() -> TextTagTable27 pub fn new() -> TextTagTable { 28 assert_initialized_main_thread!(); 29 unsafe { from_glib_full(ffi::gtk_text_tag_table_new()) } 30 } 31 } 32 33 impl Default for TextTagTable { default() -> Self34 fn default() -> Self { 35 Self::new() 36 } 37 } 38 39 pub const NONE_TEXT_TAG_TABLE: Option<&TextTagTable> = None; 40 41 pub trait TextTagTableExt: 'static { 42 #[doc(alias = "gtk_text_tag_table_add")] add<P: IsA<TextTag>>(&self, tag: &P) -> bool43 fn add<P: IsA<TextTag>>(&self, tag: &P) -> bool; 44 45 #[doc(alias = "gtk_text_tag_table_foreach")] foreach<P: FnMut(&TextTag)>(&self, func: P)46 fn foreach<P: FnMut(&TextTag)>(&self, func: P); 47 48 #[doc(alias = "gtk_text_tag_table_get_size")] 49 #[doc(alias = "get_size")] size(&self) -> i3250 fn size(&self) -> i32; 51 52 #[doc(alias = "gtk_text_tag_table_lookup")] lookup(&self, name: &str) -> Option<TextTag>53 fn lookup(&self, name: &str) -> Option<TextTag>; 54 55 #[doc(alias = "gtk_text_tag_table_remove")] remove<P: IsA<TextTag>>(&self, tag: &P)56 fn remove<P: IsA<TextTag>>(&self, tag: &P); 57 58 #[doc(alias = "tag-added")] connect_tag_added<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId59 fn connect_tag_added<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId; 60 61 #[doc(alias = "tag-changed")] connect_tag_changed<F: Fn(&Self, &TextTag, bool) + 'static>(&self, f: F) -> SignalHandlerId62 fn connect_tag_changed<F: Fn(&Self, &TextTag, bool) + 'static>(&self, f: F) -> SignalHandlerId; 63 64 #[doc(alias = "tag-removed")] connect_tag_removed<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId65 fn connect_tag_removed<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId; 66 } 67 68 impl<O: IsA<TextTagTable>> TextTagTableExt for O { add<P: IsA<TextTag>>(&self, tag: &P) -> bool69 fn add<P: IsA<TextTag>>(&self, tag: &P) -> bool { 70 unsafe { 71 from_glib(ffi::gtk_text_tag_table_add( 72 self.as_ref().to_glib_none().0, 73 tag.as_ref().to_glib_none().0, 74 )) 75 } 76 } 77 foreach<P: FnMut(&TextTag)>(&self, func: P)78 fn foreach<P: FnMut(&TextTag)>(&self, func: P) { 79 let func_data: P = func; 80 unsafe extern "C" fn func_func<P: FnMut(&TextTag)>( 81 tag: *mut ffi::GtkTextTag, 82 data: glib::ffi::gpointer, 83 ) { 84 let tag = from_glib_borrow(tag); 85 let callback: *mut P = data as *const _ as usize as *mut P; 86 (*callback)(&tag); 87 } 88 let func = Some(func_func::<P> as _); 89 let super_callback0: &P = &func_data; 90 unsafe { 91 ffi::gtk_text_tag_table_foreach( 92 self.as_ref().to_glib_none().0, 93 func, 94 super_callback0 as *const _ as usize as *mut _, 95 ); 96 } 97 } 98 size(&self) -> i3299 fn size(&self) -> i32 { 100 unsafe { ffi::gtk_text_tag_table_get_size(self.as_ref().to_glib_none().0) } 101 } 102 lookup(&self, name: &str) -> Option<TextTag>103 fn lookup(&self, name: &str) -> Option<TextTag> { 104 unsafe { 105 from_glib_none(ffi::gtk_text_tag_table_lookup( 106 self.as_ref().to_glib_none().0, 107 name.to_glib_none().0, 108 )) 109 } 110 } 111 remove<P: IsA<TextTag>>(&self, tag: &P)112 fn remove<P: IsA<TextTag>>(&self, tag: &P) { 113 unsafe { 114 ffi::gtk_text_tag_table_remove( 115 self.as_ref().to_glib_none().0, 116 tag.as_ref().to_glib_none().0, 117 ); 118 } 119 } 120 connect_tag_added<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId121 fn connect_tag_added<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId { 122 unsafe extern "C" fn tag_added_trampoline< 123 P: IsA<TextTagTable>, 124 F: Fn(&P, &TextTag) + 'static, 125 >( 126 this: *mut ffi::GtkTextTagTable, 127 tag: *mut ffi::GtkTextTag, 128 f: glib::ffi::gpointer, 129 ) { 130 let f: &F = &*(f as *const F); 131 f( 132 TextTagTable::from_glib_borrow(this).unsafe_cast_ref(), 133 &from_glib_borrow(tag), 134 ) 135 } 136 unsafe { 137 let f: Box_<F> = Box_::new(f); 138 connect_raw( 139 self.as_ptr() as *mut _, 140 b"tag-added\0".as_ptr() as *const _, 141 Some(transmute::<_, unsafe extern "C" fn()>( 142 tag_added_trampoline::<Self, F> as *const (), 143 )), 144 Box_::into_raw(f), 145 ) 146 } 147 } 148 connect_tag_changed<F: Fn(&Self, &TextTag, bool) + 'static>(&self, f: F) -> SignalHandlerId149 fn connect_tag_changed<F: Fn(&Self, &TextTag, bool) + 'static>(&self, f: F) -> SignalHandlerId { 150 unsafe extern "C" fn tag_changed_trampoline< 151 P: IsA<TextTagTable>, 152 F: Fn(&P, &TextTag, bool) + 'static, 153 >( 154 this: *mut ffi::GtkTextTagTable, 155 tag: *mut ffi::GtkTextTag, 156 size_changed: glib::ffi::gboolean, 157 f: glib::ffi::gpointer, 158 ) { 159 let f: &F = &*(f as *const F); 160 f( 161 TextTagTable::from_glib_borrow(this).unsafe_cast_ref(), 162 &from_glib_borrow(tag), 163 from_glib(size_changed), 164 ) 165 } 166 unsafe { 167 let f: Box_<F> = Box_::new(f); 168 connect_raw( 169 self.as_ptr() as *mut _, 170 b"tag-changed\0".as_ptr() as *const _, 171 Some(transmute::<_, unsafe extern "C" fn()>( 172 tag_changed_trampoline::<Self, F> as *const (), 173 )), 174 Box_::into_raw(f), 175 ) 176 } 177 } 178 connect_tag_removed<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId179 fn connect_tag_removed<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId { 180 unsafe extern "C" fn tag_removed_trampoline< 181 P: IsA<TextTagTable>, 182 F: Fn(&P, &TextTag) + 'static, 183 >( 184 this: *mut ffi::GtkTextTagTable, 185 tag: *mut ffi::GtkTextTag, 186 f: glib::ffi::gpointer, 187 ) { 188 let f: &F = &*(f as *const F); 189 f( 190 TextTagTable::from_glib_borrow(this).unsafe_cast_ref(), 191 &from_glib_borrow(tag), 192 ) 193 } 194 unsafe { 195 let f: Box_<F> = Box_::new(f); 196 connect_raw( 197 self.as_ptr() as *mut _, 198 b"tag-removed\0".as_ptr() as *const _, 199 Some(transmute::<_, unsafe extern "C" fn()>( 200 tag_removed_trampoline::<Self, F> as *const (), 201 )), 202 Box_::into_raw(f), 203 ) 204 } 205 } 206 } 207 208 impl fmt::Display for TextTagTable { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result209 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 210 f.write_str("TextTagTable") 211 } 212 } 213