gtk/auto/
gesture_single.rs1use gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib_sys;
12use gtk_sys;
13use std::boxed::Box as Box_;
14use std::fmt;
15use std::mem::transmute;
16use EventController;
17use Gesture;
18
19glib_wrapper! {
20 pub struct GestureSingle(Object<gtk_sys::GtkGestureSingle, gtk_sys::GtkGestureSingleClass, GestureSingleClass>) @extends Gesture, EventController;
21
22 match fn {
23 get_type => || gtk_sys::gtk_gesture_single_get_type(),
24 }
25}
26
27pub const NONE_GESTURE_SINGLE: Option<&GestureSingle> = None;
28
29pub trait GestureSingleExt: 'static {
30 fn get_button(&self) -> u32;
31
32 fn get_current_button(&self) -> u32;
33
34 fn get_current_sequence(&self) -> Option<gdk::EventSequence>;
35
36 fn get_exclusive(&self) -> bool;
37
38 fn get_touch_only(&self) -> bool;
39
40 fn set_button(&self, button: u32);
41
42 fn set_exclusive(&self, exclusive: bool);
43
44 fn set_touch_only(&self, touch_only: bool);
45
46 fn connect_property_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
47
48 fn connect_property_exclusive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
49
50 fn connect_property_touch_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
51}
52
53impl<O: IsA<GestureSingle>> GestureSingleExt for O {
54 fn get_button(&self) -> u32 {
55 unsafe { gtk_sys::gtk_gesture_single_get_button(self.as_ref().to_glib_none().0) }
56 }
57
58 fn get_current_button(&self) -> u32 {
59 unsafe { gtk_sys::gtk_gesture_single_get_current_button(self.as_ref().to_glib_none().0) }
60 }
61
62 fn get_current_sequence(&self) -> Option<gdk::EventSequence> {
63 unsafe {
64 from_glib_full(gtk_sys::gtk_gesture_single_get_current_sequence(
65 self.as_ref().to_glib_none().0,
66 ))
67 }
68 }
69
70 fn get_exclusive(&self) -> bool {
71 unsafe {
72 from_glib(gtk_sys::gtk_gesture_single_get_exclusive(
73 self.as_ref().to_glib_none().0,
74 ))
75 }
76 }
77
78 fn get_touch_only(&self) -> bool {
79 unsafe {
80 from_glib(gtk_sys::gtk_gesture_single_get_touch_only(
81 self.as_ref().to_glib_none().0,
82 ))
83 }
84 }
85
86 fn set_button(&self, button: u32) {
87 unsafe {
88 gtk_sys::gtk_gesture_single_set_button(self.as_ref().to_glib_none().0, button);
89 }
90 }
91
92 fn set_exclusive(&self, exclusive: bool) {
93 unsafe {
94 gtk_sys::gtk_gesture_single_set_exclusive(
95 self.as_ref().to_glib_none().0,
96 exclusive.to_glib(),
97 );
98 }
99 }
100
101 fn set_touch_only(&self, touch_only: bool) {
102 unsafe {
103 gtk_sys::gtk_gesture_single_set_touch_only(
104 self.as_ref().to_glib_none().0,
105 touch_only.to_glib(),
106 );
107 }
108 }
109
110 fn connect_property_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
111 unsafe extern "C" fn notify_button_trampoline<P, F: Fn(&P) + 'static>(
112 this: *mut gtk_sys::GtkGestureSingle,
113 _param_spec: glib_sys::gpointer,
114 f: glib_sys::gpointer,
115 ) where
116 P: IsA<GestureSingle>,
117 {
118 let f: &F = &*(f as *const F);
119 f(&GestureSingle::from_glib_borrow(this).unsafe_cast())
120 }
121 unsafe {
122 let f: Box_<F> = Box_::new(f);
123 connect_raw(
124 self.as_ptr() as *mut _,
125 b"notify::button\0".as_ptr() as *const _,
126 Some(transmute(notify_button_trampoline::<Self, F> as usize)),
127 Box_::into_raw(f),
128 )
129 }
130 }
131
132 fn connect_property_exclusive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
133 unsafe extern "C" fn notify_exclusive_trampoline<P, F: Fn(&P) + 'static>(
134 this: *mut gtk_sys::GtkGestureSingle,
135 _param_spec: glib_sys::gpointer,
136 f: glib_sys::gpointer,
137 ) where
138 P: IsA<GestureSingle>,
139 {
140 let f: &F = &*(f as *const F);
141 f(&GestureSingle::from_glib_borrow(this).unsafe_cast())
142 }
143 unsafe {
144 let f: Box_<F> = Box_::new(f);
145 connect_raw(
146 self.as_ptr() as *mut _,
147 b"notify::exclusive\0".as_ptr() as *const _,
148 Some(transmute(notify_exclusive_trampoline::<Self, F> as usize)),
149 Box_::into_raw(f),
150 )
151 }
152 }
153
154 fn connect_property_touch_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
155 unsafe extern "C" fn notify_touch_only_trampoline<P, F: Fn(&P) + 'static>(
156 this: *mut gtk_sys::GtkGestureSingle,
157 _param_spec: glib_sys::gpointer,
158 f: glib_sys::gpointer,
159 ) where
160 P: IsA<GestureSingle>,
161 {
162 let f: &F = &*(f as *const F);
163 f(&GestureSingle::from_glib_borrow(this).unsafe_cast())
164 }
165 unsafe {
166 let f: Box_<F> = Box_::new(f);
167 connect_raw(
168 self.as_ptr() as *mut _,
169 b"notify::touch-only\0".as_ptr() as *const _,
170 Some(transmute(notify_touch_only_trampoline::<Self, F> as usize)),
171 Box_::into_raw(f),
172 )
173 }
174 }
175}
176
177impl fmt::Display for GestureSingle {
178 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
179 write!(f, "GestureSingle")
180 }
181}