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::EventController;
6 use crate::Gesture;
7 use crate::GestureSingle;
8 use crate::PropagationPhase;
9 use crate::Widget;
10 use glib::object::Cast;
11 use glib::object::IsA;
12 use glib::object::ObjectType as ObjectType_;
13 use glib::signal::connect_raw;
14 use glib::signal::SignalHandlerId;
15 use glib::translate::*;
16 use glib::StaticType;
17 use glib::ToValue;
18 use std::boxed::Box as Box_;
19 use std::fmt;
20 use std::mem::transmute;
21 
22 glib::wrapper! {
23     #[doc(alias = "GtkGestureLongPress")]
24     pub struct GestureLongPress(Object<ffi::GtkGestureLongPress, ffi::GtkGestureLongPressClass>) @extends GestureSingle, Gesture, EventController;
25 
26     match fn {
27         type_ => || ffi::gtk_gesture_long_press_get_type(),
28     }
29 }
30 
31 impl GestureLongPress {
32     #[doc(alias = "gtk_gesture_long_press_new")]
new<P: IsA<Widget>>(widget: &P) -> GestureLongPress33     pub fn new<P: IsA<Widget>>(widget: &P) -> GestureLongPress {
34         skip_assert_initialized!();
35         unsafe {
36             Gesture::from_glib_full(ffi::gtk_gesture_long_press_new(
37                 widget.as_ref().to_glib_none().0,
38             ))
39             .unsafe_cast()
40         }
41     }
42 
43     // rustdoc-stripper-ignore-next
44     /// Creates a new builder-pattern struct instance to construct [`GestureLongPress`] objects.
45     ///
46     /// This method returns an instance of [`GestureLongPressBuilder`] which can be used to create [`GestureLongPress`] objects.
builder() -> GestureLongPressBuilder47     pub fn builder() -> GestureLongPressBuilder {
48         GestureLongPressBuilder::default()
49     }
50 
51     #[doc(alias = "delay-factor")]
delay_factor(&self) -> f6452     pub fn delay_factor(&self) -> f64 {
53         unsafe {
54             let mut value = glib::Value::from_type(<f64 as StaticType>::static_type());
55             glib::gobject_ffi::g_object_get_property(
56                 self.as_ptr() as *mut glib::gobject_ffi::GObject,
57                 b"delay-factor\0".as_ptr() as *const _,
58                 value.to_glib_none_mut().0,
59             );
60             value
61                 .get()
62                 .expect("Return Value for property `delay-factor` getter")
63         }
64     }
65 
66     #[doc(alias = "delay-factor")]
set_delay_factor(&self, delay_factor: f64)67     pub fn set_delay_factor(&self, delay_factor: f64) {
68         unsafe {
69             glib::gobject_ffi::g_object_set_property(
70                 self.as_ptr() as *mut glib::gobject_ffi::GObject,
71                 b"delay-factor\0".as_ptr() as *const _,
72                 delay_factor.to_value().to_glib_none().0,
73             );
74         }
75     }
76 
77     #[doc(alias = "cancelled")]
connect_cancelled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId78     pub fn connect_cancelled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
79         unsafe extern "C" fn cancelled_trampoline<F: Fn(&GestureLongPress) + 'static>(
80             this: *mut ffi::GtkGestureLongPress,
81             f: glib::ffi::gpointer,
82         ) {
83             let f: &F = &*(f as *const F);
84             f(&from_glib_borrow(this))
85         }
86         unsafe {
87             let f: Box_<F> = Box_::new(f);
88             connect_raw(
89                 self.as_ptr() as *mut _,
90                 b"cancelled\0".as_ptr() as *const _,
91                 Some(transmute::<_, unsafe extern "C" fn()>(
92                     cancelled_trampoline::<F> as *const (),
93                 )),
94                 Box_::into_raw(f),
95             )
96         }
97     }
98 
99     #[doc(alias = "pressed")]
connect_pressed<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId100     pub fn connect_pressed<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
101         unsafe extern "C" fn pressed_trampoline<F: Fn(&GestureLongPress, f64, f64) + 'static>(
102             this: *mut ffi::GtkGestureLongPress,
103             x: libc::c_double,
104             y: libc::c_double,
105             f: glib::ffi::gpointer,
106         ) {
107             let f: &F = &*(f as *const F);
108             f(&from_glib_borrow(this), x, y)
109         }
110         unsafe {
111             let f: Box_<F> = Box_::new(f);
112             connect_raw(
113                 self.as_ptr() as *mut _,
114                 b"pressed\0".as_ptr() as *const _,
115                 Some(transmute::<_, unsafe extern "C" fn()>(
116                     pressed_trampoline::<F> as *const (),
117                 )),
118                 Box_::into_raw(f),
119             )
120         }
121     }
122 
123     #[doc(alias = "delay-factor")]
connect_delay_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId124     pub fn connect_delay_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
125         unsafe extern "C" fn notify_delay_factor_trampoline<F: Fn(&GestureLongPress) + 'static>(
126             this: *mut ffi::GtkGestureLongPress,
127             _param_spec: glib::ffi::gpointer,
128             f: glib::ffi::gpointer,
129         ) {
130             let f: &F = &*(f as *const F);
131             f(&from_glib_borrow(this))
132         }
133         unsafe {
134             let f: Box_<F> = Box_::new(f);
135             connect_raw(
136                 self.as_ptr() as *mut _,
137                 b"notify::delay-factor\0".as_ptr() as *const _,
138                 Some(transmute::<_, unsafe extern "C" fn()>(
139                     notify_delay_factor_trampoline::<F> as *const (),
140                 )),
141                 Box_::into_raw(f),
142             )
143         }
144     }
145 }
146 
147 #[derive(Clone, Default)]
148 // rustdoc-stripper-ignore-next
149 /// A [builder-pattern] type to construct [`GestureLongPress`] objects.
150 ///
151 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
152 pub struct GestureLongPressBuilder {
153     delay_factor: Option<f64>,
154     button: Option<u32>,
155     exclusive: Option<bool>,
156     touch_only: Option<bool>,
157     n_points: Option<u32>,
158     window: Option<gdk::Window>,
159     propagation_phase: Option<PropagationPhase>,
160     widget: Option<Widget>,
161 }
162 
163 impl GestureLongPressBuilder {
164     // rustdoc-stripper-ignore-next
165     /// Create a new [`GestureLongPressBuilder`].
new() -> Self166     pub fn new() -> Self {
167         Self::default()
168     }
169 
170     // rustdoc-stripper-ignore-next
171     /// Build the [`GestureLongPress`].
build(self) -> GestureLongPress172     pub fn build(self) -> GestureLongPress {
173         let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
174         if let Some(ref delay_factor) = self.delay_factor {
175             properties.push(("delay-factor", delay_factor));
176         }
177         if let Some(ref button) = self.button {
178             properties.push(("button", button));
179         }
180         if let Some(ref exclusive) = self.exclusive {
181             properties.push(("exclusive", exclusive));
182         }
183         if let Some(ref touch_only) = self.touch_only {
184             properties.push(("touch-only", touch_only));
185         }
186         if let Some(ref n_points) = self.n_points {
187             properties.push(("n-points", n_points));
188         }
189         if let Some(ref window) = self.window {
190             properties.push(("window", window));
191         }
192         if let Some(ref propagation_phase) = self.propagation_phase {
193             properties.push(("propagation-phase", propagation_phase));
194         }
195         if let Some(ref widget) = self.widget {
196             properties.push(("widget", widget));
197         }
198         glib::Object::new::<GestureLongPress>(&properties)
199             .expect("Failed to create an instance of GestureLongPress")
200     }
201 
delay_factor(mut self, delay_factor: f64) -> Self202     pub fn delay_factor(mut self, delay_factor: f64) -> Self {
203         self.delay_factor = Some(delay_factor);
204         self
205     }
206 
button(mut self, button: u32) -> Self207     pub fn button(mut self, button: u32) -> Self {
208         self.button = Some(button);
209         self
210     }
211 
exclusive(mut self, exclusive: bool) -> Self212     pub fn exclusive(mut self, exclusive: bool) -> Self {
213         self.exclusive = Some(exclusive);
214         self
215     }
216 
touch_only(mut self, touch_only: bool) -> Self217     pub fn touch_only(mut self, touch_only: bool) -> Self {
218         self.touch_only = Some(touch_only);
219         self
220     }
221 
n_points(mut self, n_points: u32) -> Self222     pub fn n_points(mut self, n_points: u32) -> Self {
223         self.n_points = Some(n_points);
224         self
225     }
226 
window(mut self, window: &gdk::Window) -> Self227     pub fn window(mut self, window: &gdk::Window) -> Self {
228         self.window = Some(window.clone());
229         self
230     }
231 
propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self232     pub fn propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self {
233         self.propagation_phase = Some(propagation_phase);
234         self
235     }
236 
widget<P: IsA<Widget>>(mut self, widget: &P) -> Self237     pub fn widget<P: IsA<Widget>>(mut self, widget: &P) -> Self {
238         self.widget = Some(widget.clone().upcast());
239         self
240     }
241 }
242 
243 impl fmt::Display for GestureLongPress {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result244     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
245         f.write_str("GestureLongPress")
246     }
247 }
248