gtk4/shortcuts_section.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
// Take a look at the license at the top of the repository in the LICENSE file.
use std::mem::transmute;
use glib::{
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use crate::{ffi, prelude::*, ShortcutsSection};
impl ShortcutsSection {
// todo: figure out what the bool return value here corresponds to
/// Emitted when we change the current page.
///
/// The default bindings for this signal are
/// <kbd>Ctrl</kbd>+<kbd>PgUp</kbd>, <kbd>PgUp</kbd>,
/// <kbd>Ctrl</kbd>+<kbd>PgDn</kbd>, <kbd>PgDn</kbd>.
/// ## `offset`
/// the offset
///
/// # Returns
///
/// whether the page was changed
pub fn connect_change_current_page<F: Fn(&ShortcutsSection, i32) -> bool + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe {
unsafe extern "C" fn change_current_page_trampoline<
F: Fn(&ShortcutsSection, i32) -> bool + 'static,
>(
this: *mut ffi::GtkShortcutsSection,
object: libc::c_int,
f: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), object).into_glib()
}
let f = Box::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"change-current-page".as_ptr() as *const _,
Some(transmute::<usize, unsafe extern "C" fn()>(
change_current_page_trampoline::<F> as usize,
)),
Box::into_raw(f),
)
}
}
pub fn emit_change_current_page(&self, object: i32) -> bool {
self.emit_by_name("change-current-page", &[&object])
}
}