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 or more 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 `<` instead of
52 /// `<` and `>` 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 /// Creates a shortcut trigger that will trigger for
70 /// the usual key combinations that trigger a context
71 /// menu, such as <kbd>Menu</kbd> or
72 /// <kbd>Shift</kbd>+<kbd>F10</kbd>.
73 ///
74 /// # Returns
75 ///
76 /// a new [`ShortcutTrigger`][crate::ShortcutTrigger]
77 #[cfg(feature = "v4_24")]
78 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
79 #[doc(alias = "gtk_shortcut_trigger_create_for_menu")]
80 pub fn create_for_menu() -> ShortcutTrigger {
81 assert_initialized_main_thread!();
82 unsafe { from_glib_full(ffi::gtk_shortcut_trigger_create_for_menu()) }
83 }
84}
85
86impl std::fmt::Display for ShortcutTrigger {
87 #[inline]
88 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
89 f.write_str(&ShortcutTriggerExt::to_str(self))
90 }
91}
92
93/// Trait containing all [`struct@ShortcutTrigger`] methods.
94///
95/// # Implementors
96///
97/// [`AlternativeTrigger`][struct@crate::AlternativeTrigger], [`KeyvalTrigger`][struct@crate::KeyvalTrigger], [`MnemonicTrigger`][struct@crate::MnemonicTrigger], [`NeverTrigger`][struct@crate::NeverTrigger], [`ShortcutTrigger`][struct@crate::ShortcutTrigger]
98pub trait ShortcutTriggerExt: IsA<ShortcutTrigger> + 'static {
99 /// Gets textual representation for the given trigger.
100 ///
101 /// This function is returning a translated string for
102 /// presentation to end users for example in menu items
103 /// or in help texts.
104 ///
105 /// The @display in use may influence the resulting string in
106 /// various forms, such as resolving hardware keycodes or by
107 /// causing display-specific modifier names.
108 ///
109 /// The form of the representation may change at any time and is
110 /// not guaranteed to stay identical.
111 /// ## `display`
112 /// [`gdk::Display`][crate::gdk::Display] to print for
113 ///
114 /// # Returns
115 ///
116 /// a new string
117 #[doc(alias = "gtk_shortcut_trigger_to_label")]
118 fn to_label(&self, display: &impl IsA<gdk::Display>) -> glib::GString {
119 unsafe {
120 from_glib_full(ffi::gtk_shortcut_trigger_to_label(
121 self.as_ref().to_glib_none().0,
122 display.as_ref().to_glib_none().0,
123 ))
124 }
125 }
126
127 /// Prints the given trigger into a human-readable string.
128 ///
129 /// This is a small wrapper around `Gtk::ShortcutTrigger::print()`
130 /// to help when debugging.
131 ///
132 /// # Returns
133 ///
134 /// a new string
135 #[doc(alias = "gtk_shortcut_trigger_to_string")]
136 #[doc(alias = "to_string")]
137 fn to_str(&self) -> glib::GString {
138 unsafe {
139 from_glib_full(ffi::gtk_shortcut_trigger_to_string(
140 self.as_ref().to_glib_none().0,
141 ))
142 }
143 }
144
145 /// Checks if the given @event triggers @self.
146 /// ## `event`
147 /// the event to check
148 /// ## `enable_mnemonics`
149 /// [`true`] if mnemonics should trigger. Usually the
150 /// value of this property is determined by checking that the passed
151 /// in @event is a Key event and has the right modifiers set.
152 ///
153 /// # Returns
154 ///
155 /// Whether the event triggered the shortcut
156 #[doc(alias = "gtk_shortcut_trigger_trigger")]
157 fn trigger(&self, event: impl AsRef<gdk::Event>, enable_mnemonics: bool) -> gdk::KeyMatch {
158 unsafe {
159 from_glib(ffi::gtk_shortcut_trigger_trigger(
160 self.as_ref().to_glib_none().0,
161 event.as_ref().to_glib_none().0,
162 enable_mnemonics.into_glib(),
163 ))
164 }
165 }
166}
167
168impl<O: IsA<ShortcutTrigger>> ShortcutTriggerExt for O {}