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")]
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 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#[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 pub fn name(self, name: impl Into<glib::GString>) -> Self {
122 Self {
123 builder: self.builder.property("name", name.into()),
124 }
125 }
126
127 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 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 #[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}