[go: up one dir, main page]

gtk4/auto/
shortcut.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, ShortcutAction, ShortcutTrigger};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "GtkShortcut")]
15    pub struct Shortcut(Object<ffi::GtkShortcut, ffi::GtkShortcutClass>);
16
17    match fn {
18        type_ => || ffi::gtk_shortcut_get_type(),
19    }
20}
21
22impl Shortcut {
23    #[doc(alias = "gtk_shortcut_new")]
24    pub fn new(
25        trigger: Option<impl IsA<ShortcutTrigger>>,
26        action: Option<impl IsA<ShortcutAction>>,
27    ) -> Shortcut {
28        assert_initialized_main_thread!();
29        unsafe {
30            from_glib_full(ffi::gtk_shortcut_new(
31                trigger.map(|p| p.upcast()).into_glib_ptr(),
32                action.map(|p| p.upcast()).into_glib_ptr(),
33            ))
34        }
35    }
36
37    // rustdoc-stripper-ignore-next
38    /// Creates a new builder-pattern struct instance to construct [`Shortcut`] objects.
39    ///
40    /// This method returns an instance of [`ShortcutBuilder`](crate::builders::ShortcutBuilder) which can be used to create [`Shortcut`] objects.
41    pub fn builder() -> ShortcutBuilder {
42        ShortcutBuilder::new()
43    }
44
45    #[doc(alias = "gtk_shortcut_get_action")]
46    #[doc(alias = "get_action")]
47    pub fn action(&self) -> Option<ShortcutAction> {
48        unsafe { from_glib_none(ffi::gtk_shortcut_get_action(self.to_glib_none().0)) }
49    }
50
51    #[doc(alias = "gtk_shortcut_get_arguments")]
52    #[doc(alias = "get_arguments")]
53    pub fn arguments(&self) -> Option<glib::Variant> {
54        unsafe { from_glib_none(ffi::gtk_shortcut_get_arguments(self.to_glib_none().0)) }
55    }
56
57    #[doc(alias = "gtk_shortcut_get_trigger")]
58    #[doc(alias = "get_trigger")]
59    pub fn trigger(&self) -> Option<ShortcutTrigger> {
60        unsafe { from_glib_none(ffi::gtk_shortcut_get_trigger(self.to_glib_none().0)) }
61    }
62
63    #[doc(alias = "gtk_shortcut_set_action")]
64    #[doc(alias = "action")]
65    pub fn set_action(&self, action: Option<impl IsA<ShortcutAction>>) {
66        unsafe {
67            ffi::gtk_shortcut_set_action(
68                self.to_glib_none().0,
69                action.map(|p| p.upcast()).into_glib_ptr(),
70            );
71        }
72    }
73
74    #[doc(alias = "gtk_shortcut_set_arguments")]
75    #[doc(alias = "arguments")]
76    pub fn set_arguments(&self, args: Option<&glib::Variant>) {
77        unsafe {
78            ffi::gtk_shortcut_set_arguments(self.to_glib_none().0, args.to_glib_none().0);
79        }
80    }
81
82    #[doc(alias = "gtk_shortcut_set_trigger")]
83    #[doc(alias = "trigger")]
84    pub fn set_trigger(&self, trigger: Option<impl IsA<ShortcutTrigger>>) {
85        unsafe {
86            ffi::gtk_shortcut_set_trigger(
87                self.to_glib_none().0,
88                trigger.map(|p| p.upcast()).into_glib_ptr(),
89            );
90        }
91    }
92
93    #[doc(alias = "action")]
94    pub fn connect_action_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
95        unsafe extern "C" fn notify_action_trampoline<F: Fn(&Shortcut) + 'static>(
96            this: *mut ffi::GtkShortcut,
97            _param_spec: glib::ffi::gpointer,
98            f: glib::ffi::gpointer,
99        ) {
100            let f: &F = &*(f as *const F);
101            f(&from_glib_borrow(this))
102        }
103        unsafe {
104            let f: Box_<F> = Box_::new(f);
105            connect_raw(
106                self.as_ptr() as *mut _,
107                c"notify::action".as_ptr() as *const _,
108                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
109                    notify_action_trampoline::<F> as *const (),
110                )),
111                Box_::into_raw(f),
112            )
113        }
114    }
115
116    #[doc(alias = "arguments")]
117    pub fn connect_arguments_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
118        unsafe extern "C" fn notify_arguments_trampoline<F: Fn(&Shortcut) + 'static>(
119            this: *mut ffi::GtkShortcut,
120            _param_spec: glib::ffi::gpointer,
121            f: glib::ffi::gpointer,
122        ) {
123            let f: &F = &*(f as *const F);
124            f(&from_glib_borrow(this))
125        }
126        unsafe {
127            let f: Box_<F> = Box_::new(f);
128            connect_raw(
129                self.as_ptr() as *mut _,
130                c"notify::arguments".as_ptr() as *const _,
131                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
132                    notify_arguments_trampoline::<F> as *const (),
133                )),
134                Box_::into_raw(f),
135            )
136        }
137    }
138
139    #[doc(alias = "trigger")]
140    pub fn connect_trigger_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
141        unsafe extern "C" fn notify_trigger_trampoline<F: Fn(&Shortcut) + 'static>(
142            this: *mut ffi::GtkShortcut,
143            _param_spec: glib::ffi::gpointer,
144            f: glib::ffi::gpointer,
145        ) {
146            let f: &F = &*(f as *const F);
147            f(&from_glib_borrow(this))
148        }
149        unsafe {
150            let f: Box_<F> = Box_::new(f);
151            connect_raw(
152                self.as_ptr() as *mut _,
153                c"notify::trigger".as_ptr() as *const _,
154                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
155                    notify_trigger_trampoline::<F> as *const (),
156                )),
157                Box_::into_raw(f),
158            )
159        }
160    }
161}
162
163impl Default for Shortcut {
164    fn default() -> Self {
165        glib::object::Object::new::<Self>()
166    }
167}
168
169// rustdoc-stripper-ignore-next
170/// A [builder-pattern] type to construct [`Shortcut`] objects.
171///
172/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
173#[must_use = "The builder must be built to be used"]
174pub struct ShortcutBuilder {
175    builder: glib::object::ObjectBuilder<'static, Shortcut>,
176}
177
178impl ShortcutBuilder {
179    fn new() -> Self {
180        Self {
181            builder: glib::object::Object::builder(),
182        }
183    }
184
185    pub fn action(self, action: &impl IsA<ShortcutAction>) -> Self {
186        Self {
187            builder: self.builder.property("action", action.clone().upcast()),
188        }
189    }
190
191    pub fn arguments(self, arguments: &glib::Variant) -> Self {
192        Self {
193            builder: self.builder.property("arguments", arguments.clone()),
194        }
195    }
196
197    pub fn trigger(self, trigger: &impl IsA<ShortcutTrigger>) -> Self {
198        Self {
199            builder: self.builder.property("trigger", trigger.clone().upcast()),
200        }
201    }
202
203    // rustdoc-stripper-ignore-next
204    /// Build the [`Shortcut`].
205    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
206    pub fn build(self) -> Shortcut {
207        assert_initialized_main_thread!();
208        self.builder.build()
209    }
210}