sourceview5 0.11.0

Rust bindings for GtkSourceView 5
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

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

glib::wrapper! {
    #[doc(alias = "GtkSourceAnnotation")]
    pub struct Annotation(Object<ffi::GtkSourceAnnotation, ffi::GtkSourceAnnotationClass>);

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

impl Annotation {
    #[doc(alias = "gtk_source_annotation_new")]
    pub fn new(
        description: Option<&str>,
        icon: Option<impl IsA<gio::Icon>>,
        line: i32,
        style: AnnotationStyle,
    ) -> Annotation {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_source_annotation_new(
                description.to_glib_none().0,
                icon.map(|p| p.upcast()).into_glib_ptr(),
                line,
                style.into_glib(),
            ))
        }
    }

    #[doc(alias = "gtk_source_annotation_get_description")]
    #[doc(alias = "get_description")]
    pub fn description(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::gtk_source_annotation_get_description(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_annotation_get_icon")]
    #[doc(alias = "get_icon")]
    pub fn icon(&self) -> Option<gio::Icon> {
        unsafe { from_glib_none(ffi::gtk_source_annotation_get_icon(self.to_glib_none().0)) }
    }

    #[doc(alias = "gtk_source_annotation_get_line")]
    #[doc(alias = "get_line")]
    pub fn line(&self) -> i32 {
        unsafe { ffi::gtk_source_annotation_get_line(self.to_glib_none().0) }
    }

    #[doc(alias = "gtk_source_annotation_get_style")]
    #[doc(alias = "get_style")]
    pub fn style(&self) -> AnnotationStyle {
        unsafe { from_glib(ffi::gtk_source_annotation_get_style(self.to_glib_none().0)) }
    }

    #[cfg(feature = "v5_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v5_18")))]
    #[doc(alias = "description")]
    pub fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_description_trampoline<F: Fn(&Annotation) + 'static>(
            this: *mut ffi::GtkSourceAnnotation,
            _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::description".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_description_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v5_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v5_18")))]
    #[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(&Annotation) + 'static>(
            this: *mut ffi::GtkSourceAnnotation,
            _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::icon".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_icon_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v5_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v5_18")))]
    #[doc(alias = "line")]
    pub fn connect_line_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_line_trampoline<F: Fn(&Annotation) + 'static>(
            this: *mut ffi::GtkSourceAnnotation,
            _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::line".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_line_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v5_18")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v5_18")))]
    #[doc(alias = "style")]
    pub fn connect_style_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_style_trampoline<F: Fn(&Annotation) + 'static>(
            this: *mut ffi::GtkSourceAnnotation,
            _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::style".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_style_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}