Skip to main content

gtk4/auto/
drop_target.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#![allow(deprecated)]
5
6use crate::{EventController, PropagationLimit, PropagationPhase, ffi};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{SignalHandlerId, connect_raw},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// An event controller to receive Drag-and-Drop operations.
17    ///
18    /// The most basic way to use a [`DropTarget`][crate::DropTarget] to receive drops on a
19    /// widget is to create it via [`new()`][Self::new()], passing in the
20    /// `GType` of the data you want to receive and connect to the
21    /// [`drop`][struct@crate::DropTarget#drop] signal to receive the data:
22    ///
23    /// **⚠️ The following code is in c ⚠️**
24    ///
25    /// ```c
26    /// static gboolean
27    /// on_drop (GtkDropTarget *target,
28    ///          const GValue  *value,
29    ///          double         x,
30    ///          double         y,
31    ///          gpointer       data)
32    /// {
33    ///   MyWidget *self = data;
34    ///
35    ///   // Call the appropriate setter depending on the type of data
36    ///   // that we received
37    ///   if (G_VALUE_HOLDS (value, G_TYPE_FILE))
38    ///     my_widget_set_file (self, g_value_get_object (value));
39    ///   else if (G_VALUE_HOLDS (value, GDK_TYPE_PIXBUF))
40    ///     my_widget_set_pixbuf (self, g_value_get_object (value));
41    ///   else
42    ///     return FALSE;
43    ///
44    ///   return TRUE;
45    /// }
46    ///
47    /// static void
48    /// my_widget_init (MyWidget *self)
49    /// {
50    ///   GtkDropTarget *target =
51    ///     gtk_drop_target_new (G_TYPE_INVALID, GDK_ACTION_COPY);
52    ///
53    ///   // This widget accepts two types of drop types: GFile objects
54    ///   // and GdkPixbuf objects
55    ///   gtk_drop_target_set_gtypes (target, (GType [2]) {
56    ///     G_TYPE_FILE,
57    ///     GDK_TYPE_PIXBUF,
58    ///   }, 2);
59    ///
60    ///   g_signal_connect (target, "drop", G_CALLBACK (on_drop), self);
61    ///   gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (target));
62    /// }
63    /// ```
64    ///
65    /// [`DropTarget`][crate::DropTarget] supports more options, such as:
66    ///
67    ///  * rejecting potential drops via the [`accept`][struct@crate::DropTarget#accept] signal
68    ///    and the [`reject()`][Self::reject()] function to let other drop
69    ///    targets handle the drop
70    ///  * tracking an ongoing drag operation before the drop via the
71    ///    [`enter`][struct@crate::DropTarget#enter], [`motion`][struct@crate::DropTarget#motion] and
72    ///    [`leave`][struct@crate::DropTarget#leave] signals
73    ///  * configuring how to receive data by setting the
74    ///    [`preload`][struct@crate::DropTarget#preload] property and listening for its
75    ///    availability via the [`value`][struct@crate::DropTarget#value] property
76    ///
77    /// However, [`DropTarget`][crate::DropTarget] is ultimately modeled in a synchronous way
78    /// and only supports data transferred via `GType`. If you want full control
79    /// over an ongoing drop, the [`DropTargetAsync`][crate::DropTargetAsync] object gives you
80    /// this ability.
81    ///
82    /// While a pointer is dragged over the drop target's widget and the drop
83    /// has not been rejected, that widget will receive the
84    /// [`StateFlags::DROP_ACTIVE`][crate::StateFlags::DROP_ACTIVE] state, which can be used to style the widget.
85    ///
86    /// If you are not interested in receiving the drop, but just want to update
87    /// UI state during a Drag-and-Drop operation (e.g. switching tabs), you can
88    /// use [`DropControllerMotion`][crate::DropControllerMotion].
89    ///
90    /// ## Properties
91    ///
92    ///
93    /// #### `actions`
94    ///  The `GdkDragActions` that this drop target supports.
95    ///
96    /// Readable | Writeable
97    ///
98    ///
99    /// #### `current-drop`
100    ///  The [`gdk::Drop`][crate::gdk::Drop] that is currently being performed.
101    ///
102    /// Readable
103    ///
104    ///
105    /// #### `drop`
106    ///  The [`gdk::Drop`][crate::gdk::Drop] that is currently being performed.
107    ///
108    /// Readable
109    ///
110    ///
111    /// #### `formats`
112    ///  The [`gdk::ContentFormats`][crate::gdk::ContentFormats] that determine the supported data formats.
113    ///
114    /// Readable | Writeable | Construct Only
115    ///
116    ///
117    /// #### `preload`
118    ///  Whether the drop data should be preloaded when the pointer is only
119    /// hovering over the widget but has not been released.
120    ///
121    /// Setting this property allows finer grained reaction to an ongoing
122    /// drop at the cost of loading more data.
123    ///
124    /// The default value for this property is [`false`] to avoid downloading
125    /// huge amounts of data by accident.
126    ///
127    /// For example, if somebody drags a full document of gigabytes of text
128    /// from a text editor across a widget with a preloading drop target,
129    /// this data will be downloaded, even if the data is ultimately dropped
130    /// elsewhere.
131    ///
132    /// For a lot of data formats, the amount of data is very small (like
133    /// `GDK_TYPE_RGBA`), so enabling this property does not hurt at all.
134    /// And for local-only Drag-and-Drop operations, no data transfer is done,
135    /// so enabling it there is free.
136    ///
137    /// Readable | Writeable
138    ///
139    ///
140    /// #### `value`
141    ///  The value for this drop operation.
142    ///
143    /// This is [`None`] if the data has not been loaded yet or no drop
144    /// operation is going on.
145    ///
146    /// Data may be available before the [`drop`][struct@crate::DropTarget#drop]
147    /// signal gets emitted - for example when the [`preload`][struct@crate::DropTarget#preload]
148    /// property is set. You can use the ::notify signal to be notified
149    /// of available data.
150    ///
151    /// Readable
152    /// <details><summary><h4>EventController</h4></summary>
153    ///
154    ///
155    /// #### `name`
156    ///  The name for this controller, typically used for debugging purposes.
157    ///
158    /// Readable | Writeable
159    ///
160    ///
161    /// #### `propagation-limit`
162    ///  The limit for which events this controller will handle.
163    ///
164    /// Readable | Writeable
165    ///
166    ///
167    /// #### `propagation-phase`
168    ///  The propagation phase at which this controller will handle events.
169    ///
170    /// Readable | Writeable
171    ///
172    ///
173    /// #### `widget`
174    ///  The widget receiving the `GdkEvents` that the controller will handle.
175    ///
176    /// Readable
177    /// </details>
178    ///
179    /// ## Signals
180    ///
181    ///
182    /// #### `accept`
183    ///  Emitted on the drop site when a drop operation is about to begin.
184    ///
185    /// If the drop is not accepted, [`false`] will be returned and the drop target
186    /// will ignore the drop. If [`true`] is returned, the drop is accepted for now
187    /// but may be rejected later via a call to [`DropTarget::reject()`][crate::DropTarget::reject()]
188    /// or ultimately by returning [`false`] from a [`drop`][struct@crate::DropTarget#drop]
189    /// handler.
190    ///
191    /// The default handler for this signal decides whether to accept the drop
192    /// based on the formats provided by the @drop.
193    ///
194    /// If the decision whether the drop will be accepted or rejected depends
195    /// on the data, this function should return [`true`], the
196    /// [`preload`][struct@crate::DropTarget#preload] property should be set and the value
197    /// should be inspected via the ::notify:value signal, calling
198    /// [`DropTarget::reject()`][crate::DropTarget::reject()] if required.
199    ///
200    ///
201    ///
202    ///
203    /// #### `drop`
204    ///  Emitted on the drop site when the user drops the data onto the widget.
205    ///
206    /// The signal handler must determine whether the pointer position is in
207    /// a drop zone or not. If it is not in a drop zone, it returns [`false`]
208    /// and no further processing is necessary.
209    ///
210    /// Otherwise, the handler returns [`true`]. In this case, this handler will
211    /// accept the drop. The handler is responsible for using the given @value
212    /// and performing the drop operation.
213    ///
214    ///
215    ///
216    ///
217    /// #### `enter`
218    ///  Emitted on the drop site when the pointer enters the widget.
219    ///
220    /// It can be used to set up custom highlighting.
221    ///
222    ///
223    ///
224    ///
225    /// #### `leave`
226    ///  Emitted on the drop site when the pointer leaves the widget.
227    ///
228    /// Its main purpose it to undo things done in
229    /// [`enter`][struct@crate::DropTarget#enter].
230    ///
231    ///
232    ///
233    ///
234    /// #### `motion`
235    ///  Emitted while the pointer is moving over the drop target.
236    ///
237    ///
238    ///
239    /// # Implements
240    ///
241    /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`], [`EventControllerExtManual`][trait@crate::prelude::EventControllerExtManual]
242    #[doc(alias = "GtkDropTarget")]
243    pub struct DropTarget(Object<ffi::GtkDropTarget, ffi::GtkDropTargetClass>) @extends EventController;
244
245    match fn {
246        type_ => || ffi::gtk_drop_target_get_type(),
247    }
248}
249
250impl DropTarget {
251    /// Creates a new [`DropTarget`][crate::DropTarget] object.
252    ///
253    /// If the drop target should support more than 1 type, pass
254    /// `G_TYPE_INVALID` for @type_ and then call
255    /// [`set_types()`][Self::set_types()].
256    /// ## `type_`
257    /// The supported type or `G_TYPE_INVALID`
258    /// ## `actions`
259    /// the supported actions
260    ///
261    /// # Returns
262    ///
263    /// the new [`DropTarget`][crate::DropTarget]
264    #[doc(alias = "gtk_drop_target_new")]
265    pub fn new(type_: glib::types::Type, actions: gdk::DragAction) -> DropTarget {
266        assert_initialized_main_thread!();
267        unsafe {
268            from_glib_full(ffi::gtk_drop_target_new(
269                type_.into_glib(),
270                actions.into_glib(),
271            ))
272        }
273    }
274
275    // rustdoc-stripper-ignore-next
276    /// Creates a new builder-pattern struct instance to construct [`DropTarget`] objects.
277    ///
278    /// This method returns an instance of [`DropTargetBuilder`](crate::builders::DropTargetBuilder) which can be used to create [`DropTarget`] objects.
279    pub fn builder() -> DropTargetBuilder {
280        DropTargetBuilder::new()
281    }
282
283    /// Gets the actions that this drop target supports.
284    ///
285    /// # Returns
286    ///
287    /// the actions that this drop target supports
288    #[doc(alias = "gtk_drop_target_get_actions")]
289    #[doc(alias = "get_actions")]
290    pub fn actions(&self) -> gdk::DragAction {
291        unsafe { from_glib(ffi::gtk_drop_target_get_actions(self.to_glib_none().0)) }
292    }
293
294    /// Gets the currently handled drop operation.
295    ///
296    /// If no drop operation is going on, [`None`] is returned.
297    ///
298    /// # Returns
299    ///
300    /// The current drop
301    #[cfg(feature = "v4_4")]
302    #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
303    #[doc(alias = "gtk_drop_target_get_current_drop")]
304    #[doc(alias = "get_current_drop")]
305    #[doc(alias = "current-drop")]
306    pub fn current_drop(&self) -> Option<gdk::Drop> {
307        unsafe { from_glib_none(ffi::gtk_drop_target_get_current_drop(self.to_glib_none().0)) }
308    }
309
310    /// Gets the currently handled drop operation.
311    ///
312    /// If no drop operation is going on, [`None`] is returned.
313    ///
314    /// # Deprecated since 4.4
315    ///
316    /// Use [`current_drop()`][Self::current_drop()] instead
317    ///
318    /// # Returns
319    ///
320    /// The current drop
321    #[cfg_attr(feature = "v4_4", deprecated = "Since 4.4")]
322    #[allow(deprecated)]
323    #[doc(alias = "gtk_drop_target_get_drop")]
324    #[doc(alias = "get_drop")]
325    pub fn drop(&self) -> Option<gdk::Drop> {
326        unsafe { from_glib_none(ffi::gtk_drop_target_get_drop(self.to_glib_none().0)) }
327    }
328
329    /// Gets the data formats that this drop target accepts.
330    ///
331    /// If the result is [`None`], all formats are expected to be supported.
332    ///
333    /// # Returns
334    ///
335    /// the supported data formats
336    #[doc(alias = "gtk_drop_target_get_formats")]
337    #[doc(alias = "get_formats")]
338    pub fn formats(&self) -> Option<gdk::ContentFormats> {
339        unsafe { from_glib_none(ffi::gtk_drop_target_get_formats(self.to_glib_none().0)) }
340    }
341
342    /// Gets whether data should be preloaded on hover.
343    ///
344    /// # Returns
345    ///
346    /// [`true`] if drop data should be preloaded
347    #[doc(alias = "gtk_drop_target_get_preload")]
348    #[doc(alias = "get_preload")]
349    #[doc(alias = "preload")]
350    pub fn is_preload(&self) -> bool {
351        unsafe { from_glib(ffi::gtk_drop_target_get_preload(self.to_glib_none().0)) }
352    }
353
354    /// Gets the current drop data, as a `GValue`.
355    ///
356    /// # Returns
357    ///
358    /// The current drop data
359    #[doc(alias = "gtk_drop_target_get_value")]
360    #[doc(alias = "get_value")]
361    pub fn value(&self) -> Option<glib::Value> {
362        unsafe { from_glib_none(ffi::gtk_drop_target_get_value(self.to_glib_none().0)) }
363    }
364
365    /// Rejects the ongoing drop operation.
366    ///
367    /// If no drop operation is ongoing, i.e when [`current-drop`][struct@crate::DropTarget#current-drop]
368    /// is [`None`], this function does nothing.
369    ///
370    /// This function should be used when delaying the decision
371    /// on whether to accept a drag or not until after reading
372    /// the data.
373    #[doc(alias = "gtk_drop_target_reject")]
374    pub fn reject(&self) {
375        unsafe {
376            ffi::gtk_drop_target_reject(self.to_glib_none().0);
377        }
378    }
379
380    /// Sets the actions that this drop target supports.
381    /// ## `actions`
382    /// the supported actions
383    #[doc(alias = "gtk_drop_target_set_actions")]
384    #[doc(alias = "actions")]
385    pub fn set_actions(&self, actions: gdk::DragAction) {
386        unsafe {
387            ffi::gtk_drop_target_set_actions(self.to_glib_none().0, actions.into_glib());
388        }
389    }
390
391    /// Sets whether data should be preloaded on hover.
392    /// ## `preload`
393    /// [`true`] to preload drop data
394    #[doc(alias = "gtk_drop_target_set_preload")]
395    #[doc(alias = "preload")]
396    pub fn set_preload(&self, preload: bool) {
397        unsafe {
398            ffi::gtk_drop_target_set_preload(self.to_glib_none().0, preload.into_glib());
399        }
400    }
401
402    /// Emitted on the drop site when a drop operation is about to begin.
403    ///
404    /// If the drop is not accepted, [`false`] will be returned and the drop target
405    /// will ignore the drop. If [`true`] is returned, the drop is accepted for now
406    /// but may be rejected later via a call to [`reject()`][Self::reject()]
407    /// or ultimately by returning [`false`] from a [`drop`][struct@crate::DropTarget#drop]
408    /// handler.
409    ///
410    /// The default handler for this signal decides whether to accept the drop
411    /// based on the formats provided by the @drop.
412    ///
413    /// If the decision whether the drop will be accepted or rejected depends
414    /// on the data, this function should return [`true`], the
415    /// [`preload`][struct@crate::DropTarget#preload] property should be set and the value
416    /// should be inspected via the ::notify:value signal, calling
417    /// [`reject()`][Self::reject()] if required.
418    /// ## `drop`
419    /// the [`gdk::Drop`][crate::gdk::Drop]
420    ///
421    /// # Returns
422    ///
423    /// [`true`] if @drop is accepted
424    #[doc(alias = "accept")]
425    pub fn connect_accept<F: Fn(&Self, &gdk::Drop) -> bool + 'static>(
426        &self,
427        f: F,
428    ) -> SignalHandlerId {
429        unsafe extern "C" fn accept_trampoline<F: Fn(&DropTarget, &gdk::Drop) -> bool + 'static>(
430            this: *mut ffi::GtkDropTarget,
431            drop: *mut gdk::ffi::GdkDrop,
432            f: glib::ffi::gpointer,
433        ) -> glib::ffi::gboolean {
434            unsafe {
435                let f: &F = &*(f as *const F);
436                f(&from_glib_borrow(this), &from_glib_borrow(drop)).into_glib()
437            }
438        }
439        unsafe {
440            let f: Box_<F> = Box_::new(f);
441            connect_raw(
442                self.as_ptr() as *mut _,
443                c"accept".as_ptr() as *const _,
444                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
445                    accept_trampoline::<F> as *const (),
446                )),
447                Box_::into_raw(f),
448            )
449        }
450    }
451
452    /// Emitted on the drop site when the pointer enters the widget.
453    ///
454    /// It can be used to set up custom highlighting.
455    /// ## `x`
456    /// the x coordinate of the current pointer position
457    /// ## `y`
458    /// the y coordinate of the current pointer position
459    ///
460    /// # Returns
461    ///
462    /// Preferred action for this drag operation or `GDK_ACTION_NONE` if
463    ///   dropping is not supported at the current @x,@y location.
464    #[doc(alias = "enter")]
465    pub fn connect_enter<F: Fn(&Self, f64, f64) -> gdk::DragAction + 'static>(
466        &self,
467        f: F,
468    ) -> SignalHandlerId {
469        unsafe extern "C" fn enter_trampoline<
470            F: Fn(&DropTarget, f64, f64) -> gdk::DragAction + 'static,
471        >(
472            this: *mut ffi::GtkDropTarget,
473            x: std::ffi::c_double,
474            y: std::ffi::c_double,
475            f: glib::ffi::gpointer,
476        ) -> gdk::ffi::GdkDragAction {
477            unsafe {
478                let f: &F = &*(f as *const F);
479                f(&from_glib_borrow(this), x, y).into_glib()
480            }
481        }
482        unsafe {
483            let f: Box_<F> = Box_::new(f);
484            connect_raw(
485                self.as_ptr() as *mut _,
486                c"enter".as_ptr() as *const _,
487                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
488                    enter_trampoline::<F> as *const (),
489                )),
490                Box_::into_raw(f),
491            )
492        }
493    }
494
495    /// Emitted on the drop site when the pointer leaves the widget.
496    ///
497    /// Its main purpose it to undo things done in
498    /// [`enter`][struct@crate::DropTarget#enter].
499    #[doc(alias = "leave")]
500    pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
501        unsafe extern "C" fn leave_trampoline<F: Fn(&DropTarget) + 'static>(
502            this: *mut ffi::GtkDropTarget,
503            f: glib::ffi::gpointer,
504        ) {
505            unsafe {
506                let f: &F = &*(f as *const F);
507                f(&from_glib_borrow(this))
508            }
509        }
510        unsafe {
511            let f: Box_<F> = Box_::new(f);
512            connect_raw(
513                self.as_ptr() as *mut _,
514                c"leave".as_ptr() as *const _,
515                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
516                    leave_trampoline::<F> as *const (),
517                )),
518                Box_::into_raw(f),
519            )
520        }
521    }
522
523    /// Emitted while the pointer is moving over the drop target.
524    /// ## `x`
525    /// the x coordinate of the current pointer position
526    /// ## `y`
527    /// the y coordinate of the current pointer position
528    ///
529    /// # Returns
530    ///
531    /// Preferred action for this drag operation or `GDK_ACTION_NONE` if
532    ///   dropping is not supported at the current @x,@y location.
533    #[doc(alias = "motion")]
534    pub fn connect_motion<F: Fn(&Self, f64, f64) -> gdk::DragAction + 'static>(
535        &self,
536        f: F,
537    ) -> SignalHandlerId {
538        unsafe extern "C" fn motion_trampoline<
539            F: Fn(&DropTarget, f64, f64) -> gdk::DragAction + 'static,
540        >(
541            this: *mut ffi::GtkDropTarget,
542            x: std::ffi::c_double,
543            y: std::ffi::c_double,
544            f: glib::ffi::gpointer,
545        ) -> gdk::ffi::GdkDragAction {
546            unsafe {
547                let f: &F = &*(f as *const F);
548                f(&from_glib_borrow(this), x, y).into_glib()
549            }
550        }
551        unsafe {
552            let f: Box_<F> = Box_::new(f);
553            connect_raw(
554                self.as_ptr() as *mut _,
555                c"motion".as_ptr() as *const _,
556                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
557                    motion_trampoline::<F> as *const (),
558                )),
559                Box_::into_raw(f),
560            )
561        }
562    }
563
564    #[doc(alias = "actions")]
565    pub fn connect_actions_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
566        unsafe extern "C" fn notify_actions_trampoline<F: Fn(&DropTarget) + 'static>(
567            this: *mut ffi::GtkDropTarget,
568            _param_spec: glib::ffi::gpointer,
569            f: glib::ffi::gpointer,
570        ) {
571            unsafe {
572                let f: &F = &*(f as *const F);
573                f(&from_glib_borrow(this))
574            }
575        }
576        unsafe {
577            let f: Box_<F> = Box_::new(f);
578            connect_raw(
579                self.as_ptr() as *mut _,
580                c"notify::actions".as_ptr() as *const _,
581                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
582                    notify_actions_trampoline::<F> as *const (),
583                )),
584                Box_::into_raw(f),
585            )
586        }
587    }
588
589    #[cfg(feature = "v4_4")]
590    #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
591    #[doc(alias = "current-drop")]
592    pub fn connect_current_drop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
593        unsafe extern "C" fn notify_current_drop_trampoline<F: Fn(&DropTarget) + 'static>(
594            this: *mut ffi::GtkDropTarget,
595            _param_spec: glib::ffi::gpointer,
596            f: glib::ffi::gpointer,
597        ) {
598            unsafe {
599                let f: &F = &*(f as *const F);
600                f(&from_glib_borrow(this))
601            }
602        }
603        unsafe {
604            let f: Box_<F> = Box_::new(f);
605            connect_raw(
606                self.as_ptr() as *mut _,
607                c"notify::current-drop".as_ptr() as *const _,
608                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
609                    notify_current_drop_trampoline::<F> as *const (),
610                )),
611                Box_::into_raw(f),
612            )
613        }
614    }
615
616    #[cfg_attr(feature = "v4_4", deprecated = "Since 4.4")]
617    #[doc(alias = "drop")]
618    pub fn connect_drop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
619        unsafe extern "C" fn notify_drop_trampoline<F: Fn(&DropTarget) + 'static>(
620            this: *mut ffi::GtkDropTarget,
621            _param_spec: glib::ffi::gpointer,
622            f: glib::ffi::gpointer,
623        ) {
624            unsafe {
625                let f: &F = &*(f as *const F);
626                f(&from_glib_borrow(this))
627            }
628        }
629        unsafe {
630            let f: Box_<F> = Box_::new(f);
631            connect_raw(
632                self.as_ptr() as *mut _,
633                c"notify::drop".as_ptr() as *const _,
634                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
635                    notify_drop_trampoline::<F> as *const (),
636                )),
637                Box_::into_raw(f),
638            )
639        }
640    }
641
642    #[doc(alias = "preload")]
643    pub fn connect_preload_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
644        unsafe extern "C" fn notify_preload_trampoline<F: Fn(&DropTarget) + 'static>(
645            this: *mut ffi::GtkDropTarget,
646            _param_spec: glib::ffi::gpointer,
647            f: glib::ffi::gpointer,
648        ) {
649            unsafe {
650                let f: &F = &*(f as *const F);
651                f(&from_glib_borrow(this))
652            }
653        }
654        unsafe {
655            let f: Box_<F> = Box_::new(f);
656            connect_raw(
657                self.as_ptr() as *mut _,
658                c"notify::preload".as_ptr() as *const _,
659                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
660                    notify_preload_trampoline::<F> as *const (),
661                )),
662                Box_::into_raw(f),
663            )
664        }
665    }
666
667    #[doc(alias = "value")]
668    pub fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
669        unsafe extern "C" fn notify_value_trampoline<F: Fn(&DropTarget) + 'static>(
670            this: *mut ffi::GtkDropTarget,
671            _param_spec: glib::ffi::gpointer,
672            f: glib::ffi::gpointer,
673        ) {
674            unsafe {
675                let f: &F = &*(f as *const F);
676                f(&from_glib_borrow(this))
677            }
678        }
679        unsafe {
680            let f: Box_<F> = Box_::new(f);
681            connect_raw(
682                self.as_ptr() as *mut _,
683                c"notify::value".as_ptr() as *const _,
684                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
685                    notify_value_trampoline::<F> as *const (),
686                )),
687                Box_::into_raw(f),
688            )
689        }
690    }
691}
692
693impl Default for DropTarget {
694    fn default() -> Self {
695        glib::object::Object::new::<Self>()
696    }
697}
698
699// rustdoc-stripper-ignore-next
700/// A [builder-pattern] type to construct [`DropTarget`] objects.
701///
702/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
703#[must_use = "The builder must be built to be used"]
704pub struct DropTargetBuilder {
705    builder: glib::object::ObjectBuilder<'static, DropTarget>,
706}
707
708impl DropTargetBuilder {
709    fn new() -> Self {
710        Self {
711            builder: glib::object::Object::builder(),
712        }
713    }
714
715    /// The `GdkDragActions` that this drop target supports.
716    pub fn actions(self, actions: gdk::DragAction) -> Self {
717        Self {
718            builder: self.builder.property("actions", actions),
719        }
720    }
721
722    /// The [`gdk::ContentFormats`][crate::gdk::ContentFormats] that determine the supported data formats.
723    pub fn formats(self, formats: &gdk::ContentFormats) -> Self {
724        Self {
725            builder: self.builder.property("formats", formats.clone()),
726        }
727    }
728
729    /// Whether the drop data should be preloaded when the pointer is only
730    /// hovering over the widget but has not been released.
731    ///
732    /// Setting this property allows finer grained reaction to an ongoing
733    /// drop at the cost of loading more data.
734    ///
735    /// The default value for this property is [`false`] to avoid downloading
736    /// huge amounts of data by accident.
737    ///
738    /// For example, if somebody drags a full document of gigabytes of text
739    /// from a text editor across a widget with a preloading drop target,
740    /// this data will be downloaded, even if the data is ultimately dropped
741    /// elsewhere.
742    ///
743    /// For a lot of data formats, the amount of data is very small (like
744    /// `GDK_TYPE_RGBA`), so enabling this property does not hurt at all.
745    /// And for local-only Drag-and-Drop operations, no data transfer is done,
746    /// so enabling it there is free.
747    pub fn preload(self, preload: bool) -> Self {
748        Self {
749            builder: self.builder.property("preload", preload),
750        }
751    }
752
753    /// The name for this controller, typically used for debugging purposes.
754    pub fn name(self, name: impl Into<glib::GString>) -> Self {
755        Self {
756            builder: self.builder.property("name", name.into()),
757        }
758    }
759
760    /// The limit for which events this controller will handle.
761    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
762        Self {
763            builder: self
764                .builder
765                .property("propagation-limit", propagation_limit),
766        }
767    }
768
769    /// The propagation phase at which this controller will handle events.
770    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
771        Self {
772            builder: self
773                .builder
774                .property("propagation-phase", propagation_phase),
775        }
776    }
777
778    // rustdoc-stripper-ignore-next
779    /// Build the [`DropTarget`].
780    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
781    pub fn build(self) -> DropTarget {
782        assert_initialized_main_thread!();
783        self.builder.build()
784    }
785}