1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::PropagationLimit;
use crate::PropagationPhase;
use crate::Widget;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    /// [`EventController`][crate::EventController] is the base class for event controllers.
    ///
    /// These are ancillary objects associated to widgets, which react
    /// to `GdkEvents`, and possibly trigger actions as a consequence.
    ///
    /// Event controllers are added to a widget with
    /// [`WidgetExt::add_controller()`][crate::prelude::WidgetExt::add_controller()]. It is rarely necessary to
    /// explicitly remove a controller with [`WidgetExt::remove_controller()`][crate::prelude::WidgetExt::remove_controller()].
    ///
    /// See the chapter on [input handling](input-handling.html) for
    /// an overview of the basic concepts, such as the capture and bubble
    /// phases of even propagation.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "GtkEventController")]
    pub struct EventController(Object<ffi::GtkEventController, ffi::GtkEventControllerClass>);

    match fn {
        type_ => || ffi::gtk_event_controller_get_type(),
    }
}

impl EventController {
    pub const NONE: Option<&'static EventController> = None;
}

/// Trait containing all [`struct@EventController`] methods.
///
/// # Implementors
///
/// [`DropControllerMotion`][struct@crate::DropControllerMotion], [`DropTargetAsync`][struct@crate::DropTargetAsync], [`DropTarget`][struct@crate::DropTarget], [`EventControllerFocus`][struct@crate::EventControllerFocus], [`EventControllerKey`][struct@crate::EventControllerKey], [`EventControllerLegacy`][struct@crate::EventControllerLegacy], [`EventControllerMotion`][struct@crate::EventControllerMotion], [`EventControllerScroll`][struct@crate::EventControllerScroll], [`EventController`][struct@crate::EventController], [`Gesture`][struct@crate::Gesture], [`PadController`][struct@crate::PadController], [`ShortcutController`][struct@crate::ShortcutController]
pub trait EventControllerExt: 'static {
    /// Returns the event that is currently being handled by the controller.
    ///
    /// At other times, [`None`] is returned.
    ///
    /// # Returns
    ///
    /// the event that is currently
    ///   handled by @self
    #[doc(alias = "gtk_event_controller_get_current_event")]
    #[doc(alias = "get_current_event")]
    fn current_event(&self) -> Option<gdk::Event>;

    /// Returns the device of the event that is currently being
    /// handled by the controller.
    ///
    /// At other times, [`None`] is returned.
    ///
    /// # Returns
    ///
    /// device of the event is
    ///   currently handled by @self
    #[doc(alias = "gtk_event_controller_get_current_event_device")]
    #[doc(alias = "get_current_event_device")]
    fn current_event_device(&self) -> Option<gdk::Device>;

    /// Returns the modifier state of the event that is currently being
    /// handled by the controller.
    ///
    /// At other times, 0 is returned.
    ///
    /// # Returns
    ///
    /// modifier state of the event is currently handled by @self
    #[doc(alias = "gtk_event_controller_get_current_event_state")]
    #[doc(alias = "get_current_event_state")]
    fn current_event_state(&self) -> gdk::ModifierType;

    /// Returns the timestamp of the event that is currently being
    /// handled by the controller.
    ///
    /// At other times, 0 is returned.
    ///
    /// # Returns
    ///
    /// timestamp of the event is currently handled by @self
    #[doc(alias = "gtk_event_controller_get_current_event_time")]
    #[doc(alias = "get_current_event_time")]
    fn current_event_time(&self) -> u32;

    /// Gets the name of @self.
    ///
    /// # Returns
    ///
    /// The controller name
    #[doc(alias = "gtk_event_controller_get_name")]
    #[doc(alias = "get_name")]
    fn name(&self) -> Option<glib::GString>;

    /// Gets the propagation limit of the event controller.
    ///
    /// # Returns
    ///
    /// the propagation limit
    #[doc(alias = "gtk_event_controller_get_propagation_limit")]
    #[doc(alias = "get_propagation_limit")]
    fn propagation_limit(&self) -> PropagationLimit;

    /// Gets the propagation phase at which @self handles events.
    ///
    /// # Returns
    ///
    /// the propagation phase
    #[doc(alias = "gtk_event_controller_get_propagation_phase")]
    #[doc(alias = "get_propagation_phase")]
    fn propagation_phase(&self) -> PropagationPhase;

    /// Returns the [`Widget`][crate::Widget] this controller relates to.
    ///
    /// # Returns
    ///
    /// a [`Widget`][crate::Widget]
    #[doc(alias = "gtk_event_controller_get_widget")]
    #[doc(alias = "get_widget")]
    fn widget(&self) -> Widget;

    /// Resets the @self to a clean state.
    #[doc(alias = "gtk_event_controller_reset")]
    fn reset(&self);

    /// Sets a name on the controller that can be used for debugging.
    /// ## `name`
    /// a name for @self
    #[doc(alias = "gtk_event_controller_set_name")]
    fn set_name(&self, name: Option<&str>);

    /// Sets the event propagation limit on the event controller.
    ///
    /// If the limit is set to [`PropagationLimit::SameNative`][crate::PropagationLimit::SameNative], the controller
    /// won't handle events that are targeted at widgets on a different
    /// surface, such as popovers.
    /// ## `limit`
    /// the propagation limit
    #[doc(alias = "gtk_event_controller_set_propagation_limit")]
    fn set_propagation_limit(&self, limit: PropagationLimit);

    /// Sets the propagation phase at which a controller handles events.
    ///
    /// If @phase is [`PropagationPhase::None`][crate::PropagationPhase::None], no automatic event handling will be
    /// performed, but other additional gesture maintenance will.
    /// ## `phase`
    /// a propagation phase
    #[doc(alias = "gtk_event_controller_set_propagation_phase")]
    fn set_propagation_phase(&self, phase: PropagationPhase);

    /// Sets a name on the controller that can be used for debugging.
    /// ## `name`
    /// a name for @self, must be a static string
    #[cfg(any(feature = "v4_8", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v4_8")))]
    #[doc(alias = "gtk_event_controller_set_static_name")]
    fn set_static_name(&self, name: Option<&str>);

    #[doc(alias = "name")]
    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "propagation-limit")]
    fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "propagation-phase")]
    fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "widget")]
    fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<EventController>> EventControllerExt for O {
    fn current_event(&self) -> Option<gdk::Event> {
        unsafe {
            from_glib_none(ffi::gtk_event_controller_get_current_event(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn current_event_device(&self) -> Option<gdk::Device> {
        unsafe {
            from_glib_none(ffi::gtk_event_controller_get_current_event_device(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn current_event_state(&self) -> gdk::ModifierType {
        unsafe {
            from_glib(ffi::gtk_event_controller_get_current_event_state(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn current_event_time(&self) -> u32 {
        unsafe { ffi::gtk_event_controller_get_current_event_time(self.as_ref().to_glib_none().0) }
    }

    fn name(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gtk_event_controller_get_name(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn propagation_limit(&self) -> PropagationLimit {
        unsafe {
            from_glib(ffi::gtk_event_controller_get_propagation_limit(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn propagation_phase(&self) -> PropagationPhase {
        unsafe {
            from_glib(ffi::gtk_event_controller_get_propagation_phase(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn widget(&self) -> Widget {
        unsafe {
            from_glib_none(ffi::gtk_event_controller_get_widget(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn reset(&self) {
        unsafe {
            ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
        }
    }

    fn set_name(&self, name: Option<&str>) {
        unsafe {
            ffi::gtk_event_controller_set_name(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
            );
        }
    }

    fn set_propagation_limit(&self, limit: PropagationLimit) {
        unsafe {
            ffi::gtk_event_controller_set_propagation_limit(
                self.as_ref().to_glib_none().0,
                limit.into_glib(),
            );
        }
    }

    fn set_propagation_phase(&self, phase: PropagationPhase) {
        unsafe {
            ffi::gtk_event_controller_set_propagation_phase(
                self.as_ref().to_glib_none().0,
                phase.into_glib(),
            );
        }
    }

    #[cfg(any(feature = "v4_8", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v4_8")))]
    fn set_static_name(&self, name: Option<&str>) {
        unsafe {
            ffi::gtk_event_controller_set_static_name(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
            );
        }
    }

    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_name_trampoline<
            P: IsA<EventController>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkEventController,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::name\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_name_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_propagation_limit_trampoline<
            P: IsA<EventController>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkEventController,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::propagation-limit\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_propagation_limit_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_propagation_phase_trampoline<
            P: IsA<EventController>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkEventController,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::propagation-phase\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_propagation_phase_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_widget_trampoline<
            P: IsA<EventController>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkEventController,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(EventController::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::widget\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_widget_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for EventController {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("EventController")
    }
}