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 gdk_pixbuf_sys; 6 use glib; 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_sys; 13 use libc; 14 use std::boxed::Box as Box_; 15 use std::fmt; 16 use std::mem::transmute; 17 use std::ptr; 18 use Pixbuf; 19 use PixbufAnimation; 20 use PixbufFormat; 21 22 glib_wrapper! { 23 pub struct PixbufLoader(Object<gdk_pixbuf_sys::GdkPixbufLoader, gdk_pixbuf_sys::GdkPixbufLoaderClass, PixbufLoaderClass>); 24 25 match fn { 26 get_type => || gdk_pixbuf_sys::gdk_pixbuf_loader_get_type(), 27 } 28 } 29 30 impl PixbufLoader { new() -> PixbufLoader31 pub fn new() -> PixbufLoader { 32 unsafe { from_glib_full(gdk_pixbuf_sys::gdk_pixbuf_loader_new()) } 33 } 34 new_with_mime_type(mime_type: &str) -> Result<PixbufLoader, glib::Error>35 pub fn new_with_mime_type(mime_type: &str) -> Result<PixbufLoader, glib::Error> { 36 unsafe { 37 let mut error = ptr::null_mut(); 38 let ret = gdk_pixbuf_sys::gdk_pixbuf_loader_new_with_mime_type( 39 mime_type.to_glib_none().0, 40 &mut error, 41 ); 42 if error.is_null() { 43 Ok(from_glib_full(ret)) 44 } else { 45 Err(from_glib_full(error)) 46 } 47 } 48 } 49 new_with_type(image_type: &str) -> Result<PixbufLoader, glib::Error>50 pub fn new_with_type(image_type: &str) -> Result<PixbufLoader, glib::Error> { 51 unsafe { 52 let mut error = ptr::null_mut(); 53 let ret = gdk_pixbuf_sys::gdk_pixbuf_loader_new_with_type( 54 image_type.to_glib_none().0, 55 &mut error, 56 ); 57 if error.is_null() { 58 Ok(from_glib_full(ret)) 59 } else { 60 Err(from_glib_full(error)) 61 } 62 } 63 } 64 } 65 66 impl Default for PixbufLoader { default() -> Self67 fn default() -> Self { 68 Self::new() 69 } 70 } 71 72 pub const NONE_PIXBUF_LOADER: Option<&PixbufLoader> = None; 73 74 pub trait PixbufLoaderExt: 'static { close(&self) -> Result<(), glib::Error>75 fn close(&self) -> Result<(), glib::Error>; 76 get_animation(&self) -> Option<PixbufAnimation>77 fn get_animation(&self) -> Option<PixbufAnimation>; 78 get_format(&self) -> Option<PixbufFormat>79 fn get_format(&self) -> Option<PixbufFormat>; 80 get_pixbuf(&self) -> Option<Pixbuf>81 fn get_pixbuf(&self) -> Option<Pixbuf>; 82 set_size(&self, width: i32, height: i32)83 fn set_size(&self, width: i32, height: i32); 84 write(&self, buf: &[u8]) -> Result<(), glib::Error>85 fn write(&self, buf: &[u8]) -> Result<(), glib::Error>; 86 write_bytes(&self, buffer: &glib::Bytes) -> Result<(), glib::Error>87 fn write_bytes(&self, buffer: &glib::Bytes) -> Result<(), glib::Error>; 88 connect_area_prepared<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId89 fn connect_area_prepared<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 90 connect_area_updated<F: Fn(&Self, i32, i32, i32, i32) + 'static>( &self, f: F, ) -> SignalHandlerId91 fn connect_area_updated<F: Fn(&Self, i32, i32, i32, i32) + 'static>( 92 &self, 93 f: F, 94 ) -> SignalHandlerId; 95 connect_closed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId96 fn connect_closed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 97 connect_size_prepared<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId98 fn connect_size_prepared<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId; 99 } 100 101 impl<O: IsA<PixbufLoader>> PixbufLoaderExt for O { close(&self) -> Result<(), glib::Error>102 fn close(&self) -> Result<(), glib::Error> { 103 unsafe { 104 let mut error = ptr::null_mut(); 105 let _ = 106 gdk_pixbuf_sys::gdk_pixbuf_loader_close(self.as_ref().to_glib_none().0, &mut error); 107 if error.is_null() { 108 Ok(()) 109 } else { 110 Err(from_glib_full(error)) 111 } 112 } 113 } 114 get_animation(&self) -> Option<PixbufAnimation>115 fn get_animation(&self) -> Option<PixbufAnimation> { 116 unsafe { 117 from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_loader_get_animation( 118 self.as_ref().to_glib_none().0, 119 )) 120 } 121 } 122 get_format(&self) -> Option<PixbufFormat>123 fn get_format(&self) -> Option<PixbufFormat> { 124 unsafe { 125 from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_loader_get_format( 126 self.as_ref().to_glib_none().0, 127 )) 128 } 129 } 130 get_pixbuf(&self) -> Option<Pixbuf>131 fn get_pixbuf(&self) -> Option<Pixbuf> { 132 unsafe { 133 from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_loader_get_pixbuf( 134 self.as_ref().to_glib_none().0, 135 )) 136 } 137 } 138 set_size(&self, width: i32, height: i32)139 fn set_size(&self, width: i32, height: i32) { 140 unsafe { 141 gdk_pixbuf_sys::gdk_pixbuf_loader_set_size( 142 self.as_ref().to_glib_none().0, 143 width, 144 height, 145 ); 146 } 147 } 148 write(&self, buf: &[u8]) -> Result<(), glib::Error>149 fn write(&self, buf: &[u8]) -> Result<(), glib::Error> { 150 let count = buf.len() as usize; 151 unsafe { 152 let mut error = ptr::null_mut(); 153 let _ = gdk_pixbuf_sys::gdk_pixbuf_loader_write( 154 self.as_ref().to_glib_none().0, 155 buf.to_glib_none().0, 156 count, 157 &mut error, 158 ); 159 if error.is_null() { 160 Ok(()) 161 } else { 162 Err(from_glib_full(error)) 163 } 164 } 165 } 166 write_bytes(&self, buffer: &glib::Bytes) -> Result<(), glib::Error>167 fn write_bytes(&self, buffer: &glib::Bytes) -> Result<(), glib::Error> { 168 unsafe { 169 let mut error = ptr::null_mut(); 170 let _ = gdk_pixbuf_sys::gdk_pixbuf_loader_write_bytes( 171 self.as_ref().to_glib_none().0, 172 buffer.to_glib_none().0, 173 &mut error, 174 ); 175 if error.is_null() { 176 Ok(()) 177 } else { 178 Err(from_glib_full(error)) 179 } 180 } 181 } 182 connect_area_prepared<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId183 fn connect_area_prepared<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 184 unsafe extern "C" fn area_prepared_trampoline<P, F: Fn(&P) + 'static>( 185 this: *mut gdk_pixbuf_sys::GdkPixbufLoader, 186 f: glib_sys::gpointer, 187 ) where 188 P: IsA<PixbufLoader>, 189 { 190 let f: &F = &*(f as *const F); 191 f(&PixbufLoader::from_glib_borrow(this).unsafe_cast()) 192 } 193 unsafe { 194 let f: Box_<F> = Box_::new(f); 195 connect_raw( 196 self.as_ptr() as *mut _, 197 b"area-prepared\0".as_ptr() as *const _, 198 Some(transmute(area_prepared_trampoline::<Self, F> as usize)), 199 Box_::into_raw(f), 200 ) 201 } 202 } 203 connect_area_updated<F: Fn(&Self, i32, i32, i32, i32) + 'static>( &self, f: F, ) -> SignalHandlerId204 fn connect_area_updated<F: Fn(&Self, i32, i32, i32, i32) + 'static>( 205 &self, 206 f: F, 207 ) -> SignalHandlerId { 208 unsafe extern "C" fn area_updated_trampoline<P, F: Fn(&P, i32, i32, i32, i32) + 'static>( 209 this: *mut gdk_pixbuf_sys::GdkPixbufLoader, 210 x: libc::c_int, 211 y: libc::c_int, 212 width: libc::c_int, 213 height: libc::c_int, 214 f: glib_sys::gpointer, 215 ) where 216 P: IsA<PixbufLoader>, 217 { 218 let f: &F = &*(f as *const F); 219 f( 220 &PixbufLoader::from_glib_borrow(this).unsafe_cast(), 221 x, 222 y, 223 width, 224 height, 225 ) 226 } 227 unsafe { 228 let f: Box_<F> = Box_::new(f); 229 connect_raw( 230 self.as_ptr() as *mut _, 231 b"area-updated\0".as_ptr() as *const _, 232 Some(transmute(area_updated_trampoline::<Self, F> as usize)), 233 Box_::into_raw(f), 234 ) 235 } 236 } 237 connect_closed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId238 fn connect_closed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 239 unsafe extern "C" fn closed_trampoline<P, F: Fn(&P) + 'static>( 240 this: *mut gdk_pixbuf_sys::GdkPixbufLoader, 241 f: glib_sys::gpointer, 242 ) where 243 P: IsA<PixbufLoader>, 244 { 245 let f: &F = &*(f as *const F); 246 f(&PixbufLoader::from_glib_borrow(this).unsafe_cast()) 247 } 248 unsafe { 249 let f: Box_<F> = Box_::new(f); 250 connect_raw( 251 self.as_ptr() as *mut _, 252 b"closed\0".as_ptr() as *const _, 253 Some(transmute(closed_trampoline::<Self, F> as usize)), 254 Box_::into_raw(f), 255 ) 256 } 257 } 258 connect_size_prepared<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId259 fn connect_size_prepared<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId { 260 unsafe extern "C" fn size_prepared_trampoline<P, F: Fn(&P, i32, i32) + 'static>( 261 this: *mut gdk_pixbuf_sys::GdkPixbufLoader, 262 width: libc::c_int, 263 height: libc::c_int, 264 f: glib_sys::gpointer, 265 ) where 266 P: IsA<PixbufLoader>, 267 { 268 let f: &F = &*(f as *const F); 269 f( 270 &PixbufLoader::from_glib_borrow(this).unsafe_cast(), 271 width, 272 height, 273 ) 274 } 275 unsafe { 276 let f: Box_<F> = Box_::new(f); 277 connect_raw( 278 self.as_ptr() as *mut _, 279 b"size-prepared\0".as_ptr() as *const _, 280 Some(transmute(size_prepared_trampoline::<Self, F> as usize)), 281 Box_::into_raw(f), 282 ) 283 } 284 } 285 } 286 287 impl fmt::Display for PixbufLoader { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result288 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 289 write!(f, "PixbufLoader") 290 } 291 } 292