gtk4/
shortcuts_section.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::mem::transmute;
4
5use glib::{
6    signal::{connect_raw, SignalHandlerId},
7    translate::*,
8};
9
10use crate::{ffi, prelude::*, ShortcutsSection};
11
12impl ShortcutsSection {
13    // todo: figure out what the bool return value here corresponds to
14    /// Emitted when we change the current page.
15    ///
16    /// The default bindings for this signal are
17    /// <kbd>Ctrl</kbd>+<kbd>PgUp</kbd>, <kbd>PgUp</kbd>,
18    /// <kbd>Ctrl</kbd>+<kbd>PgDn</kbd>, <kbd>PgDn</kbd>.
19    ///
20    /// # Deprecated since 4.18
21    ///
22    /// This widget will be removed in GTK 5
23    /// ## `offset`
24    /// the offset
25    ///
26    /// # Returns
27    ///
28    /// whether the page was changed
29    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}