1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use gdk;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib_sys;
use gtk_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use EventController;
use Gesture;

glib_wrapper! {
    /// `GestureSingle` is a subclass of `Gesture`, optimized (although
    /// not restricted) for dealing with mouse and single-touch gestures. Under
    /// interaction, these gestures stick to the first interacting sequence, which
    /// is accessible through `GestureSingleExt::get_current_sequence` while the
    /// gesture is being interacted with.
    ///
    /// By default gestures react to both `GDK_BUTTON_PRIMARY` and touch
    /// events, `GestureSingleExt::set_touch_only` can be used to change the
    /// touch behavior. Callers may also specify a different mouse button number
    /// to interact with through `GestureSingleExt::set_button`, or react to any
    /// mouse button by setting 0. While the gesture is active, the button being
    /// currently pressed can be known through `GestureSingleExt::get_current_button`.
    ///
    /// # Implements
    ///
    /// [`GestureSingleExt`](trait.GestureSingleExt.html), [`GestureExt`](trait.GestureExt.html), [`EventControllerExt`](trait.EventControllerExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html)
    pub struct GestureSingle(Object<gtk_sys::GtkGestureSingle, gtk_sys::GtkGestureSingleClass, GestureSingleClass>) @extends Gesture, EventController;

    match fn {
        get_type => || gtk_sys::gtk_gesture_single_get_type(),
    }
}

pub const NONE_GESTURE_SINGLE: Option<&GestureSingle> = None;

/// Trait containing all `GestureSingle` methods.
///
/// # Implementors
///
/// [`GestureDrag`](struct.GestureDrag.html), [`GestureLongPress`](struct.GestureLongPress.html), [`GestureMultiPress`](struct.GestureMultiPress.html), [`GestureSingle`](struct.GestureSingle.html), [`GestureStylus`](struct.GestureStylus.html), [`GestureSwipe`](struct.GestureSwipe.html)
pub trait GestureSingleExt: 'static {
    /// Returns the button number `self` listens for, or 0 if `self`
    /// reacts to any button press.
    ///
    /// # Returns
    ///
    /// The button number, or 0 for any button
    fn get_button(&self) -> u32;

    /// Returns the button number currently interacting with `self`, or 0 if there
    /// is none.
    ///
    /// # Returns
    ///
    /// The current button number
    fn get_current_button(&self) -> u32;

    /// Returns the event sequence currently interacting with `self`.
    /// This is only meaningful if `GestureExt::is_active` returns `true`.
    ///
    /// # Returns
    ///
    /// the current sequence
    fn get_current_sequence(&self) -> Option<gdk::EventSequence>;

    /// Gets whether a gesture is exclusive. For more information, see
    /// `GestureSingleExt::set_exclusive`.
    ///
    /// # Returns
    ///
    /// Whether the gesture is exclusive
    fn get_exclusive(&self) -> bool;

    /// Returns `true` if the gesture is only triggered by touch events.
    ///
    /// # Returns
    ///
    /// `true` if the gesture only handles touch events
    fn get_touch_only(&self) -> bool;

    /// Sets the button number `self` listens to. If non-0, every
    /// button press from a different button number will be ignored.
    /// Touch events implicitly match with button 1.
    /// ## `button`
    /// button number to listen to, or 0 for any button
    fn set_button(&self, button: u32);

    /// Sets whether `self` is exclusive. An exclusive gesture will
    /// only handle pointer and "pointer emulated" touch events, so at
    /// any given time, there is only one sequence able to interact with
    /// those.
    /// ## `exclusive`
    /// `true` to make `self` exclusive
    fn set_exclusive(&self, exclusive: bool);

    /// If `touch_only` is `true`, `self` will only handle events of type
    /// `gdk::EventType::TouchBegin`, `gdk::EventType::TouchUpdate` or `gdk::EventType::TouchEnd`. If `false`,
    /// mouse events will be handled too.
    /// ## `touch_only`
    /// whether `self` handles only touch events
    fn set_touch_only(&self, touch_only: bool);

    fn connect_property_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_exclusive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_touch_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<GestureSingle>> GestureSingleExt for O {
    fn get_button(&self) -> u32 {
        unsafe { gtk_sys::gtk_gesture_single_get_button(self.as_ref().to_glib_none().0) }
    }

    fn get_current_button(&self) -> u32 {
        unsafe { gtk_sys::gtk_gesture_single_get_current_button(self.as_ref().to_glib_none().0) }
    }

    fn get_current_sequence(&self) -> Option<gdk::EventSequence> {
        unsafe {
            from_glib_full(gtk_sys::gtk_gesture_single_get_current_sequence(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_exclusive(&self) -> bool {
        unsafe {
            from_glib(gtk_sys::gtk_gesture_single_get_exclusive(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_touch_only(&self) -> bool {
        unsafe {
            from_glib(gtk_sys::gtk_gesture_single_get_touch_only(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_button(&self, button: u32) {
        unsafe {
            gtk_sys::gtk_gesture_single_set_button(self.as_ref().to_glib_none().0, button);
        }
    }

    fn set_exclusive(&self, exclusive: bool) {
        unsafe {
            gtk_sys::gtk_gesture_single_set_exclusive(
                self.as_ref().to_glib_none().0,
                exclusive.to_glib(),
            );
        }
    }

    fn set_touch_only(&self, touch_only: bool) {
        unsafe {
            gtk_sys::gtk_gesture_single_set_touch_only(
                self.as_ref().to_glib_none().0,
                touch_only.to_glib(),
            );
        }
    }

    fn connect_property_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_button_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gtk_sys::GtkGestureSingle,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<GestureSingle>,
        {
            let f: &F = &*(f as *const F);
            f(&GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::button\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_button_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_exclusive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_exclusive_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gtk_sys::GtkGestureSingle,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<GestureSingle>,
        {
            let f: &F = &*(f as *const F);
            f(&GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::exclusive\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_exclusive_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_touch_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_touch_only_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gtk_sys::GtkGestureSingle,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<GestureSingle>,
        {
            let f: &F = &*(f as *const F);
            f(&GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::touch-only\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_touch_only_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for GestureSingle {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "GestureSingle")
    }
}