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    /// .
15    ///
16    /// # Deprecated since 4.18
17    ///
18    /// This widget will be removed in GTK 5
19    /// ## `offset`
20    /// the offset
21    ///
22    /// # Returns
23    ///
24    /// whether the page was changed
25    pub fn connect_change_current_page<F: Fn(&ShortcutsSection, i32) -> bool + 'static>(
26        &self,
27        f: F,
28    ) -> SignalHandlerId {
29        unsafe {
30            unsafe extern "C" fn change_current_page_trampoline<
31                F: Fn(&ShortcutsSection, i32) -> bool + 'static,
32            >(
33                this: *mut ffi::GtkShortcutsSection,
34                object: libc::c_int,
35                f: glib::ffi::gpointer,
36            ) -> glib::ffi::gboolean {
37                unsafe {
38                    let f: &F = &*(f as *const F);
39                    f(&from_glib_borrow(this), object).into_glib()
40                }
41            }
42            let f = Box::new(f);
43            connect_raw(
44                self.as_ptr() as *mut _,
45                c"change-current-page".as_ptr() as *const _,
46                Some(transmute::<*const (), unsafe extern "C" fn()>(
47                    change_current_page_trampoline::<F> as *const (),
48                )),
49                Box::into_raw(f),
50            )
51        }
52    }
53
54    pub fn emit_change_current_page(&self, object: i32) -> bool {
55        self.emit_by_name("change-current-page", &[&object])
56    }
57}