gtk4/
shortcuts_section.rs1use 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>(
15 &self,
16 f: F,
17 ) -> SignalHandlerId {
18 unsafe {
19 unsafe extern "C" fn change_current_page_trampoline<
20 F: Fn(&ShortcutsSection, i32) -> bool + 'static,
21 >(
22 this: *mut ffi::GtkShortcutsSection,
23 object: libc::c_int,
24 f: glib::ffi::gpointer,
25 ) -> glib::ffi::gboolean {
26 let f: &F = &*(f as *const F);
27 f(&from_glib_borrow(this), object).into_glib()
28 }
29 let f = Box::new(f);
30 connect_raw(
31 self.as_ptr() as *mut _,
32 c"change-current-page".as_ptr() as *const _,
33 Some(transmute::<usize, unsafe extern "C" fn()>(
34 change_current_page_trampoline::<F> as usize,
35 )),
36 Box::into_raw(f),
37 )
38 }
39 }
40
41 pub fn emit_change_current_page(&self, object: i32) -> bool {
42 self.emit_by_name("change-current-page", &[&object])
43 }
44}