gtk4/
shortcuts_section.rs1use std::mem::transmute;
4
5use glib::{
6 signal::{SignalHandlerId, connect_raw},
7 translate::*,
8};
9
10use crate::{ShortcutsSection, ffi, prelude::*};
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 unsafe {
42 let f: &F = &*(f as *const F);
43 f(&from_glib_borrow(this), object).into_glib()
44 }
45 }
46 let f = Box::new(f);
47 connect_raw(
48 self.as_ptr() as *mut _,
49 c"change-current-page".as_ptr() as *const _,
50 Some(transmute::<*const (), unsafe extern "C" fn()>(
51 change_current_page_trampoline::<F> as *const (),
52 )),
53 Box::into_raw(f),
54 )
55 }
56 }
57
58 pub fn emit_change_current_page(&self, object: i32) -> bool {
59 self.emit_by_name("change-current-page", &[&object])
60 }
61}