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::signal::connect_raw;
13 use glib::signal::SignalHandlerId;
14 use glib::translate::*;
15 use glib::StaticType;
16 use glib::ToValue;
17 use std::boxed::Box as Box_;
18 use std::fmt;
19 use std::mem;
20 use std::mem::transmute;
21 
22 glib::wrapper! {
23     #[doc(alias = "GtkGestureDrag")]
24     pub struct GestureDrag(Object<ffi::GtkGestureDrag, ffi::GtkGestureDragClass>) @extends GestureSingle, Gesture, EventController;
25 
26     match fn {
27         type_ => || ffi::gtk_gesture_drag_get_type(),
28     }
29 }
30 
31 impl GestureDrag {
32     #[doc(alias = "gtk_gesture_drag_new")]
new<P: IsA<Widget>>(widget: &P) -> GestureDrag33     pub fn new<P: IsA<Widget>>(widget: &P) -> GestureDrag {
34         skip_assert_initialized!();
35         unsafe {
36             Gesture::from_glib_full(ffi::gtk_gesture_drag_new(widget.as_ref().to_glib_none().0))
37                 .unsafe_cast()
38         }
39     }
40 
41     // rustdoc-stripper-ignore-next
42     /// Creates a new builder-pattern struct instance to construct [`GestureDrag`] objects.
43     ///
44     /// This method returns an instance of [`GestureDragBuilder`] which can be used to create [`GestureDrag`] objects.
builder() -> GestureDragBuilder45     pub fn builder() -> GestureDragBuilder {
46         GestureDragBuilder::default()
47     }
48 }
49 
50 #[derive(Clone, Default)]
51 // rustdoc-stripper-ignore-next
52 /// A [builder-pattern] type to construct [`GestureDrag`] objects.
53 ///
54 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
55 pub struct GestureDragBuilder {
56     button: Option<u32>,
57     exclusive: Option<bool>,
58     touch_only: Option<bool>,
59     n_points: Option<u32>,
60     window: Option<gdk::Window>,
61     propagation_phase: Option<PropagationPhase>,
62     widget: Option<Widget>,
63 }
64 
65 impl GestureDragBuilder {
66     // rustdoc-stripper-ignore-next
67     /// Create a new [`GestureDragBuilder`].
new() -> Self68     pub fn new() -> Self {
69         Self::default()
70     }
71 
72     // rustdoc-stripper-ignore-next
73     /// Build the [`GestureDrag`].
build(self) -> GestureDrag74     pub fn build(self) -> GestureDrag {
75         let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
76         if let Some(ref button) = self.button {
77             properties.push(("button", button));
78         }
79         if let Some(ref exclusive) = self.exclusive {
80             properties.push(("exclusive", exclusive));
81         }
82         if let Some(ref touch_only) = self.touch_only {
83             properties.push(("touch-only", touch_only));
84         }
85         if let Some(ref n_points) = self.n_points {
86             properties.push(("n-points", n_points));
87         }
88         if let Some(ref window) = self.window {
89             properties.push(("window", window));
90         }
91         if let Some(ref propagation_phase) = self.propagation_phase {
92             properties.push(("propagation-phase", propagation_phase));
93         }
94         if let Some(ref widget) = self.widget {
95             properties.push(("widget", widget));
96         }
97         glib::Object::new::<GestureDrag>(&properties)
98             .expect("Failed to create an instance of GestureDrag")
99     }
100 
button(mut self, button: u32) -> Self101     pub fn button(mut self, button: u32) -> Self {
102         self.button = Some(button);
103         self
104     }
105 
exclusive(mut self, exclusive: bool) -> Self106     pub fn exclusive(mut self, exclusive: bool) -> Self {
107         self.exclusive = Some(exclusive);
108         self
109     }
110 
touch_only(mut self, touch_only: bool) -> Self111     pub fn touch_only(mut self, touch_only: bool) -> Self {
112         self.touch_only = Some(touch_only);
113         self
114     }
115 
n_points(mut self, n_points: u32) -> Self116     pub fn n_points(mut self, n_points: u32) -> Self {
117         self.n_points = Some(n_points);
118         self
119     }
120 
window(mut self, window: &gdk::Window) -> Self121     pub fn window(mut self, window: &gdk::Window) -> Self {
122         self.window = Some(window.clone());
123         self
124     }
125 
propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self126     pub fn propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self {
127         self.propagation_phase = Some(propagation_phase);
128         self
129     }
130 
widget<P: IsA<Widget>>(mut self, widget: &P) -> Self131     pub fn widget<P: IsA<Widget>>(mut self, widget: &P) -> Self {
132         self.widget = Some(widget.clone().upcast());
133         self
134     }
135 }
136 
137 pub const NONE_GESTURE_DRAG: Option<&GestureDrag> = None;
138 
139 pub trait GestureDragExt: 'static {
140     #[doc(alias = "gtk_gesture_drag_get_offset")]
141     #[doc(alias = "get_offset")]
offset(&self) -> Option<(f64, f64)>142     fn offset(&self) -> Option<(f64, f64)>;
143 
144     #[doc(alias = "gtk_gesture_drag_get_start_point")]
145     #[doc(alias = "get_start_point")]
start_point(&self) -> Option<(f64, f64)>146     fn start_point(&self) -> Option<(f64, f64)>;
147 
148     #[doc(alias = "drag-begin")]
connect_drag_begin<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId149     fn connect_drag_begin<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId;
150 
151     #[doc(alias = "drag-end")]
connect_drag_end<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId152     fn connect_drag_end<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId;
153 
154     #[doc(alias = "drag-update")]
connect_drag_update<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId155     fn connect_drag_update<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId;
156 }
157 
158 impl<O: IsA<GestureDrag>> GestureDragExt for O {
offset(&self) -> Option<(f64, f64)>159     fn offset(&self) -> Option<(f64, f64)> {
160         unsafe {
161             let mut x = mem::MaybeUninit::uninit();
162             let mut y = mem::MaybeUninit::uninit();
163             let ret = from_glib(ffi::gtk_gesture_drag_get_offset(
164                 self.as_ref().to_glib_none().0,
165                 x.as_mut_ptr(),
166                 y.as_mut_ptr(),
167             ));
168             let x = x.assume_init();
169             let y = y.assume_init();
170             if ret {
171                 Some((x, y))
172             } else {
173                 None
174             }
175         }
176     }
177 
start_point(&self) -> Option<(f64, f64)>178     fn start_point(&self) -> Option<(f64, f64)> {
179         unsafe {
180             let mut x = mem::MaybeUninit::uninit();
181             let mut y = mem::MaybeUninit::uninit();
182             let ret = from_glib(ffi::gtk_gesture_drag_get_start_point(
183                 self.as_ref().to_glib_none().0,
184                 x.as_mut_ptr(),
185                 y.as_mut_ptr(),
186             ));
187             let x = x.assume_init();
188             let y = y.assume_init();
189             if ret {
190                 Some((x, y))
191             } else {
192                 None
193             }
194         }
195     }
196 
connect_drag_begin<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId197     fn connect_drag_begin<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
198         unsafe extern "C" fn drag_begin_trampoline<
199             P: IsA<GestureDrag>,
200             F: Fn(&P, f64, f64) + 'static,
201         >(
202             this: *mut ffi::GtkGestureDrag,
203             start_x: libc::c_double,
204             start_y: libc::c_double,
205             f: glib::ffi::gpointer,
206         ) {
207             let f: &F = &*(f as *const F);
208             f(
209                 GestureDrag::from_glib_borrow(this).unsafe_cast_ref(),
210                 start_x,
211                 start_y,
212             )
213         }
214         unsafe {
215             let f: Box_<F> = Box_::new(f);
216             connect_raw(
217                 self.as_ptr() as *mut _,
218                 b"drag-begin\0".as_ptr() as *const _,
219                 Some(transmute::<_, unsafe extern "C" fn()>(
220                     drag_begin_trampoline::<Self, F> as *const (),
221                 )),
222                 Box_::into_raw(f),
223             )
224         }
225     }
226 
connect_drag_end<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId227     fn connect_drag_end<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
228         unsafe extern "C" fn drag_end_trampoline<
229             P: IsA<GestureDrag>,
230             F: Fn(&P, f64, f64) + 'static,
231         >(
232             this: *mut ffi::GtkGestureDrag,
233             offset_x: libc::c_double,
234             offset_y: libc::c_double,
235             f: glib::ffi::gpointer,
236         ) {
237             let f: &F = &*(f as *const F);
238             f(
239                 GestureDrag::from_glib_borrow(this).unsafe_cast_ref(),
240                 offset_x,
241                 offset_y,
242             )
243         }
244         unsafe {
245             let f: Box_<F> = Box_::new(f);
246             connect_raw(
247                 self.as_ptr() as *mut _,
248                 b"drag-end\0".as_ptr() as *const _,
249                 Some(transmute::<_, unsafe extern "C" fn()>(
250                     drag_end_trampoline::<Self, F> as *const (),
251                 )),
252                 Box_::into_raw(f),
253             )
254         }
255     }
256 
connect_drag_update<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId257     fn connect_drag_update<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
258         unsafe extern "C" fn drag_update_trampoline<
259             P: IsA<GestureDrag>,
260             F: Fn(&P, f64, f64) + 'static,
261         >(
262             this: *mut ffi::GtkGestureDrag,
263             offset_x: libc::c_double,
264             offset_y: libc::c_double,
265             f: glib::ffi::gpointer,
266         ) {
267             let f: &F = &*(f as *const F);
268             f(
269                 GestureDrag::from_glib_borrow(this).unsafe_cast_ref(),
270                 offset_x,
271                 offset_y,
272             )
273         }
274         unsafe {
275             let f: Box_<F> = Box_::new(f);
276             connect_raw(
277                 self.as_ptr() as *mut _,
278                 b"drag-update\0".as_ptr() as *const _,
279                 Some(transmute::<_, unsafe extern "C" fn()>(
280                     drag_update_trampoline::<Self, F> as *const (),
281                 )),
282                 Box_::into_raw(f),
283             )
284         }
285     }
286 }
287 
288 impl fmt::Display for GestureDrag {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result289     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
290         f.write_str("GestureDrag")
291     }
292 }
293