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

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

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

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

    #[doc(alias = "pps_annotation_attachment_get_attachment")]
    #[doc(alias = "get_attachment")]
    pub fn attachment(&self) -> Option<Attachment> {
        unsafe {
            from_glib_none(ffi::pps_annotation_attachment_get_attachment(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_annotation_attachment_set_attachment")]
    #[doc(alias = "attachment")]
    pub fn set_attachment(&self, attachment: &impl IsA<Attachment>) -> bool {
        unsafe {
            from_glib(ffi::pps_annotation_attachment_set_attachment(
                self.to_glib_none().0,
                attachment.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "attachment")]
    pub fn connect_attachment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_attachment_trampoline<
            F: Fn(&AnnotationAttachment) + 'static,
        >(
            this: *mut ffi::PpsAnnotationAttachment,
            _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 _,
                b"notify::attachment\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_attachment_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}
