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, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
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 | Writable
27    ///
28    ///
29    /// #### `widget`
30    ///  The widget receiving the `GdkEvents` that the controller will handle.
31    ///
32    /// Readable | Writable | 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
49/// Trait containing all [`struct@EventController`] methods.
50///
51/// # Implementors
52///
53/// [`EventControllerKey`][struct@crate::EventControllerKey], [`EventControllerMotion`][struct@crate::EventControllerMotion], [`EventControllerScroll`][struct@crate::EventControllerScroll], [`EventController`][struct@crate::EventController], [`Gesture`][struct@crate::Gesture], [`PadController`][struct@crate::PadController]
54pub trait EventControllerExt: IsA<EventController> + 'static {
55    /// Gets the propagation phase at which `self` handles events.
56    ///
57    /// # Returns
58    ///
59    /// the propagation phase
60    #[doc(alias = "gtk_event_controller_get_propagation_phase")]
61    #[doc(alias = "get_propagation_phase")]
62    #[doc(alias = "propagation-phase")]
63    fn propagation_phase(&self) -> PropagationPhase {
64        unsafe {
65            from_glib(ffi::gtk_event_controller_get_propagation_phase(
66                self.as_ref().to_glib_none().0,
67            ))
68        }
69    }
70
71    /// Returns the [`Widget`][crate::Widget] this controller relates to.
72    ///
73    /// # Returns
74    ///
75    /// a [`Widget`][crate::Widget]
76    #[doc(alias = "gtk_event_controller_get_widget")]
77    #[doc(alias = "get_widget")]
78    fn widget(&self) -> Option<Widget> {
79        unsafe {
80            from_glib_none(ffi::gtk_event_controller_get_widget(
81                self.as_ref().to_glib_none().0,
82            ))
83        }
84    }
85
86    /// Feeds an events into `self`, so it can be interpreted
87    /// and the controller actions triggered.
88    /// ## `event`
89    /// a `GdkEvent`
90    ///
91    /// # Returns
92    ///
93    /// [`true`] if the event was potentially useful to trigger the
94    ///  controller action
95    #[doc(alias = "gtk_event_controller_handle_event")]
96    fn handle_event(&self, event: &gdk::Event) -> bool {
97        unsafe {
98            from_glib(ffi::gtk_event_controller_handle_event(
99                self.as_ref().to_glib_none().0,
100                event.to_glib_none().0,
101            ))
102        }
103    }
104
105    /// Resets the `self` to a clean state. Every interaction
106    /// the controller did through [`handle-event`][struct@crate::EventController#handle-event]
107    /// will be dropped at this point.
108    #[doc(alias = "gtk_event_controller_reset")]
109    fn reset(&self) {
110        unsafe {
111            ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
112        }
113    }
114
115    /// Sets the propagation phase at which a controller handles events.
116    ///
117    /// If `phase` is [`PropagationPhase::None`][crate::PropagationPhase::None], no automatic event handling will be
118    /// performed, but other additional gesture maintenance will. In that phase,
119    /// the events can be managed by calling [`handle_event()`][Self::handle_event()].
120    /// ## `phase`
121    /// a propagation phase
122    #[doc(alias = "gtk_event_controller_set_propagation_phase")]
123    #[doc(alias = "propagation-phase")]
124    fn set_propagation_phase(&self, phase: PropagationPhase) {
125        unsafe {
126            ffi::gtk_event_controller_set_propagation_phase(
127                self.as_ref().to_glib_none().0,
128                phase.into_glib(),
129            );
130        }
131    }
132
133    #[doc(alias = "propagation-phase")]
134    fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
135        unsafe extern "C" fn notify_propagation_phase_trampoline<
136            P: IsA<EventController>,
137            F: Fn(&P) + 'static,
138        >(
139            this: *mut ffi::GtkEventController,
140            _param_spec: glib::ffi::gpointer,
141            f: glib::ffi::gpointer,
142        ) {
143            unsafe {
144                let f: &F = &*(f as *const F);
145                f(EventController::from_glib_borrow(this).unsafe_cast_ref())
146            }
147        }
148        unsafe {
149            let f: Box_<F> = Box_::new(f);
150            connect_raw(
151                self.as_ptr() as *mut _,
152                c"notify::propagation-phase".as_ptr(),
153                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
154                    notify_propagation_phase_trampoline::<Self, F> as *const (),
155                )),
156                Box_::into_raw(f),
157            )
158        }
159    }
160}
161
162impl<O: IsA<EventController>> EventControllerExt for O {}