Skip to main content

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 glib::{
6    prelude::*,
7    signal::{connect_raw, SignalHandlerId},
8    translate::*,
9};
10use std::{boxed::Box as Box_, fmt, mem::transmute};
11
12glib::wrapper! {
13    /// A [`AccelGroup`][crate::AccelGroup] represents a group of keyboard accelerators,
14    /// typically attached to a toplevel [`Window`][crate::Window] (with
15    /// [`GtkWindowExt::add_accel_group()`][crate::prelude::GtkWindowExt::add_accel_group()]). Usually you won’t need to create a
16    /// [`AccelGroup`][crate::AccelGroup] directly; instead, when using `GtkUIManager`, GTK+
17    /// automatically sets up the accelerators for your menus in the ui
18    /// manager’s [`AccelGroup`][crate::AccelGroup].
19    ///
20    /// Note that “accelerators” are different from
21    /// “mnemonics”. Accelerators are shortcuts for
22    /// activating a menu item; they appear alongside the menu item they’re a
23    /// shortcut for. For example “Ctrl+Q” might appear alongside the “Quit”
24    /// menu item. Mnemonics are shortcuts for GUI elements such as text
25    /// entries or buttons; they appear as underlined characters. See
26    /// [`Label::with_mnemonic()`][crate::Label::with_mnemonic()]. Menu items can have both accelerators
27    /// and mnemonics, of course.
28    ///
29    /// ## Properties
30    ///
31    ///
32    /// #### `is-locked`
33    ///  Readable
34    ///
35    ///
36    /// #### `modifier-mask`
37    ///  Readable
38    ///
39    /// ## Signals
40    ///
41    ///
42    /// #### `accel-activate`
43    ///  The accel-activate signal is an implementation detail of
44    /// [`AccelGroup`][crate::AccelGroup] and not meant to be used by applications.
45    ///
46    /// Detailed
47    ///
48    ///
49    /// #### `accel-changed`
50    ///  The accel-changed signal is emitted when an entry
51    /// is added to or removed from the accel group.
52    ///
53    /// Widgets like [`AccelLabel`][crate::AccelLabel] which display an associated
54    /// accelerator should connect to this signal, and rebuild
55    /// their visual representation if the `accel_closure` is theirs.
56    ///
57    /// Detailed
58    ///
59    /// # Implements
60    ///
61    /// [`AccelGroupExt`][trait@crate::prelude::AccelGroupExt], [`trait@glib::ObjectExt`], [`AccelGroupExtManual`][trait@crate::prelude::AccelGroupExtManual]
62    #[doc(alias = "GtkAccelGroup")]
63    pub struct AccelGroup(Object<ffi::GtkAccelGroup, ffi::GtkAccelGroupClass>);
64
65    match fn {
66        type_ => || ffi::gtk_accel_group_get_type(),
67    }
68}
69
70impl AccelGroup {
71    pub const NONE: Option<&'static AccelGroup> = None;
72
73    /// Creates a new [`AccelGroup`][crate::AccelGroup].
74    ///
75    /// # Returns
76    ///
77    /// a new [`AccelGroup`][crate::AccelGroup] object
78    #[doc(alias = "gtk_accel_group_new")]
79    pub fn new() -> AccelGroup {
80        assert_initialized_main_thread!();
81        unsafe { from_glib_full(ffi::gtk_accel_group_new()) }
82    }
83
84    /// Finds the [`AccelGroup`][crate::AccelGroup] to which `closure` is connected;
85    /// see [`AccelGroupExtManual::connect_accel_group()`][crate::prelude::AccelGroupExtManual::connect_accel_group()].
86    /// ## `closure`
87    /// a [`glib::Closure`][crate::glib::Closure]
88    ///
89    /// # Returns
90    ///
91    /// the [`AccelGroup`][crate::AccelGroup] to which `closure`
92    ///  is connected, or [`None`]
93    #[doc(alias = "gtk_accel_group_from_accel_closure")]
94    pub fn from_accel_closure(closure: &glib::Closure) -> Option<AccelGroup> {
95        assert_initialized_main_thread!();
96        unsafe {
97            from_glib_none(ffi::gtk_accel_group_from_accel_closure(
98                closure.to_glib_none().0,
99            ))
100        }
101    }
102}
103
104impl Default for AccelGroup {
105    fn default() -> Self {
106        Self::new()
107    }
108}
109
110mod sealed {
111    pub trait Sealed {}
112    impl<T: super::IsA<super::AccelGroup>> Sealed for T {}
113}
114
115/// Trait containing all [`struct@AccelGroup`] methods.
116///
117/// # Implementors
118///
119/// [`AccelGroup`][struct@crate::AccelGroup]
120pub trait AccelGroupExt: IsA<AccelGroup> + sealed::Sealed + 'static {
121    /// Finds the first accelerator in `self` that matches
122    /// `accel_key` and `accel_mods`, and activates it.
123    /// ## `accel_quark`
124    /// the quark for the accelerator name
125    /// ## `acceleratable`
126    /// the [`glib::Object`][crate::glib::Object], usually a [`Window`][crate::Window], on which
127    ///  to activate the accelerator
128    /// ## `accel_key`
129    /// accelerator keyval from a key event
130    /// ## `accel_mods`
131    /// keyboard state mask from a key event
132    ///
133    /// # Returns
134    ///
135    /// [`true`] if an accelerator was activated and handled
136    ///  this keypress
137    #[doc(alias = "gtk_accel_group_activate")]
138    fn activate(
139        &self,
140        accel_quark: glib::Quark,
141        acceleratable: &impl IsA<glib::Object>,
142        accel_key: u32,
143        accel_mods: gdk::ModifierType,
144    ) -> bool {
145        unsafe {
146            from_glib(ffi::gtk_accel_group_activate(
147                self.as_ref().to_glib_none().0,
148                accel_quark.into_glib(),
149                acceleratable.as_ref().to_glib_none().0,
150                accel_key,
151                accel_mods.into_glib(),
152            ))
153        }
154    }
155
156    /// Removes an accelerator previously installed through
157    /// [`AccelGroupExtManual::connect_accel_group()`][crate::prelude::AccelGroupExtManual::connect_accel_group()].
158    ///
159    /// Since 2.20 `closure` can be [`None`].
160    /// ## `closure`
161    /// the closure to remove from this accelerator
162    ///  group, or [`None`] to remove all closures
163    ///
164    /// # Returns
165    ///
166    /// [`true`] if the closure was found and got disconnected
167    #[doc(alias = "gtk_accel_group_disconnect")]
168    fn disconnect(&self, closure: Option<&glib::Closure>) -> bool {
169        unsafe {
170            from_glib(ffi::gtk_accel_group_disconnect(
171                self.as_ref().to_glib_none().0,
172                closure.to_glib_none().0,
173            ))
174        }
175    }
176
177    /// Removes an accelerator previously installed through
178    /// [`AccelGroupExtManual::connect_accel_group()`][crate::prelude::AccelGroupExtManual::connect_accel_group()].
179    /// ## `accel_key`
180    /// key value of the accelerator
181    /// ## `accel_mods`
182    /// modifier combination of the accelerator
183    ///
184    /// # Returns
185    ///
186    /// [`true`] if there was an accelerator which could be
187    ///  removed, [`false`] otherwise
188    #[doc(alias = "gtk_accel_group_disconnect_key")]
189    fn disconnect_key(&self, accel_key: u32, accel_mods: gdk::ModifierType) -> bool {
190        unsafe {
191            from_glib(ffi::gtk_accel_group_disconnect_key(
192                self.as_ref().to_glib_none().0,
193                accel_key,
194                accel_mods.into_glib(),
195            ))
196        }
197    }
198
199    //#[doc(alias = "gtk_accel_group_find")]
200    //fn find(&self, find_func: /*Unimplemented*/FnMut(/*Ignored*/AccelKey, &glib::Closure) -> bool, data: /*Unimplemented*/Option<Basic: Pointer>) -> /*Ignored*/Option<AccelKey> {
201    //    unsafe { TODO: call ffi:gtk_accel_group_find() }
202    //}
203
204    /// Locks are added and removed using [`lock()`][Self::lock()] and
205    /// [`unlock()`][Self::unlock()].
206    ///
207    /// # Returns
208    ///
209    /// [`true`] if there are 1 or more locks on the `self`,
210    ///  [`false`] otherwise.
211    #[doc(alias = "gtk_accel_group_get_is_locked")]
212    #[doc(alias = "get_is_locked")]
213    fn is_locked(&self) -> bool {
214        unsafe {
215            from_glib(ffi::gtk_accel_group_get_is_locked(
216                self.as_ref().to_glib_none().0,
217            ))
218        }
219    }
220
221    /// Gets a [`gdk::ModifierType`][crate::gdk::ModifierType] representing the mask for this
222    /// `self`. For example, [`gdk::ModifierType::CONTROL_MASK`][crate::gdk::ModifierType::CONTROL_MASK], [`gdk::ModifierType::SHIFT_MASK`][crate::gdk::ModifierType::SHIFT_MASK], etc.
223    ///
224    /// # Returns
225    ///
226    /// the modifier mask for this accel group.
227    #[doc(alias = "gtk_accel_group_get_modifier_mask")]
228    #[doc(alias = "get_modifier_mask")]
229    fn modifier_mask(&self) -> gdk::ModifierType {
230        unsafe {
231            from_glib(ffi::gtk_accel_group_get_modifier_mask(
232                self.as_ref().to_glib_none().0,
233            ))
234        }
235    }
236
237    /// Locks the given accelerator group.
238    ///
239    /// Locking an acelerator group prevents the accelerators contained
240    /// within it to be changed during runtime. Refer to
241    /// `gtk_accel_map_change_entry()` about runtime accelerator changes.
242    ///
243    /// If called more than once, `self` remains locked until
244    /// [`unlock()`][Self::unlock()] has been called an equivalent number
245    /// of times.
246    #[doc(alias = "gtk_accel_group_lock")]
247    fn lock(&self) {
248        unsafe {
249            ffi::gtk_accel_group_lock(self.as_ref().to_glib_none().0);
250        }
251    }
252
253    /// Undoes the last call to [`lock()`][Self::lock()] on this `self`.
254    #[doc(alias = "gtk_accel_group_unlock")]
255    fn unlock(&self) {
256        unsafe {
257            ffi::gtk_accel_group_unlock(self.as_ref().to_glib_none().0);
258        }
259    }
260
261    /// The accel-activate signal is an implementation detail of
262    /// [`AccelGroup`][crate::AccelGroup] and not meant to be used by applications.
263    /// ## `acceleratable`
264    /// the object on which the accelerator was activated
265    /// ## `keyval`
266    /// the accelerator keyval
267    /// ## `modifier`
268    /// the modifier combination of the accelerator
269    ///
270    /// # Returns
271    ///
272    /// [`true`] if the accelerator was activated
273    #[doc(alias = "accel-activate")]
274    fn connect_accel_activate<
275        F: Fn(&Self, &glib::Object, u32, gdk::ModifierType) -> bool + 'static,
276    >(
277        &self,
278        detail: Option<&str>,
279        f: F,
280    ) -> SignalHandlerId {
281        unsafe extern "C" fn accel_activate_trampoline<
282            P: IsA<AccelGroup>,
283            F: Fn(&P, &glib::Object, u32, gdk::ModifierType) -> bool + 'static,
284        >(
285            this: *mut ffi::GtkAccelGroup,
286            acceleratable: *mut glib::gobject_ffi::GObject,
287            keyval: libc::c_uint,
288            modifier: gdk::ffi::GdkModifierType,
289            f: glib::ffi::gpointer,
290        ) -> glib::ffi::gboolean {
291            let f: &F = &*(f as *const F);
292            f(
293                AccelGroup::from_glib_borrow(this).unsafe_cast_ref(),
294                &from_glib_borrow(acceleratable),
295                keyval,
296                from_glib(modifier),
297            )
298            .into_glib()
299        }
300        unsafe {
301            let f: Box_<F> = Box_::new(f);
302            let detailed_signal_name = detail.map(|name| format!("accel-activate::{name}\0"));
303            let signal_name: &[u8] = detailed_signal_name
304                .as_ref()
305                .map_or(&b"accel-activate\0"[..], |n| n.as_bytes());
306            connect_raw(
307                self.as_ptr() as *mut _,
308                signal_name.as_ptr() as *const _,
309                Some(transmute::<_, unsafe extern "C" fn()>(
310                    accel_activate_trampoline::<Self, F> as *const (),
311                )),
312                Box_::into_raw(f),
313            )
314        }
315    }
316
317    /// The accel-changed signal is emitted when an entry
318    /// is added to or removed from the accel group.
319    ///
320    /// Widgets like [`AccelLabel`][crate::AccelLabel] which display an associated
321    /// accelerator should connect to this signal, and rebuild
322    /// their visual representation if the `accel_closure` is theirs.
323    /// ## `keyval`
324    /// the accelerator keyval
325    /// ## `modifier`
326    /// the modifier combination of the accelerator
327    /// ## `accel_closure`
328    /// the [`glib::Closure`][crate::glib::Closure] of the accelerator
329    #[doc(alias = "accel-changed")]
330    fn connect_accel_changed<F: Fn(&Self, u32, gdk::ModifierType, &glib::Closure) + 'static>(
331        &self,
332        detail: Option<&str>,
333        f: F,
334    ) -> SignalHandlerId {
335        unsafe extern "C" fn accel_changed_trampoline<
336            P: IsA<AccelGroup>,
337            F: Fn(&P, u32, gdk::ModifierType, &glib::Closure) + 'static,
338        >(
339            this: *mut ffi::GtkAccelGroup,
340            keyval: libc::c_uint,
341            modifier: gdk::ffi::GdkModifierType,
342            accel_closure: *mut glib::gobject_ffi::GClosure,
343            f: glib::ffi::gpointer,
344        ) {
345            let f: &F = &*(f as *const F);
346            f(
347                AccelGroup::from_glib_borrow(this).unsafe_cast_ref(),
348                keyval,
349                from_glib(modifier),
350                &from_glib_borrow(accel_closure),
351            )
352        }
353        unsafe {
354            let f: Box_<F> = Box_::new(f);
355            let detailed_signal_name = detail.map(|name| format!("accel-changed::{name}\0"));
356            let signal_name: &[u8] = detailed_signal_name
357                .as_ref()
358                .map_or(&b"accel-changed\0"[..], |n| n.as_bytes());
359            connect_raw(
360                self.as_ptr() as *mut _,
361                signal_name.as_ptr() as *const _,
362                Some(transmute::<_, unsafe extern "C" fn()>(
363                    accel_changed_trampoline::<Self, F> as *const (),
364                )),
365                Box_::into_raw(f),
366            )
367        }
368    }
369
370    #[doc(alias = "is-locked")]
371    fn connect_is_locked_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
372        unsafe extern "C" fn notify_is_locked_trampoline<
373            P: IsA<AccelGroup>,
374            F: Fn(&P) + 'static,
375        >(
376            this: *mut ffi::GtkAccelGroup,
377            _param_spec: glib::ffi::gpointer,
378            f: glib::ffi::gpointer,
379        ) {
380            let f: &F = &*(f as *const F);
381            f(AccelGroup::from_glib_borrow(this).unsafe_cast_ref())
382        }
383        unsafe {
384            let f: Box_<F> = Box_::new(f);
385            connect_raw(
386                self.as_ptr() as *mut _,
387                b"notify::is-locked\0".as_ptr() as *const _,
388                Some(transmute::<_, unsafe extern "C" fn()>(
389                    notify_is_locked_trampoline::<Self, F> as *const (),
390                )),
391                Box_::into_raw(f),
392            )
393        }
394    }
395
396    #[doc(alias = "modifier-mask")]
397    fn connect_modifier_mask_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
398        unsafe extern "C" fn notify_modifier_mask_trampoline<
399            P: IsA<AccelGroup>,
400            F: Fn(&P) + 'static,
401        >(
402            this: *mut ffi::GtkAccelGroup,
403            _param_spec: glib::ffi::gpointer,
404            f: glib::ffi::gpointer,
405        ) {
406            let f: &F = &*(f as *const F);
407            f(AccelGroup::from_glib_borrow(this).unsafe_cast_ref())
408        }
409        unsafe {
410            let f: Box_<F> = Box_::new(f);
411            connect_raw(
412                self.as_ptr() as *mut _,
413                b"notify::modifier-mask\0".as_ptr() as *const _,
414                Some(transmute::<_, unsafe extern "C" fn()>(
415                    notify_modifier_mask_trampoline::<Self, F> as *const (),
416                )),
417                Box_::into_raw(f),
418            )
419        }
420    }
421}
422
423impl<O: IsA<AccelGroup>> AccelGroupExt for O {}
424
425impl fmt::Display for AccelGroup {
426    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
427        f.write_str("AccelGroup")
428    }
429}