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    /// 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`]
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            let f: &F = &*(f as *const F);
82            f(&from_glib_borrow(this), &from_glib_borrow(event)).into_glib()
83        }
84        unsafe {
85            let f: Box_<F> = Box_::new(f);
86            connect_raw(
87                self.as_ptr() as *mut _,
88                c"event".as_ptr() as *const _,
89                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
90                    event_trampoline::<F> as *const (),
91                )),
92                Box_::into_raw(f),
93            )
94        }
95    }
96}
97
98impl Default for EventControllerLegacy {
99    fn default() -> Self {
100        Self::new()
101    }
102}
103
104// rustdoc-stripper-ignore-next
105/// A [builder-pattern] type to construct [`EventControllerLegacy`] objects.
106///
107/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
108#[must_use = "The builder must be built to be used"]
109pub struct EventControllerLegacyBuilder {
110    builder: glib::object::ObjectBuilder<'static, EventControllerLegacy>,
111}
112
113impl EventControllerLegacyBuilder {
114    fn new() -> Self {
115        Self {
116            builder: glib::object::Object::builder(),
117        }
118    }
119
120    /// The name for this controller, typically used for debugging purposes.
121    pub fn name(self, name: impl Into<glib::GString>) -> Self {
122        Self {
123            builder: self.builder.property("name", name.into()),
124        }
125    }
126
127    /// The limit for which events this controller will handle.
128    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
129        Self {
130            builder: self
131                .builder
132                .property("propagation-limit", propagation_limit),
133        }
134    }
135
136    /// The propagation phase at which this controller will handle events.
137    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
138        Self {
139            builder: self
140                .builder
141                .property("propagation-phase", propagation_phase),
142        }
143    }
144
145    // rustdoc-stripper-ignore-next
146    /// Build the [`EventControllerLegacy`].
147    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
148    pub fn build(self) -> EventControllerLegacy {
149        assert_initialized_main_thread!();
150        self.builder.build()
151    }
152}