gtk4/
shortcuts_section.rs
1use std::mem::transmute;
4
5use glib::{
6 signal::{connect_raw, SignalHandlerId},
7 translate::*,
8};
9
10use crate::{ffi, prelude::*, ShortcutsSection};
11
12impl ShortcutsSection {
13 pub fn connect_change_current_page<F: Fn(&ShortcutsSection, i32) -> bool + 'static>(
30 &self,
31 f: F,
32 ) -> SignalHandlerId {
33 unsafe {
34 unsafe extern "C" fn change_current_page_trampoline<
35 F: Fn(&ShortcutsSection, i32) -> bool + 'static,
36 >(
37 this: *mut ffi::GtkShortcutsSection,
38 object: libc::c_int,
39 f: glib::ffi::gpointer,
40 ) -> glib::ffi::gboolean {
41 let f: &F = &*(f as *const F);
42 f(&from_glib_borrow(this), object).into_glib()
43 }
44 let f = Box::new(f);
45 connect_raw(
46 self.as_ptr() as *mut _,
47 b"change-current-page\0".as_ptr() as *const _,
48 Some(transmute::<usize, unsafe extern "C" fn()>(
49 change_current_page_trampoline::<F> as usize,
50 )),
51 Box::into_raw(f),
52 )
53 }
54 }
55
56 pub fn emit_change_current_page(&self, object: i32) -> bool {
57 self.emit_by_name("change-current-page", &[&object])
58 }
59}