[go: up one dir, main page]

gio/auto/
action.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;
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "GAction")]
15    pub struct Action(Interface<ffi::GAction, ffi::GActionInterface>);
16
17    match fn {
18        type_ => || ffi::g_action_get_type(),
19    }
20}
21
22impl Action {
23    pub const NONE: Option<&'static Action> = None;
24
25    #[doc(alias = "g_action_name_is_valid")]
26    pub fn name_is_valid(action_name: &str) -> bool {
27        unsafe { from_glib(ffi::g_action_name_is_valid(action_name.to_glib_none().0)) }
28    }
29
30    #[doc(alias = "g_action_parse_detailed_name")]
31    pub fn parse_detailed_name(
32        detailed_name: &str,
33    ) -> Result<(glib::GString, Option<glib::Variant>), glib::Error> {
34        unsafe {
35            let mut action_name = std::ptr::null_mut();
36            let mut target_value = std::ptr::null_mut();
37            let mut error = std::ptr::null_mut();
38            let is_ok = ffi::g_action_parse_detailed_name(
39                detailed_name.to_glib_none().0,
40                &mut action_name,
41                &mut target_value,
42                &mut error,
43            );
44            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
45            if error.is_null() {
46                Ok((from_glib_full(action_name), from_glib_full(target_value)))
47            } else {
48                Err(from_glib_full(error))
49            }
50        }
51    }
52
53    #[doc(alias = "g_action_print_detailed_name")]
54    pub fn print_detailed_name(
55        action_name: &str,
56        target_value: Option<&glib::Variant>,
57    ) -> glib::GString {
58        unsafe {
59            from_glib_full(ffi::g_action_print_detailed_name(
60                action_name.to_glib_none().0,
61                target_value.to_glib_none().0,
62            ))
63        }
64    }
65}
66
67pub trait ActionExt: IsA<Action> + 'static {
68    #[doc(alias = "g_action_activate")]
69    fn activate(&self, parameter: Option<&glib::Variant>) {
70        unsafe {
71            ffi::g_action_activate(self.as_ref().to_glib_none().0, parameter.to_glib_none().0);
72        }
73    }
74
75    #[doc(alias = "g_action_change_state")]
76    fn change_state(&self, value: &glib::Variant) {
77        unsafe {
78            ffi::g_action_change_state(self.as_ref().to_glib_none().0, value.to_glib_none().0);
79        }
80    }
81
82    #[doc(alias = "g_action_get_enabled")]
83    #[doc(alias = "get_enabled")]
84    #[doc(alias = "enabled")]
85    fn is_enabled(&self) -> bool {
86        unsafe { from_glib(ffi::g_action_get_enabled(self.as_ref().to_glib_none().0)) }
87    }
88
89    #[doc(alias = "g_action_get_name")]
90    #[doc(alias = "get_name")]
91    fn name(&self) -> glib::GString {
92        unsafe { from_glib_none(ffi::g_action_get_name(self.as_ref().to_glib_none().0)) }
93    }
94
95    #[doc(alias = "g_action_get_parameter_type")]
96    #[doc(alias = "get_parameter_type")]
97    #[doc(alias = "parameter-type")]
98    fn parameter_type(&self) -> Option<glib::VariantType> {
99        unsafe {
100            from_glib_none(ffi::g_action_get_parameter_type(
101                self.as_ref().to_glib_none().0,
102            ))
103        }
104    }
105
106    #[doc(alias = "g_action_get_state")]
107    #[doc(alias = "get_state")]
108    fn state(&self) -> Option<glib::Variant> {
109        unsafe { from_glib_full(ffi::g_action_get_state(self.as_ref().to_glib_none().0)) }
110    }
111
112    #[doc(alias = "g_action_get_state_hint")]
113    #[doc(alias = "get_state_hint")]
114    fn state_hint(&self) -> Option<glib::Variant> {
115        unsafe { from_glib_full(ffi::g_action_get_state_hint(self.as_ref().to_glib_none().0)) }
116    }
117
118    #[doc(alias = "g_action_get_state_type")]
119    #[doc(alias = "get_state_type")]
120    #[doc(alias = "state-type")]
121    fn state_type(&self) -> Option<glib::VariantType> {
122        unsafe { from_glib_none(ffi::g_action_get_state_type(self.as_ref().to_glib_none().0)) }
123    }
124
125    #[doc(alias = "enabled")]
126    fn connect_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
127        unsafe extern "C" fn notify_enabled_trampoline<P: IsA<Action>, F: Fn(&P) + 'static>(
128            this: *mut ffi::GAction,
129            _param_spec: glib::ffi::gpointer,
130            f: glib::ffi::gpointer,
131        ) {
132            let f: &F = &*(f as *const F);
133            f(Action::from_glib_borrow(this).unsafe_cast_ref())
134        }
135        unsafe {
136            let f: Box_<F> = Box_::new(f);
137            connect_raw(
138                self.as_ptr() as *mut _,
139                c"notify::enabled".as_ptr() as *const _,
140                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
141                    notify_enabled_trampoline::<Self, F> as *const (),
142                )),
143                Box_::into_raw(f),
144            )
145        }
146    }
147
148    #[doc(alias = "name")]
149    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
150        unsafe extern "C" fn notify_name_trampoline<P: IsA<Action>, F: Fn(&P) + 'static>(
151            this: *mut ffi::GAction,
152            _param_spec: glib::ffi::gpointer,
153            f: glib::ffi::gpointer,
154        ) {
155            let f: &F = &*(f as *const F);
156            f(Action::from_glib_borrow(this).unsafe_cast_ref())
157        }
158        unsafe {
159            let f: Box_<F> = Box_::new(f);
160            connect_raw(
161                self.as_ptr() as *mut _,
162                c"notify::name".as_ptr() as *const _,
163                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164                    notify_name_trampoline::<Self, F> as *const (),
165                )),
166                Box_::into_raw(f),
167            )
168        }
169    }
170
171    #[doc(alias = "parameter-type")]
172    fn connect_parameter_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
173        unsafe extern "C" fn notify_parameter_type_trampoline<
174            P: IsA<Action>,
175            F: Fn(&P) + 'static,
176        >(
177            this: *mut ffi::GAction,
178            _param_spec: glib::ffi::gpointer,
179            f: glib::ffi::gpointer,
180        ) {
181            let f: &F = &*(f as *const F);
182            f(Action::from_glib_borrow(this).unsafe_cast_ref())
183        }
184        unsafe {
185            let f: Box_<F> = Box_::new(f);
186            connect_raw(
187                self.as_ptr() as *mut _,
188                c"notify::parameter-type".as_ptr() as *const _,
189                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
190                    notify_parameter_type_trampoline::<Self, F> as *const (),
191                )),
192                Box_::into_raw(f),
193            )
194        }
195    }
196
197    #[doc(alias = "state")]
198    fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
199        unsafe extern "C" fn notify_state_trampoline<P: IsA<Action>, F: Fn(&P) + 'static>(
200            this: *mut ffi::GAction,
201            _param_spec: glib::ffi::gpointer,
202            f: glib::ffi::gpointer,
203        ) {
204            let f: &F = &*(f as *const F);
205            f(Action::from_glib_borrow(this).unsafe_cast_ref())
206        }
207        unsafe {
208            let f: Box_<F> = Box_::new(f);
209            connect_raw(
210                self.as_ptr() as *mut _,
211                c"notify::state".as_ptr() as *const _,
212                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
213                    notify_state_trampoline::<Self, F> as *const (),
214                )),
215                Box_::into_raw(f),
216            )
217        }
218    }
219
220    #[doc(alias = "state-type")]
221    fn connect_state_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
222        unsafe extern "C" fn notify_state_type_trampoline<P: IsA<Action>, F: Fn(&P) + 'static>(
223            this: *mut ffi::GAction,
224            _param_spec: glib::ffi::gpointer,
225            f: glib::ffi::gpointer,
226        ) {
227            let f: &F = &*(f as *const F);
228            f(Action::from_glib_borrow(this).unsafe_cast_ref())
229        }
230        unsafe {
231            let f: Box_<F> = Box_::new(f);
232            connect_raw(
233                self.as_ptr() as *mut _,
234                c"notify::state-type".as_ptr() as *const _,
235                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236                    notify_state_type_trampoline::<Self, F> as *const (),
237                )),
238                Box_::into_raw(f),
239            )
240        }
241    }
242}
243
244impl<O: IsA<Action>> ActionExt for O {}