1 // This file was generated by gir (https://github.com/gtk-rs/gir)
2 // from gir-files (https://github.com/gtk-rs/gir-files)
3 // DO NOT EDIT
4 
5 use crate::PropagationPhase;
6 use crate::Widget;
7 use glib::object::Cast;
8 use glib::object::IsA;
9 use glib::signal::connect_raw;
10 use glib::signal::SignalHandlerId;
11 use glib::translate::*;
12 use std::boxed::Box as Box_;
13 use std::fmt;
14 use std::mem::transmute;
15 
16 glib::wrapper! {
17     #[doc(alias = "GtkEventController")]
18     pub struct EventController(Object<ffi::GtkEventController, ffi::GtkEventControllerClass>);
19 
20     match fn {
21         type_ => || ffi::gtk_event_controller_get_type(),
22     }
23 }
24 
25 pub const NONE_EVENT_CONTROLLER: Option<&EventController> = None;
26 
27 pub trait EventControllerExt: 'static {
28     #[doc(alias = "gtk_event_controller_get_propagation_phase")]
29     #[doc(alias = "get_propagation_phase")]
propagation_phase(&self) -> PropagationPhase30     fn propagation_phase(&self) -> PropagationPhase;
31 
32     #[doc(alias = "gtk_event_controller_get_widget")]
33     #[doc(alias = "get_widget")]
widget(&self) -> Option<Widget>34     fn widget(&self) -> Option<Widget>;
35 
36     #[doc(alias = "gtk_event_controller_handle_event")]
handle_event(&self, event: &gdk::Event) -> bool37     fn handle_event(&self, event: &gdk::Event) -> bool;
38 
39     #[doc(alias = "gtk_event_controller_reset")]
reset(&self)40     fn reset(&self);
41 
42     #[doc(alias = "gtk_event_controller_set_propagation_phase")]
set_propagation_phase(&self, phase: PropagationPhase)43     fn set_propagation_phase(&self, phase: PropagationPhase);
44 
45     #[doc(alias = "propagation-phase")]
connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId46     fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
47 }
48 
49 impl<O: IsA<EventController>> EventControllerExt for O {
propagation_phase(&self) -> PropagationPhase50     fn propagation_phase(&self) -> PropagationPhase {
51         unsafe {
52             from_glib(ffi::gtk_event_controller_get_propagation_phase(
53                 self.as_ref().to_glib_none().0,
54             ))
55         }
56     }
57 
widget(&self) -> Option<Widget>58     fn widget(&self) -> Option<Widget> {
59         unsafe {
60             from_glib_none(ffi::gtk_event_controller_get_widget(
61                 self.as_ref().to_glib_none().0,
62             ))
63         }
64     }
65 
handle_event(&self, event: &gdk::Event) -> bool66     fn handle_event(&self, event: &gdk::Event) -> bool {
67         unsafe {
68             from_glib(ffi::gtk_event_controller_handle_event(
69                 self.as_ref().to_glib_none().0,
70                 event.to_glib_none().0,
71             ))
72         }
73     }
74 
reset(&self)75     fn reset(&self) {
76         unsafe {
77             ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
78         }
79     }
80 
set_propagation_phase(&self, phase: PropagationPhase)81     fn set_propagation_phase(&self, phase: PropagationPhase) {
82         unsafe {
83             ffi::gtk_event_controller_set_propagation_phase(
84                 self.as_ref().to_glib_none().0,
85                 phase.into_glib(),
86             );
87         }
88     }
89 
connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId90     fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
91         unsafe extern "C" fn notify_propagation_phase_trampoline<
92             P: IsA<EventController>,
93             F: Fn(&P) + 'static,
94         >(
95             this: *mut ffi::GtkEventController,
96             _param_spec: glib::ffi::gpointer,
97             f: glib::ffi::gpointer,
98         ) {
99             let f: &F = &*(f as *const F);
100             f(EventController::from_glib_borrow(this).unsafe_cast_ref())
101         }
102         unsafe {
103             let f: Box_<F> = Box_::new(f);
104             connect_raw(
105                 self.as_ptr() as *mut _,
106                 b"notify::propagation-phase\0".as_ptr() as *const _,
107                 Some(transmute::<_, unsafe extern "C" fn()>(
108                     notify_propagation_phase_trampoline::<Self, F> as *const (),
109                 )),
110                 Box_::into_raw(f),
111             )
112         }
113     }
114 }
115 
116 impl fmt::Display for EventController {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result117     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
118         f.write_str("EventController")
119     }
120 }
121