// 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;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::GString;
use glib::StaticType;
use glib::Value;
use glib_sys;
use gobject_sys;
use libc;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use std::ptr;
use webkit2_webextension_sys;
use DOMElement;
use DOMEventTarget;
use DOMHTMLElement;
use DOMHTMLFormElement;
use DOMHTMLOptionsCollection;
use DOMNode;
use DOMObject;

glib_wrapper! {
    pub struct DOMHTMLSelectElement(Object<webkit2_webextension_sys::WebKitDOMHTMLSelectElement, webkit2_webextension_sys::WebKitDOMHTMLSelectElementClass, DOMHTMLSelectElementClass>) @extends DOMHTMLElement, DOMElement, DOMNode, DOMObject, @implements DOMEventTarget;

    match fn {
        get_type => || webkit2_webextension_sys::webkit_dom_html_select_element_get_type(),
    }
}

pub const NONE_DOMHTML_SELECT_ELEMENT: Option<&DOMHTMLSelectElement> = None;

pub trait DOMHTMLSelectElementExt: 'static {
    #[cfg_attr(feature = "v2_22", deprecated)]
    fn add<P: IsA<DOMHTMLElement>, Q: IsA<DOMHTMLElement>>(
        &self,
        element: &P,
        before: &Q,
    ) -> Result<(), glib::Error>;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_autofocus(&self) -> bool;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_disabled(&self) -> bool;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_form(&self) -> Option<DOMHTMLFormElement>;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_length(&self) -> libc::c_ulong;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_multiple(&self) -> bool;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_name(&self) -> Option<GString>;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_options(&self) -> Option<DOMHTMLOptionsCollection>;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_select_type(&self) -> Option<GString>;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_selected_index(&self) -> libc::c_long;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_size(&self) -> libc::c_long;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_value(&self) -> Option<GString>;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn get_will_validate(&self) -> bool;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn item(&self, index: libc::c_ulong) -> Option<DOMNode>;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn named_item(&self, name: &str) -> Option<DOMNode>;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn remove(&self, index: libc::c_long);

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn set_autofocus(&self, value: bool);

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn set_disabled(&self, value: bool);

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn set_length(&self, value: libc::c_ulong) -> Result<(), glib::Error>;

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn set_multiple(&self, value: bool);

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn set_name(&self, value: &str);

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn set_selected_index(&self, value: libc::c_long);

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn set_size(&self, value: libc::c_long);

    #[cfg_attr(feature = "v2_22", deprecated)]
    fn set_value(&self, value: &str);

    fn get_property_type(&self) -> Option<GString>;

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

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

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

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

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

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

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

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

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

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

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

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

