gio/auto/
action_group.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 gio_sys;
6use glib;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib::GString;
13use glib_sys;
14use libc;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18
19glib_wrapper! {
20    pub struct ActionGroup(Interface<gio_sys::GActionGroup>);
21
22    match fn {
23        get_type => || gio_sys::g_action_group_get_type(),
24    }
25}
26
27pub const NONE_ACTION_GROUP: Option<&ActionGroup> = None;
28
29pub trait ActionGroupExt: 'static {
30    fn action_added(&self, action_name: &str);
31
32    fn action_enabled_changed(&self, action_name: &str, enabled: bool);
33
34    fn action_removed(&self, action_name: &str);
35
36    fn action_state_changed(&self, action_name: &str, state: &glib::Variant);
37
38    fn activate_action(&self, action_name: &str, parameter: Option<&glib::Variant>);
39
40    fn change_action_state(&self, action_name: &str, value: &glib::Variant);
41
42    fn get_action_enabled(&self, action_name: &str) -> bool;
43
44    fn get_action_parameter_type(&self, action_name: &str) -> Option<glib::VariantType>;
45
46    fn get_action_state(&self, action_name: &str) -> Option<glib::Variant>;
47
48    fn get_action_state_hint(&self, action_name: &str) -> Option<glib::Variant>;
49
50    fn get_action_state_type(&self, action_name: &str) -> Option<glib::VariantType>;
51
52    fn has_action(&self, action_name: &str) -> bool;
53
54    fn list_actions(&self) -> Vec<GString>;
55
56    fn connect_action_added<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId;
57
58    fn connect_action_enabled_changed<F: Fn(&Self, &str, bool) + 'static>(
59        &self,
60        f: F,
61    ) -> SignalHandlerId;
62
63    fn connect_action_removed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId;
64
65    fn connect_action_state_changed<F: Fn(&Self, &str, &glib::Variant) + 'static>(
66        &self,
67        f: F,
68    ) -> SignalHandlerId;
69}
70
71impl<O: IsA<ActionGroup>> ActionGroupExt for O {
72    fn action_added(&self, action_name: &str) {
73        unsafe {
74            gio_sys::g_action_group_action_added(
75                self.as_ref().to_glib_none().0,
76                action_name.to_glib_none().0,
77            );
78        }
79    }
80
81    fn action_enabled_changed(&self, action_name: &str, enabled: bool) {
82        unsafe {
83            gio_sys::g_action_group_action_enabled_changed(
84                self.as_ref().to_glib_none().0,
85                action_name.to_glib_none().0,
86                enabled.to_glib(),
87            );
88        }
89    }
90
91    fn action_removed(&self, action_name: &str) {
92        unsafe {
93            gio_sys::g_action_group_action_removed(
94                self.as_ref().to_glib_none().0,
95                action_name.to_glib_none().0,
96            );
97        }
98    }
99
100    fn action_state_changed(&self, action_name: &str, state: &glib::Variant) {
101        unsafe {
102            gio_sys::g_action_group_action_state_changed(
103                self.as_ref().to_glib_none().0,
104                action_name.to_glib_none().0,
105                state.to_glib_none().0,
106            );
107        }
108    }
109
110    fn activate_action(&self, action_name: &str, parameter: Option<&glib::Variant>) {
111        unsafe {
112            gio_sys::g_action_group_activate_action(
113                self.as_ref().to_glib_none().0,
114                action_name.to_glib_none().0,
115                parameter.to_glib_none().0,
116            );
117        }
118    }
119
120    fn change_action_state(&self, action_name: &str, value: &glib::Variant) {
121        unsafe {
122            gio_sys::g_action_group_change_action_state(
123                self.as_ref().to_glib_none().0,
124                action_name.to_glib_none().0,
125                value.to_glib_none().0,
126            );
127        }
128    }
129
130    fn get_action_enabled(&self, action_name: &str) -> bool {
131        unsafe {
132            from_glib(gio_sys::g_action_group_get_action_enabled(
133                self.as_ref().to_glib_none().0,
134                action_name.to_glib_none().0,
135            ))
136        }
137    }
138
139    fn get_action_parameter_type(&self, action_name: &str) -> Option<glib::VariantType> {
140        unsafe {
141            from_glib_none(gio_sys::g_action_group_get_action_parameter_type(
142                self.as_ref().to_glib_none().0,
143                action_name.to_glib_none().0,
144            ))
145        }
146    }
147
148    fn get_action_state(&self, action_name: &str) -> Option<glib::Variant> {
149        unsafe {
150            from_glib_full(gio_sys::g_action_group_get_action_state(
151                self.as_ref().to_glib_none().0,
152                action_name.to_glib_none().0,
153            ))
154        }
155    }
156
157    fn get_action_state_hint(&self, action_name: &str) -> Option<glib::Variant> {
158        unsafe {
159            from_glib_full(gio_sys::g_action_group_get_action_state_hint(
160                self.as_ref().to_glib_none().0,
161                action_name.to_glib_none().0,
162            ))
163        }
164    }
165
166    fn get_action_state_type(&self, action_name: &str) -> Option<glib::VariantType> {
167        unsafe {
168            from_glib_none(gio_sys::g_action_group_get_action_state_type(
169                self.as_ref().to_glib_none().0,
170                action_name.to_glib_none().0,
171            ))
172        }
173    }
174
175    fn has_action(&self, action_name: &str) -> bool {
176        unsafe {
177            from_glib(gio_sys::g_action_group_has_action(
178                self.as_ref().to_glib_none().0,
179                action_name.to_glib_none().0,
180            ))
181        }
182    }
183
184    fn list_actions(&self) -> Vec<GString> {
185        unsafe {
186            FromGlibPtrContainer::from_glib_full(gio_sys::g_action_group_list_actions(
187                self.as_ref().to_glib_none().0,
188            ))
189        }
190    }
191
192    fn connect_action_added<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
193        unsafe extern "C" fn action_added_trampoline<P, F: Fn(&P, &str) + 'static>(
194            this: *mut gio_sys::GActionGroup,
195            action_name: *mut libc::c_char,
196            f: glib_sys::gpointer,
197        ) where
198            P: IsA<ActionGroup>,
199        {
200            let f: &F = &*(f as *const F);
201            f(
202                &ActionGroup::from_glib_borrow(this).unsafe_cast(),
203                &GString::from_glib_borrow(action_name),
204            )
205        }
206        unsafe {
207            let f: Box_<F> = Box_::new(f);
208            connect_raw(
209                self.as_ptr() as *mut _,
210                b"action-added\0".as_ptr() as *const _,
211                Some(transmute(action_added_trampoline::<Self, F> as usize)),
212                Box_::into_raw(f),
213            )
214        }
215    }
216
217    fn connect_action_enabled_changed<F: Fn(&Self, &str, bool) + 'static>(
218        &self,
219        f: F,
220    ) -> SignalHandlerId {
221        unsafe extern "C" fn action_enabled_changed_trampoline<P, F: Fn(&P, &str, bool) + 'static>(
222            this: *mut gio_sys::GActionGroup,
223            action_name: *mut libc::c_char,
224            enabled: glib_sys::gboolean,
225            f: glib_sys::gpointer,
226        ) where
227            P: IsA<ActionGroup>,
228        {
229            let f: &F = &*(f as *const F);
230            f(
231                &ActionGroup::from_glib_borrow(this).unsafe_cast(),
232                &GString::from_glib_borrow(action_name),
233                from_glib(enabled),
234            )
235        }
236        unsafe {
237            let f: Box_<F> = Box_::new(f);
238            connect_raw(
239                self.as_ptr() as *mut _,
240                b"action-enabled-changed\0".as_ptr() as *const _,
241                Some(transmute(
242                    action_enabled_changed_trampoline::<Self, F> as usize,
243                )),
244                Box_::into_raw(f),
245            )
246        }
247    }
248
249    fn connect_action_removed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
250        unsafe extern "C" fn action_removed_trampoline<P, F: Fn(&P, &str) + 'static>(
251            this: *mut gio_sys::GActionGroup,
252            action_name: *mut libc::c_char,
253            f: glib_sys::gpointer,
254        ) where
255            P: IsA<ActionGroup>,
256        {
257            let f: &F = &*(f as *const F);
258            f(
259                &ActionGroup::from_glib_borrow(this).unsafe_cast(),
260                &GString::from_glib_borrow(action_name),
261            )
262        }
263        unsafe {
264            let f: Box_<F> = Box_::new(f);
265            connect_raw(
266                self.as_ptr() as *mut _,
267                b"action-removed\0".as_ptr() as *const _,
268                Some(transmute(action_removed_trampoline::<Self, F> as usize)),
269                Box_::into_raw(f),
270            )
271        }
272    }
273
274    fn connect_action_state_changed<F: Fn(&Self, &str, &glib::Variant) + 'static>(
275        &self,
276        f: F,
277    ) -> SignalHandlerId {
278        unsafe extern "C" fn action_state_changed_trampoline<
279            P,
280            F: Fn(&P, &str, &glib::Variant) + 'static,
281        >(
282            this: *mut gio_sys::GActionGroup,
283            action_name: *mut libc::c_char,
284            value: *mut glib_sys::GVariant,
285            f: glib_sys::gpointer,
286        ) where
287            P: IsA<ActionGroup>,
288        {
289            let f: &F = &*(f as *const F);
290            f(
291                &ActionGroup::from_glib_borrow(this).unsafe_cast(),
292                &GString::from_glib_borrow(action_name),
293                &from_glib_borrow(value),
294            )
295        }
296        unsafe {
297            let f: Box_<F> = Box_::new(f);
298            connect_raw(
299                self.as_ptr() as *mut _,
300                b"action-state-changed\0".as_ptr() as *const _,
301                Some(transmute(
302                    action_state_changed_trampoline::<Self, F> as usize,
303                )),
304                Box_::into_raw(f),
305            )
306        }
307    }
308}
309
310impl fmt::Display for ActionGroup {
311    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
312        write!(f, "ActionGroup")
313    }
314}