Skip to main content

gtk4/auto/
drop_controller_motion.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{EventController, PropagationLimit, PropagationPhase, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// An event controller tracking the pointer during Drag-and-Drop operations.
16    ///
17    /// It is modeled after [`EventControllerMotion`][crate::EventControllerMotion] so if you
18    /// have used that, this should feel really familiar.
19    ///
20    /// This controller is not able to accept drops, use [`DropTarget`][crate::DropTarget]
21    /// for that purpose.
22    ///
23    /// ## Properties
24    ///
25    ///
26    /// #### `contains-pointer`
27    ///  Whether the pointer of a Drag-and-Drop operation is in
28    /// the controller's widget or a descendant.
29    ///
30    /// See also [`is-pointer`][struct@crate::DropControllerMotion#is-pointer].
31    ///
32    /// When handling crossing events, this property is updated
33    /// before [`enter`][struct@crate::DropControllerMotion#enter], but after
34    /// [`leave`][struct@crate::DropControllerMotion#leave] is emitted.
35    ///
36    /// Readable
37    ///
38    ///
39    /// #### `drop`
40    ///  The ongoing drop operation over the controller's widget or
41    /// its descendant.
42    ///
43    /// If no drop operation is going on, this property returns [`None`].
44    ///
45    /// The event controller should not modify the @drop, but it might
46    /// want to query its properties.
47    ///
48    /// When handling crossing events, this property is updated
49    /// before [`enter`][struct@crate::DropControllerMotion#enter], but after
50    /// [`leave`][struct@crate::DropControllerMotion#leave] is emitted.
51    ///
52    /// Readable
53    ///
54    ///
55    /// #### `is-pointer`
56    ///  Whether the pointer is in the controllers widget itself,
57    /// as opposed to in a descendent widget.
58    ///
59    /// See also [`contains-pointer`][struct@crate::DropControllerMotion#contains-pointer].
60    ///
61    /// When handling crossing events, this property is updated
62    /// before [`enter`][struct@crate::DropControllerMotion#enter], but after
63    /// [`leave`][struct@crate::DropControllerMotion#leave] is emitted.
64    ///
65    /// Readable
66    /// <details><summary><h4>EventController</h4></summary>
67    ///
68    ///
69    /// #### `name`
70    ///  The name for this controller, typically used for debugging purposes.
71    ///
72    /// Readable | Writeable
73    ///
74    ///
75    /// #### `propagation-limit`
76    ///  The limit for which events this controller will handle.
77    ///
78    /// Readable | Writeable
79    ///
80    ///
81    /// #### `propagation-phase`
82    ///  The propagation phase at which this controller will handle events.
83    ///
84    /// Readable | Writeable
85    ///
86    ///
87    /// #### `widget`
88    ///  The widget receiving the `GdkEvents` that the controller will handle.
89    ///
90    /// Readable
91    /// </details>
92    ///
93    /// ## Signals
94    ///
95    ///
96    /// #### `enter`
97    ///  Signals that the pointer has entered the widget.
98    ///
99    ///
100    ///
101    ///
102    /// #### `leave`
103    ///  Signals that the pointer has left the widget.
104    ///
105    ///
106    ///
107    ///
108    /// #### `motion`
109    ///  Emitted when the pointer moves inside the widget.
110    ///
111    ///
112    ///
113    /// # Implements
114    ///
115    /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`], [`EventControllerExtManual`][trait@crate::prelude::EventControllerExtManual]
116    #[doc(alias = "GtkDropControllerMotion")]
117    pub struct DropControllerMotion(Object<ffi::GtkDropControllerMotion, ffi::GtkDropControllerMotionClass>) @extends EventController;
118
119    match fn {
120        type_ => || ffi::gtk_drop_controller_motion_get_type(),
121    }
122}
123
124impl DropControllerMotion {
125    /// Creates a new event controller that will handle pointer motion
126    /// events during drag and drop.
127    ///
128    /// # Returns
129    ///
130    /// a new [`DropControllerMotion`][crate::DropControllerMotion]
131    #[doc(alias = "gtk_drop_controller_motion_new")]
132    pub fn new() -> DropControllerMotion {
133        assert_initialized_main_thread!();
134        unsafe {
135            EventController::from_glib_full(ffi::gtk_drop_controller_motion_new()).unsafe_cast()
136        }
137    }
138
139    // rustdoc-stripper-ignore-next
140    /// Creates a new builder-pattern struct instance to construct [`DropControllerMotion`] objects.
141    ///
142    /// This method returns an instance of [`DropControllerMotionBuilder`](crate::builders::DropControllerMotionBuilder) which can be used to create [`DropControllerMotion`] objects.
143    pub fn builder() -> DropControllerMotionBuilder {
144        DropControllerMotionBuilder::new()
145    }
146
147    /// Returns if a Drag-and-Drop operation is within the widget
148    /// @self or one of its children.
149    ///
150    /// # Returns
151    ///
152    /// [`true`] if a dragging pointer is within @self or one of its children.
153    #[doc(alias = "gtk_drop_controller_motion_contains_pointer")]
154    #[doc(alias = "contains-pointer")]
155    pub fn contains_pointer(&self) -> bool {
156        unsafe {
157            from_glib(ffi::gtk_drop_controller_motion_contains_pointer(
158                self.to_glib_none().0,
159            ))
160        }
161    }
162
163    /// Returns the [`gdk::Drop`][crate::gdk::Drop] of a current Drag-and-Drop operation
164    /// over the widget of @self.
165    ///
166    /// # Returns
167    ///
168    /// The [`gdk::Drop`][crate::gdk::Drop] currently
169    ///   happening within @self
170    #[doc(alias = "gtk_drop_controller_motion_get_drop")]
171    #[doc(alias = "get_drop")]
172    pub fn drop(&self) -> Option<gdk::Drop> {
173        unsafe {
174            from_glib_none(ffi::gtk_drop_controller_motion_get_drop(
175                self.to_glib_none().0,
176            ))
177        }
178    }
179
180    /// Returns if a Drag-and-Drop operation is within the widget
181    /// @self, not one of its children.
182    ///
183    /// # Returns
184    ///
185    /// [`true`] if a dragging pointer is within @self but
186    ///   not one of its children
187    #[doc(alias = "gtk_drop_controller_motion_is_pointer")]
188    #[doc(alias = "is-pointer")]
189    pub fn is_pointer(&self) -> bool {
190        unsafe {
191            from_glib(ffi::gtk_drop_controller_motion_is_pointer(
192                self.to_glib_none().0,
193            ))
194        }
195    }
196
197    /// Signals that the pointer has entered the widget.
198    /// ## `x`
199    /// coordinates of pointer location
200    /// ## `y`
201    /// coordinates of pointer location
202    #[doc(alias = "enter")]
203    pub fn connect_enter<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
204        unsafe extern "C" fn enter_trampoline<F: Fn(&DropControllerMotion, f64, f64) + 'static>(
205            this: *mut ffi::GtkDropControllerMotion,
206            x: std::ffi::c_double,
207            y: std::ffi::c_double,
208            f: glib::ffi::gpointer,
209        ) {
210            unsafe {
211                let f: &F = &*(f as *const F);
212                f(&from_glib_borrow(this), x, y)
213            }
214        }
215        unsafe {
216            let f: Box_<F> = Box_::new(f);
217            connect_raw(
218                self.as_ptr() as *mut _,
219                c"enter".as_ptr() as *const _,
220                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221                    enter_trampoline::<F> as *const (),
222                )),
223                Box_::into_raw(f),
224            )
225        }
226    }
227
228    /// Signals that the pointer has left the widget.
229    #[doc(alias = "leave")]
230    pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
231        unsafe extern "C" fn leave_trampoline<F: Fn(&DropControllerMotion) + 'static>(
232            this: *mut ffi::GtkDropControllerMotion,
233            f: glib::ffi::gpointer,
234        ) {
235            unsafe {
236                let f: &F = &*(f as *const F);
237                f(&from_glib_borrow(this))
238            }
239        }
240        unsafe {
241            let f: Box_<F> = Box_::new(f);
242            connect_raw(
243                self.as_ptr() as *mut _,
244                c"leave".as_ptr() as *const _,
245                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
246                    leave_trampoline::<F> as *const (),
247                )),
248                Box_::into_raw(f),
249            )
250        }
251    }
252
253    /// Emitted when the pointer moves inside the widget.
254    /// ## `x`
255    /// the x coordinate
256    /// ## `y`
257    /// the y coordinate
258    #[doc(alias = "motion")]
259    pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
260        unsafe extern "C" fn motion_trampoline<F: Fn(&DropControllerMotion, f64, f64) + 'static>(
261            this: *mut ffi::GtkDropControllerMotion,
262            x: std::ffi::c_double,
263            y: std::ffi::c_double,
264            f: glib::ffi::gpointer,
265        ) {
266            unsafe {
267                let f: &F = &*(f as *const F);
268                f(&from_glib_borrow(this), x, y)
269            }
270        }
271        unsafe {
272            let f: Box_<F> = Box_::new(f);
273            connect_raw(
274                self.as_ptr() as *mut _,
275                c"motion".as_ptr() as *const _,
276                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
277                    motion_trampoline::<F> as *const (),
278                )),
279                Box_::into_raw(f),
280            )
281        }
282    }
283
284    #[doc(alias = "contains-pointer")]
285    pub fn connect_contains_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
286        unsafe extern "C" fn notify_contains_pointer_trampoline<
287            F: Fn(&DropControllerMotion) + 'static,
288        >(
289            this: *mut ffi::GtkDropControllerMotion,
290            _param_spec: glib::ffi::gpointer,
291            f: glib::ffi::gpointer,
292        ) {
293            unsafe {
294                let f: &F = &*(f as *const F);
295                f(&from_glib_borrow(this))
296            }
297        }
298        unsafe {
299            let f: Box_<F> = Box_::new(f);
300            connect_raw(
301                self.as_ptr() as *mut _,
302                c"notify::contains-pointer".as_ptr() as *const _,
303                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
304                    notify_contains_pointer_trampoline::<F> as *const (),
305                )),
306                Box_::into_raw(f),
307            )
308        }
309    }
310
311    #[doc(alias = "drop")]
312    pub fn connect_drop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
313        unsafe extern "C" fn notify_drop_trampoline<F: Fn(&DropControllerMotion) + 'static>(
314            this: *mut ffi::GtkDropControllerMotion,
315            _param_spec: glib::ffi::gpointer,
316            f: glib::ffi::gpointer,
317        ) {
318            unsafe {
319                let f: &F = &*(f as *const F);
320                f(&from_glib_borrow(this))
321            }
322        }
323        unsafe {
324            let f: Box_<F> = Box_::new(f);
325            connect_raw(
326                self.as_ptr() as *mut _,
327                c"notify::drop".as_ptr() as *const _,
328                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
329                    notify_drop_trampoline::<F> as *const (),
330                )),
331                Box_::into_raw(f),
332            )
333        }
334    }
335
336    #[doc(alias = "is-pointer")]
337    pub fn connect_is_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
338        unsafe extern "C" fn notify_is_pointer_trampoline<
339            F: Fn(&DropControllerMotion) + 'static,
340        >(
341            this: *mut ffi::GtkDropControllerMotion,
342            _param_spec: glib::ffi::gpointer,
343            f: glib::ffi::gpointer,
344        ) {
345            unsafe {
346                let f: &F = &*(f as *const F);
347                f(&from_glib_borrow(this))
348            }
349        }
350        unsafe {
351            let f: Box_<F> = Box_::new(f);
352            connect_raw(
353                self.as_ptr() as *mut _,
354                c"notify::is-pointer".as_ptr() as *const _,
355                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
356                    notify_is_pointer_trampoline::<F> as *const (),
357                )),
358                Box_::into_raw(f),
359            )
360        }
361    }
362}
363
364impl Default for DropControllerMotion {
365    fn default() -> Self {
366        Self::new()
367    }
368}
369
370// rustdoc-stripper-ignore-next
371/// A [builder-pattern] type to construct [`DropControllerMotion`] objects.
372///
373/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
374#[must_use = "The builder must be built to be used"]
375pub struct DropControllerMotionBuilder {
376    builder: glib::object::ObjectBuilder<'static, DropControllerMotion>,
377}
378
379impl DropControllerMotionBuilder {
380    fn new() -> Self {
381        Self {
382            builder: glib::object::Object::builder(),
383        }
384    }
385
386    /// The name for this controller, typically used for debugging purposes.
387    pub fn name(self, name: impl Into<glib::GString>) -> Self {
388        Self {
389            builder: self.builder.property("name", name.into()),
390        }
391    }
392
393    /// The limit for which events this controller will handle.
394    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
395        Self {
396            builder: self
397                .builder
398                .property("propagation-limit", propagation_limit),
399        }
400    }
401
402    /// The propagation phase at which this controller will handle events.
403    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
404        Self {
405            builder: self
406                .builder
407                .property("propagation-phase", propagation_phase),
408        }
409    }
410
411    // rustdoc-stripper-ignore-next
412    /// Build the [`DropControllerMotion`].
413    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
414    pub fn build(self) -> DropControllerMotion {
415        assert_initialized_main_thread!();
416        self.builder.build()
417    }
418}