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    /// Tries to parse the given string into a trigger.
38    ///
39    /// On success, the parsed trigger is returned.
40    /// When parsing failed, [`None`] is returned.
41    ///
42    /// The accepted strings are:
43    ///
44    ///   - `never`, for [`NeverTrigger`][crate::NeverTrigger]
45    ///   - a string parsed by gtk_accelerator_parse(), for a [`KeyvalTrigger`][crate::KeyvalTrigger], e.g. `<Control>C`
46    ///   - underscore, followed by a single character, for [`MnemonicTrigger`][crate::MnemonicTrigger], e.g. `_l`
47    ///   - two valid trigger strings, separated by a `|` character, for a
48    ///     [`AlternativeTrigger`][crate::AlternativeTrigger]: `<Control>q|<Control>w`
49    ///
50    /// Note that you will have to escape the `<` and `>` characters when specifying
51    /// triggers in XML files, such as GtkBuilder ui files. Use `&lt;` instead of
52    /// `<` and `&gt;` instead of `>`.
53    /// ## `string`
54    /// the string to parse
55    ///
56    /// # Returns
57    ///
58    /// a new [`ShortcutTrigger`][crate::ShortcutTrigger]
59    #[doc(alias = "gtk_shortcut_trigger_parse_string")]
60    pub fn parse_string(string: &str) -> Option<ShortcutTrigger> {
61        assert_initialized_main_thread!();
62        unsafe {
63            from_glib_full(ffi::gtk_shortcut_trigger_parse_string(
64                string.to_glib_none().0,
65            ))
66        }
67    }
68}
69
70impl std::fmt::Display for ShortcutTrigger {
71    #[inline]
72    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
73        f.write_str(&ShortcutTriggerExt::to_str(self))
74    }
75}
76
77/// Trait containing all [`struct@ShortcutTrigger`] methods.
78///
79/// # Implementors
80///
81/// [`AlternativeTrigger`][struct@crate::AlternativeTrigger], [`KeyvalTrigger`][struct@crate::KeyvalTrigger], [`MnemonicTrigger`][struct@crate::MnemonicTrigger], [`NeverTrigger`][struct@crate::NeverTrigger], [`ShortcutTrigger`][struct@crate::ShortcutTrigger]
82pub trait ShortcutTriggerExt: IsA<ShortcutTrigger> + 'static {
83    /// Gets textual representation for the given trigger.
84    ///
85    /// This function is returning a translated string for
86    /// presentation to end users for example in menu items
87    /// or in help texts.
88    ///
89    /// The @display in use may influence the resulting string in
90    /// various forms, such as resolving hardware keycodes or by
91    /// causing display-specific modifier names.
92    ///
93    /// The form of the representation may change at any time and is
94    /// not guaranteed to stay identical.
95    /// ## `display`
96    /// [`gdk::Display`][crate::gdk::Display] to print for
97    ///
98    /// # Returns
99    ///
100    /// a new string
101    #[doc(alias = "gtk_shortcut_trigger_to_label")]
102    fn to_label(&self, display: &impl IsA<gdk::Display>) -> glib::GString {
103        unsafe {
104            from_glib_full(ffi::gtk_shortcut_trigger_to_label(
105                self.as_ref().to_glib_none().0,
106                display.as_ref().to_glib_none().0,
107            ))
108        }
109    }
110
111    /// Prints the given trigger into a human-readable string.
112    ///
113    /// This is a small wrapper around `Gtk::ShortcutTrigger::print()`
114    /// to help when debugging.
115    ///
116    /// # Returns
117    ///
118    /// a new string
119    #[doc(alias = "gtk_shortcut_trigger_to_string")]
120    #[doc(alias = "to_string")]
121    fn to_str(&self) -> glib::GString {
122        unsafe {
123            from_glib_full(ffi::gtk_shortcut_trigger_to_string(
124                self.as_ref().to_glib_none().0,
125            ))
126        }
127    }
128
129    /// Checks if the given @event triggers @self.
130    /// ## `event`
131    /// the event to check
132    /// ## `enable_mnemonics`
133    /// [`true`] if mnemonics should trigger. Usually the
134    ///   value of this property is determined by checking that the passed
135    ///   in @event is a Key event and has the right modifiers set.
136    ///
137    /// # Returns
138    ///
139    /// Whether the event triggered the shortcut
140    #[doc(alias = "gtk_shortcut_trigger_trigger")]
141    fn trigger(&self, event: impl AsRef<gdk::Event>, enable_mnemonics: bool) -> gdk::KeyMatch {
142        unsafe {
143            from_glib(ffi::gtk_shortcut_trigger_trigger(
144                self.as_ref().to_glib_none().0,
145                event.as_ref().to_glib_none().0,
146                enable_mnemonics.into_glib(),
147            ))
148        }
149    }
150}
151
152impl<O: IsA<ShortcutTrigger>> ShortcutTriggerExt for O {}