// 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::{ActionRow, EnumValueObject, PreferencesRow};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute};

glib::wrapper! {
    #[doc(alias = "HdyComboRow")]
    pub struct ComboRow(Object<ffi::HdyComboRow, ffi::HdyComboRowClass>) @extends ActionRow, PreferencesRow, gtk::ListBoxRow, gtk::Bin, gtk::Container, gtk::Widget, @implements gtk::Buildable, gtk::Actionable;

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

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

    #[doc(alias = "hdy_combo_row_new")]
    pub fn new() -> ComboRow {
        assert_initialized_main_thread!();
        unsafe { gtk::Widget::from_glib_none(ffi::hdy_combo_row_new()).unsafe_cast() }
    }

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

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

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`ComboRow`] 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 ComboRowBuilder {
    builder: glib::object::ObjectBuilder<'static, ComboRow>,
}

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

    pub fn selected_index(self, selected_index: i32) -> Self {
        Self {
            builder: self.builder.property("selected-index", selected_index),
        }
    }

    pub fn use_subtitle(self, use_subtitle: bool) -> Self {
        Self {
            builder: self.builder.property("use-subtitle", use_subtitle),
        }
    }

    pub fn activatable_widget(self, activatable_widget: &impl IsA<gtk::Widget>) -> Self {
        Self {
            builder: self
                .builder
                .property("activatable-widget", activatable_widget.clone().upcast()),
        }
    }

    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("icon-name", icon_name.into()),
        }
    }

    pub fn subtitle(self, subtitle: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("subtitle", subtitle.into()),
        }
    }

    #[cfg(feature = "v1_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
    pub fn subtitle_lines(self, subtitle_lines: i32) -> Self {
        Self {
            builder: self.builder.property("subtitle-lines", subtitle_lines),
        }
    }

    #[cfg(feature = "v1_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
    pub fn title_lines(self, title_lines: i32) -> Self {
        Self {
            builder: self.builder.property("title-lines", title_lines),
        }
    }

    pub fn use_underline(self, use_underline: bool) -> Self {
        Self {
            builder: self.builder.property("use-underline", use_underline),
        }
    }

    pub fn title(self, title: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("title", title.into()),
        }
    }

    pub fn activatable(self, activatable: bool) -> Self {
        Self {
            builder: self.builder.property("activatable", activatable),
        }
    }

    pub fn selectable(self, selectable: bool) -> Self {
        Self {
            builder: self.builder.property("selectable", selectable),
        }
    }

    pub fn border_width(self, border_width: u32) -> Self {
        Self {
            builder: self.builder.property("border-width", border_width),
        }
    }

    pub fn child(self, child: &impl IsA<gtk::Widget>) -> Self {
        Self {
            builder: self.builder.property("child", child.clone().upcast()),
        }
    }

    pub fn resize_mode(self, resize_mode: gtk::ResizeMode) -> Self {
        Self {
            builder: self.builder.property("resize-mode", resize_mode),
        }
    }

    pub fn app_paintable(self, app_paintable: bool) -> Self {
        Self {
            builder: self.builder.property("app-paintable", app_paintable),
        }
    }

    pub fn can_default(self, can_default: bool) -> Self {
        Self {
            builder: self.builder.property("can-default", can_default),
        }
    }

    pub fn can_focus(self, can_focus: bool) -> Self {
        Self {
            builder: self.builder.property("can-focus", can_focus),
        }
    }

    pub fn events(self, events: gdk::EventMask) -> Self {
        Self {
            builder: self.builder.property("events", events),
        }
    }

    pub fn expand(self, expand: bool) -> Self {
        Self {
            builder: self.builder.property("expand", expand),
        }
    }

    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
        Self {
            builder: self.builder.property("focus-on-click", focus_on_click),
        }
    }

    pub fn halign(self, halign: gtk::Align) -> Self {
        Self {
            builder: self.builder.property("halign", halign),
        }
    }

    pub fn has_default(self, has_default: bool) -> Self {
        Self {
            builder: self.builder.property("has-default", has_default),
        }
    }

    pub fn has_focus(self, has_focus: bool) -> Self {
        Self {
            builder: self.builder.property("has-focus", has_focus),
        }
    }

    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
        Self {
            builder: self.builder.property("has-tooltip", has_tooltip),
        }
    }

    pub fn height_request(self, height_request: i32) -> Self {
        Self {
            builder: self.builder.property("height-request", height_request),
        }
    }

    pub fn hexpand(self, hexpand: bool) -> Self {
        Self {
            builder: self.builder.property("hexpand", hexpand),
        }
    }

    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
        Self {
            builder: self.builder.property("hexpand-set", hexpand_set),
        }
    }

    pub fn is_focus(self, is_focus: bool) -> Self {
        Self {
            builder: self.builder.property("is-focus", is_focus),
        }
    }

    pub fn margin(self, margin: i32) -> Self {
        Self {
            builder: self.builder.property("margin", margin),
        }
    }

    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
        Self {
            builder: self.builder.property("margin-bottom", margin_bottom),
        }
    }

    pub fn margin_end(self, margin_end: i32) -> Self {
        Self {
            builder: self.builder.property("margin-end", margin_end),
        }
    }

    pub fn margin_start(self, margin_start: i32) -> Self {
        Self {
            builder: self.builder.property("margin-start", margin_start),
        }
    }

    pub fn margin_top(self, margin_top: i32) -> Self {
        Self {
            builder: self.builder.property("margin-top", margin_top),
        }
    }

    pub fn name(self, name: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("name", name.into()),
        }
    }

    pub fn no_show_all(self, no_show_all: bool) -> Self {
        Self {
            builder: self.builder.property("no-show-all", no_show_all),
        }
    }

    pub fn opacity(self, opacity: f64) -> Self {
        Self {
            builder: self.builder.property("opacity", opacity),
        }
    }

    pub fn parent(self, parent: &impl IsA<gtk::Container>) -> Self {
        Self {
            builder: self.builder.property("parent", parent.clone().upcast()),
        }
    }

    pub fn receives_default(self, receives_default: bool) -> Self {
        Self {
            builder: self.builder.property("receives-default", receives_default),
        }
    }

    pub fn sensitive(self, sensitive: bool) -> Self {
        Self {
            builder: self.builder.property("sensitive", sensitive),
        }
    }

    //pub fn style(self, style: &impl IsA</*Ignored*/gtk::Style>) -> Self {
    //    Self { builder: self.builder.property("style", style.clone().upcast()), }
    //}

    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
        Self {
            builder: self
                .builder
                .property("tooltip-markup", tooltip_markup.into()),
        }
    }

    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("tooltip-text", tooltip_text.into()),
        }
    }

    pub fn valign(self, valign: gtk::Align) -> Self {
        Self {
            builder: self.builder.property("valign", valign),
        }
    }

    pub fn vexpand(self, vexpand: bool) -> Self {
        Self {
            builder: self.builder.property("vexpand", vexpand),
        }
    }

    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
        Self {
            builder: self.builder.property("vexpand-set", vexpand_set),
        }
    }

    pub fn visible(self, visible: bool) -> Self {
        Self {
            builder: self.builder.property("visible", visible),
        }
    }

    pub fn width_request(self, width_request: i32) -> Self {
        Self {
            builder: self.builder.property("width-request", width_request),
        }
    }

    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("action-name", action_name.into()),
        }
    }

    pub fn action_target(self, action_target: &glib::Variant) -> Self {
        Self {
            builder: self
                .builder
                .property("action-target", action_target.clone()),
        }
    }

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

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::ComboRow>> Sealed for T {}
}

