Skip to main content

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