gtk4/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::{ffi, PropagationLimit, PropagationPhase, Widget};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// [`EventController`][crate::EventController] is the base class for event controllers.
15    ///
16    /// These are ancillary objects associated to widgets, which react
17    /// to `GdkEvents`, and possibly trigger actions as a consequence.
18    ///
19    /// Event controllers are added to a widget with
20    /// [`WidgetExt::add_controller()`][crate::prelude::WidgetExt::add_controller()]. It is rarely necessary to
21    /// explicitly remove a controller with [`WidgetExt::remove_controller()`][crate::prelude::WidgetExt::remove_controller()].
22    ///
23    /// See the chapter on [input handling](input-handling.html) for
24    /// an overview of the basic concepts, such as the capture and bubble
25    /// phases of event propagation.
26    ///
27    /// This is an Abstract Base Class, you cannot instantiate it.
28    ///
29    /// ## Properties
30    ///
31    ///
32    /// #### `name`
33    ///  The name for this controller, typically used for debugging purposes.
34    ///
35    /// Readable | Writeable
36    ///
37    ///
38    /// #### `propagation-limit`
39    ///  The limit for which events this controller will handle.
40    ///
41    /// Readable | Writeable
42    ///
43    ///
44    /// #### `propagation-phase`
45    ///  The propagation phase at which this controller will handle events.
46    ///
47    /// Readable | Writeable
48    ///
49    ///
50    /// #### `widget`
51    ///  The widget receiving the `GdkEvents` that the controller will handle.
52    ///
53    /// Readable
54    ///
55    /// # Implements
56    ///
57    /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
58    #[doc(alias = "GtkEventController")]
59    pub struct EventController(Object<ffi::GtkEventController, ffi::GtkEventControllerClass>);
60
61    match fn {
62        type_ => || ffi::gtk_event_controller_get_type(),
63    }
64}
65
66impl EventController {
67    pub const NONE: Option<&'static EventController> = None;
68}
69
70mod sealed {
71    pub trait Sealed {}
72    impl<T: super::IsA<super::EventController>> Sealed for T {}
73}
74
75/// Trait containing all [`struct@EventController`] methods.
76///
77/// # Implementors
78///
79/// [`DropControllerMotion`][struct@crate::DropControllerMotion], [`DropTargetAsync`][struct@crate::DropTargetAsync], [`DropTarget`][struct@crate::DropTarget], [`EventControllerFocus`][struct@crate::EventControllerFocus], [`EventControllerKey`][struct@crate::EventControllerKey], [`EventControllerLegacy`][struct@crate::EventControllerLegacy], [`EventControllerMotion`][struct@crate::EventControllerMotion], [`EventControllerScroll`][struct@crate::EventControllerScroll], [`EventController`][struct@crate::EventController], [`Gesture`][struct@crate::Gesture], [`PadController`][struct@crate::PadController], [`ShortcutController`][struct@crate::ShortcutController]
80pub trait EventControllerExt: IsA<EventController> + sealed::Sealed + 'static {
81    /// Returns the event that is currently being handled by the controller.
82    ///
83    /// At other times, [`None`] is returned.
84    ///
85    /// # Returns
86    ///
87    /// the event that is currently
88    ///   handled by @self
89    #[doc(alias = "gtk_event_controller_get_current_event")]
90    #[doc(alias = "get_current_event")]
91    fn current_event(&self) -> Option<gdk::Event> {
92        unsafe {
93            from_glib_none(ffi::gtk_event_controller_get_current_event(
94                self.as_ref().to_glib_none().0,
95            ))
96        }
97    }
98
99    /// Returns the device of the event that is currently being
100    /// handled by the controller.
101    ///
102    /// At other times, [`None`] is returned.
103    ///
104    /// # Returns
105    ///
106    /// device of the event is
107    ///   currently handled by @self
108    #[doc(alias = "gtk_event_controller_get_current_event_device")]
109    #[doc(alias = "get_current_event_device")]
110    fn current_event_device(&self) -> Option<gdk::Device> {
111        unsafe {
112            from_glib_none(ffi::gtk_event_controller_get_current_event_device(
113                self.as_ref().to_glib_none().0,
114            ))
115        }
116    }
117
118    /// Returns the modifier state of the event that is currently being
119    /// handled by the controller.
120    ///
121    /// At other times, 0 is returned.
122    ///
123    /// # Returns
124    ///
125    /// modifier state of the event is currently handled by @self
126    #[doc(alias = "gtk_event_controller_get_current_event_state")]
127    #[doc(alias = "get_current_event_state")]
128    fn current_event_state(&self) -> gdk::ModifierType {
129        unsafe {
130            from_glib(ffi::gtk_event_controller_get_current_event_state(
131                self.as_ref().to_glib_none().0,
132            ))
133        }
134    }
135
136    /// Returns the timestamp of the event that is currently being
137    /// handled by the controller.
138    ///
139    /// At other times, 0 is returned.
140    ///
141    /// # Returns
142    ///
143    /// timestamp of the event is currently handled by @self
144    #[doc(alias = "gtk_event_controller_get_current_event_time")]
145    #[doc(alias = "get_current_event_time")]
146    fn current_event_time(&self) -> u32 {
147        unsafe { ffi::gtk_event_controller_get_current_event_time(self.as_ref().to_glib_none().0) }
148    }
149
150    /// Gets the name of @self.
151    ///
152    /// # Returns
153    ///
154    /// The controller name
155    #[doc(alias = "gtk_event_controller_get_name")]
156    #[doc(alias = "get_name")]
157    fn name(&self) -> Option<glib::GString> {
158        unsafe {
159            from_glib_none(ffi::gtk_event_controller_get_name(
160                self.as_ref().to_glib_none().0,
161            ))
162        }
163    }
164
165    /// Gets the propagation limit of the event controller.
166    ///
167    /// # Returns
168    ///
169    /// the propagation limit
170    #[doc(alias = "gtk_event_controller_get_propagation_limit")]
171    #[doc(alias = "get_propagation_limit")]
172    #[doc(alias = "propagation-limit")]
173    fn propagation_limit(&self) -> PropagationLimit {
174        unsafe {
175            from_glib(ffi::gtk_event_controller_get_propagation_limit(
176                self.as_ref().to_glib_none().0,
177            ))
178        }
179    }
180
181    /// Gets the propagation phase at which @self handles events.
182    ///
183    /// # Returns
184    ///
185    /// the propagation phase
186    #[doc(alias = "gtk_event_controller_get_propagation_phase")]
187    #[doc(alias = "get_propagation_phase")]
188    #[doc(alias = "propagation-phase")]
189    fn propagation_phase(&self) -> PropagationPhase {
190        unsafe {
191            from_glib(ffi::gtk_event_controller_get_propagation_phase(
192                self.as_ref().to_glib_none().0,
193            ))
194        }
195    }
196
197    /// Returns the [`Widget`][crate::Widget] this controller relates to.
198    ///
199    /// # Returns
200    ///
201    /// a [`Widget`][crate::Widget]
202    #[doc(alias = "gtk_event_controller_get_widget")]
203    #[doc(alias = "get_widget")]
204    fn widget(&self) -> Option<Widget> {
205        unsafe {
206            from_glib_none(ffi::gtk_event_controller_get_widget(
207                self.as_ref().to_glib_none().0,
208            ))
209        }
210    }
211
212    /// Resets the @self to a clean state.
213    #[doc(alias = "gtk_event_controller_reset")]
214    fn reset(&self) {
215        unsafe {
216            ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
217        }
218    }
219
220    /// Sets a name on the controller that can be used for debugging.
221    /// ## `name`
222    /// a name for @self
223    #[doc(alias = "gtk_event_controller_set_name")]
224    #[doc(alias = "name")]
225    fn set_name(&self, name: Option<&str>) {
226        unsafe {
227            ffi::gtk_event_controller_set_name(
228                self.as_ref().to_glib_none().0,
229                name.to_glib_none().0,
230            );
231        }
232    }
233
234    /// Sets the event propagation limit on the event controller.
235    ///
236    /// If the limit is set to [`PropagationLimit::SameNative`][crate::PropagationLimit::SameNative], the controller
237    /// won't handle events that are targeted at widgets on a different
238    /// surface, such as popovers.
239    /// ## `limit`
240    /// the propagation limit
241    #[doc(alias = "gtk_event_controller_set_propagation_limit")]
242    #[doc(alias = "propagation-limit")]
243    fn set_propagation_limit(&self, limit: PropagationLimit) {
244        unsafe {
245            ffi::gtk_event_controller_set_propagation_limit(
246                self.as_ref().to_glib_none().0,
247                limit.into_glib(),
248            );
249        }
250    }
251
252    /// Sets the propagation phase at which a controller handles events.
253    ///
254    /// If @phase is [`PropagationPhase::None`][crate::PropagationPhase::None], no automatic event handling will be
255    /// performed, but other additional gesture maintenance will.
256    /// ## `phase`
257    /// a propagation phase
258    #[doc(alias = "gtk_event_controller_set_propagation_phase")]
259    #[doc(alias = "propagation-phase")]
260    fn set_propagation_phase(&self, phase: PropagationPhase) {
261        unsafe {
262            ffi::gtk_event_controller_set_propagation_phase(
263                self.as_ref().to_glib_none().0,
264                phase.into_glib(),
265            );
266        }
267    }
268
269    /// Sets a name on the controller that can be used for debugging.
270    /// ## `name`
271    /// a name for @self, must be a static string
272    #[cfg(feature = "v4_8")]
273    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
274    #[doc(alias = "gtk_event_controller_set_static_name")]
275    fn set_static_name(&self, name: Option<&str>) {
276        unsafe {
277            ffi::gtk_event_controller_set_static_name(
278                self.as_ref().to_glib_none().0,
279                name.to_glib_none().0,
280            );
281        }
282    }
283
284    #[doc(alias = "name")]
285    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
286        unsafe extern "C" fn notify_name_trampoline<
287            P: IsA<EventController>,
288            F: Fn(&P) + 'static,
289        >(
290            this: *mut ffi::GtkEventController,
291            _param_spec: glib::ffi::gpointer,
292            f: glib::ffi::gpointer,
293        ) {
294            let f: &F = &*(f as *const F);
295            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
296        }
297        unsafe {
298            let f: Box_<F> = Box_::new(f);
299            connect_raw(
300                self.as_ptr() as *mut _,
301                b"notify::name\0".as_ptr() as *const _,
302                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
303                    notify_name_trampoline::<Self, F> as *const (),
304                )),
305                Box_::into_raw(f),
306            )
307        }
308    }
309
310    #[doc(alias = "propagation-limit")]
311    fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
312        unsafe extern "C" fn notify_propagation_limit_trampoline<
313            P: IsA<EventController>,
314            F: Fn(&P) + 'static,
315        >(
316            this: *mut ffi::GtkEventController,
317            _param_spec: glib::ffi::gpointer,
318            f: glib::ffi::gpointer,
319        ) {
320            let f: &F = &*(f as *const F);
321            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
322        }
323        unsafe {
324            let f: Box_<F> = Box_::new(f);
325            connect_raw(
326                self.as_ptr() as *mut _,
327                b"notify::propagation-limit\0".as_ptr() as *const _,
328                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
329                    notify_propagation_limit_trampoline::<Self, F> as *const (),
330                )),
331                Box_::into_raw(f),
332            )
333        }
334    }
335
336    #[doc(alias = "propagation-phase")]
337    fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
338        unsafe extern "C" fn notify_propagation_phase_trampoline<
339            P: IsA<EventController>,
340            F: Fn(&P) + 'static,
341        >(
342            this: *mut ffi::GtkEventController,
343            _param_spec: glib::ffi::gpointer,
344            f: glib::ffi::gpointer,
345        ) {
346            let f: &F = &*(f as *const F);
347            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
348        }
349        unsafe {
350            let f: Box_<F> = Box_::new(f);
351            connect_raw(
352                self.as_ptr() as *mut _,
353                b"notify::propagation-phase\0".as_ptr() as *const _,
354                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
355                    notify_propagation_phase_trampoline::<Self, F> as *const (),
356                )),
357                Box_::into_raw(f),
358            )
359        }
360    }
361
362    #[doc(alias = "widget")]
363    fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
364        unsafe extern "C" fn notify_widget_trampoline<
365            P: IsA<EventController>,
366            F: Fn(&P) + 'static,
367        >(
368            this: *mut ffi::GtkEventController,
369            _param_spec: glib::ffi::gpointer,
370            f: glib::ffi::gpointer,
371        ) {
372            let f: &F = &*(f as *const F);
373            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
374        }
375        unsafe {
376            let f: Box_<F> = Box_::new(f);
377            connect_raw(
378                self.as_ptr() as *mut _,
379                b"notify::widget\0".as_ptr() as *const _,
380                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
381                    notify_widget_trampoline::<Self, F> as *const (),
382                )),
383                Box_::into_raw(f),
384            )
385        }
386    }
387}
388
389impl<O: IsA<EventController>> EventControllerExt for O {}