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

use crate::{ffi, DocumentModel, UndoContext};
use glib::{
    object::ObjectType as _,
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "PpsAnnotationsContext")]
    pub struct AnnotationsContext(Object<ffi::PpsAnnotationsContext, ffi::PpsAnnotationsContextClass>);

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

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

    #[doc(alias = "pps_annotations_context_new")]
    pub fn new(model: &DocumentModel, undo_context: &UndoContext) -> AnnotationsContext {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(ffi::pps_annotations_context_new(
                model.to_glib_none().0,
                undo_context.to_glib_none().0,
            ))
        }
    }
}

pub trait AnnotationsContextExt: IsA<AnnotationsContext> + 'static {
    //#[cfg(feature = "v48")]
    //#[cfg_attr(docsrs, doc(cfg(feature = "v48")))]
    //#[doc(alias = "pps_annotations_context_add_annotation_sync")]
    //fn add_annotation_sync(&self, page_index: i32, type_: papers_document::AnnotationType, start: &papers_document::Point, end: &papers_document::Point, color: &gdk::RGBA, user_data: /*Unimplemented*/Option<Basic: Pointer>) -> Option<papers_document::Annotation> {
    //    unsafe { TODO: call ffi:pps_annotations_context_add_annotation_sync() }
    //}

    #[cfg(feature = "v49")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v49")))]
    #[doc(alias = "pps_annotations_context_get_annot_at_doc_point")]
    #[doc(alias = "get_annot_at_doc_point")]
    fn annot_at_doc_point(
        &self,
        doc_point: &papers_document::DocumentPoint,
    ) -> Option<papers_document::Annotation> {
        unsafe {
            from_glib_none(ffi::pps_annotations_context_get_annot_at_doc_point(
                self.as_ref().to_glib_none().0,
                doc_point.to_glib_none().0,
            ))
        }
    }

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

    #[doc(alias = "pps_annotations_context_remove_annotation")]
    fn remove_annotation(&self, annot: &impl IsA<papers_document::Annotation>) {
        unsafe {
            ffi::pps_annotations_context_remove_annotation(
                self.as_ref().to_glib_none().0,
                annot.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "pps_annotations_context_set_color")]
    fn set_color(&self, color: &gdk::RGBA) {
        unsafe {
            ffi::pps_annotations_context_set_color(
                self.as_ref().to_glib_none().0,
                color.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "annot-added")]
    fn connect_annot_added<F: Fn(&Self, &papers_document::Annotation) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn annot_added_trampoline<
            P: IsA<AnnotationsContext>,
            F: Fn(&P, &papers_document::Annotation) + 'static,
        >(
            this: *mut ffi::PpsAnnotationsContext,
            object: *mut papers_document::ffi::PpsAnnotation,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                AnnotationsContext::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(object),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"annot-added".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    annot_added_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "annot-removed")]
    fn connect_annot_removed<F: Fn(&Self, &papers_document::Annotation) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn annot_removed_trampoline<
            P: IsA<AnnotationsContext>,
            F: Fn(&P, &papers_document::Annotation) + 'static,
        >(
            this: *mut ffi::PpsAnnotationsContext,
            object: *mut papers_document::ffi::PpsAnnotation,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                AnnotationsContext::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(object),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"annot-removed".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    annot_removed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "annots-loaded")]
    fn connect_annots_loaded<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn annots_loaded_trampoline<
            P: IsA<AnnotationsContext>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::PpsAnnotationsContext,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(AnnotationsContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"annots-loaded".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    annots_loaded_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<AnnotationsContext>> AnnotationsContextExt for O {}
