// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::ExpressionWatch;
use glib::{prelude::*, translate::*};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "GtkExpression")]
    pub struct Expression(Shared<ffi::GtkExpression>);

    match fn {
        ref => |ptr| ffi::gtk_expression_ref(ptr),
        unref => |ptr| ffi::gtk_expression_unref(ptr),
    }
}

impl StaticType for Expression {
    fn static_type() -> glib::Type {
        unsafe { from_glib(ffi::gtk_expression_get_type()) }
    }
}

impl Expression {
    pub const NONE: Option<&'static Expression> = None;

    #[doc(alias = "gtk_expression_bind")]
    pub fn bind(
        &self,
        target: &impl IsA<glib::Object>,
        property: &str,
        this_: Option<&impl IsA<glib::Object>>,
    ) -> ExpressionWatch {
        unsafe {
            from_glib_none(ffi::gtk_expression_bind(
                self.as_ref().to_glib_full(),
                target.as_ref().to_glib_none().0,
                property.to_glib_none().0,
                this_.map(|p| p.as_ref()).to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_expression_get_value_type")]
    #[doc(alias = "get_value_type")]
    pub fn value_type(&self) -> glib::types::Type {
        unsafe {
            from_glib(ffi::gtk_expression_get_value_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_expression_is_static")]
    pub fn is_static(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_expression_is_static(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_expression_watch")]
    pub fn watch<P: Fn() + 'static>(
        &self,
        this_: Option<&impl IsA<glib::Object>>,
        notify: P,
    ) -> ExpressionWatch {
        let notify_data: Box_<P> = Box_::new(notify);
        unsafe extern "C" fn notify_func<P: Fn() + 'static>(user_data: glib::ffi::gpointer) {
            let callback = &*(user_data as *mut P);
            (*callback)()
        }
        let notify = Some(notify_func::<P> as _);
        unsafe extern "C" fn user_destroy_func<P: Fn() + 'static>(data: glib::ffi::gpointer) {
            let _callback = Box_::from_raw(data as *mut P);
        }
        let destroy_call4 = Some(user_destroy_func::<P> as _);
        let super_callback0: Box_<P> = notify_data;
        unsafe {
            from_glib_none(ffi::gtk_expression_watch(
                self.as_ref().to_glib_none().0,
                this_.map(|p| p.as_ref()).to_glib_none().0,
                notify,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call4,
            ))
        }
    }
}
