gtk4/auto/
event_controller_legacy.rs
1use 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 #[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 #[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 pub fn builder() -> EventControllerLegacyBuilder {
59 EventControllerLegacyBuilder::new()
60 }
61
62 #[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#[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 pub fn name(self, name: impl Into<glib::GString>) -> Self {
123 Self {
124 builder: self.builder.property("name", name.into()),
125 }
126 }
127
128 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 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 #[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}