gtk4/auto/
shortcut_controller.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Buildable, EventController, Shortcut, ShortcutScope};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "GtkShortcutController")]
15    pub struct ShortcutController(Object<ffi::GtkShortcutController, ffi::GtkShortcutControllerClass>) @extends EventController, @implements gio::ListModel, Buildable;
16
17    match fn {
18        type_ => || ffi::gtk_shortcut_controller_get_type(),
19    }
20}
21
22impl ShortcutController {
23    #[doc(alias = "gtk_shortcut_controller_new")]
24    pub fn new() -> ShortcutController {
25        assert_initialized_main_thread!();
26        unsafe { EventController::from_glib_full(ffi::gtk_shortcut_controller_new()).unsafe_cast() }
27    }
28
29    #[doc(alias = "gtk_shortcut_controller_new_for_model")]
30    #[doc(alias = "new_for_model")]
31    pub fn for_model(model: &impl IsA<gio::ListModel>) -> ShortcutController {
32        assert_initialized_main_thread!();
33        unsafe {
34            EventController::from_glib_full(ffi::gtk_shortcut_controller_new_for_model(
35                model.as_ref().to_glib_none().0,
36            ))
37            .unsafe_cast()
38        }
39    }
40
41    #[doc(alias = "gtk_shortcut_controller_add_shortcut")]
42    pub fn add_shortcut(&self, shortcut: Shortcut) {
43        unsafe {
44            ffi::gtk_shortcut_controller_add_shortcut(
45                self.to_glib_none().0,
46                shortcut.into_glib_ptr(),
47            );
48        }
49    }
50
51    #[doc(alias = "gtk_shortcut_controller_get_mnemonics_modifiers")]
52    #[doc(alias = "get_mnemonics_modifiers")]
53    #[doc(alias = "mnemonic-modifiers")]
54    pub fn mnemonics_modifiers(&self) -> gdk::ModifierType {
55        unsafe {
56            from_glib(ffi::gtk_shortcut_controller_get_mnemonics_modifiers(
57                self.to_glib_none().0,
58            ))
59        }
60    }
61
62    #[doc(alias = "gtk_shortcut_controller_get_scope")]
63    #[doc(alias = "get_scope")]
64    pub fn scope(&self) -> ShortcutScope {
65        unsafe {
66            from_glib(ffi::gtk_shortcut_controller_get_scope(
67                self.to_glib_none().0,
68            ))
69        }
70    }
71
72    #[doc(alias = "gtk_shortcut_controller_remove_shortcut")]
73    pub fn remove_shortcut(&self, shortcut: &Shortcut) {
74        unsafe {
75            ffi::gtk_shortcut_controller_remove_shortcut(
76                self.to_glib_none().0,
77                shortcut.to_glib_none().0,
78            );
79        }
80    }
81
82    #[doc(alias = "gtk_shortcut_controller_set_mnemonics_modifiers")]
83    #[doc(alias = "mnemonic-modifiers")]
84    pub fn set_mnemonics_modifiers(&self, modifiers: gdk::ModifierType) {
85        unsafe {
86            ffi::gtk_shortcut_controller_set_mnemonics_modifiers(
87                self.to_glib_none().0,
88                modifiers.into_glib(),
89            );
90        }
91    }
92
93    #[doc(alias = "gtk_shortcut_controller_set_scope")]
94    #[doc(alias = "scope")]
95    pub fn set_scope(&self, scope: ShortcutScope) {
96        unsafe {
97            ffi::gtk_shortcut_controller_set_scope(self.to_glib_none().0, scope.into_glib());
98        }
99    }
100
101    #[doc(alias = "mnemonic-modifiers")]
102    pub fn connect_mnemonic_modifiers_notify<F: Fn(&Self) + 'static>(
103        &self,
104        f: F,
105    ) -> SignalHandlerId {
106        unsafe extern "C" fn notify_mnemonic_modifiers_trampoline<
107            F: Fn(&ShortcutController) + 'static,
108        >(
109            this: *mut ffi::GtkShortcutController,
110            _param_spec: glib::ffi::gpointer,
111            f: glib::ffi::gpointer,
112        ) {
113            let f: &F = &*(f as *const F);
114            f(&from_glib_borrow(this))
115        }
116        unsafe {
117            let f: Box_<F> = Box_::new(f);
118            connect_raw(
119                self.as_ptr() as *mut _,
120                c"notify::mnemonic-modifiers".as_ptr() as *const _,
121                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
122                    notify_mnemonic_modifiers_trampoline::<F> as *const (),
123                )),
124                Box_::into_raw(f),
125            )
126        }
127    }
128
129    #[doc(alias = "scope")]
130    pub fn connect_scope_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
131        unsafe extern "C" fn notify_scope_trampoline<F: Fn(&ShortcutController) + 'static>(
132            this: *mut ffi::GtkShortcutController,
133            _param_spec: glib::ffi::gpointer,
134            f: glib::ffi::gpointer,
135        ) {
136            let f: &F = &*(f as *const F);
137            f(&from_glib_borrow(this))
138        }
139        unsafe {
140            let f: Box_<F> = Box_::new(f);
141            connect_raw(
142                self.as_ptr() as *mut _,
143                c"notify::scope".as_ptr() as *const _,
144                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
145                    notify_scope_trampoline::<F> as *const (),
146                )),
147                Box_::into_raw(f),
148            )
149        }
150    }
151}
152
153impl Default for ShortcutController {
154    fn default() -> Self {
155        Self::new()
156    }
157}