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