gtk4/auto/
event_controller.rs1use crate::{PropagationLimit, PropagationPhase, Widget, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkEventController")]
15 pub struct EventController(Object<ffi::GtkEventController, ffi::GtkEventControllerClass>);
16
17 match fn {
18 type_ => || ffi::gtk_event_controller_get_type(),
19 }
20}
21
22impl EventController {
23 pub const NONE: Option<&'static EventController> = None;
24}
25
26pub trait EventControllerExt: IsA<EventController> + 'static {
27 #[doc(alias = "gtk_event_controller_get_current_event")]
28 #[doc(alias = "get_current_event")]
29 fn current_event(&self) -> Option<gdk::Event> {
30 unsafe {
31 from_glib_none(ffi::gtk_event_controller_get_current_event(
32 self.as_ref().to_glib_none().0,
33 ))
34 }
35 }
36
37 #[doc(alias = "gtk_event_controller_get_current_event_device")]
38 #[doc(alias = "get_current_event_device")]
39 fn current_event_device(&self) -> Option<gdk::Device> {
40 unsafe {
41 from_glib_none(ffi::gtk_event_controller_get_current_event_device(
42 self.as_ref().to_glib_none().0,
43 ))
44 }
45 }
46
47 #[doc(alias = "gtk_event_controller_get_current_event_state")]
48 #[doc(alias = "get_current_event_state")]
49 fn current_event_state(&self) -> gdk::ModifierType {
50 unsafe {
51 from_glib(ffi::gtk_event_controller_get_current_event_state(
52 self.as_ref().to_glib_none().0,
53 ))
54 }
55 }
56
57 #[doc(alias = "gtk_event_controller_get_current_event_time")]
58 #[doc(alias = "get_current_event_time")]
59 fn current_event_time(&self) -> u32 {
60 unsafe { ffi::gtk_event_controller_get_current_event_time(self.as_ref().to_glib_none().0) }
61 }
62
63 #[doc(alias = "gtk_event_controller_get_name")]
64 #[doc(alias = "get_name")]
65 fn name(&self) -> Option<glib::GString> {
66 unsafe {
67 from_glib_none(ffi::gtk_event_controller_get_name(
68 self.as_ref().to_glib_none().0,
69 ))
70 }
71 }
72
73 #[doc(alias = "gtk_event_controller_get_propagation_limit")]
74 #[doc(alias = "get_propagation_limit")]
75 #[doc(alias = "propagation-limit")]
76 fn propagation_limit(&self) -> PropagationLimit {
77 unsafe {
78 from_glib(ffi::gtk_event_controller_get_propagation_limit(
79 self.as_ref().to_glib_none().0,
80 ))
81 }
82 }
83
84 #[doc(alias = "gtk_event_controller_get_propagation_phase")]
85 #[doc(alias = "get_propagation_phase")]
86 #[doc(alias = "propagation-phase")]
87 fn propagation_phase(&self) -> PropagationPhase {
88 unsafe {
89 from_glib(ffi::gtk_event_controller_get_propagation_phase(
90 self.as_ref().to_glib_none().0,
91 ))
92 }
93 }
94
95 #[doc(alias = "gtk_event_controller_get_widget")]
96 #[doc(alias = "get_widget")]
97 fn widget(&self) -> Option<Widget> {
98 unsafe {
99 from_glib_none(ffi::gtk_event_controller_get_widget(
100 self.as_ref().to_glib_none().0,
101 ))
102 }
103 }
104
105 #[doc(alias = "gtk_event_controller_reset")]
106 fn reset(&self) {
107 unsafe {
108 ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
109 }
110 }
111
112 #[doc(alias = "gtk_event_controller_set_name")]
113 #[doc(alias = "name")]
114 fn set_name(&self, name: Option<&str>) {
115 unsafe {
116 ffi::gtk_event_controller_set_name(
117 self.as_ref().to_glib_none().0,
118 name.to_glib_none().0,
119 );
120 }
121 }
122
123 #[doc(alias = "gtk_event_controller_set_propagation_limit")]
124 #[doc(alias = "propagation-limit")]
125 fn set_propagation_limit(&self, limit: PropagationLimit) {
126 unsafe {
127 ffi::gtk_event_controller_set_propagation_limit(
128 self.as_ref().to_glib_none().0,
129 limit.into_glib(),
130 );
131 }
132 }
133
134 #[doc(alias = "gtk_event_controller_set_propagation_phase")]
135 #[doc(alias = "propagation-phase")]
136 fn set_propagation_phase(&self, phase: PropagationPhase) {
137 unsafe {
138 ffi::gtk_event_controller_set_propagation_phase(
139 self.as_ref().to_glib_none().0,
140 phase.into_glib(),
141 );
142 }
143 }
144
145 #[doc(alias = "name")]
146 fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
147 unsafe extern "C" fn notify_name_trampoline<
148 P: IsA<EventController>,
149 F: Fn(&P) + 'static,
150 >(
151 this: *mut ffi::GtkEventController,
152 _param_spec: glib::ffi::gpointer,
153 f: glib::ffi::gpointer,
154 ) {
155 unsafe {
156 let f: &F = &*(f as *const F);
157 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
158 }
159 }
160 unsafe {
161 let f: Box_<F> = Box_::new(f);
162 connect_raw(
163 self.as_ptr() as *mut _,
164 c"notify::name".as_ptr() as *const _,
165 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
166 notify_name_trampoline::<Self, F> as *const (),
167 )),
168 Box_::into_raw(f),
169 )
170 }
171 }
172
173 #[doc(alias = "propagation-limit")]
174 fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
175 unsafe extern "C" fn notify_propagation_limit_trampoline<
176 P: IsA<EventController>,
177 F: Fn(&P) + 'static,
178 >(
179 this: *mut ffi::GtkEventController,
180 _param_spec: glib::ffi::gpointer,
181 f: glib::ffi::gpointer,
182 ) {
183 unsafe {
184 let f: &F = &*(f as *const F);
185 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
186 }
187 }
188 unsafe {
189 let f: Box_<F> = Box_::new(f);
190 connect_raw(
191 self.as_ptr() as *mut _,
192 c"notify::propagation-limit".as_ptr() as *const _,
193 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
194 notify_propagation_limit_trampoline::<Self, F> as *const (),
195 )),
196 Box_::into_raw(f),
197 )
198 }
199 }
200
201 #[doc(alias = "propagation-phase")]
202 fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
203 unsafe extern "C" fn notify_propagation_phase_trampoline<
204 P: IsA<EventController>,
205 F: Fn(&P) + 'static,
206 >(
207 this: *mut ffi::GtkEventController,
208 _param_spec: glib::ffi::gpointer,
209 f: glib::ffi::gpointer,
210 ) {
211 unsafe {
212 let f: &F = &*(f as *const F);
213 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
214 }
215 }
216 unsafe {
217 let f: Box_<F> = Box_::new(f);
218 connect_raw(
219 self.as_ptr() as *mut _,
220 c"notify::propagation-phase".as_ptr() as *const _,
221 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
222 notify_propagation_phase_trampoline::<Self, F> as *const (),
223 )),
224 Box_::into_raw(f),
225 )
226 }
227 }
228
229 #[doc(alias = "widget")]
230 fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
231 unsafe extern "C" fn notify_widget_trampoline<
232 P: IsA<EventController>,
233 F: Fn(&P) + 'static,
234 >(
235 this: *mut ffi::GtkEventController,
236 _param_spec: glib::ffi::gpointer,
237 f: glib::ffi::gpointer,
238 ) {
239 unsafe {
240 let f: &F = &*(f as *const F);
241 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
242 }
243 }
244 unsafe {
245 let f: Box_<F> = Box_::new(f);
246 connect_raw(
247 self.as_ptr() as *mut _,
248 c"notify::widget".as_ptr() as *const _,
249 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
250 notify_widget_trampoline::<Self, F> as *const (),
251 )),
252 Box_::into_raw(f),
253 )
254 }
255 }
256}
257
258impl<O: IsA<EventController>> EventControllerExt for O {}