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