1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::TextView;
use glib::translate::*;
use glib::IsA;

// rustdoc-stripper-ignore-next
/// Trait containing manually implemented methods of [`TextView`](crate::TextView).
pub trait TextViewExtManual {
    /// Allow the [`TextView`][crate::TextView] input method to internally handle key press
    /// and release events.
    ///
    /// If this function returns [`true`], then no further processing should be
    /// done for this key event. See [`IMContextExtManual::filter_keypress()`][crate::prelude::IMContextExtManual::filter_keypress()].
    ///
    /// Note that you are expected to call this function from your handler
    /// when overriding key event handling. This is needed in the case when
    /// you need to insert your own key handling between the input method
    /// and the default key event handling of the [`TextView`][crate::TextView].
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static gboolean
    /// gtk_foo_bar_key_press_event (GtkWidget *widget,
    ///                              GdkEvent  *event)
    /// {
    ///   guint keyval;
    ///
    ///   gdk_event_get_keyval ((GdkEvent*)event, &keyval);
    ///
    ///   if (keyval == GDK_KEY_Return || keyval == GDK_KEY_KP_Enter)
    ///     {
    ///       if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (widget), event))
    ///         return TRUE;
    ///     }
    ///
    ///   // Do some stuff
    ///
    ///   return GTK_WIDGET_CLASS (gtk_foo_bar_parent_class)->key_press_event (widget, event);
    /// }
    /// ```
    /// ## `event`
    /// the key event
    ///
    /// # Returns
    ///
    /// [`true`] if the input method handled the key event.
    #[doc(alias = "gtk_text_view_im_context_filter_keypress")]
    fn im_context_filter_keypress(&self, event: &impl AsRef<gdk::Event>) -> bool;
}

impl<O: IsA<TextView>> TextViewExtManual for O {
    fn im_context_filter_keypress(&self, event: &impl AsRef<gdk::Event>) -> bool {
        unsafe {
            from_glib(ffi::gtk_text_view_im_context_filter_keypress(
                self.as_ref().to_glib_none().0,
                event.as_ref().to_glib_none().0,
            ))
        }
    }
}