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 GestureDrag;
23use GestureSingle;
24use Orientation;
25use PanDirection;
26use PropagationPhase;
27use Widget;
28
29glib_wrapper! {
30 pub struct GesturePan(Object<gtk_sys::GtkGesturePan, gtk_sys::GtkGesturePanClass, GesturePanClass>) @extends GestureDrag, GestureSingle, Gesture, EventController;
31
32 match fn {
33 get_type => || gtk_sys::gtk_gesture_pan_get_type(),
34 }
35}
36
37impl GesturePan {
38 pub fn new<P: IsA<Widget>>(widget: &P, orientation: Orientation) -> GesturePan {
39 skip_assert_initialized!();
40 unsafe {
41 Gesture::from_glib_full(gtk_sys::gtk_gesture_pan_new(
42 widget.as_ref().to_glib_none().0,
43 orientation.to_glib(),
44 ))
45 .unsafe_cast()
46 }
47 }
48
49 pub fn get_orientation(&self) -> Orientation {
50 unsafe {
51 from_glib(gtk_sys::gtk_gesture_pan_get_orientation(
52 self.to_glib_none().0,
53 ))
54 }
55 }
56
57 pub fn set_orientation(&self, orientation: Orientation) {
58 unsafe {
59 gtk_sys::gtk_gesture_pan_set_orientation(self.to_glib_none().0, orientation.to_glib());
60 }
61 }
62
63 pub fn connect_pan<F: Fn(&GesturePan, PanDirection, f64) + 'static>(
64 &self,
65 f: F,
66 ) -> SignalHandlerId {
67 unsafe extern "C" fn pan_trampoline<F: Fn(&GesturePan, PanDirection, f64) + 'static>(
68 this: *mut gtk_sys::GtkGesturePan,
69 direction: gtk_sys::GtkPanDirection,
70 offset: libc::c_double,
71 f: glib_sys::gpointer,
72 ) {
73 let f: &F = &*(f as *const F);
74 f(&from_glib_borrow(this), from_glib(direction), offset)
75 }
76 unsafe {
77 let f: Box_<F> = Box_::new(f);
78 connect_raw(
79 self.as_ptr() as *mut _,
80 b"pan\0".as_ptr() as *const _,
81 Some(transmute(pan_trampoline::<F> as usize)),
82 Box_::into_raw(f),
83 )
84 }
85 }
86
87 pub fn connect_property_orientation_notify<F: Fn(&GesturePan) + 'static>(
88 &self,
89 f: F,
90 ) -> SignalHandlerId {
91 unsafe extern "C" fn notify_orientation_trampoline<F: Fn(&GesturePan) + 'static>(
92 this: *mut gtk_sys::GtkGesturePan,
93 _param_spec: glib_sys::gpointer,
94 f: glib_sys::gpointer,
95 ) {
96 let f: &F = &*(f as *const F);
97 f(&from_glib_borrow(this))
98 }
99 unsafe {
100 let f: Box_<F> = Box_::new(f);
101 connect_raw(
102 self.as_ptr() as *mut _,
103 b"notify::orientation\0".as_ptr() as *const _,
104 Some(transmute(notify_orientation_trampoline::<F> as usize)),
105 Box_::into_raw(f),
106 )
107 }
108 }
109}
110
111pub struct GesturePanBuilder {
112 orientation: Option<Orientation>,
113 button: Option<u32>,
114 exclusive: Option<bool>,
115 touch_only: Option<bool>,
116 n_points: Option<u32>,
117 window: Option<gdk::Window>,
118 propagation_phase: Option<PropagationPhase>,
119 widget: Option<Widget>,
120}
121
122impl GesturePanBuilder {
123 pub fn new() -> Self {
124 Self {
125 orientation: None,
126 button: None,
127 exclusive: None,
128 touch_only: None,
129 n_points: None,
130 window: None,
131 propagation_phase: None,
132 widget: None,
133 }
134 }
135
136 pub fn build(self) -> GesturePan {
137 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
138 if let Some(ref orientation) = self.orientation {
139 properties.push(("orientation", orientation));
140 }
141 if let Some(ref button) = self.button {
142 properties.push(("button", button));
143 }
144 if let Some(ref exclusive) = self.exclusive {
145 properties.push(("exclusive", exclusive));
146 }
147 if let Some(ref touch_only) = self.touch_only {
148 properties.push(("touch-only", touch_only));
149 }
150 if let Some(ref n_points) = self.n_points {
151 properties.push(("n-points", n_points));
152 }
153 if let Some(ref window) = self.window {
154 properties.push(("window", window));
155 }
156 if let Some(ref propagation_phase) = self.propagation_phase {
157 properties.push(("propagation-phase", propagation_phase));
158 }
159 if let Some(ref widget) = self.widget {
160 properties.push(("widget", widget));
161 }
162 glib::Object::new(GesturePan::static_type(), &properties)
163 .expect("object new")
164 .downcast()
165 .expect("downcast")
166 }
167
168 pub fn orientation(mut self, orientation: Orientation) -> Self {
169 self.orientation = Some(orientation);
170 self
171 }
172
173 pub fn button(mut self, button: u32) -> Self {
174 self.button = Some(button);
175 self
176 }
177
178 pub fn exclusive(mut self, exclusive: bool) -> Self {
179 self.exclusive = Some(exclusive);
180 self
181 }
182
183 pub fn touch_only(mut self, touch_only: bool) -> Self {
184 self.touch_only = Some(touch_only);
185 self
186 }
187
188 pub fn n_points(mut self, n_points: u32) -> Self {
189 self.n_points = Some(n_points);
190 self
191 }
192
193 pub fn window(mut self, window: &gdk::Window) -> Self {
194 self.window = Some(window.clone());
195 self
196 }
197
198 pub fn propagation_phase(mut self, propagation_phase: PropagationPhase) -> Self {
199 self.propagation_phase = Some(propagation_phase);
200 self
201 }
202
203 pub fn widget(mut self, widget: &Widget) -> Self {
204 self.widget = Some(widget.clone());
205 self
206 }
207}
208
209impl fmt::Display for GesturePan {
210 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
211 write!(f, "GesturePan")
212 }
213}