gtk4/auto/
signal_list_item_factory.rs1use crate::{ffi, ListItemFactory};
6#[cfg(feature = "v4_8")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
8use glib::{
9 object::ObjectType as _,
10 signal::{connect_raw, SignalHandlerId},
11};
12use glib::{prelude::*, translate::*};
13#[cfg(feature = "v4_8")]
14#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GtkSignalListItemFactory")]
19 pub struct SignalListItemFactory(Object<ffi::GtkSignalListItemFactory, ffi::GtkSignalListItemFactoryClass>) @extends ListItemFactory;
20
21 match fn {
22 type_ => || ffi::gtk_signal_list_item_factory_get_type(),
23 }
24}
25
26impl SignalListItemFactory {
27 #[doc(alias = "gtk_signal_list_item_factory_new")]
28 pub fn new() -> SignalListItemFactory {
29 assert_initialized_main_thread!();
30 unsafe {
31 ListItemFactory::from_glib_full(ffi::gtk_signal_list_item_factory_new()).unsafe_cast()
32 }
33 }
34
35 #[cfg(feature = "v4_8")]
36 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
37 #[doc(alias = "bind")]
38 pub fn connect_bind<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
39 unsafe extern "C" fn bind_trampoline<
40 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
41 >(
42 this: *mut ffi::GtkSignalListItemFactory,
43 object: *mut glib::gobject_ffi::GObject,
44 f: glib::ffi::gpointer,
45 ) {
46 let f: &F = &*(f as *const F);
47 f(&from_glib_borrow(this), &from_glib_borrow(object))
48 }
49 unsafe {
50 let f: Box_<F> = Box_::new(f);
51 connect_raw(
52 self.as_ptr() as *mut _,
53 c"bind".as_ptr() as *const _,
54 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
55 bind_trampoline::<F> as *const (),
56 )),
57 Box_::into_raw(f),
58 )
59 }
60 }
61
62 #[cfg(feature = "v4_8")]
63 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
64 #[doc(alias = "setup")]
65 pub fn connect_setup<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
66 unsafe extern "C" fn setup_trampoline<
67 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
68 >(
69 this: *mut ffi::GtkSignalListItemFactory,
70 object: *mut glib::gobject_ffi::GObject,
71 f: glib::ffi::gpointer,
72 ) {
73 let f: &F = &*(f as *const F);
74 f(&from_glib_borrow(this), &from_glib_borrow(object))
75 }
76 unsafe {
77 let f: Box_<F> = Box_::new(f);
78 connect_raw(
79 self.as_ptr() as *mut _,
80 c"setup".as_ptr() as *const _,
81 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
82 setup_trampoline::<F> as *const (),
83 )),
84 Box_::into_raw(f),
85 )
86 }
87 }
88
89 #[cfg(feature = "v4_8")]
90 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
91 #[doc(alias = "teardown")]
92 pub fn connect_teardown<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
93 unsafe extern "C" fn teardown_trampoline<
94 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
95 >(
96 this: *mut ffi::GtkSignalListItemFactory,
97 object: *mut glib::gobject_ffi::GObject,
98 f: glib::ffi::gpointer,
99 ) {
100 let f: &F = &*(f as *const F);
101 f(&from_glib_borrow(this), &from_glib_borrow(object))
102 }
103 unsafe {
104 let f: Box_<F> = Box_::new(f);
105 connect_raw(
106 self.as_ptr() as *mut _,
107 c"teardown".as_ptr() as *const _,
108 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
109 teardown_trampoline::<F> as *const (),
110 )),
111 Box_::into_raw(f),
112 )
113 }
114 }
115
116 #[cfg(feature = "v4_8")]
117 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
118 #[doc(alias = "unbind")]
119 pub fn connect_unbind<F: Fn(&Self, &glib::Object) + 'static>(&self, f: F) -> SignalHandlerId {
120 unsafe extern "C" fn unbind_trampoline<
121 F: Fn(&SignalListItemFactory, &glib::Object) + 'static,
122 >(
123 this: *mut ffi::GtkSignalListItemFactory,
124 object: *mut glib::gobject_ffi::GObject,
125 f: glib::ffi::gpointer,
126 ) {
127 let f: &F = &*(f as *const F);
128 f(&from_glib_borrow(this), &from_glib_borrow(object))
129 }
130 unsafe {
131 let f: Box_<F> = Box_::new(f);
132 connect_raw(
133 self.as_ptr() as *mut _,
134 c"unbind".as_ptr() as *const _,
135 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
136 unbind_trampoline::<F> as *const (),
137 )),
138 Box_::into_raw(f),
139 )
140 }
141 }
142}
143
144impl Default for SignalListItemFactory {
145 fn default() -> Self {
146 Self::new()
147 }
148}