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

#[cfg(feature = "v48")]
#[cfg_attr(docsrs, doc(cfg(feature = "v48")))]
use crate::{AnnotationsContext, ViewSelection};
use crate::{DocumentModel, SearchContext, ffi};
use glib::{
    object::ObjectType as _,
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "PpsView")]
    pub struct View(Object<ffi::PpsView, ffi::PpsViewClass>) @extends gtk::Widget;

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

impl View {
    #[doc(alias = "pps_view_new")]
    pub fn new() -> View {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::pps_view_new()) }
    }

    #[doc(alias = "pps_view_can_zoom_in")]
    #[doc(alias = "can-zoom-in")]
    pub fn can_zoom_in(&self) -> bool {
        unsafe { from_glib(ffi::pps_view_can_zoom_in(self.to_glib_none().0)) }
    }

    #[doc(alias = "pps_view_can_zoom_out")]
    #[doc(alias = "can-zoom-out")]
    pub fn can_zoom_out(&self) -> bool {
        unsafe { from_glib(ffi::pps_view_can_zoom_out(self.to_glib_none().0)) }
    }

    #[doc(alias = "pps_view_cancel_signature_rect")]
    pub fn cancel_signature_rect(&self) {
        unsafe {
            ffi::pps_view_cancel_signature_rect(self.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_copy")]
    pub fn copy(&self) {
        unsafe {
            ffi::pps_view_copy(self.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_copy_link_address")]
    pub fn copy_link_address(&self, action: &papers_document::LinkAction) {
        unsafe {
            ffi::pps_view_copy_link_address(self.to_glib_none().0, action.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_current_event_is_type")]
    pub fn current_event_is_type(&self, type_: gdk::EventType) -> bool {
        unsafe {
            from_glib(ffi::pps_view_current_event_is_type(
                self.to_glib_none().0,
                type_.into_glib(),
            ))
        }
    }

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

    #[doc(alias = "pps_view_get_allow_links_change_zoom")]
    #[doc(alias = "get_allow_links_change_zoom")]
    pub fn allows_links_change_zoom(&self) -> bool {
        unsafe {
            from_glib(ffi::pps_view_get_allow_links_change_zoom(
                self.to_glib_none().0,
            ))
        }
    }

    #[cfg(feature = "v48")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v48")))]
    #[doc(alias = "pps_view_get_document_point_for_view_point")]
    #[doc(alias = "get_document_point_for_view_point")]
    pub fn document_point_for_view_point(
        &self,
        view_point_x: f64,
        view_point_y: f64,
    ) -> Option<papers_document::DocumentPoint> {
        unsafe {
            from_glib_full(ffi::pps_view_get_document_point_for_view_point(
                self.to_glib_none().0,
                view_point_x,
                view_point_y,
            ))
        }
    }

    #[doc(alias = "pps_view_get_enable_spellchecking")]
    #[doc(alias = "get_enable_spellchecking")]
    pub fn enables_spellchecking(&self) -> bool {
        unsafe {
            from_glib(ffi::pps_view_get_enable_spellchecking(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_view_get_selected_text")]
    #[doc(alias = "get_selected_text")]
    pub fn selected_text(&self) -> Option<glib::GString> {
        unsafe { from_glib_full(ffi::pps_view_get_selected_text(self.to_glib_none().0)) }
    }

    #[cfg(feature = "v48")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v48")))]
    #[doc(alias = "pps_view_get_selections")]
    #[doc(alias = "get_selections")]
    pub fn selections(&self) -> Vec<ViewSelection> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::pps_view_get_selections(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_view_handle_link")]
    pub fn handle_link(&self, link: &papers_document::Link) {
        unsafe {
            ffi::pps_view_handle_link(self.to_glib_none().0, link.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_has_selection")]
    pub fn has_selection(&self) -> bool {
        unsafe { from_glib(ffi::pps_view_has_selection(self.to_glib_none().0)) }
    }

    #[doc(alias = "pps_view_is_caret_navigation_enabled")]
    pub fn is_caret_navigation_enabled(&self) -> bool {
        unsafe {
            from_glib(ffi::pps_view_is_caret_navigation_enabled(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_view_next_page")]
    pub fn next_page(&self) -> bool {
        unsafe { from_glib(ffi::pps_view_next_page(self.to_glib_none().0)) }
    }

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

    #[doc(alias = "pps_view_previous_page")]
    pub fn previous_page(&self) -> bool {
        unsafe { from_glib(ffi::pps_view_previous_page(self.to_glib_none().0)) }
    }

    #[doc(alias = "pps_view_reload")]
    pub fn reload(&self) {
        unsafe {
            ffi::pps_view_reload(self.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_select_all")]
    pub fn select_all(&self) {
        unsafe {
            ffi::pps_view_select_all(self.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_set_allow_links_change_zoom")]
    pub fn set_allow_links_change_zoom(&self, allowed: bool) {
        unsafe {
            ffi::pps_view_set_allow_links_change_zoom(self.to_glib_none().0, allowed.into_glib());
        }
    }

    #[cfg(feature = "v48")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v48")))]
    #[doc(alias = "pps_view_set_annotations_context")]
    pub fn set_annotations_context(&self, context: &impl IsA<AnnotationsContext>) {
        unsafe {
            ffi::pps_view_set_annotations_context(
                self.to_glib_none().0,
                context.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "pps_view_set_caret_cursor_position")]
    pub fn set_caret_cursor_position(&self, page: u32, offset: u32) {
        unsafe {
            ffi::pps_view_set_caret_cursor_position(self.to_glib_none().0, page, offset);
        }
    }

    #[doc(alias = "pps_view_set_caret_navigation_enabled")]
    pub fn set_caret_navigation_enabled(&self, enabled: bool) {
        unsafe {
            ffi::pps_view_set_caret_navigation_enabled(self.to_glib_none().0, enabled.into_glib());
        }
    }

    #[doc(alias = "pps_view_set_enable_spellchecking")]
    pub fn set_enable_spellchecking(&self, spellcheck: bool) {
        unsafe {
            ffi::pps_view_set_enable_spellchecking(self.to_glib_none().0, spellcheck.into_glib());
        }
    }

    #[doc(alias = "pps_view_set_model")]
    pub fn set_model(&self, model: &DocumentModel) {
        unsafe {
            ffi::pps_view_set_model(self.to_glib_none().0, model.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_set_page_cache_size")]
    pub fn set_page_cache_size(&self, cache_size: usize) {
        unsafe {
            ffi::pps_view_set_page_cache_size(self.to_glib_none().0, cache_size);
        }
    }

    #[doc(alias = "pps_view_set_search_context")]
    pub fn set_search_context(&self, context: &impl IsA<SearchContext>) {
        unsafe {
            ffi::pps_view_set_search_context(
                self.to_glib_none().0,
                context.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "pps_view_start_signature_rect")]
    pub fn start_signature_rect(&self) {
        unsafe {
            ffi::pps_view_start_signature_rect(self.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_supports_caret_navigation")]
    pub fn supports_caret_navigation(&self) -> bool {
        unsafe {
            from_glib(ffi::pps_view_supports_caret_navigation(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_view_zoom_in")]
    pub fn zoom_in(&self) {
        unsafe {
            ffi::pps_view_zoom_in(self.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_zoom_out")]
    pub fn zoom_out(&self) {
        unsafe {
            ffi::pps_view_zoom_out(self.to_glib_none().0);
        }
    }

    #[doc(alias = "pps_view_get_resource")]
    #[doc(alias = "get_resource")]
    pub fn resource() -> Option<gio::Resource> {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::pps_view_get_resource()) }
    }

    #[doc(alias = "activate")]
    pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn activate_trampoline<F: Fn(&View) + 'static>(
            this: *mut ffi::PpsView,
            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"activate".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    activate_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn emit_activate(&self) {
        self.emit_by_name::<()>("activate", &[]);
    }

    #[doc(alias = "cursor-moved")]
    pub fn connect_cursor_moved<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn cursor_moved_trampoline<F: Fn(&View, i32, i32) + 'static>(
            this: *mut ffi::PpsView,
            object: std::ffi::c_int,
            p0: std::ffi::c_int,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this), object, p0)
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"cursor-moved".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    cursor_moved_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "external-link")]
    pub fn connect_external_link<F: Fn(&Self, &papers_document::LinkAction) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn external_link_trampoline<
            F: Fn(&View, &papers_document::LinkAction) + 'static,
        >(
            this: *mut ffi::PpsView,
            object: *mut papers_document::ffi::PpsLinkAction,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this), &from_glib_borrow(object))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"external-link".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    external_link_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn emit_external_link(&self, object: &papers_document::LinkAction) {
        self.emit_by_name::<()>("external-link", &[&object]);
    }

    #[doc(alias = "handle-link")]
    pub fn connect_handle_link<F: Fn(&Self, &glib::Object, &glib::Object) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn handle_link_trampoline<
            F: Fn(&View, &glib::Object, &glib::Object) + 'static,
        >(
            this: *mut ffi::PpsView,
            object: *mut glib::gobject_ffi::GObject,
            p0: *mut glib::gobject_ffi::GObject,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(
                    &from_glib_borrow(this),
                    &from_glib_borrow(object),
                    &from_glib_borrow(p0),
                )
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"handle-link".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    handle_link_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn emit_handle_link(&self, object: &glib::Object, p0: &glib::Object) {
        self.emit_by_name::<()>("handle-link", &[&object, &p0]);
    }

    #[doc(alias = "layers-changed")]
    pub fn connect_layers_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn layers_changed_trampoline<F: Fn(&View) + 'static>(
            this: *mut ffi::PpsView,
            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"layers-changed".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    layers_changed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn emit_layers_changed(&self) {
        self.emit_by_name::<()>("layers-changed", &[]);
    }

    #[doc(alias = "move-cursor")]
    pub fn connect_move_cursor<F: Fn(&Self, gtk::MovementStep, i32, bool) -> bool + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn move_cursor_trampoline<
            F: Fn(&View, gtk::MovementStep, i32, bool) -> bool + 'static,
        >(
            this: *mut ffi::PpsView,
            object: gtk::ffi::GtkMovementStep,
            p0: std::ffi::c_int,
            p1: glib::ffi::gboolean,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            unsafe {
                let f: &F = &*(f as *const F);
                f(
                    &from_glib_borrow(this),
                    from_glib(object),
                    p0,
                    from_glib(p1),
                )
                .into_glib()
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"move-cursor".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    move_cursor_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn emit_move_cursor(&self, object: gtk::MovementStep, p0: i32, p1: bool) -> bool {
        self.emit_by_name("move-cursor", &[&object, &p0, &p1])
    }

    #[doc(alias = "scroll")]
    pub fn connect_scroll<F: Fn(&Self, gtk::ScrollType, gtk::Orientation) -> bool + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn scroll_trampoline<
            F: Fn(&View, gtk::ScrollType, gtk::Orientation) -> bool + 'static,
        >(
            this: *mut ffi::PpsView,
            object: gtk::ffi::GtkScrollType,
            p0: gtk::ffi::GtkOrientation,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this), from_glib(object), from_glib(p0)).into_glib()
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"scroll".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    scroll_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn emit_scroll(&self, object: gtk::ScrollType, p0: gtk::Orientation) -> bool {
        self.emit_by_name("scroll", &[&object, &p0])
    }

    #[doc(alias = "selection-changed")]
    pub fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn selection_changed_trampoline<F: Fn(&View) + 'static>(
            this: *mut ffi::PpsView,
            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"selection-changed".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    selection_changed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    pub fn emit_selection_changed(&self) {
        self.emit_by_name::<()>("selection-changed", &[]);
    }

    //#[doc(alias = "signature-rect")]
    //pub fn connect_signature_rect<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
    //    Ignored p0: PapersDocument.Rectangle
    //}

    #[doc(alias = "can-zoom-in")]
    pub fn connect_can_zoom_in_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_can_zoom_in_trampoline<F: Fn(&View) + 'static>(
            this: *mut ffi::PpsView,
            _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::can-zoom-in".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_can_zoom_in_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "can-zoom-out")]
    pub fn connect_can_zoom_out_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_can_zoom_out_trampoline<F: Fn(&View) + 'static>(
            this: *mut ffi::PpsView,
            _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::can-zoom-out".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_can_zoom_out_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for View {
    fn default() -> Self {
        Self::new()
    }
}
