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

use crate::{ffi, HoverProvider};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "GtkSourceHover")]
    pub struct Hover(Object<ffi::GtkSourceHover, ffi::GtkSourceHoverClass>);

    match fn {
        type_ => || ffi::gtk_source_hover_get_type(),
    }
}

impl Hover {
    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`Hover`] objects.
    ///
    /// This method returns an instance of [`HoverBuilder`](crate::builders::HoverBuilder) which can be used to create [`Hover`] objects.
    pub fn builder() -> HoverBuilder {
        HoverBuilder::new()
    }

    #[doc(alias = "gtk_source_hover_add_provider")]
    pub fn add_provider(&self, provider: &impl IsA<HoverProvider>) {
        unsafe {
            ffi::gtk_source_hover_add_provider(
                self.to_glib_none().0,
                provider.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "gtk_source_hover_remove_provider")]
    pub fn remove_provider(&self, provider: &impl IsA<HoverProvider>) {
        unsafe {
            ffi::gtk_source_hover_remove_provider(
                self.to_glib_none().0,
                provider.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "hover-delay")]
    pub fn hover_delay(&self) -> u32 {
        ObjectExt::property(self, "hover-delay")
    }

    #[doc(alias = "hover-delay")]
    pub fn set_hover_delay(&self, hover_delay: u32) {
        ObjectExt::set_property(self, "hover-delay", hover_delay)
    }

    #[doc(alias = "hover-delay")]
    pub fn connect_hover_delay_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_hover_delay_trampoline<F: Fn(&Hover) + 'static>(
            this: *mut ffi::GtkSourceHover,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::hover-delay".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_hover_delay_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Hover`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct HoverBuilder {
    builder: glib::object::ObjectBuilder<'static, Hover>,
}

impl HoverBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    pub fn hover_delay(self, hover_delay: u32) -> Self {
        Self {
            builder: self.builder.property("hover-delay", hover_delay),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`Hover`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> Hover {
        assert_initialized_main_thread!();
        self.builder.build()
    }
}
