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`], [`EventControllerExtManual`][trait@crate::prelude::EventControllerExtManual]
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    #[doc(alias = "name")]
270    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
271        unsafe extern "C" fn notify_name_trampoline<
272            P: IsA<EventController>,
273            F: Fn(&P) + 'static,
274        >(
275            this: *mut ffi::GtkEventController,
276            _param_spec: glib::ffi::gpointer,
277            f: glib::ffi::gpointer,
278        ) {
279            let f: &F = &*(f as *const F);
280            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
281        }
282        unsafe {
283            let f: Box_<F> = Box_::new(f);
284            connect_raw(
285                self.as_ptr() as *mut _,
286                b"notify::name\0".as_ptr() as *const _,
287                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
288                    notify_name_trampoline::<Self, F> as *const (),
289                )),
290                Box_::into_raw(f),
291            )
292        }
293    }
294
295    #[doc(alias = "propagation-limit")]
296    fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
297        unsafe extern "C" fn notify_propagation_limit_trampoline<
298            P: IsA<EventController>,
299            F: Fn(&P) + 'static,
300        >(
301            this: *mut ffi::GtkEventController,
302            _param_spec: glib::ffi::gpointer,
303            f: glib::ffi::gpointer,
304        ) {
305            let f: &F = &*(f as *const F);
306            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
307        }
308        unsafe {
309            let f: Box_<F> = Box_::new(f);
310            connect_raw(
311                self.as_ptr() as *mut _,
312                b"notify::propagation-limit\0".as_ptr() as *const _,
313                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
314                    notify_propagation_limit_trampoline::<Self, F> as *const (),
315                )),
316                Box_::into_raw(f),
317            )
318        }
319    }
320
321    #[doc(alias = "propagation-phase")]
322    fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
323        unsafe extern "C" fn notify_propagation_phase_trampoline<
324            P: IsA<EventController>,
325            F: Fn(&P) + 'static,
326        >(
327            this: *mut ffi::GtkEventController,
328            _param_spec: glib::ffi::gpointer,
329            f: glib::ffi::gpointer,
330        ) {
331            let f: &F = &*(f as *const F);
332            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
333        }
334        unsafe {
335            let f: Box_<F> = Box_::new(f);
336            connect_raw(
337                self.as_ptr() as *mut _,
338                b"notify::propagation-phase\0".as_ptr() as *const _,
339                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
340                    notify_propagation_phase_trampoline::<Self, F> as *const (),
341                )),
342                Box_::into_raw(f),
343            )
344        }
345    }
346
347    #[doc(alias = "widget")]
348    fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
349        unsafe extern "C" fn notify_widget_trampoline<
350            P: IsA<EventController>,
351            F: Fn(&P) + 'static,
352        >(
353            this: *mut ffi::GtkEventController,
354            _param_spec: glib::ffi::gpointer,
355            f: glib::ffi::gpointer,
356        ) {
357            let f: &F = &*(f as *const F);
358            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
359        }
360        unsafe {
361            let f: Box_<F> = Box_::new(f);
362            connect_raw(
363                self.as_ptr() as *mut _,
364                b"notify::widget\0".as_ptr() as *const _,
365                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
366                    notify_widget_trampoline::<Self, F> as *const (),
367                )),
368                Box_::into_raw(f),
369            )
370        }
371    }
372}
373
374impl<O: IsA<EventController>> EventControllerExt for O {}