Skip to main content

gtk4/auto/
shortcut_trigger.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::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// Tracks how a [`Shortcut`][crate::Shortcut] can be activated.
10    ///
11    /// To find out if a [`ShortcutTrigger`][crate::ShortcutTrigger] triggers, you can call
12    /// [`ShortcutTriggerExt::trigger()`][crate::prelude::ShortcutTriggerExt::trigger()] on a [`gdk::Event`][crate::gdk::Event].
13    ///
14    /// `GtkShortcutTriggers` contain functions that allow easy presentation
15    /// to end users as well as being printed for debugging.
16    ///
17    /// All `GtkShortcutTriggers` are immutable, you can only specify their
18    /// properties during construction. If you want to change a trigger, you
19    /// have to replace it with a new one.
20    ///
21    /// This is an Abstract Base Class, you cannot instantiate it.
22    ///
23    /// # Implements
24    ///
25    /// [`ShortcutTriggerExt`][trait@crate::prelude::ShortcutTriggerExt], [`trait@glib::ObjectExt`], [`ShortcutTriggerExtManual`][trait@crate::prelude::ShortcutTriggerExtManual]
26    #[doc(alias = "GtkShortcutTrigger")]
27    pub struct ShortcutTrigger(Object<ffi::GtkShortcutTrigger, ffi::GtkShortcutTriggerClass>);
28
29    match fn {
30        type_ => || ffi::gtk_shortcut_trigger_get_type(),
31    }
32}
33
34impl ShortcutTrigger {
35    pub const NONE: Option<&'static ShortcutTrigger> = None;
36
37    /// `.
38    /// ## `string`
39    /// the string to parse
40    ///
41    /// # Returns
42    ///
43    /// a new [`ShortcutTrigger`][crate::ShortcutTrigger]
44    #[doc(alias = "gtk_shortcut_trigger_parse_string")]
45    pub fn parse_string(string: &str) -> Option<ShortcutTrigger> {
46        assert_initialized_main_thread!();
47        unsafe {
48            from_glib_full(ffi::gtk_shortcut_trigger_parse_string(
49                string.to_glib_none().0,
50            ))
51        }
52    }
53
54    /// .
55    ///
56    /// # Returns
57    ///
58    /// a new [`ShortcutTrigger`][crate::ShortcutTrigger]
59    #[cfg(feature = "v4_24")]
60    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
61    #[doc(alias = "gtk_shortcut_trigger_create_for_menu")]
62    pub fn create_for_menu() -> ShortcutTrigger {
63        assert_initialized_main_thread!();
64        unsafe { from_glib_full(ffi::gtk_shortcut_trigger_create_for_menu()) }
65    }
66}
67
68impl std::fmt::Display for ShortcutTrigger {
69    #[inline]
70    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
71        f.write_str(&ShortcutTriggerExt::to_str(self))
72    }
73}
74
75/// Trait containing all [`struct@ShortcutTrigger`] methods.
76///
77/// # Implementors
78///
79/// [`AlternativeTrigger`][struct@crate::AlternativeTrigger], [`KeyvalTrigger`][struct@crate::KeyvalTrigger], [`MnemonicTrigger`][struct@crate::MnemonicTrigger], [`NeverTrigger`][struct@crate::NeverTrigger], [`ShortcutTrigger`][struct@crate::ShortcutTrigger]
80pub trait ShortcutTriggerExt: IsA<ShortcutTrigger> + 'static {
81    /// Gets textual representation for the given trigger.
82    ///
83    /// This function is returning a translated string for
84    /// presentation to end users for example in menu items
85    /// or in help texts.
86    ///
87    /// The @display in use may influence the resulting string in
88    /// various forms, such as resolving hardware keycodes or by
89    /// causing display-specific modifier names.
90    ///
91    /// The form of the representation may change at any time and is
92    /// not guaranteed to stay identical.
93    /// ## `display`
94    /// [`gdk::Display`][crate::gdk::Display] to print for
95    ///
96    /// # Returns
97    ///
98    /// a new string
99    #[doc(alias = "gtk_shortcut_trigger_to_label")]
100    fn to_label(&self, display: &impl IsA<gdk::Display>) -> glib::GString {
101        unsafe {
102            from_glib_full(ffi::gtk_shortcut_trigger_to_label(
103                self.as_ref().to_glib_none().0,
104                display.as_ref().to_glib_none().0,
105            ))
106        }
107    }
108
109    /// Prints the given trigger into a human-readable string.
110    ///
111    /// This is a small wrapper around `Gtk::ShortcutTrigger::print()`
112    /// to help when debugging.
113    ///
114    /// # Returns
115    ///
116    /// a new string
117    #[doc(alias = "gtk_shortcut_trigger_to_string")]
118    #[doc(alias = "to_string")]
119    fn to_str(&self) -> glib::GString {
120        unsafe {
121            from_glib_full(ffi::gtk_shortcut_trigger_to_string(
122                self.as_ref().to_glib_none().0,
123            ))
124        }
125    }
126
127    /// Checks if the given @event triggers @self.
128    /// ## `event`
129    /// the event to check
130    /// ## `enable_mnemonics`
131    /// [`true`] if mnemonics should trigger. Usually the
132    ///   value of this property is determined by checking that the passed
133    ///   in @event is a Key event and has the right modifiers set.
134    ///
135    /// # Returns
136    ///
137    /// Whether the event triggered the shortcut
138    #[doc(alias = "gtk_shortcut_trigger_trigger")]
139    fn trigger(&self, event: impl AsRef<gdk::Event>, enable_mnemonics: bool) -> gdk::KeyMatch {
140        unsafe {
141            from_glib(ffi::gtk_shortcut_trigger_trigger(
142                self.as_ref().to_glib_none().0,
143                event.as_ref().to_glib_none().0,
144                enable_mnemonics.into_glib(),
145            ))
146        }
147    }
148}
149
150impl<O: IsA<ShortcutTrigger>> ShortcutTriggerExt for O {}