use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute};
glib::wrapper! {
#[doc(alias = "DzlListStoreAdapter")]
pub struct ListStoreAdapter(Object<ffi::DzlListStoreAdapter, ffi::DzlListStoreAdapterClass>) @implements gtk::TreeModel;
match fn {
type_ => || ffi::dzl_list_store_adapter_get_type(),
}
}
impl ListStoreAdapter {
pub const NONE: Option<&'static ListStoreAdapter> = None;
#[doc(alias = "dzl_list_store_adapter_new")]
pub fn new(model: &impl IsA<gio::ListModel>) -> ListStoreAdapter {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::dzl_list_store_adapter_new(
model.as_ref().to_glib_none().0,
))
}
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::ListStoreAdapter>> Sealed for T {}
}
pub trait ListStoreAdapterExt: IsA<ListStoreAdapter> + sealed::Sealed + 'static {
#[cfg(feature = "v3_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v3_26")))]
#[doc(alias = "dzl_list_store_adapter_get_model")]
#[doc(alias = "get_model")]
fn model(&self) -> Option<gio::ListModel> {
unsafe {
from_glib_none(ffi::dzl_list_store_adapter_get_model(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "dzl_list_store_adapter_set_model")]
fn set_model(&self, model: &impl IsA<gio::ListModel>) {
unsafe {
ffi::dzl_list_store_adapter_set_model(
self.as_ref().to_glib_none().0,
model.as_ref().to_glib_none().0,
);
}
}
fn get_property_model(&self) -> Option<gio::ListModel> {
ObjectExt::property(self.as_ref(), "model")
}
#[doc(alias = "model")]
fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_model_trampoline<
P: IsA<ListStoreAdapter>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::DzlListStoreAdapter,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListStoreAdapter::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::model\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_model_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<ListStoreAdapter>> ListStoreAdapterExt for O {}
impl fmt::Display for ListStoreAdapter {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("ListStoreAdapter")
}
}