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

glib::wrapper! {
    #[doc(alias = "AdwShortcutLabel")]
    pub struct ShortcutLabel(Object<ffi::AdwShortcutLabel, ffi::AdwShortcutLabelClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;

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

impl ShortcutLabel {
    #[doc(alias = "adw_shortcut_label_new")]
    pub fn new(accelerator: &str) -> ShortcutLabel {
        assert_initialized_main_thread!();
        unsafe {
            gtk::Widget::from_glib_none(ffi::adw_shortcut_label_new(accelerator.to_glib_none().0))
                .unsafe_cast()
        }
    }

    #[doc(alias = "adw_shortcut_label_get_accelerator")]
    #[doc(alias = "get_accelerator")]
    pub fn accelerator(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::adw_shortcut_label_get_accelerator(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "adw_shortcut_label_get_disabled_text")]
    #[doc(alias = "get_disabled_text")]
    #[doc(alias = "disabled-text")]
    pub fn disabled_text(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::adw_shortcut_label_get_disabled_text(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "adw_shortcut_label_set_accelerator")]
    #[doc(alias = "accelerator")]
    pub fn set_accelerator(&self, accelerator: &str) {
        unsafe {
            ffi::adw_shortcut_label_set_accelerator(
                self.to_glib_none().0,
                accelerator.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "adw_shortcut_label_set_disabled_text")]
    #[doc(alias = "disabled-text")]
    pub fn set_disabled_text(&self, disabled_text: &str) {
        unsafe {
            ffi::adw_shortcut_label_set_disabled_text(
                self.to_glib_none().0,
                disabled_text.to_glib_none().0,
            );
        }
    }

    #[cfg(feature = "v1_8")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
    #[doc(alias = "accelerator")]
    pub fn connect_accelerator_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_accelerator_trampoline<F: Fn(&ShortcutLabel) + 'static>(
            this: *mut ffi::AdwShortcutLabel,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                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::accelerator".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_accelerator_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v1_8")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
    #[doc(alias = "disabled-text")]
    pub fn connect_disabled_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_disabled_text_trampoline<F: Fn(&ShortcutLabel) + 'static>(
            this: *mut ffi::AdwShortcutLabel,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                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::disabled-text".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_disabled_text_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}
