gtk4/auto/
text_tag_table.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Buildable, TextTag};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GtkTextTagTable")]
16    pub struct TextTagTable(Object<ffi::GtkTextTagTable>) @implements Buildable;
17
18    match fn {
19        type_ => || ffi::gtk_text_tag_table_get_type(),
20    }
21}
22
23impl TextTagTable {
24    #[doc(alias = "gtk_text_tag_table_new")]
25    pub fn new() -> TextTagTable {
26        assert_initialized_main_thread!();
27        unsafe { from_glib_full(ffi::gtk_text_tag_table_new()) }
28    }
29
30    #[doc(alias = "gtk_text_tag_table_add")]
31    pub fn add(&self, tag: &impl IsA<TextTag>) -> bool {
32        unsafe {
33            from_glib(ffi::gtk_text_tag_table_add(
34                self.to_glib_none().0,
35                tag.as_ref().to_glib_none().0,
36            ))
37        }
38    }
39
40    #[doc(alias = "gtk_text_tag_table_foreach")]
41    pub fn foreach<P: FnMut(&TextTag)>(&self, func: P) {
42        let mut func_data: P = func;
43        unsafe extern "C" fn func_func<P: FnMut(&TextTag)>(
44            tag: *mut ffi::GtkTextTag,
45            data: glib::ffi::gpointer,
46        ) {
47            let tag = from_glib_borrow(tag);
48            let callback = data as *mut P;
49            (*callback)(&tag)
50        }
51        let func = Some(func_func::<P> as _);
52        let super_callback0: &mut P = &mut func_data;
53        unsafe {
54            ffi::gtk_text_tag_table_foreach(
55                self.to_glib_none().0,
56                func,
57                super_callback0 as *mut _ as *mut _,
58            );
59        }
60    }
61
62    #[doc(alias = "gtk_text_tag_table_get_size")]
63    #[doc(alias = "get_size")]
64    pub fn size(&self) -> i32 {
65        unsafe { ffi::gtk_text_tag_table_get_size(self.to_glib_none().0) }
66    }
67
68    #[doc(alias = "gtk_text_tag_table_lookup")]
69    pub fn lookup(&self, name: &str) -> Option<TextTag> {
70        unsafe {
71            from_glib_none(ffi::gtk_text_tag_table_lookup(
72                self.to_glib_none().0,
73                name.to_glib_none().0,
74            ))
75        }
76    }
77
78    #[doc(alias = "gtk_text_tag_table_remove")]
79    pub fn remove(&self, tag: &impl IsA<TextTag>) {
80        unsafe {
81            ffi::gtk_text_tag_table_remove(self.to_glib_none().0, tag.as_ref().to_glib_none().0);
82        }
83    }
84
85    #[doc(alias = "tag-added")]
86    pub fn connect_tag_added<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId {
87        unsafe extern "C" fn tag_added_trampoline<F: Fn(&TextTagTable, &TextTag) + 'static>(
88            this: *mut ffi::GtkTextTagTable,
89            tag: *mut ffi::GtkTextTag,
90            f: glib::ffi::gpointer,
91        ) {
92            let f: &F = &*(f as *const F);
93            f(&from_glib_borrow(this), &from_glib_borrow(tag))
94        }
95        unsafe {
96            let f: Box_<F> = Box_::new(f);
97            connect_raw(
98                self.as_ptr() as *mut _,
99                c"tag-added".as_ptr() as *const _,
100                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
101                    tag_added_trampoline::<F> as *const (),
102                )),
103                Box_::into_raw(f),
104            )
105        }
106    }
107
108    #[doc(alias = "tag-changed")]
109    pub fn connect_tag_changed<F: Fn(&Self, &TextTag, bool) + 'static>(
110        &self,
111        f: F,
112    ) -> SignalHandlerId {
113        unsafe extern "C" fn tag_changed_trampoline<
114            F: Fn(&TextTagTable, &TextTag, bool) + 'static,
115        >(
116            this: *mut ffi::GtkTextTagTable,
117            tag: *mut ffi::GtkTextTag,
118            size_changed: glib::ffi::gboolean,
119            f: glib::ffi::gpointer,
120        ) {
121            let f: &F = &*(f as *const F);
122            f(
123                &from_glib_borrow(this),
124                &from_glib_borrow(tag),
125                from_glib(size_changed),
126            )
127        }
128        unsafe {
129            let f: Box_<F> = Box_::new(f);
130            connect_raw(
131                self.as_ptr() as *mut _,
132                c"tag-changed".as_ptr() as *const _,
133                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
134                    tag_changed_trampoline::<F> as *const (),
135                )),
136                Box_::into_raw(f),
137            )
138        }
139    }
140
141    #[doc(alias = "tag-removed")]
142    pub fn connect_tag_removed<F: Fn(&Self, &TextTag) + 'static>(&self, f: F) -> SignalHandlerId {
143        unsafe extern "C" fn tag_removed_trampoline<F: Fn(&TextTagTable, &TextTag) + 'static>(
144            this: *mut ffi::GtkTextTagTable,
145            tag: *mut ffi::GtkTextTag,
146            f: glib::ffi::gpointer,
147        ) {
148            let f: &F = &*(f as *const F);
149            f(&from_glib_borrow(this), &from_glib_borrow(tag))
150        }
151        unsafe {
152            let f: Box_<F> = Box_::new(f);
153            connect_raw(
154                self.as_ptr() as *mut _,
155                c"tag-removed".as_ptr() as *const _,
156                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
157                    tag_removed_trampoline::<F> as *const (),
158                )),
159                Box_::into_raw(f),
160            )
161        }
162    }
163}
164
165impl Default for TextTagTable {
166    fn default() -> Self {
167        Self::new()
168    }
169}