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

glib_wrapper! {
    pub struct HeaderGroup(Object<handy_sys::HdyHeaderGroup, handy_sys::HdyHeaderGroupClass, HeaderGroupClass>) @implements gtk::Buildable;

    match fn {
        get_type => || handy_sys::hdy_header_group_get_type(),
    }
}

impl HeaderGroup {
    pub fn new() -> HeaderGroup {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(handy_sys::hdy_header_group_new()) }
    }
}

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

#[derive(Clone, Default)]
pub struct HeaderGroupBuilder {
    decorate_all: Option<bool>,
}

impl HeaderGroupBuilder {
    pub fn new() -> Self {
        Self::default()
    }

    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));
        }
        let ret = glib::Object::new(HeaderGroup::static_type(), &properties)
            .expect("object new")
            .downcast::<HeaderGroup>()
            .expect("downcast");
        ret
    }

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

pub const NONE_HEADER_GROUP: Option<&HeaderGroup> = None;

pub trait HeaderGroupExt: 'static {
    fn add_gtk_header_bar<P: IsA<gtk::HeaderBar>>(&self, header_bar: &P);

    fn add_header_bar<P: IsA<HeaderBar>>(&self, header_bar: &P);

    fn add_header_group<P: IsA<HeaderGroup>>(&self, header_group: &P);

    fn get_children(&self) -> Vec<HeaderGroupChild>;

    fn get_decorate_all(&self) -> bool;

    fn remove_child<P: IsA<HeaderGroupChild>>(&self, child: &P);

    fn remove_gtk_header_bar<P: IsA<gtk::HeaderBar>>(&self, header_bar: &P);

    fn remove_header_bar<P: IsA<HeaderBar>>(&self, header_bar: &P);

    fn remove_header_group<P: IsA<HeaderGroup>>(&self, header_group: &P);

    fn set_decorate_all(&self, decorate_all: bool);

    fn connect_update_decoration_layouts<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_decorate_all_notify<F: Fn(&Self) + 'static>(&self, f: F)
        -> SignalHandlerId;
}

impl<O: IsA<HeaderGroup>> HeaderGroupExt for O {
    fn add_gtk_header_bar<P: IsA<gtk::HeaderBar>>(&self, header_bar: &P) {
        unsafe {
            handy_sys::hdy_header_group_add_gtk_header_bar(
                self.as_ref().to_glib_none().0,
                header_bar.as_ref().to_glib_none().0,
            );
        }
    }

    fn add_header_bar<P: IsA<HeaderBar>>(&self, header_bar: &P) {
        unsafe {
            handy_sys::hdy_header_group_add_header_bar(
                self.as_ref().to_glib_none().0,
                header_bar.as_ref().to_glib_none().0,
            );
        }
    }

    fn add_header_group<P: IsA<HeaderGroup>>(&self, header_group: &P) {
        unsafe {
            handy_sys::hdy_header_group_add_header_group(
                self.as_ref().to_glib_none().0,
                header_group.as_ref().to_glib_none().0,
            );
        }
    }

    fn get_children(&self) -> Vec<HeaderGroupChild> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(handy_sys::hdy_header_group_get_children(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_decorate_all(&self) -> bool {
        unsafe {
            from_glib(handy_sys::hdy_header_group_get_decorate_all(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn remove_child<P: IsA<HeaderGroupChild>>(&self, child: &P) {
        unsafe {
            handy_sys::hdy_header_group_remove_child(
                self.as_ref().to_glib_none().0,
                child.as_ref().to_glib_none().0,
            );
        }
    }

    fn remove_gtk_header_bar<P: IsA<gtk::HeaderBar>>(&self, header_bar: &P) {
        unsafe {
            handy_sys::hdy_header_group_remove_gtk_header_bar(
                self.as_ref().to_glib_none().0,
                header_bar.as_ref().to_glib_none().0,
            );
        }
    }

    fn remove_header_bar<P: IsA<HeaderBar>>(&self, header_bar: &P) {
        unsafe {
            handy_sys::hdy_header_group_remove_header_bar(
                self.as_ref().to_glib_none().0,
                header_bar.as_ref().to_glib_none().0,
            );
        }
    }

    fn remove_header_group<P: IsA<HeaderGroup>>(&self, header_group: &P) {
        unsafe {
            handy_sys::hdy_header_group_remove_header_group(
                self.as_ref().to_glib_none().0,
                header_group.as_ref().to_glib_none().0,
            );
        }
    }

    fn set_decorate_all(&self, decorate_all: bool) {
        unsafe {
            handy_sys::hdy_header_group_set_decorate_all(
                self.as_ref().to_glib_none().0,
                decorate_all.to_glib(),
            );
        }
    }

    fn connect_update_decoration_layouts<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn update_decoration_layouts_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut handy_sys::HdyHeaderGroup,
            f: glib_sys::gpointer,
        ) where
            P: IsA<HeaderGroup>,
        {
            let f: &F = &*(f as *const F);
            f(&HeaderGroup::from_glib_borrow(this).unsafe_cast_ref())
        }
        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::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_decorate_all_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_decorate_all_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut handy_sys::HdyHeaderGroup,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<HeaderGroup>,
        {
            let f: &F = &*(f as *const F);
            f(&HeaderGroup::from_glib_borrow(this).unsafe_cast_ref())
        }
        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::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

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