| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
use std::boxed::Box as Box_; |
| 7 |
|
| 8 |
use glib::prelude::*; |
| 9 |
use glib::signal::{SignalHandlerId, connect_raw}; |
| 10 |
use glib::translate::*; |
| 11 |
|
| 12 |
use crate::ffi; |
| 13 |
|
| 14 |
glib::wrapper! { |
| 15 |
#[doc(alias = "GlyEncodedImage")] |
| 16 |
pub struct EncodedImage(Object<ffi::GlyEncodedImage, ffi::GlyEncodedImageClass>); |
| 17 |
|
| 18 |
match fn { |
| 19 |
type_ => || ffi::gly_encoded_image_get_type(), |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
impl EncodedImage { |
| 24 |
#[doc(alias = "gly_encoded_image_get_data")] |
| 25 |
#[doc(alias = "get_data")] |
| 26 |
pub fn data(&self) -> glib::Bytes { |
| 27 |
unsafe { from_glib_full(ffi::gly_encoded_image_get_data(self.to_glib_none().0)) } |
| 28 |
} |
| 29 |
|
| 30 |
#[doc(alias = "data")] |
| 31 |
pub fn connect_data_notify<F: Fn(&Self) + Send + Sync + 'static>( |
| 32 |
&self, |
| 33 |
f: F, |
| 34 |
) -> SignalHandlerId { |
| 35 |
unsafe extern "C" fn notify_data_trampoline< |
| 36 |
F: Fn(&EncodedImage) + Send + Sync + 'static, |
| 37 |
>( |
| 38 |
this: *mut ffi::GlyEncodedImage, |
| 39 |
_param_spec: glib::ffi::gpointer, |
| 40 |
f: glib::ffi::gpointer, |
| 41 |
) { |
| 42 |
unsafe { |
| 43 |
let f: &F = &*(f as *const F); |
| 44 |
f(&from_glib_borrow(this)) |
| 45 |
} |
| 46 |
} |
| 47 |
unsafe { |
| 48 |
let f: Box_<F> = Box_::new(f); |
| 49 |
connect_raw( |
| 50 |
self.as_ptr() as *mut _, |
| 51 |
c"notify::data".as_ptr() as *const _, |
| 52 |
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>( |
| 53 |
notify_data_trampoline::<F> as *const (), |
| 54 |
)), |
| 55 |
Box_::into_raw(f), |
| 56 |
) |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
unsafe impl Send for EncodedImage {} |
| 62 |
unsafe impl Sync for EncodedImage {} |