1use gdk;
6use gdk_sys;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib::StaticType;
13use glib::Value;
14use glib_sys;
15use gobject_sys;
16use gtk_sys;
17use std::boxed::Box as Box_;
18use std::fmt;
19use std::mem;
20use std::mem::transmute;
21use EventController;
22use EventSequenceState;
23
24glib_wrapper! {
25 pub struct Gesture(Object<gtk_sys::GtkGesture, gtk_sys::GtkGestureClass, GestureClass>) @extends EventController;
26
27 match fn {
28 get_type => || gtk_sys::gtk_gesture_get_type(),
29 }
30}
31
32pub const NONE_GESTURE: Option<&Gesture> = None;
33
34pub trait GestureExt: 'static {
35 fn get_bounding_box(&self) -> Option<gdk::Rectangle>;
36
37 fn get_bounding_box_center(&self) -> Option<(f64, f64)>;
38
39 fn get_device(&self) -> Option<gdk::Device>;
40
41 fn get_group(&self) -> Vec<Gesture>;
42
43 fn get_last_event(&self, sequence: Option<&gdk::EventSequence>) -> Option<gdk::Event>;
44
45 fn get_last_updated_sequence(&self) -> Option<gdk::EventSequence>;
46
47 fn get_point(&self, sequence: Option<&gdk::EventSequence>) -> Option<(f64, f64)>;
48
49 fn get_sequence_state(&self, sequence: &gdk::EventSequence) -> EventSequenceState;
50
51 fn get_sequences(&self) -> Vec<gdk::EventSequence>;
52
53 fn get_window(&self) -> Option<gdk::Window>;
54
55 fn group<P: IsA<Gesture>>(&self, gesture: &P);
56
57 fn handles_sequence(&self, sequence: Option<&gdk::EventSequence>) -> bool;
58
59 fn is_active(&self) -> bool;
60
61 fn is_grouped_with<P: IsA<Gesture>>(&self, other: &P) -> bool;
62
63 fn is_recognized(&self) -> bool;
64
65 fn set_sequence_state(&self, sequence: &gdk::EventSequence, state: EventSequenceState) -> bool;
66
67 fn set_state(&self, state: EventSequenceState) -> bool;
68
69 fn set_window<P: IsA<gdk::Window>>(&self, window: Option<&P>);
70
71 fn ungroup(&self);
72
73 fn get_property_n_points(&self) -> u32;
74
75 fn connect_begin<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId;
76
77 fn connect_cancel<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId;
78
79 fn connect_end<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId;
80
81 fn connect_sequence_state_changed<
82 F: Fn(&Self, &gdk::EventSequence, EventSequenceState) + 'static,
83 >(
84 &self,
85 f: F,
86 ) -> SignalHandlerId;
87
88 fn connect_update<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId;
89
90 fn connect_property_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
91}
92
93impl<O: IsA<Gesture>> GestureExt for O {
94 fn get_bounding_box(&self) -> Option<gdk::Rectangle> {
95 unsafe {
96 let mut rect = gdk::Rectangle::uninitialized();
97 let ret = from_glib(gtk_sys::gtk_gesture_get_bounding_box(
98 self.as_ref().to_glib_none().0,
99 rect.to_glib_none_mut().0,
100 ));
101 if ret {
102 Some(rect)
103 } else {
104 None
105 }
106 }
107 }
108
109 fn get_bounding_box_center(&self) -> Option<(f64, f64)> {
110 unsafe {
111 let mut x = mem::uninitialized();
112 let mut y = mem::uninitialized();
113 let ret = from_glib(gtk_sys::gtk_gesture_get_bounding_box_center(
114 self.as_ref().to_glib_none().0,
115 &mut x,
116 &mut y,
117 ));
118 if ret {
119 Some((x, y))
120 } else {
121 None
122 }
123 }
124 }
125
126 fn get_device(&self) -> Option<gdk::Device> {
127 unsafe {
128 from_glib_none(gtk_sys::gtk_gesture_get_device(
129 self.as_ref().to_glib_none().0,
130 ))
131 }
132 }
133
134 fn get_group(&self) -> Vec<Gesture> {
135 unsafe {
136 FromGlibPtrContainer::from_glib_container(gtk_sys::gtk_gesture_get_group(
137 self.as_ref().to_glib_none().0,
138 ))
139 }
140 }
141
142 fn get_last_event(&self, sequence: Option<&gdk::EventSequence>) -> Option<gdk::Event> {
143 unsafe {
144 from_glib_none(gtk_sys::gtk_gesture_get_last_event(
145 self.as_ref().to_glib_none().0,
146 mut_override(sequence.to_glib_none().0),
147 ))
148 }
149 }
150
151 fn get_last_updated_sequence(&self) -> Option<gdk::EventSequence> {
152 unsafe {
153 from_glib_none(gtk_sys::gtk_gesture_get_last_updated_sequence(
154 self.as_ref().to_glib_none().0,
155 ))
156 }
157 }
158
159 fn get_point(&self, sequence: Option<&gdk::EventSequence>) -> Option<(f64, f64)> {
160 unsafe {
161 let mut x = mem::uninitialized();
162 let mut y = mem::uninitialized();
163 let ret = from_glib(gtk_sys::gtk_gesture_get_point(
164 self.as_ref().to_glib_none().0,
165 mut_override(sequence.to_glib_none().0),
166 &mut x,
167 &mut y,
168 ));
169 if ret {
170 Some((x, y))
171 } else {
172 None
173 }
174 }
175 }
176
177 fn get_sequence_state(&self, sequence: &gdk::EventSequence) -> EventSequenceState {
178 unsafe {
179 from_glib(gtk_sys::gtk_gesture_get_sequence_state(
180 self.as_ref().to_glib_none().0,
181 mut_override(sequence.to_glib_none().0),
182 ))
183 }
184 }
185
186 fn get_sequences(&self) -> Vec<gdk::EventSequence> {
187 unsafe {
188 FromGlibPtrContainer::from_glib_container(gtk_sys::gtk_gesture_get_sequences(
189 self.as_ref().to_glib_none().0,
190 ))
191 }
192 }
193
194 fn get_window(&self) -> Option<gdk::Window> {
195 unsafe {
196 from_glib_none(gtk_sys::gtk_gesture_get_window(
197 self.as_ref().to_glib_none().0,
198 ))
199 }
200 }
201
202 fn group<P: IsA<Gesture>>(&self, gesture: &P) {
203 unsafe {
204 gtk_sys::gtk_gesture_group(
205 self.as_ref().to_glib_none().0,
206 gesture.as_ref().to_glib_none().0,
207 );
208 }
209 }
210
211 fn handles_sequence(&self, sequence: Option<&gdk::EventSequence>) -> bool {
212 unsafe {
213 from_glib(gtk_sys::gtk_gesture_handles_sequence(
214 self.as_ref().to_glib_none().0,
215 mut_override(sequence.to_glib_none().0),
216 ))
217 }
218 }
219
220 fn is_active(&self) -> bool {
221 unsafe {
222 from_glib(gtk_sys::gtk_gesture_is_active(
223 self.as_ref().to_glib_none().0,
224 ))
225 }
226 }
227
228 fn is_grouped_with<P: IsA<Gesture>>(&self, other: &P) -> bool {
229 unsafe {
230 from_glib(gtk_sys::gtk_gesture_is_grouped_with(
231 self.as_ref().to_glib_none().0,
232 other.as_ref().to_glib_none().0,
233 ))
234 }
235 }
236
237 fn is_recognized(&self) -> bool {
238 unsafe {
239 from_glib(gtk_sys::gtk_gesture_is_recognized(
240 self.as_ref().to_glib_none().0,
241 ))
242 }
243 }
244
245 fn set_sequence_state(&self, sequence: &gdk::EventSequence, state: EventSequenceState) -> bool {
246 unsafe {
247 from_glib(gtk_sys::gtk_gesture_set_sequence_state(
248 self.as_ref().to_glib_none().0,
249 mut_override(sequence.to_glib_none().0),
250 state.to_glib(),
251 ))
252 }
253 }
254
255 fn set_state(&self, state: EventSequenceState) -> bool {
256 unsafe {
257 from_glib(gtk_sys::gtk_gesture_set_state(
258 self.as_ref().to_glib_none().0,
259 state.to_glib(),
260 ))
261 }
262 }
263
264 fn set_window<P: IsA<gdk::Window>>(&self, window: Option<&P>) {
265 unsafe {
266 gtk_sys::gtk_gesture_set_window(
267 self.as_ref().to_glib_none().0,
268 window.map(|p| p.as_ref()).to_glib_none().0,
269 );
270 }
271 }
272
273 fn ungroup(&self) {
274 unsafe {
275 gtk_sys::gtk_gesture_ungroup(self.as_ref().to_glib_none().0);
276 }
277 }
278
279 fn get_property_n_points(&self) -> u32 {
280 unsafe {
281 let mut value = Value::from_type(<u32 as StaticType>::static_type());
282 gobject_sys::g_object_get_property(
283 self.to_glib_none().0 as *mut gobject_sys::GObject,
284 b"n-points\0".as_ptr() as *const _,
285 value.to_glib_none_mut().0,
286 );
287 value.get().unwrap()
288 }
289 }
290
291 fn connect_begin<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId {
292 unsafe extern "C" fn begin_trampoline<P, F: Fn(&P, &gdk::EventSequence) + 'static>(
293 this: *mut gtk_sys::GtkGesture,
294 sequence: *mut gdk_sys::GdkEventSequence,
295 f: glib_sys::gpointer,
296 ) where
297 P: IsA<Gesture>,
298 {
299 let f: &F = &*(f as *const F);
300 f(
301 &Gesture::from_glib_borrow(this).unsafe_cast(),
302 &from_glib_borrow(sequence),
303 )
304 }
305 unsafe {
306 let f: Box_<F> = Box_::new(f);
307 connect_raw(
308 self.as_ptr() as *mut _,
309 b"begin\0".as_ptr() as *const _,
310 Some(transmute(begin_trampoline::<Self, F> as usize)),
311 Box_::into_raw(f),
312 )
313 }
314 }
315
316 fn connect_cancel<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId {
317 unsafe extern "C" fn cancel_trampoline<P, F: Fn(&P, &gdk::EventSequence) + 'static>(
318 this: *mut gtk_sys::GtkGesture,
319 sequence: *mut gdk_sys::GdkEventSequence,
320 f: glib_sys::gpointer,
321 ) where
322 P: IsA<Gesture>,
323 {
324 let f: &F = &*(f as *const F);
325 f(
326 &Gesture::from_glib_borrow(this).unsafe_cast(),
327 &from_glib_borrow(sequence),
328 )
329 }
330 unsafe {
331 let f: Box_<F> = Box_::new(f);
332 connect_raw(
333 self.as_ptr() as *mut _,
334 b"cancel\0".as_ptr() as *const _,
335 Some(transmute(cancel_trampoline::<Self, F> as usize)),
336 Box_::into_raw(f),
337 )
338 }
339 }
340
341 fn connect_end<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId {
342 unsafe extern "C" fn end_trampoline<P, F: Fn(&P, &gdk::EventSequence) + 'static>(
343 this: *mut gtk_sys::GtkGesture,
344 sequence: *mut gdk_sys::GdkEventSequence,
345 f: glib_sys::gpointer,
346 ) where
347 P: IsA<Gesture>,
348 {
349 let f: &F = &*(f as *const F);
350 f(
351 &Gesture::from_glib_borrow(this).unsafe_cast(),
352 &from_glib_borrow(sequence),
353 )
354 }
355 unsafe {
356 let f: Box_<F> = Box_::new(f);
357 connect_raw(
358 self.as_ptr() as *mut _,
359 b"end\0".as_ptr() as *const _,
360 Some(transmute(end_trampoline::<Self, F> as usize)),
361 Box_::into_raw(f),
362 )
363 }
364 }
365
366 fn connect_sequence_state_changed<
367 F: Fn(&Self, &gdk::EventSequence, EventSequenceState) + 'static,
368 >(
369 &self,
370 f: F,
371 ) -> SignalHandlerId {
372 unsafe extern "C" fn sequence_state_changed_trampoline<
373 P,
374 F: Fn(&P, &gdk::EventSequence, EventSequenceState) + 'static,
375 >(
376 this: *mut gtk_sys::GtkGesture,
377 sequence: *mut gdk_sys::GdkEventSequence,
378 state: gtk_sys::GtkEventSequenceState,
379 f: glib_sys::gpointer,
380 ) where
381 P: IsA<Gesture>,
382 {
383 let f: &F = &*(f as *const F);
384 f(
385 &Gesture::from_glib_borrow(this).unsafe_cast(),
386 &from_glib_borrow(sequence),
387 from_glib(state),
388 )
389 }
390 unsafe {
391 let f: Box_<F> = Box_::new(f);
392 connect_raw(
393 self.as_ptr() as *mut _,
394 b"sequence-state-changed\0".as_ptr() as *const _,
395 Some(transmute(
396 sequence_state_changed_trampoline::<Self, F> as usize,
397 )),
398 Box_::into_raw(f),
399 )
400 }
401 }
402
403 fn connect_update<F: Fn(&Self, &gdk::EventSequence) + 'static>(&self, f: F) -> SignalHandlerId {
404 unsafe extern "C" fn update_trampoline<P, F: Fn(&P, &gdk::EventSequence) + 'static>(
405 this: *mut gtk_sys::GtkGesture,
406 sequence: *mut gdk_sys::GdkEventSequence,
407 f: glib_sys::gpointer,
408 ) where
409 P: IsA<Gesture>,
410 {
411 let f: &F = &*(f as *const F);
412 f(
413 &Gesture::from_glib_borrow(this).unsafe_cast(),
414 &from_glib_borrow(sequence),
415 )
416 }
417 unsafe {
418 let f: Box_<F> = Box_::new(f);
419 connect_raw(
420 self.as_ptr() as *mut _,
421 b"update\0".as_ptr() as *const _,
422 Some(transmute(update_trampoline::<Self, F> as usize)),
423 Box_::into_raw(f),
424 )
425 }
426 }
427
428 fn connect_property_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
429 unsafe extern "C" fn notify_window_trampoline<P, F: Fn(&P) + 'static>(
430 this: *mut gtk_sys::GtkGesture,
431 _param_spec: glib_sys::gpointer,
432 f: glib_sys::gpointer,
433 ) where
434 P: IsA<Gesture>,
435 {
436 let f: &F = &*(f as *const F);
437 f(&Gesture::from_glib_borrow(this).unsafe_cast())
438 }
439 unsafe {
440 let f: Box_<F> = Box_::new(f);
441 connect_raw(
442 self.as_ptr() as *mut _,
443 b"notify::window\0".as_ptr() as *const _,
444 Some(transmute(notify_window_trampoline::<Self, F> as usize)),
445 Box_::into_raw(f),
446 )
447 }
448 }
449}
450
451impl fmt::Display for Gesture {
452 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
453 write!(f, "Gesture")
454 }
455}