gtk4/
signal_list_item_factory.rs1#[cfg(not(feature = "v4_8"))]
4use std::{boxed::Box as Box_, mem::transmute};
5
6#[cfg(not(feature = "v4_8"))]
7use glib::{
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11
12use crate::SignalListItemFactory;
13#[cfg(not(feature = "v4_8"))]
14use crate::{ListItem, ffi, prelude::*};
15
16impl SignalListItemFactory {
17 #[doc(alias = "bind")]
18 #[cfg(not(feature = "v4_8"))]
19 pub fn connect_bind<F: Fn(&Self, &ListItem) + 'static>(&self, f: F) -> SignalHandlerId {
20 unsafe extern "C" fn bind_trampoline<F: Fn(&SignalListItemFactory, &ListItem) + 'static>(
21 this: *mut ffi::GtkSignalListItemFactory,
22 listitem: *mut ffi::GtkListItem,
23 f: glib::ffi::gpointer,
24 ) {
25 unsafe {
26 let f: &F = &*(f as *const F);
27 f(&from_glib_borrow(this), &from_glib_borrow(listitem))
28 }
29 }
30 unsafe {
31 let f: Box_<F> = Box_::new(f);
32 connect_raw(
33 self.as_ptr() as *mut _,
34 c"bind".as_ptr() as *const _,
35 Some(transmute::<*const (), unsafe extern "C" fn()>(
36 bind_trampoline::<F> as *const (),
37 )),
38 Box_::into_raw(f),
39 )
40 }
41 }
42
43 #[doc(alias = "setup")]
44 #[cfg(not(feature = "v4_8"))]
45 pub fn connect_setup<F: Fn(&Self, &ListItem) + 'static>(&self, f: F) -> SignalHandlerId {
46 unsafe extern "C" fn setup_trampoline<
47 F: Fn(&SignalListItemFactory, &ListItem) + 'static,
48 >(
49 this: *mut ffi::GtkSignalListItemFactory,
50 listitem: *mut ffi::GtkListItem,
51 f: glib::ffi::gpointer,
52 ) {
53 unsafe {
54 let f: &F = &*(f as *const F);
55 f(&from_glib_borrow(this), &from_glib_borrow(listitem))
56 }
57 }
58 unsafe {
59 let f: Box_<F> = Box_::new(f);
60 connect_raw(
61 self.as_ptr() as *mut _,
62 c"setup".as_ptr() as *const _,
63 Some(transmute::<*const (), unsafe extern "C" fn()>(
64 setup_trampoline::<F> as *const (),
65 )),
66 Box_::into_raw(f),
67 )
68 }
69 }
70
71 #[doc(alias = "teardown")]
72 #[cfg(not(feature = "v4_8"))]
73 pub fn connect_teardown<F: Fn(&Self, &ListItem) + 'static>(&self, f: F) -> SignalHandlerId {
74 unsafe extern "C" fn teardown_trampoline<
75 F: Fn(&SignalListItemFactory, &ListItem) + 'static,
76 >(
77 this: *mut ffi::GtkSignalListItemFactory,
78 listitem: *mut ffi::GtkListItem,
79 f: glib::ffi::gpointer,
80 ) {
81 unsafe {
82 let f: &F = &*(f as *const F);
83 f(&from_glib_borrow(this), &from_glib_borrow(listitem))
84 }
85 }
86 unsafe {
87 let f: Box_<F> = Box_::new(f);
88 connect_raw(
89 self.as_ptr() as *mut _,
90 c"teardown".as_ptr() as *const _,
91 Some(transmute::<*const (), unsafe extern "C" fn()>(
92 teardown_trampoline::<F> as *const (),
93 )),
94 Box_::into_raw(f),
95 )
96 }
97 }
98
99 #[doc(alias = "unbind")]
100 #[cfg(not(feature = "v4_8"))]
101 pub fn connect_unbind<F: Fn(&Self, &ListItem) + 'static>(&self, f: F) -> SignalHandlerId {
102 unsafe extern "C" fn unbind_trampoline<
103 F: Fn(&SignalListItemFactory, &ListItem) + 'static,
104 >(
105 this: *mut ffi::GtkSignalListItemFactory,
106 listitem: *mut ffi::GtkListItem,
107 f: glib::ffi::gpointer,
108 ) {
109 unsafe {
110 let f: &F = &*(f as *const F);
111 f(&from_glib_borrow(this), &from_glib_borrow(listitem))
112 }
113 }
114 unsafe {
115 let f: Box_<F> = Box_::new(f);
116 connect_raw(
117 self.as_ptr() as *mut _,
118 c"unbind".as_ptr() as *const _,
119 Some(transmute::<*const (), unsafe extern "C" fn()>(
120 unbind_trampoline::<F> as *const (),
121 )),
122 Box_::into_raw(f),
123 )
124 }
125 }
126}