impl<O: IsA<DOMHTMLSelectElement>> DOMHTMLSelectElementExt for O {
    fn add<P: IsA<DOMHTMLElement>, Q: IsA<DOMHTMLElement>>(
        &self,
        element: &P,
        before: &Q,
    ) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = webkit2_webextension_sys::webkit_dom_html_select_element_add(
                self.as_ref().to_glib_none().0,
                element.as_ref().to_glib_none().0,
                before.as_ref().to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn get_autofocus(&self) -> bool {
        unsafe {
            from_glib(
                webkit2_webextension_sys::webkit_dom_html_select_element_get_autofocus(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn get_disabled(&self) -> bool {
        unsafe {
            from_glib(
                webkit2_webextension_sys::webkit_dom_html_select_element_get_disabled(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn get_form(&self) -> Option<DOMHTMLFormElement> {
        unsafe {
            from_glib_none(
                webkit2_webextension_sys::webkit_dom_html_select_element_get_form(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn get_length(&self) -> libc::c_ulong {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_get_length(
                self.as_ref().to_glib_none().0,
            )
        }
    }

    fn get_multiple(&self) -> bool {
        unsafe {
            from_glib(
                webkit2_webextension_sys::webkit_dom_html_select_element_get_multiple(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn get_name(&self) -> Option<GString> {
        unsafe {
            from_glib_full(
                webkit2_webextension_sys::webkit_dom_html_select_element_get_name(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn get_options(&self) -> Option<DOMHTMLOptionsCollection> {
        unsafe {
            from_glib_full(
                webkit2_webextension_sys::webkit_dom_html_select_element_get_options(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn get_select_type(&self) -> Option<GString> {
        unsafe {
            from_glib_full(
                webkit2_webextension_sys::webkit_dom_html_select_element_get_select_type(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn get_selected_index(&self) -> libc::c_long {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_get_selected_index(
                self.as_ref().to_glib_none().0,
            )
        }
    }

    fn get_size(&self) -> libc::c_long {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_get_size(
                self.as_ref().to_glib_none().0,
            )
        }
    }

    fn get_value(&self) -> Option<GString> {
        unsafe {
            from_glib_full(
                webkit2_webextension_sys::webkit_dom_html_select_element_get_value(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn get_will_validate(&self) -> bool {
        unsafe {
            from_glib(
                webkit2_webextension_sys::webkit_dom_html_select_element_get_will_validate(
                    self.as_ref().to_glib_none().0,
                ),
            )
        }
    }

    fn item(&self, index: libc::c_ulong) -> Option<DOMNode> {
        unsafe {
            from_glib_none(
                webkit2_webextension_sys::webkit_dom_html_select_element_item(
                    self.as_ref().to_glib_none().0,
                    index,
                ),
            )
        }
    }

    fn named_item(&self, name: &str) -> Option<DOMNode> {
        unsafe {
            from_glib_none(
                webkit2_webextension_sys::webkit_dom_html_select_element_named_item(
                    self.as_ref().to_glib_none().0,
                    name.to_glib_none().0,
                ),
            )
        }
    }

    fn remove(&self, index: libc::c_long) {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_remove(
                self.as_ref().to_glib_none().0,
                index,
            );
        }
    }

    fn set_autofocus(&self, value: bool) {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_set_autofocus(
                self.as_ref().to_glib_none().0,
                value.to_glib(),
            );
        }
    }

    fn set_disabled(&self, value: bool) {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_set_disabled(
                self.as_ref().to_glib_none().0,
                value.to_glib(),
            );
        }
    }

    fn set_length(&self, value: libc::c_ulong) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = webkit2_webextension_sys::webkit_dom_html_select_element_set_length(
                self.as_ref().to_glib_none().0,
                value,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_multiple(&self, value: bool) {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_set_multiple(
                self.as_ref().to_glib_none().0,
                value.to_glib(),
            );
        }
    }

    fn set_name(&self, value: &str) {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_set_name(
                self.as_ref().to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    fn set_selected_index(&self, value: libc::c_long) {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_set_selected_index(
                self.as_ref().to_glib_none().0,
                value,
            );
        }
    }

    fn set_size(&self, value: libc::c_long) {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_set_size(
                self.as_ref().to_glib_none().0,
                value,
            );
        }
    }

    fn set_value(&self, value: &str) {
        unsafe {
            webkit2_webextension_sys::webkit_dom_html_select_element_set_value(
                self.as_ref().to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    fn get_property_type(&self) -> Option<GString> {
        unsafe {
            let mut value = Value::from_type(<GString as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"type\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `type` getter")
        }
    }

    fn connect_property_autofocus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_autofocus_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::autofocus\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_autofocus_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_disabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_disabled_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::disabled\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_disabled_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_form_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_form_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::form\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_form_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_length_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::length\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_length_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_multiple_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_multiple_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::multiple\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_multiple_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_name_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::name\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_name_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_options_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_options_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::options\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_options_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_selected_index_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_selected_index_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::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),
            )
        }
    }

    fn connect_property_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_size_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::size\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_size_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_type_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::type\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_type_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_value_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::value\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_value_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_will_validate_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_will_validate_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut webkit2_webextension_sys::WebKitDOMHTMLSelectElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<DOMHTMLSelectElement>,
        {
            let f: &F = &*(f as *const F);
            f(&DOMHTMLSelectElement::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::will-validate\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_will_validate_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

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