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