gtk4/auto/
event_controller_legacy.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, EventController, PropagationLimit, PropagationPhase};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// [`EventControllerLegacy`][crate::EventControllerLegacy] is an event controller that provides raw
16    /// access to the event stream.
17    ///
18    /// It should only be used as a last resort if none of the other event
19    /// controllers or gestures do the job.
20    ///
21    /// ## Signals
22    ///
23    ///
24    /// #### `event`
25    ///  Emitted for each GDK event delivered to @controller.
26    ///
27    ///
28    ///
29    /// # Implements
30    ///
31    /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
32    #[doc(alias = "GtkEventControllerLegacy")]
33    pub struct EventControllerLegacy(Object<ffi::GtkEventControllerLegacy, ffi::GtkEventControllerLegacyClass>) @extends EventController;
34
35    match fn {
36        type_ => || ffi::gtk_event_controller_legacy_get_type(),
37    }
38}
39
40impl EventControllerLegacy {
41    /// Creates a new legacy event controller.
42    ///
43    /// # Returns
44    ///
45    /// the newly created event controller.
46    #[doc(alias = "gtk_event_controller_legacy_new")]
47    pub fn new() -> EventControllerLegacy {
48        assert_initialized_main_thread!();
49        unsafe {
50            EventController::from_glib_full(ffi::gtk_event_controller_legacy_new()).unsafe_cast()
51        }
52    }
53
54    // rustdoc-stripper-ignore-next
55    /// Creates a new builder-pattern struct instance to construct [`EventControllerLegacy`] objects.
56    ///
57    /// This method returns an instance of [`EventControllerLegacyBuilder`](crate::builders::EventControllerLegacyBuilder) which can be used to create [`EventControllerLegacy`] objects.
58    pub fn builder() -> EventControllerLegacyBuilder {
59        EventControllerLegacyBuilder::new()
60    }
61
62    /// Emitted for each GDK event delivered to @controller.
63    /// ## `event`
64    /// the [`gdk::Event`][crate::gdk::Event] which triggered this signal
65    ///
66    /// # Returns
67    ///
68    /// [`true`] to stop other handlers from being invoked for the event
69    ///   and the emission of this signal. [`false`] to propagate the event further.
70    #[doc(alias = "event")]
71    pub fn connect_event<F: Fn(&Self, &gdk::Event) -> glib::Propagation + 'static>(
72        &self,
73        f: F,
74    ) -> SignalHandlerId {
75        unsafe extern "C" fn event_trampoline<
76            F: Fn(&EventControllerLegacy, &gdk::Event) -> glib::Propagation + 'static,
77        >(
78            this: *mut ffi::GtkEventControllerLegacy,
79            event: *mut gdk::ffi::GdkEvent,
80            f: glib::ffi::gpointer,
81        ) -> glib::ffi::gboolean {
82            let f: &F = &*(f as *const F);
83            f(&from_glib_borrow(this), &from_glib_borrow(event)).into_glib()
84        }
85        unsafe {
86            let f: Box_<F> = Box_::new(f);
87            connect_raw(
88                self.as_ptr() as *mut _,
89                b"event\0".as_ptr() as *const _,
90                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
91                    event_trampoline::<F> as *const (),
92                )),
93                Box_::into_raw(f),
94            )
95        }
96    }
97}
98
99impl Default for EventControllerLegacy {
100    fn default() -> Self {
101        Self::new()
102    }
103}
104
105// rustdoc-stripper-ignore-next
106/// A [builder-pattern] type to construct [`EventControllerLegacy`] objects.
107///
108/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
109#[must_use = "The builder must be built to be used"]
110pub struct EventControllerLegacyBuilder {
111    builder: glib::object::ObjectBuilder<'static, EventControllerLegacy>,
112}
113
114impl EventControllerLegacyBuilder {
115    fn new() -> Self {
116        Self {
117            builder: glib::object::Object::builder(),
118        }
119    }
120
121    /// The name for this controller, typically used for debugging purposes.
122    pub fn name(self, name: impl Into<glib::GString>) -> Self {
123        Self {
124            builder: self.builder.property("name", name.into()),
125        }
126    }
127
128    /// The limit for which events this controller will handle.
129    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
130        Self {
131            builder: self
132                .builder
133                .property("propagation-limit", propagation_limit),
134        }
135    }
136
137    /// The propagation phase at which this controller will handle events.
138    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
139        Self {
140            builder: self
141                .builder
142                .property("propagation-phase", propagation_phase),
143        }
144    }
145
146    // rustdoc-stripper-ignore-next
147    /// Build the [`EventControllerLegacy`].
148    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
149    pub fn build(self) -> EventControllerLegacy {
150        assert_initialized_main_thread!();
151        self.builder.build()
152    }
153}