gtk4/auto/
event_controller_legacy.rs1use 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")]
16 pub struct EventControllerLegacy(Object<ffi::GtkEventControllerLegacy, ffi::GtkEventControllerLegacyClass>) @extends EventController;
17
18 match fn {
19 type_ => || ffi::gtk_event_controller_legacy_get_type(),
20 }
21}
22
23impl EventControllerLegacy {
24 #[doc(alias = "gtk_event_controller_legacy_new")]
25 pub fn new() -> EventControllerLegacy {
26 assert_initialized_main_thread!();
27 unsafe {
28 EventController::from_glib_full(ffi::gtk_event_controller_legacy_new()).unsafe_cast()
29 }
30 }
31
32 pub fn builder() -> EventControllerLegacyBuilder {
37 EventControllerLegacyBuilder::new()
38 }
39
40 #[doc(alias = "event")]
41 pub fn connect_event<F: Fn(&Self, &gdk::Event) -> glib::Propagation + 'static>(
42 &self,
43 f: F,
44 ) -> SignalHandlerId {
45 unsafe extern "C" fn event_trampoline<
46 F: Fn(&EventControllerLegacy, &gdk::Event) -> glib::Propagation + 'static,
47 >(
48 this: *mut ffi::GtkEventControllerLegacy,
49 event: *mut gdk::ffi::GdkEvent,
50 f: glib::ffi::gpointer,
51 ) -> glib::ffi::gboolean {
52 let f: &F = &*(f as *const F);
53 f(&from_glib_borrow(this), &from_glib_borrow(event)).into_glib()
54 }
55 unsafe {
56 let f: Box_<F> = Box_::new(f);
57 connect_raw(
58 self.as_ptr() as *mut _,
59 c"event".as_ptr() as *const _,
60 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
61 event_trampoline::<F> as *const (),
62 )),
63 Box_::into_raw(f),
64 )
65 }
66 }
67}
68
69impl Default for EventControllerLegacy {
70 fn default() -> Self {
71 Self::new()
72 }
73}
74
75#[must_use = "The builder must be built to be used"]
80pub struct EventControllerLegacyBuilder {
81 builder: glib::object::ObjectBuilder<'static, EventControllerLegacy>,
82}
83
84impl EventControllerLegacyBuilder {
85 fn new() -> Self {
86 Self {
87 builder: glib::object::Object::builder(),
88 }
89 }
90
91 pub fn name(self, name: impl Into<glib::GString>) -> Self {
92 Self {
93 builder: self.builder.property("name", name.into()),
94 }
95 }
96
97 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
98 Self {
99 builder: self
100 .builder
101 .property("propagation-limit", propagation_limit),
102 }
103 }
104
105 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
106 Self {
107 builder: self
108 .builder
109 .property("propagation-phase", propagation_phase),
110 }
111 }
112
113 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
116 pub fn build(self) -> EventControllerLegacy {
117 assert_initialized_main_thread!();
118 self.builder.build()
119 }
120}