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
67mod sealed {
68    pub trait Sealed {}
69    impl<T: super::IsA<super::PixbufLoader>> Sealed for T {}
70}
71
72pub trait PixbufLoaderExt: IsA<PixbufLoader> + sealed::Sealed + 'static {
73    #[doc(alias = "gdk_pixbuf_loader_close")]
74    fn close(&self) -> Result<(), glib::Error> {
75        unsafe {
76            let mut error = std::ptr::null_mut();
77            let is_ok = ffi::gdk_pixbuf_loader_close(self.as_ref().to_glib_none().0, &mut error);
78            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
79            if error.is_null() {
80                Ok(())
81            } else {
82                Err(from_glib_full(error))
83            }
84        }
85    }
86
87    #[doc(alias = "gdk_pixbuf_loader_get_animation")]
88    #[doc(alias = "get_animation")]
89    fn animation(&self) -> Option<PixbufAnimation> {
90        unsafe {
91            from_glib_none(ffi::gdk_pixbuf_loader_get_animation(
92                self.as_ref().to_glib_none().0,
93            ))
94        }
95    }
96
97    #[doc(alias = "gdk_pixbuf_loader_get_format")]
98    #[doc(alias = "get_format")]
99    fn format(&self) -> Option<PixbufFormat> {
100        unsafe {
101            from_glib_none(ffi::gdk_pixbuf_loader_get_format(
102                self.as_ref().to_glib_none().0,
103            ))
104        }
105    }
106
107    #[doc(alias = "gdk_pixbuf_loader_get_pixbuf")]
108    #[doc(alias = "get_pixbuf")]
109    fn pixbuf(&self) -> Option<Pixbuf> {
110        unsafe {
111            from_glib_none(ffi::gdk_pixbuf_loader_get_pixbuf(
112                self.as_ref().to_glib_none().0,
113            ))
114        }
115    }
116
117    #[doc(alias = "gdk_pixbuf_loader_set_size")]
118    fn set_size(&self, width: i32, height: i32) {
119        unsafe {
120            ffi::gdk_pixbuf_loader_set_size(self.as_ref().to_glib_none().0, width, height);
121        }
122    }
123
124    #[doc(alias = "gdk_pixbuf_loader_write")]
125    fn write(&self, buf: &[u8]) -> Result<(), glib::Error> {
126        let count = buf.len() as _;
127        unsafe {
128            let mut error = std::ptr::null_mut();
129            let is_ok = ffi::gdk_pixbuf_loader_write(
130                self.as_ref().to_glib_none().0,
131                buf.to_glib_none().0,
132                count,
133                &mut error,
134            );
135            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
136            if error.is_null() {
137                Ok(())
138            } else {
139                Err(from_glib_full(error))
140            }
141        }
142    }
143
144    #[doc(alias = "gdk_pixbuf_loader_write_bytes")]
145    fn write_bytes(&self, buffer: &glib::Bytes) -> Result<(), glib::Error> {
146        unsafe {
147            let mut error = std::ptr::null_mut();
148            let is_ok = ffi::gdk_pixbuf_loader_write_bytes(
149                self.as_ref().to_glib_none().0,
150                buffer.to_glib_none().0,
151                &mut error,
152            );
153            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
154            if error.is_null() {
155                Ok(())
156            } else {
157                Err(from_glib_full(error))
158            }
159        }
160    }
161
162    #[doc(alias = "area-prepared")]
163    fn connect_area_prepared<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
164        unsafe extern "C" fn area_prepared_trampoline<P: IsA<PixbufLoader>, F: Fn(&P) + 'static>(
165            this: *mut ffi::GdkPixbufLoader,
166            f: glib::ffi::gpointer,
167        ) {
168            let f: &F = &*(f as *const F);
169            f(PixbufLoader::from_glib_borrow(this).unsafe_cast_ref())
170        }
171        unsafe {
172            let f: Box_<F> = Box_::new(f);
173            connect_raw(
174                self.as_ptr() as *mut _,
175                b"area-prepared\0".as_ptr() as *const _,
176                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
177                    area_prepared_trampoline::<Self, F> as *const (),
178                )),
179                Box_::into_raw(f),
180            )
181        }
182    }
183
184    #[doc(alias = "area-updated")]
185    fn connect_area_updated<F: Fn(&Self, i32, i32, i32, i32) + 'static>(
186        &self,
187        f: F,
188    ) -> SignalHandlerId {
189        unsafe extern "C" fn area_updated_trampoline<
190            P: IsA<PixbufLoader>,
191            F: Fn(&P, i32, i32, i32, i32) + 'static,
192        >(
193            this: *mut ffi::GdkPixbufLoader,
194            x: std::ffi::c_int,
195            y: std::ffi::c_int,
196            width: std::ffi::c_int,
197            height: std::ffi::c_int,
198            f: glib::ffi::gpointer,
199        ) {
200            let f: &F = &*(f as *const F);
201            f(
202                PixbufLoader::from_glib_borrow(this).unsafe_cast_ref(),
203                x,
204                y,
205                width,
206                height,
207            )
208        }
209        unsafe {
210            let f: Box_<F> = Box_::new(f);
211            connect_raw(
212                self.as_ptr() as *mut _,
213                b"area-updated\0".as_ptr() as *const _,
214                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
215                    area_updated_trampoline::<Self, F> as *const (),
216                )),
217                Box_::into_raw(f),
218            )
219        }
220    }
221
222    #[doc(alias = "closed")]
223    fn connect_closed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
224        unsafe extern "C" fn closed_trampoline<P: IsA<PixbufLoader>, F: Fn(&P) + 'static>(
225            this: *mut ffi::GdkPixbufLoader,
226            f: glib::ffi::gpointer,
227        ) {
228            let f: &F = &*(f as *const F);
229            f(PixbufLoader::from_glib_borrow(this).unsafe_cast_ref())
230        }
231        unsafe {
232            let f: Box_<F> = Box_::new(f);
233            connect_raw(
234                self.as_ptr() as *mut _,
235                b"closed\0".as_ptr() as *const _,
236                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
237                    closed_trampoline::<Self, F> as *const (),
238                )),
239                Box_::into_raw(f),
240            )
241        }
242    }
243
244    #[doc(alias = "size-prepared")]
245    fn connect_size_prepared<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
246        unsafe extern "C" fn size_prepared_trampoline<
247            P: IsA<PixbufLoader>,
248            F: Fn(&P, i32, i32) + 'static,
249        >(
250            this: *mut ffi::GdkPixbufLoader,
251            width: std::ffi::c_int,
252            height: std::ffi::c_int,
253            f: glib::ffi::gpointer,
254        ) {
255            let f: &F = &*(f as *const F);
256            f(
257                PixbufLoader::from_glib_borrow(this).unsafe_cast_ref(),
258                width,
259                height,
260            )
261        }
262        unsafe {
263            let f: Box_<F> = Box_::new(f);
264            connect_raw(
265                self.as_ptr() as *mut _,
266                b"size-prepared\0".as_ptr() as *const _,
267                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268                    size_prepared_trampoline::<Self, F> as *const (),
269                )),
270                Box_::into_raw(f),
271            )
272        }
273    }
274}
275
276impl<O: IsA<PixbufLoader>> PixbufLoaderExt for O {}