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