Skip to main content

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::{SignalHandlerId, connect_raw},
7    translate::*,
8};
9
10use crate::{ShortcutsSection, ffi, prelude::*};
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                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}