pub trait ComboRowExt: IsA<ComboRow> + sealed::Sealed + 'static {
    //#[doc(alias = "hdy_combo_row_bind_model")]
    //fn bind_model(&self, model: Option<&impl IsA<gio::ListModel>>, create_list_widget_func: Option<&mut dyn (FnMut(&glib::Object) -> gtk::Widget)>, create_current_widget_func: Option<Box_<dyn Fn(&glib::Object) -> gtk::Widget + 'static>>) {
    //    unsafe { TODO: call ffi:hdy_combo_row_bind_model() }
    //}

    #[doc(alias = "hdy_combo_row_bind_name_model")]
    fn bind_name_model(
        &self,
        model: Option<&impl IsA<gio::ListModel>>,
        get_name_func: Option<Box_<dyn Fn(&glib::Object) -> String + 'static>>,
    ) {
        let get_name_func_data: Box_<Option<Box_<dyn Fn(&glib::Object) -> String + 'static>>> =
            Box_::new(get_name_func);
        unsafe extern "C" fn get_name_func_func(
            item: *mut glib::gobject_ffi::GObject,
            user_data: glib::ffi::gpointer,
        ) -> *mut libc::c_char {
            let item = from_glib_borrow(item);
            let callback: &Option<Box_<dyn Fn(&glib::Object) -> String + 'static>> =
                &*(user_data as *mut _);
            if let Some(ref callback) = *callback {
                callback(&item)
            } else {
                panic!("cannot get closure...")
            }
            .to_glib_full()
        }
        let get_name_func = if get_name_func_data.is_some() {
            Some(get_name_func_func as _)
        } else {
            None
        };
        unsafe extern "C" fn user_data_free_func_func(data: glib::ffi::gpointer) {
            let _callback: Box_<Option<Box_<dyn Fn(&glib::Object) -> String + 'static>>> =
                Box_::from_raw(data as *mut _);
        }
        let destroy_call4 = Some(user_data_free_func_func as _);
        let super_callback0: Box_<Option<Box_<dyn Fn(&glib::Object) -> String + 'static>>> =
            get_name_func_data;
        unsafe {
            ffi::hdy_combo_row_bind_name_model(
                self.as_ref().to_glib_none().0,
                model.map(|p| p.as_ref()).to_glib_none().0,
                get_name_func,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call4,
            );
        }
    }

    #[doc(alias = "hdy_combo_row_get_model")]
    #[doc(alias = "get_model")]
    fn model(&self) -> Option<gio::ListModel> {
        unsafe { from_glib_none(ffi::hdy_combo_row_get_model(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "hdy_combo_row_get_selected_index")]
    #[doc(alias = "get_selected_index")]
    fn selected_index(&self) -> i32 {
        unsafe { ffi::hdy_combo_row_get_selected_index(self.as_ref().to_glib_none().0) }
    }

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

    #[doc(alias = "hdy_combo_row_set_for_enum")]
    fn set_for_enum(
        &self,
        enum_type: glib::types::Type,
        get_name_func: Option<Box_<dyn Fn(&EnumValueObject) -> String + 'static>>,
    ) {
        let get_name_func_data: Box_<Option<Box_<dyn Fn(&EnumValueObject) -> String + 'static>>> =
            Box_::new(get_name_func);
        unsafe extern "C" fn get_name_func_func(
            value: *mut ffi::HdyEnumValueObject,
            user_data: glib::ffi::gpointer,
        ) -> *mut libc::c_char {
            let value = from_glib_borrow(value);
            let callback: &Option<Box_<dyn Fn(&EnumValueObject) -> String + 'static>> =
                &*(user_data as *mut _);
            if let Some(ref callback) = *callback {
                callback(&value)
            } else {
                panic!("cannot get closure...")
            }
            .to_glib_full()
        }
        let get_name_func = if get_name_func_data.is_some() {
            Some(get_name_func_func as _)
        } else {
            None
        };
        unsafe extern "C" fn user_data_free_func_func(data: glib::ffi::gpointer) {
            let _callback: Box_<Option<Box_<dyn Fn(&EnumValueObject) -> String + 'static>>> =
                Box_::from_raw(data as *mut _);
        }
        let destroy_call4 = Some(user_data_free_func_func as _);
        let super_callback0: Box_<Option<Box_<dyn Fn(&EnumValueObject) -> String + 'static>>> =
            get_name_func_data;
        unsafe {
            ffi::hdy_combo_row_set_for_enum(
                self.as_ref().to_glib_none().0,
                enum_type.into_glib(),
                get_name_func,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call4,
            );
        }
    }

    #[doc(alias = "hdy_combo_row_set_get_name_func")]
    fn set_get_name_func(
        &self,
        get_name_func: Option<Box_<dyn Fn(&glib::Object) -> String + 'static>>,
    ) {
        let get_name_func_data: Box_<Option<Box_<dyn Fn(&glib::Object) -> String + 'static>>> =
            Box_::new(get_name_func);
        unsafe extern "C" fn get_name_func_func(
            item: *mut glib::gobject_ffi::GObject,
            user_data: glib::ffi::gpointer,
        ) -> *mut libc::c_char {
            let item = from_glib_borrow(item);
            let callback: &Option<Box_<dyn Fn(&glib::Object) -> String + 'static>> =
                &*(user_data as *mut _);
            if let Some(ref callback) = *callback {
                callback(&item)
            } else {
                panic!("cannot get closure...")
            }
            .to_glib_full()
        }
        let get_name_func = if get_name_func_data.is_some() {
            Some(get_name_func_func as _)
        } else {
            None
        };
        unsafe extern "C" fn user_data_free_func_func(data: glib::ffi::gpointer) {
            let _callback: Box_<Option<Box_<dyn Fn(&glib::Object) -> String + 'static>>> =
                Box_::from_raw(data as *mut _);
        }
        let destroy_call3 = Some(user_data_free_func_func as _);
        let super_callback0: Box_<Option<Box_<dyn Fn(&glib::Object) -> String + 'static>>> =
            get_name_func_data;
        unsafe {
            ffi::hdy_combo_row_set_get_name_func(
                self.as_ref().to_glib_none().0,
                get_name_func,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call3,
            );
        }
    }

    #[doc(alias = "hdy_combo_row_set_selected_index")]
    fn set_selected_index(&self, selected_index: i32) {
        unsafe {
            ffi::hdy_combo_row_set_selected_index(self.as_ref().to_glib_none().0, selected_index);
        }
    }

    #[doc(alias = "hdy_combo_row_set_use_subtitle")]
    fn set_use_subtitle(&self, use_subtitle: bool) {
        unsafe {
            ffi::hdy_combo_row_set_use_subtitle(
                self.as_ref().to_glib_none().0,
                use_subtitle.into_glib(),
            );
        }
    }

    #[doc(alias = "selected-index")]
    fn connect_selected_index_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_selected_index_trampoline<
            P: IsA<ComboRow>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::HdyComboRow,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(ComboRow::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::selected-index\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_selected_index_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "use-subtitle")]
    fn connect_use_subtitle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_use_subtitle_trampoline<
            P: IsA<ComboRow>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::HdyComboRow,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(ComboRow::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::use-subtitle\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_use_subtitle_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<ComboRow>> ComboRowExt for O {}

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