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