gtk/auto/
gesture_long_press.rs

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
5use gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::object::ObjectType as ObjectType_;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib::StaticType;
13use glib::ToValue;
14use glib::Value;
15use glib_sys;
16use gobject_sys;
17use gtk_sys;
18use libc;
19use std::boxed::Box as Box_;
20use std::fmt;
21use std::mem::transmute;
22use EventController;
23use Gesture;
24use GestureSingle;
25use PropagationPhase;
26use Widget;
27
28glib_wrapper! {
29    pub struct GestureLongPress(Object<gtk_sys::GtkGestureLongPress, gtk_sys::GtkGestureLongPressClass, GestureLongPressClass>) @extends GestureSingle, Gesture, EventController;
30
31    match fn {
32        get_type => || gtk_sys::gtk_gesture_long_press_get_type(),
33    }
34}
35
36impl GestureLongPress {
37    pub fn new<P: IsA<Widget>>(widget: &P) -> GestureLongPress {
38        skip_assert_initialized!();
39        unsafe {
40            Gesture::from_glib_full(gtk_sys::gtk_gesture_long_press_new(
41                widget.as_ref().to_glib_none().0,
42            ))
43            .unsafe_cast()
44        }
45    }
46
47    pub fn get_property_delay_factor(&self) -> f64 {
48        unsafe {
49            let mut value = Value::from_type(<f64 as StaticType>::static_type());
50            gobject_sys::g_object_get_property(
51                self.as_ptr() as *mut gobject_sys::GObject,
52                b"delay-factor\0".as_ptr() as *const _,
53                value.to_glib_none_mut().0,
54            );
55            value.get().unwrap()
56        }
57    }
58
59    pub fn set_property_delay_factor(&self, delay_factor: f64) {
60        unsafe {
61            gobject_sys::g_object_set_property(
62                self.as_ptr() as *mut gobject_sys::GObject,
63                b"delay-factor\0".as_ptr() as *const _,
64                Value::from(&delay_factor).to_glib_none().0,
65            );
66        }
67    }
68
69    pub fn connect_cancelled<F: Fn(&GestureLongPress) + 'static>(&self, f: F) -> SignalHandlerId {
70        unsafe extern "C" fn cancelled_trampoline<F: Fn(&GestureLongPress) + 'static>(
71            this: *mut gtk_sys::GtkGestureLongPress,
72            f: glib_sys::gpointer,
73        ) {
74            let f: &F = &*(f as *const F);
75            f(&from_glib_borrow(this))
76        }
77        unsafe {
78            let f: Box_<F> = Box_::new(f);
79            connect_raw(
80                self.as_ptr() as *mut _,
81                b"cancelled\0".as_ptr() as *const _,
82                Some(transmute(cancelled_trampoline::<F> as usize)),
83                Box_::into_raw(f),
84            )
85        }
86    }
87
88    pub fn connect_pressed<F: Fn(&GestureLongPress, f64, f64) + 'static>(
89        &self,
90        f: F,
91    ) -> SignalHandlerId {
92        unsafe extern "C" fn pressed_trampoline<F: Fn(&GestureLongPress, f64, f64) + 'static>(
93            this: *mut gtk_sys::GtkGestureLongPress,
94            x: libc::c_double,
95            y: libc::c_double,
96            f: glib_sys::gpointer,
97        ) {
98            let f: &F = &*(f as *const F);
99            f(&from_glib_borrow(this), x, y)
100        }
101        unsafe {
102            let f: Box_<F> = Box_::new(f);
103            connect_raw(
104                self.as_ptr() as *mut _,
105                b"pressed\0".as_ptr() as *const _,
106                Some(transmute(pressed_trampoline::<F> as usize)),
107                Box_::into_raw(f),
108            )
109        }
110    }
111
112    pub fn connect_property_delay_factor_notify<F: Fn(&GestureLongPress) + 'static>(
113        &self,
114        f: F,
115    ) -> SignalHandlerId {
116        unsafe extern "C" fn notify_delay_factor_trampoline<F: Fn(&GestureLongPress) + 'static>(
117            this: *mut gtk_sys::GtkGestureLongPress,
118            _param_spec: glib_sys::gpointer,
119            f: glib_sys::gpointer,
120        ) {
121            let f: &F = &*(f as *const F);
122            f(&from_glib_borrow(this))
123        }
124        unsafe {
125            let f: Box_<F> = Box_::new(f);
126            connect_raw(
127                self.as_ptr() as *mut _,
128                b"notify::delay-factor\0".as_ptr() as *const _,
129                Some(transmute(notify_delay_factor_trampoline::<F> as usize)),
130                Box_::into_raw(f),
131            )
132        }
133    }
134}
135
136pub struct GestureLongPressBuilder {
137    delay_factor: Option<f64>,
138    button: Option<u32>,
139    exclusive: Option<bool>,
140    touch_only: Option<bool>,
141    n_points: Option<u32>,
142    window: Option<gdk::Window>,
143    propagation_phase: Option<PropagationPhase>,
144    widget: Option<Widget>,
145}
146
147impl GestureLongPressBuilder {
148    pub fn new() -> Self {
149        Self {
150            delay_factor: None,
151            button: None,
152            exclusive: None,
153            touch_only: None,
154            n_points: None,
155            window: None,
156            propagation_phase: None,
157            widget: None,
158        }
159    }
160
161    pub fn build(self) -> GestureLongPress {
162        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
163        if let Some(ref delay_factor) = self.delay_factor {
164            properties.push(("delay-factor", delay_factor));
165        }
166        if let Some(ref button) = self.button {
167            properties.push(("button", button));
168        }
169        if let Some(ref exclusive) = self.exclusive {
170            properties.push(("exclusive", exclusive));
171        }
172        if let Some(ref touch_only) = self.touch_only {
173            properties.push(("touch-only", touch_only));
174        }
175        if let Some(ref n_points) = self.n_points {
176            properties.push(("n-points", n_points));
177        }
178        if let Some(ref window) = self.window {
179            properties.push(("window", window));
180        }
181        if let Some(ref propagation_phase) = self.propagation_phase {
182            properties.push(("propagation-phase", propagation_phase));
183        }
184        if let Some(ref widget) = self.widget {
185            properties.push(("widget", widget));
186        }
187        glib::Object::new(GestureLongPress::static_type(), &properties)
188            .expect("object new")
189            .downcast()
190            .expect("downcast")
191    }
192
193    pub fn delay_factor(mut self, delay_factor: f64) -> Self {
194        self.delay_factor = Some(delay_factor);
195        self
196    }
197
198    pub fn button(mut self, button: u32) -> Self {
199        self.button = Some(button);
200        self
201    }
202
203    pub fn exclusive(mut self, exclusive: bool) -> Self {
204        self.exclusive = Some(exclusive);
205        self
206    }
207
208    pub fn touch_only(mut self, touch_only: bool) -> Self {
209        self.touch_only = Some(touch_only);
210        self
211    }
212
213    pub fn n_points(mut self, n_points: u32) -> Self {
214        self.n_points = Some(n_points);
215        self
216    }
217
218    pub fn window(mut self, window: &gdk::Window) -> Self {
219        self.window = Some(window.clone());
220        self
221    }
222
223    pub fn propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self {
224        self.propagation_phase = Some(propagation_phase);
225        self
226    }
227
228    pub fn widget(mut self, widget: &Widget) -> Self {
229        self.widget = Some(widget.clone());
230        self
231    }
232}
233
234impl fmt::Display for GestureLongPress {
235    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
236        write!(f, "GestureLongPress")
237    }
238}