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    /// 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
70/// Trait containing all [`struct@EventController`] methods.
71///
72/// # Implementors
73///
74/// [`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]
75pub trait EventControllerExt: IsA<EventController> + 'static {
76    /// Returns the event that is currently being handled by the controller.
77    ///
78    /// At other times, [`None`] is returned.
79    ///
80    /// # Returns
81    ///
82    /// the event that is currently
83    ///   handled by @self
84    #[doc(alias = "gtk_event_controller_get_current_event")]
85    #[doc(alias = "get_current_event")]
86    fn current_event(&self) -> Option<gdk::Event> {
87        unsafe {
88            from_glib_none(ffi::gtk_event_controller_get_current_event(
89                self.as_ref().to_glib_none().0,
90            ))
91        }
92    }
93
94    /// Returns the device of the event that is currently being
95    /// handled by the controller.
96    ///
97    /// At other times, [`None`] is returned.
98    ///
99    /// # Returns
100    ///
101    /// device of the event is
102    ///   currently handled by @self
103    #[doc(alias = "gtk_event_controller_get_current_event_device")]
104    #[doc(alias = "get_current_event_device")]
105    fn current_event_device(&self) -> Option<gdk::Device> {
106        unsafe {
107            from_glib_none(ffi::gtk_event_controller_get_current_event_device(
108                self.as_ref().to_glib_none().0,
109            ))
110        }
111    }
112
113    /// Returns the modifier state of the event that is currently being
114    /// handled by the controller.
115    ///
116    /// At other times, 0 is returned.
117    ///
118    /// # Returns
119    ///
120    /// modifier state of the event is currently handled by @self
121    #[doc(alias = "gtk_event_controller_get_current_event_state")]
122    #[doc(alias = "get_current_event_state")]
123    fn current_event_state(&self) -> gdk::ModifierType {
124        unsafe {
125            from_glib(ffi::gtk_event_controller_get_current_event_state(
126                self.as_ref().to_glib_none().0,
127            ))
128        }
129    }
130
131    /// Returns the timestamp of the event that is currently being
132    /// handled by the controller.
133    ///
134    /// At other times, 0 is returned.
135    ///
136    /// # Returns
137    ///
138    /// timestamp of the event is currently handled by @self
139    #[doc(alias = "gtk_event_controller_get_current_event_time")]
140    #[doc(alias = "get_current_event_time")]
141    fn current_event_time(&self) -> u32 {
142        unsafe { ffi::gtk_event_controller_get_current_event_time(self.as_ref().to_glib_none().0) }
143    }
144
145    /// Gets the name of @self.
146    ///
147    /// # Returns
148    ///
149    /// The controller name
150    #[doc(alias = "gtk_event_controller_get_name")]
151    #[doc(alias = "get_name")]
152    fn name(&self) -> Option<glib::GString> {
153        unsafe {
154            from_glib_none(ffi::gtk_event_controller_get_name(
155                self.as_ref().to_glib_none().0,
156            ))
157        }
158    }
159
160    /// Gets the propagation limit of the event controller.
161    ///
162    /// # Returns
163    ///
164    /// the propagation limit
165    #[doc(alias = "gtk_event_controller_get_propagation_limit")]
166    #[doc(alias = "get_propagation_limit")]
167    #[doc(alias = "propagation-limit")]
168    fn propagation_limit(&self) -> PropagationLimit {
169        unsafe {
170            from_glib(ffi::gtk_event_controller_get_propagation_limit(
171                self.as_ref().to_glib_none().0,
172            ))
173        }
174    }
175
176    /// Gets the propagation phase at which @self handles events.
177    ///
178    /// # Returns
179    ///
180    /// the propagation phase
181    #[doc(alias = "gtk_event_controller_get_propagation_phase")]
182    #[doc(alias = "get_propagation_phase")]
183    #[doc(alias = "propagation-phase")]
184    fn propagation_phase(&self) -> PropagationPhase {
185        unsafe {
186            from_glib(ffi::gtk_event_controller_get_propagation_phase(
187                self.as_ref().to_glib_none().0,
188            ))
189        }
190    }
191
192    /// Returns the [`Widget`][crate::Widget] this controller relates to.
193    ///
194    /// # Returns
195    ///
196    /// a [`Widget`][crate::Widget]
197    #[doc(alias = "gtk_event_controller_get_widget")]
198    #[doc(alias = "get_widget")]
199    fn widget(&self) -> Option<Widget> {
200        unsafe {
201            from_glib_none(ffi::gtk_event_controller_get_widget(
202                self.as_ref().to_glib_none().0,
203            ))
204        }
205    }
206
207    /// Resets the @self to a clean state.
208    #[doc(alias = "gtk_event_controller_reset")]
209    fn reset(&self) {
210        unsafe {
211            ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
212        }
213    }
214
215    /// Sets a name on the controller that can be used for debugging.
216    /// ## `name`
217    /// a name for @self
218    #[doc(alias = "gtk_event_controller_set_name")]
219    #[doc(alias = "name")]
220    fn set_name(&self, name: Option<&str>) {
221        unsafe {
222            ffi::gtk_event_controller_set_name(
223                self.as_ref().to_glib_none().0,
224                name.to_glib_none().0,
225            );
226        }
227    }
228
229    /// Sets the event propagation limit on the event controller.
230    ///
231    /// If the limit is set to [`PropagationLimit::SameNative`][crate::PropagationLimit::SameNative], the controller
232    /// won't handle events that are targeted at widgets on a different
233    /// surface, such as popovers.
234    /// ## `limit`
235    /// the propagation limit
236    #[doc(alias = "gtk_event_controller_set_propagation_limit")]
237    #[doc(alias = "propagation-limit")]
238    fn set_propagation_limit(&self, limit: PropagationLimit) {
239        unsafe {
240            ffi::gtk_event_controller_set_propagation_limit(
241                self.as_ref().to_glib_none().0,
242                limit.into_glib(),
243            );
244        }
245    }
246
247    /// Sets the propagation phase at which a controller handles events.
248    ///
249    /// If @phase is [`PropagationPhase::None`][crate::PropagationPhase::None], no automatic event handling will be
250    /// performed, but other additional gesture maintenance will.
251    /// ## `phase`
252    /// a propagation phase
253    #[doc(alias = "gtk_event_controller_set_propagation_phase")]
254    #[doc(alias = "propagation-phase")]
255    fn set_propagation_phase(&self, phase: PropagationPhase) {
256        unsafe {
257            ffi::gtk_event_controller_set_propagation_phase(
258                self.as_ref().to_glib_none().0,
259                phase.into_glib(),
260            );
261        }
262    }
263
264    /// Sets a name on the controller that can be used for debugging.
265    /// ## `name`
266    /// a name for @self, must be a static string
267    #[cfg(feature = "v4_8")]
268    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
269    #[doc(alias = "gtk_event_controller_set_static_name")]
270    fn set_static_name(&self, name: Option<&str>) {
271        unsafe {
272            ffi::gtk_event_controller_set_static_name(
273                self.as_ref().to_glib_none().0,
274                name.to_glib_none().0,
275            );
276        }
277    }
278
279    #[doc(alias = "name")]
280    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
281        unsafe extern "C" fn notify_name_trampoline<
282            P: IsA<EventController>,
283            F: Fn(&P) + 'static,
284        >(
285            this: *mut ffi::GtkEventController,
286            _param_spec: glib::ffi::gpointer,
287            f: glib::ffi::gpointer,
288        ) {
289            let f: &F = &*(f as *const F);
290            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
291        }
292        unsafe {
293            let f: Box_<F> = Box_::new(f);
294            connect_raw(
295                self.as_ptr() as *mut _,
296                c"notify::name".as_ptr() as *const _,
297                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
298                    notify_name_trampoline::<Self, F> as *const (),
299                )),
300                Box_::into_raw(f),
301            )
302        }
303    }
304
305    #[doc(alias = "propagation-limit")]
306    fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
307        unsafe extern "C" fn notify_propagation_limit_trampoline<
308            P: IsA<EventController>,
309            F: Fn(&P) + 'static,
310        >(
311            this: *mut ffi::GtkEventController,
312            _param_spec: glib::ffi::gpointer,
313            f: glib::ffi::gpointer,
314        ) {
315            let f: &F = &*(f as *const F);
316            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
317        }
318        unsafe {
319            let f: Box_<F> = Box_::new(f);
320            connect_raw(
321                self.as_ptr() as *mut _,
322                c"notify::propagation-limit".as_ptr() as *const _,
323                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
324                    notify_propagation_limit_trampoline::<Self, F> as *const (),
325                )),
326                Box_::into_raw(f),
327            )
328        }
329    }
330
331    #[doc(alias = "propagation-phase")]
332    fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
333        unsafe extern "C" fn notify_propagation_phase_trampoline<
334            P: IsA<EventController>,
335            F: Fn(&P) + 'static,
336        >(
337            this: *mut ffi::GtkEventController,
338            _param_spec: glib::ffi::gpointer,
339            f: glib::ffi::gpointer,
340        ) {
341            let f: &F = &*(f as *const F);
342            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
343        }
344        unsafe {
345            let f: Box_<F> = Box_::new(f);
346            connect_raw(
347                self.as_ptr() as *mut _,
348                c"notify::propagation-phase".as_ptr() as *const _,
349                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
350                    notify_propagation_phase_trampoline::<Self, F> as *const (),
351                )),
352                Box_::into_raw(f),
353            )
354        }
355    }
356
357    #[doc(alias = "widget")]
358    fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
359        unsafe extern "C" fn notify_widget_trampoline<
360            P: IsA<EventController>,
361            F: Fn(&P) + 'static,
362        >(
363            this: *mut ffi::GtkEventController,
364            _param_spec: glib::ffi::gpointer,
365            f: glib::ffi::gpointer,
366        ) {
367            let f: &F = &*(f as *const F);
368            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
369        }
370        unsafe {
371            let f: Box_<F> = Box_::new(f);
372            connect_raw(
373                self.as_ptr() as *mut _,
374                c"notify::widget".as_ptr() as *const _,
375                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
376                    notify_widget_trampoline::<Self, F> as *const (),
377                )),
378                Box_::into_raw(f),
379            )
380        }
381    }
382}
383
384impl<O: IsA<EventController>> EventControllerExt for O {}