use crate::{Contextual, ffi};
use glib::{
object::ObjectType as _,
prelude::*,
signal::{SignalHandlerId, connect_raw},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "MirageObject")]
pub struct Object(Object<ffi::MirageObject, ffi::MirageObjectClass>) @implements Contextual;
match fn {
type_ => || ffi::mirage_object_get_type(),
}
}
impl Object {
pub const NONE: Option<&'static Object> = None;
}
pub trait MirageObjectExt: IsA<Object> + 'static {
#[doc(alias = "mirage_object_get_parent")]
#[doc(alias = "get_parent")]
#[must_use]
fn parent(&self) -> Option<Object> {
unsafe {
from_glib_full(ffi::mirage_object_get_parent(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "mirage_object_set_parent")]
fn set_parent(&self, parent: Option<&impl IsA<Object>>) {
unsafe {
ffi::mirage_object_set_parent(
self.as_ref().to_glib_none().0,
parent.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
#[doc(alias = "context-changed")]
fn connect_context_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn context_changed_trampoline<P: IsA<Object>, F: Fn(&P) + 'static>(
this: *mut ffi::MirageObject,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(Object::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"context-changed".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
context_changed_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<Object>> MirageObjectExt for O {}