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