Skip to main content

gtk/auto/
event_controller.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::{PropagationPhase, Widget};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14    /// [`EventController`][crate::EventController] is a base, low-level implementation for event
15    /// controllers. Those react to a series of `GdkEvents`, and possibly trigger
16    /// actions as a consequence of those.
17    ///
18    /// This is an Abstract Base Class, you cannot instantiate it.
19    ///
20    /// ## Properties
21    ///
22    ///
23    /// #### `propagation-phase`
24    ///  The propagation phase at which this controller will handle events.
25    ///
26    /// Readable | Writeable
27    ///
28    ///
29    /// #### `widget`
30    ///  The widget receiving the `GdkEvents` that the controller will handle.
31    ///
32    /// Readable | Writeable | Construct Only
33    ///
34    /// # Implements
35    ///
36    /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
37    #[doc(alias = "GtkEventController")]
38    pub struct EventController(Object<ffi::GtkEventController, ffi::GtkEventControllerClass>);
39
40    match fn {
41        type_ => || ffi::gtk_event_controller_get_type(),
42    }
43}
44
45impl EventController {
46    pub const NONE: Option<&'static EventController> = None;
47}
48
49mod sealed {
50    pub trait Sealed {}
51    impl<T: super::IsA<super::EventController>> Sealed for T {}
52}
53
54/// Trait containing all [`struct@EventController`] methods.
55///
56/// # Implementors
57///
58/// [`EventControllerKey`][struct@crate::EventControllerKey], [`EventControllerMotion`][struct@crate::EventControllerMotion], [`EventControllerScroll`][struct@crate::EventControllerScroll], [`EventController`][struct@crate::EventController], [`Gesture`][struct@crate::Gesture], [`PadController`][struct@crate::PadController]
59pub trait EventControllerExt: IsA<EventController> + sealed::Sealed + 'static {
60    /// Gets the propagation phase at which `self` handles events.
61    ///
62    /// # Returns
63    ///
64    /// the propagation phase
65    #[doc(alias = "gtk_event_controller_get_propagation_phase")]
66    #[doc(alias = "get_propagation_phase")]
67    fn propagation_phase(&self) -> PropagationPhase {
68        unsafe {
69            from_glib(ffi::gtk_event_controller_get_propagation_phase(
70                self.as_ref().to_glib_none().0,
71            ))
72        }
73    }
74
75    /// Returns the [`Widget`][crate::Widget] this controller relates to.
76    ///
77    /// # Returns
78    ///
79    /// a [`Widget`][crate::Widget]
80    #[doc(alias = "gtk_event_controller_get_widget")]
81    #[doc(alias = "get_widget")]
82    fn widget(&self) -> Option<Widget> {
83        unsafe {
84            from_glib_none(ffi::gtk_event_controller_get_widget(
85                self.as_ref().to_glib_none().0,
86            ))
87        }
88    }
89
90    /// Feeds an events into `self`, so it can be interpreted
91    /// and the controller actions triggered.
92    /// ## `event`
93    /// a `GdkEvent`
94    ///
95    /// # Returns
96    ///
97    /// [`true`] if the event was potentially useful to trigger the
98    ///  controller action
99    #[doc(alias = "gtk_event_controller_handle_event")]
100    fn handle_event(&self, event: &gdk::Event) -> bool {
101        unsafe {
102            from_glib(ffi::gtk_event_controller_handle_event(
103                self.as_ref().to_glib_none().0,
104                event.to_glib_none().0,
105            ))
106        }
107    }
108
109    /// Resets the `self` to a clean state. Every interaction
110    /// the controller did through [`handle-event`][struct@crate::EventController#handle-event]
111    /// will be dropped at this point.
112    #[doc(alias = "gtk_event_controller_reset")]
113    fn reset(&self) {
114        unsafe {
115            ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
116        }
117    }
118
119    /// Sets the propagation phase at which a controller handles events.
120    ///
121    /// If `phase` is [`PropagationPhase::None`][crate::PropagationPhase::None], no automatic event handling will be
122    /// performed, but other additional gesture maintenance will. In that phase,
123    /// the events can be managed by calling [`handle_event()`][Self::handle_event()].
124    /// ## `phase`
125    /// a propagation phase
126    #[doc(alias = "gtk_event_controller_set_propagation_phase")]
127    fn set_propagation_phase(&self, phase: PropagationPhase) {
128        unsafe {
129            ffi::gtk_event_controller_set_propagation_phase(
130                self.as_ref().to_glib_none().0,
131                phase.into_glib(),
132            );
133        }
134    }
135
136    #[doc(alias = "propagation-phase")]
137    fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
138        unsafe extern "C" fn notify_propagation_phase_trampoline<
139            P: IsA<EventController>,
140            F: Fn(&P) + 'static,
141        >(
142            this: *mut ffi::GtkEventController,
143            _param_spec: glib::ffi::gpointer,
144            f: glib::ffi::gpointer,
145        ) {
146            let f: &F = &*(f as *const F);
147            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
148        }
149        unsafe {
150            let f: Box_<F> = Box_::new(f);
151            connect_raw(
152                self.as_ptr() as *mut _,
153                b"notify::propagation-phase\0".as_ptr() as *const _,
154                Some(transmute::<_, unsafe extern "C" fn()>(
155                    notify_propagation_phase_trampoline::<Self, F> as *const (),
156                )),
157                Box_::into_raw(f),
158            )
159        }
160    }
161}
162
163impl<O: IsA<EventController>> EventControllerExt for O {}
164
165impl fmt::Display for EventController {
166    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
167        f.write_str("EventController")
168    }
169}