// 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::HeaderBar;
use crate::HeaderGroupChild;
use glib::object::Cast;
use glib::object::IsA;
use glib::object::ObjectType as ObjectType_;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    #[doc(alias = "HdyHeaderGroup")]
    pub struct HeaderGroup(Object<ffi::HdyHeaderGroup, ffi::HdyHeaderGroupClass>) @implements gtk::Buildable;

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

impl HeaderGroup {
    #[doc(alias = "hdy_header_group_new")]
    pub fn new() -> HeaderGroup {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::hdy_header_group_new()) }
    }

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

    #[doc(alias = "hdy_header_group_add_gtk_header_bar")]
    pub fn add_gtk_header_bar<P: IsA<gtk::HeaderBar>>(&self, header_bar: &P) {
        unsafe {
            ffi::hdy_header_group_add_gtk_header_bar(
                self.to_glib_none().0,
                header_bar.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "hdy_header_group_add_header_bar")]
    pub fn add_header_bar<P: IsA<HeaderBar>>(&self, header_bar: &P) {
        unsafe {
            ffi::hdy_header_group_add_header_bar(
                self.to_glib_none().0,
                header_bar.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "hdy_header_group_add_header_group")]
    pub fn add_header_group(&self, header_group: &HeaderGroup) {
        unsafe {
            ffi::hdy_header_group_add_header_group(
                self.to_glib_none().0,
                header_group.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "hdy_header_group_get_children")]
    #[doc(alias = "get_children")]
    pub fn children(&self) -> Vec<HeaderGroupChild> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::hdy_header_group_get_children(
                self.to_glib_none().0,
            ))
        }
    }

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

    #[doc(alias = "hdy_header_group_remove_child")]
    pub fn remove_child(&self, child: &HeaderGroupChild) {
        unsafe {
            ffi::hdy_header_group_remove_child(self.to_glib_none().0, child.to_glib_none().0);
        }
    }

    #[doc(alias = "hdy_header_group_remove_gtk_header_bar")]
    pub fn remove_gtk_header_bar<P: IsA<gtk::HeaderBar>>(&self, header_bar: &P) {
        unsafe {
            ffi::hdy_header_group_remove_gtk_header_bar(
                self.to_glib_none().0,
                header_bar.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "hdy_header_group_remove_header_bar")]
    pub fn remove_header_bar<P: IsA<HeaderBar>>(&self, header_bar: &P) {
        unsafe {
            ffi::hdy_header_group_remove_header_bar(
                self.to_glib_none().0,
                header_bar.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "hdy_header_group_remove_header_group")]
    pub fn remove_header_group(&self, header_group: &HeaderGroup) {
        unsafe {
            ffi::hdy_header_group_remove_header_group(
                self.to_glib_none().0,
                header_group.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "hdy_header_group_set_decorate_all")]
    pub fn set_decorate_all(&self, decorate_all: bool) {
        unsafe {
            ffi::hdy_header_group_set_decorate_all(self.to_glib_none().0, decorate_all.into_glib());
        }
    }

    #[doc(alias = "update-decoration-layouts")]
    pub fn connect_update_decoration_layouts<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn update_decoration_layouts_trampoline<F: Fn(&HeaderGroup) + 'static>(
            this: *mut ffi::HdyHeaderGroup,
            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 _,
                b"update-decoration-layouts\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    update_decoration_layouts_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "decorate-all")]
    pub fn connect_decorate_all_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_decorate_all_trampoline<F: Fn(&HeaderGroup) + 'static>(
            this: *mut ffi::HdyHeaderGroup,
            _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 _,
                b"notify::decorate-all\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_decorate_all_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for HeaderGroup {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`HeaderGroup`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
pub struct HeaderGroupBuilder {
    decorate_all: Option<bool>,
}

impl HeaderGroupBuilder {
    // rustdoc-stripper-ignore-next
    /// Create a new [`HeaderGroupBuilder`].
    pub fn new() -> Self {
        Self::default()
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`HeaderGroup`].
    pub fn build(self) -> HeaderGroup {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref decorate_all) = self.decorate_all {
            properties.push(("decorate-all", decorate_all));
        }
        glib::Object::new::<HeaderGroup>(&properties)
            .expect("Failed to create an instance of HeaderGroup")
    }

    pub fn decorate_all(mut self, decorate_all: bool) -> Self {
        self.decorate_all = Some(decorate_all);
        self
    }
}

impl fmt::Display for HeaderGroup {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("HeaderGroup")
    }
}
