// This file was generated by gir (https://github.com/gtk-rs/gir)
// from ../gir-files
// from ../pps-girs
// DO NOT EDIT

use crate::{ffi, Annotation, AnnotationMarkup, AnnotationTextIcon, Page};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "PpsAnnotationText")]
    pub struct AnnotationText(Object<ffi::PpsAnnotationText, ffi::PpsAnnotationTextClass>) @extends AnnotationMarkup, Annotation;

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

impl AnnotationText {
    #[doc(alias = "pps_annotation_text_new")]
    pub fn new(page: &impl IsA<Page>) -> AnnotationText {
        skip_assert_initialized!();
        unsafe {
            Annotation::from_glib_full(ffi::pps_annotation_text_new(page.as_ref().to_glib_none().0))
                .unsafe_cast()
        }
    }

    #[doc(alias = "pps_annotation_text_get_icon")]
    #[doc(alias = "get_icon")]
    pub fn icon(&self) -> AnnotationTextIcon {
        unsafe { from_glib(ffi::pps_annotation_text_get_icon(self.to_glib_none().0)) }
    }

    #[doc(alias = "pps_annotation_text_get_is_open")]
    #[doc(alias = "get_is_open")]
    #[doc(alias = "is-open")]
    pub fn is_open(&self) -> bool {
        unsafe { from_glib(ffi::pps_annotation_text_get_is_open(self.to_glib_none().0)) }
    }

    #[doc(alias = "pps_annotation_text_set_icon")]
    #[doc(alias = "icon")]
    pub fn set_icon(&self, icon: AnnotationTextIcon) -> bool {
        unsafe {
            from_glib(ffi::pps_annotation_text_set_icon(
                self.to_glib_none().0,
                icon.into_glib(),
            ))
        }
    }

    #[doc(alias = "pps_annotation_text_set_is_open")]
    #[doc(alias = "is-open")]
    pub fn set_is_open(&self, is_open: bool) -> bool {
        unsafe {
            from_glib(ffi::pps_annotation_text_set_is_open(
                self.to_glib_none().0,
                is_open.into_glib(),
            ))
        }
    }

    #[doc(alias = "icon")]
    pub fn connect_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_icon_trampoline<F: Fn(&AnnotationText) + 'static>(
            this: *mut ffi::PpsAnnotationText,
            _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 _,
                c"notify::icon".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_icon_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "is-open")]
    pub fn connect_is_open_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_is_open_trampoline<F: Fn(&AnnotationText) + 'static>(
            this: *mut ffi::PpsAnnotationText,
            _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 _,
                c"notify::is-open".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_is_open_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}
