gtk/auto/
accel_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 gdk;
6use gdk_sys;
7use glib;
8use glib::object::Cast;
9use glib::object::IsA;
10use glib::signal::connect_raw;
11use glib::signal::SignalHandlerId;
12use glib::translate::*;
13use glib_sys;
14use gobject_sys;
15use gtk_sys;
16use libc;
17use std::boxed::Box as Box_;
18use std::fmt;
19use std::mem::transmute;
20use AccelFlags;
21
22glib_wrapper! {
23    pub struct AccelGroup(Object<gtk_sys::GtkAccelGroup, gtk_sys::GtkAccelGroupClass, AccelGroupClass>);
24
25    match fn {
26        get_type => || gtk_sys::gtk_accel_group_get_type(),
27    }
28}
29
30impl AccelGroup {
31    pub fn new() -> AccelGroup {
32        assert_initialized_main_thread!();
33        unsafe { from_glib_full(gtk_sys::gtk_accel_group_new()) }
34    }
35
36    pub fn from_accel_closure(closure: &glib::Closure) -> Option<AccelGroup> {
37        assert_initialized_main_thread!();
38        unsafe {
39            from_glib_none(gtk_sys::gtk_accel_group_from_accel_closure(
40                closure.to_glib_none().0,
41            ))
42        }
43    }
44}
45
46impl Default for AccelGroup {
47    fn default() -> Self {
48        Self::new()
49    }
50}
51
52pub const NONE_ACCEL_GROUP: Option<&AccelGroup> = None;
53
54pub trait AccelGroupExt: 'static {
55    fn activate<P: IsA<glib::Object>>(
56        &self,
57        accel_quark: glib::Quark,
58        acceleratable: &P,
59        accel_key: u32,
60        accel_mods: gdk::ModifierType,
61    ) -> bool;
62
63    fn connect(
64        &self,
65        accel_key: u32,
66        accel_mods: gdk::ModifierType,
67        accel_flags: AccelFlags,
68        closure: &glib::Closure,
69    );
70
71    fn connect_by_path(&self, accel_path: &str, closure: &glib::Closure);
72
73    fn disconnect(&self, closure: Option<&glib::Closure>) -> bool;
74
75    fn disconnect_key(&self, accel_key: u32, accel_mods: gdk::ModifierType) -> bool;
76
77    //fn find(&self, find_func: /*Unimplemented*/FnMut(/*Ignored*/AccelKey, &glib::Closure) -> bool, data: /*Unimplemented*/Option<Fundamental: Pointer>) -> /*Ignored*/Option<AccelKey>;
78
79    fn get_is_locked(&self) -> bool;
80
81    fn get_modifier_mask(&self) -> gdk::ModifierType;
82
83    fn lock(&self);
84
85    fn unlock(&self);
86
87    fn connect_accel_activate<
88        F: Fn(&Self, &glib::Object, u32, gdk::ModifierType) -> bool + 'static,
89    >(
90        &self,
91        f: F,
92    ) -> SignalHandlerId;
93
94    fn connect_accel_changed<F: Fn(&Self, u32, gdk::ModifierType, &glib::Closure) + 'static>(
95        &self,
96        f: F,
97    ) -> SignalHandlerId;
98
99    fn connect_property_is_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
100
101    fn connect_property_modifier_mask_notify<F: Fn(&Self) + 'static>(
102        &self,
103        f: F,
104    ) -> SignalHandlerId;
105}
106
107impl<O: IsA<AccelGroup>> AccelGroupExt for O {
108    fn activate<P: IsA<glib::Object>>(
109        &self,
110        accel_quark: glib::Quark,
111        acceleratable: &P,
112        accel_key: u32,
113        accel_mods: gdk::ModifierType,
114    ) -> bool {
115        unsafe {
116            from_glib(gtk_sys::gtk_accel_group_activate(
117                self.as_ref().to_glib_none().0,
118                accel_quark.to_glib(),
119                acceleratable.as_ref().to_glib_none().0,
120                accel_key,
121                accel_mods.to_glib(),
122            ))
123        }
124    }
125
126    fn connect(
127        &self,
128        accel_key: u32,
129        accel_mods: gdk::ModifierType,
130        accel_flags: AccelFlags,
131        closure: &glib::Closure,
132    ) {
133        unsafe {
134            gtk_sys::gtk_accel_group_connect(
135                self.as_ref().to_glib_none().0,
136                accel_key,
137                accel_mods.to_glib(),
138                accel_flags.to_glib(),
139                closure.to_glib_none().0,
140            );
141        }
142    }
143
144    fn connect_by_path(&self, accel_path: &str, closure: &glib::Closure) {
145        unsafe {
146            gtk_sys::gtk_accel_group_connect_by_path(
147                self.as_ref().to_glib_none().0,
148                accel_path.to_glib_none().0,
149                closure.to_glib_none().0,
150            );
151        }
152    }
153
154    fn disconnect(&self, closure: Option<&glib::Closure>) -> bool {
155        unsafe {
156            from_glib(gtk_sys::gtk_accel_group_disconnect(
157                self.as_ref().to_glib_none().0,
158                closure.to_glib_none().0,
159            ))
160        }
161    }
162
163    fn disconnect_key(&self, accel_key: u32, accel_mods: gdk::ModifierType) -> bool {
164        unsafe {
165            from_glib(gtk_sys::gtk_accel_group_disconnect_key(
166                self.as_ref().to_glib_none().0,
167                accel_key,
168                accel_mods.to_glib(),
169            ))
170        }
171    }
172
173    //fn find(&self, find_func: /*Unimplemented*/FnMut(/*Ignored*/AccelKey, &glib::Closure) -> bool, data: /*Unimplemented*/Option<Fundamental: Pointer>) -> /*Ignored*/Option<AccelKey> {
174    //    unsafe { TODO: call gtk_sys:gtk_accel_group_find() }
175    //}
176
177    fn get_is_locked(&self) -> bool {
178        unsafe {
179            from_glib(gtk_sys::gtk_accel_group_get_is_locked(
180                self.as_ref().to_glib_none().0,
181            ))
182        }
183    }
184
185    fn get_modifier_mask(&self) -> gdk::ModifierType {
186        unsafe {
187            from_glib(gtk_sys::gtk_accel_group_get_modifier_mask(
188                self.as_ref().to_glib_none().0,
189            ))
190        }
191    }
192
193    fn lock(&self) {
194        unsafe {
195            gtk_sys::gtk_accel_group_lock(self.as_ref().to_glib_none().0);
196        }
197    }
198
199    fn unlock(&self) {
200        unsafe {
201            gtk_sys::gtk_accel_group_unlock(self.as_ref().to_glib_none().0);
202        }
203    }
204
205    fn connect_accel_activate<
206        F: Fn(&Self, &glib::Object, u32, gdk::ModifierType) -> bool + 'static,
207    >(
208        &self,
209        f: F,
210    ) -> SignalHandlerId {
211        unsafe extern "C" fn accel_activate_trampoline<
212            P,
213            F: Fn(&P, &glib::Object, u32, gdk::ModifierType) -> bool + 'static,
214        >(
215            this: *mut gtk_sys::GtkAccelGroup,
216            acceleratable: *mut gobject_sys::GObject,
217            keyval: libc::c_uint,
218            modifier: gdk_sys::GdkModifierType,
219            f: glib_sys::gpointer,
220        ) -> glib_sys::gboolean
221        where
222            P: IsA<AccelGroup>,
223        {
224            let f: &F = &*(f as *const F);
225            f(
226                &AccelGroup::from_glib_borrow(this).unsafe_cast(),
227                &from_glib_borrow(acceleratable),
228                keyval,
229                from_glib(modifier),
230            )
231            .to_glib()
232        }
233        unsafe {
234            let f: Box_<F> = Box_::new(f);
235            connect_raw(
236                self.as_ptr() as *mut _,
237                b"accel-activate\0".as_ptr() as *const _,
238                Some(transmute(accel_activate_trampoline::<Self, F> as usize)),
239                Box_::into_raw(f),
240            )
241        }
242    }
243
244    fn connect_accel_changed<F: Fn(&Self, u32, gdk::ModifierType, &glib::Closure) + 'static>(
245        &self,
246        f: F,
247    ) -> SignalHandlerId {
248        unsafe extern "C" fn accel_changed_trampoline<
249            P,
250            F: Fn(&P, u32, gdk::ModifierType, &glib::Closure) + 'static,
251        >(
252            this: *mut gtk_sys::GtkAccelGroup,
253            keyval: libc::c_uint,
254            modifier: gdk_sys::GdkModifierType,
255            accel_closure: *mut gobject_sys::GClosure,
256            f: glib_sys::gpointer,
257        ) where
258            P: IsA<AccelGroup>,
259        {
260            let f: &F = &*(f as *const F);
261            f(
262                &AccelGroup::from_glib_borrow(this).unsafe_cast(),
263                keyval,
264                from_glib(modifier),
265                &from_glib_borrow(accel_closure),
266            )
267        }
268        unsafe {
269            let f: Box_<F> = Box_::new(f);
270            connect_raw(
271                self.as_ptr() as *mut _,
272                b"accel-changed\0".as_ptr() as *const _,
273                Some(transmute(accel_changed_trampoline::<Self, F> as usize)),
274                Box_::into_raw(f),
275            )
276        }
277    }
278
279    fn connect_property_is_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
280        unsafe extern "C" fn notify_is_locked_trampoline<P, F: Fn(&P) + 'static>(
281            this: *mut gtk_sys::GtkAccelGroup,
282            _param_spec: glib_sys::gpointer,
283            f: glib_sys::gpointer,
284        ) where
285            P: IsA<AccelGroup>,
286        {
287            let f: &F = &*(f as *const F);
288            f(&AccelGroup::from_glib_borrow(this).unsafe_cast())
289        }
290        unsafe {
291            let f: Box_<F> = Box_::new(f);
292            connect_raw(
293                self.as_ptr() as *mut _,
294                b"notify::is-locked\0".as_ptr() as *const _,
295                Some(transmute(notify_is_locked_trampoline::<Self, F> as usize)),
296                Box_::into_raw(f),
297            )
298        }
299    }
300
301    fn connect_property_modifier_mask_notify<F: Fn(&Self) + 'static>(
302        &self,
303        f: F,
304    ) -> SignalHandlerId {
305        unsafe extern "C" fn notify_modifier_mask_trampoline<P, F: Fn(&P) + 'static>(
306            this: *mut gtk_sys::GtkAccelGroup,
307            _param_spec: glib_sys::gpointer,
308            f: glib_sys::gpointer,
309        ) where
310            P: IsA<AccelGroup>,
311        {
312            let f: &F = &*(f as *const F);
313            f(&AccelGroup::from_glib_borrow(this).unsafe_cast())
314        }
315        unsafe {
316            let f: Box_<F> = Box_::new(f);
317            connect_raw(
318                self.as_ptr() as *mut _,
319                b"notify::modifier-mask\0".as_ptr() as *const _,
320                Some(transmute(
321                    notify_modifier_mask_trampoline::<Self, F> as usize,
322                )),
323                Box_::into_raw(f),
324            )
325        }
326    }
327}
328
329impl fmt::Display for AccelGroup {
330    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
331        write!(f, "AccelGroup")
332    }
333}