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

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

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

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

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::GutterRenderer>> Sealed for T {}
}

pub trait GutterRendererExt: IsA<GutterRenderer> + sealed::Sealed + 'static {
    #[doc(alias = "gtk_source_gutter_renderer_activate")]
    fn activate(
        &self,
        iter: &gtk::TextIter,
        area: &gdk::Rectangle,
        button: u32,
        state: gdk::ModifierType,
        n_presses: i32,
    ) {
        unsafe {
            ffi::gtk_source_gutter_renderer_activate(
                self.as_ref().to_glib_none().0,
                iter.to_glib_none().0,
                area.to_glib_none().0,
                button,
                state.into_glib(),
                n_presses,
            );
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_align_cell")]
    fn align_cell(&self, line: u32, width: f32, height: f32) -> (f32, f32) {
        unsafe {
            let mut x = std::mem::MaybeUninit::uninit();
            let mut y = std::mem::MaybeUninit::uninit();
            ffi::gtk_source_gutter_renderer_align_cell(
                self.as_ref().to_glib_none().0,
                line,
                width,
                height,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
            );
            (x.assume_init(), y.assume_init())
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_get_alignment_mode")]
    #[doc(alias = "get_alignment_mode")]
    #[doc(alias = "alignment-mode")]
    fn alignment_mode(&self) -> GutterRendererAlignmentMode {
        unsafe {
            from_glib(ffi::gtk_source_gutter_renderer_get_alignment_mode(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_get_buffer")]
    #[doc(alias = "get_buffer")]
    fn buffer(&self) -> Option<Buffer> {
        unsafe {
            from_glib_none(ffi::gtk_source_gutter_renderer_get_buffer(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_get_view")]
    #[doc(alias = "get_view")]
    fn view(&self) -> View {
        unsafe {
            from_glib_none(ffi::gtk_source_gutter_renderer_get_view(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_get_xalign")]
    #[doc(alias = "get_xalign")]
    fn xalign(&self) -> f32 {
        unsafe { ffi::gtk_source_gutter_renderer_get_xalign(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "gtk_source_gutter_renderer_get_xpad")]
    #[doc(alias = "get_xpad")]
    fn xpad(&self) -> i32 {
        unsafe { ffi::gtk_source_gutter_renderer_get_xpad(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "gtk_source_gutter_renderer_get_yalign")]
    #[doc(alias = "get_yalign")]
    fn yalign(&self) -> f32 {
        unsafe { ffi::gtk_source_gutter_renderer_get_yalign(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "gtk_source_gutter_renderer_get_ypad")]
    #[doc(alias = "get_ypad")]
    fn ypad(&self) -> i32 {
        unsafe { ffi::gtk_source_gutter_renderer_get_ypad(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "gtk_source_gutter_renderer_query_activatable")]
    fn query_activatable(&self, iter: &gtk::TextIter, area: &gdk::Rectangle) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_gutter_renderer_query_activatable(
                self.as_ref().to_glib_none().0,
                iter.to_glib_none().0,
                area.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_set_alignment_mode")]
    #[doc(alias = "alignment-mode")]
    fn set_alignment_mode(&self, mode: GutterRendererAlignmentMode) {
        unsafe {
            ffi::gtk_source_gutter_renderer_set_alignment_mode(
                self.as_ref().to_glib_none().0,
                mode.into_glib(),
            );
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_set_xalign")]
    #[doc(alias = "xalign")]
    fn set_xalign(&self, xalign: f32) {
        unsafe {
            ffi::gtk_source_gutter_renderer_set_xalign(self.as_ref().to_glib_none().0, xalign);
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_set_xpad")]
    #[doc(alias = "xpad")]
    fn set_xpad(&self, xpad: i32) {
        unsafe {
            ffi::gtk_source_gutter_renderer_set_xpad(self.as_ref().to_glib_none().0, xpad);
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_set_yalign")]
    #[doc(alias = "yalign")]
    fn set_yalign(&self, yalign: f32) {
        unsafe {
            ffi::gtk_source_gutter_renderer_set_yalign(self.as_ref().to_glib_none().0, yalign);
        }
    }

    #[doc(alias = "gtk_source_gutter_renderer_set_ypad")]
    #[doc(alias = "ypad")]
    fn set_ypad(&self, ypad: i32) {
        unsafe {
            ffi::gtk_source_gutter_renderer_set_ypad(self.as_ref().to_glib_none().0, ypad);
        }
    }

    fn lines(&self) -> Option<GutterLines> {
        ObjectExt::property(self.as_ref(), "lines")
    }

    #[doc(alias = "activate")]
    fn connect_activate<
        F: Fn(&Self, &gtk::TextIter, &gdk::Rectangle, u32, gdk::ModifierType, i32) + 'static,
    >(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn activate_trampoline<
            P: IsA<GutterRenderer>,
            F: Fn(&P, &gtk::TextIter, &gdk::Rectangle, u32, gdk::ModifierType, i32) + 'static,
        >(
            this: *mut ffi::GtkSourceGutterRenderer,
            iter: *mut gtk::ffi::GtkTextIter,
            area: *mut gdk::ffi::GdkRectangle,
            button: libc::c_uint,
            state: gdk::ffi::GdkModifierType,
            n_presses: libc::c_int,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                GutterRenderer::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(iter),
                &from_glib_borrow(area),
                button,
                from_glib(state),
                n_presses,
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"activate\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    activate_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "query-activatable")]
    fn connect_query_activatable<
        F: Fn(&Self, &gtk::TextIter, &gdk::Rectangle) -> bool + 'static,
    >(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn query_activatable_trampoline<
            P: IsA<GutterRenderer>,
            F: Fn(&P, &gtk::TextIter, &gdk::Rectangle) -> bool + 'static,
        >(
            this: *mut ffi::GtkSourceGutterRenderer,
            iter: *mut gtk::ffi::GtkTextIter,
            area: *mut gdk::ffi::GdkRectangle,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let f: &F = &*(f as *const F);
            f(
                GutterRenderer::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(iter),
                &from_glib_borrow(area),
            )
            .into_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"query-activatable\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    query_activatable_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "query-data")]
    fn connect_query_data<F: Fn(&Self, &glib::Object, u32) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn query_data_trampoline<
            P: IsA<GutterRenderer>,
            F: Fn(&P, &glib::Object, u32) + 'static,
        >(
            this: *mut ffi::GtkSourceGutterRenderer,
            object: *mut glib::gobject_ffi::GObject,
            p0: libc::c_uint,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                GutterRenderer::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(object),
                p0,
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"query-data\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    query_data_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "alignment-mode")]
    fn connect_alignment_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_alignment_mode_trampoline<
            P: IsA<GutterRenderer>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkSourceGutterRenderer,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GutterRenderer::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::alignment-mode\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_alignment_mode_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "lines")]
    fn connect_lines_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_lines_trampoline<
            P: IsA<GutterRenderer>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkSourceGutterRenderer,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GutterRenderer::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::lines\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_lines_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "view")]
    fn connect_view_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_view_trampoline<P: IsA<GutterRenderer>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkSourceGutterRenderer,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GutterRenderer::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::view\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_view_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "xalign")]
    fn connect_xalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_xalign_trampoline<
            P: IsA<GutterRenderer>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkSourceGutterRenderer,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GutterRenderer::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::xalign\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_xalign_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "xpad")]
    fn connect_xpad_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_xpad_trampoline<P: IsA<GutterRenderer>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkSourceGutterRenderer,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GutterRenderer::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::xpad\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_xpad_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "yalign")]
    fn connect_yalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_yalign_trampoline<
            P: IsA<GutterRenderer>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkSourceGutterRenderer,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GutterRenderer::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::yalign\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_yalign_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "ypad")]
    fn connect_ypad_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_ypad_trampoline<P: IsA<GutterRenderer>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkSourceGutterRenderer,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GutterRenderer::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::ypad\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_ypad_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<GutterRenderer>> GutterRendererExt for O {}
