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::{ffi, EventController, PropagationLimit, PropagationPhase};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 /// [`DropTarget`][crate::DropTarget] is 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`]
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 let f: &F = &*(f as *const F);
435 f(&from_glib_borrow(this), &from_glib_borrow(drop)).into_glib()
436 }
437 unsafe {
438 let f: Box_<F> = Box_::new(f);
439 connect_raw(
440 self.as_ptr() as *mut _,
441 b"accept\0".as_ptr() as *const _,
442 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
443 accept_trampoline::<F> as *const (),
444 )),
445 Box_::into_raw(f),
446 )
447 }
448 }
449
450 /// Emitted on the drop site when the pointer enters the widget.
451 ///
452 /// It can be used to set up custom highlighting.
453 /// ## `x`
454 /// the x coordinate of the current pointer position
455 /// ## `y`
456 /// the y coordinate of the current pointer position
457 ///
458 /// # Returns
459 ///
460 /// Preferred action for this drag operation or 0 if
461 /// dropping is not supported at the current @x,@y location.
462 #[doc(alias = "enter")]
463 pub fn connect_enter<F: Fn(&Self, f64, f64) -> gdk::DragAction + 'static>(
464 &self,
465 f: F,
466 ) -> SignalHandlerId {
467 unsafe extern "C" fn enter_trampoline<
468 F: Fn(&DropTarget, f64, f64) -> gdk::DragAction + 'static,
469 >(
470 this: *mut ffi::GtkDropTarget,
471 x: std::ffi::c_double,
472 y: std::ffi::c_double,
473 f: glib::ffi::gpointer,
474 ) -> gdk::ffi::GdkDragAction {
475 let f: &F = &*(f as *const F);
476 f(&from_glib_borrow(this), x, y).into_glib()
477 }
478 unsafe {
479 let f: Box_<F> = Box_::new(f);
480 connect_raw(
481 self.as_ptr() as *mut _,
482 b"enter\0".as_ptr() as *const _,
483 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
484 enter_trampoline::<F> as *const (),
485 )),
486 Box_::into_raw(f),
487 )
488 }
489 }
490
491 /// Emitted on the drop site when the pointer leaves the widget.
492 ///
493 /// Its main purpose it to undo things done in
494 /// [`enter`][struct@crate::DropTarget#enter].
495 #[doc(alias = "leave")]
496 pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
497 unsafe extern "C" fn leave_trampoline<F: Fn(&DropTarget) + 'static>(
498 this: *mut ffi::GtkDropTarget,
499 f: glib::ffi::gpointer,
500 ) {
501 let f: &F = &*(f as *const F);
502 f(&from_glib_borrow(this))
503 }
504 unsafe {
505 let f: Box_<F> = Box_::new(f);
506 connect_raw(
507 self.as_ptr() as *mut _,
508 b"leave\0".as_ptr() as *const _,
509 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
510 leave_trampoline::<F> as *const (),
511 )),
512 Box_::into_raw(f),
513 )
514 }
515 }
516
517 /// Emitted while the pointer is moving over the drop target.
518 /// ## `x`
519 /// the x coordinate of the current pointer position
520 /// ## `y`
521 /// the y coordinate of the current pointer position
522 ///
523 /// # Returns
524 ///
525 /// Preferred action for this drag operation or 0 if
526 /// dropping is not supported at the current @x,@y location.
527 #[doc(alias = "motion")]
528 pub fn connect_motion<F: Fn(&Self, f64, f64) -> gdk::DragAction + 'static>(
529 &self,
530 f: F,
531 ) -> SignalHandlerId {
532 unsafe extern "C" fn motion_trampoline<
533 F: Fn(&DropTarget, f64, f64) -> gdk::DragAction + 'static,
534 >(
535 this: *mut ffi::GtkDropTarget,
536 x: std::ffi::c_double,
537 y: std::ffi::c_double,
538 f: glib::ffi::gpointer,
539 ) -> gdk::ffi::GdkDragAction {
540 let f: &F = &*(f as *const F);
541 f(&from_glib_borrow(this), x, y).into_glib()
542 }
543 unsafe {
544 let f: Box_<F> = Box_::new(f);
545 connect_raw(
546 self.as_ptr() as *mut _,
547 b"motion\0".as_ptr() as *const _,
548 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
549 motion_trampoline::<F> as *const (),
550 )),
551 Box_::into_raw(f),
552 )
553 }
554 }
555
556 #[doc(alias = "actions")]
557 pub fn connect_actions_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
558 unsafe extern "C" fn notify_actions_trampoline<F: Fn(&DropTarget) + 'static>(
559 this: *mut ffi::GtkDropTarget,
560 _param_spec: glib::ffi::gpointer,
561 f: glib::ffi::gpointer,
562 ) {
563 let f: &F = &*(f as *const F);
564 f(&from_glib_borrow(this))
565 }
566 unsafe {
567 let f: Box_<F> = Box_::new(f);
568 connect_raw(
569 self.as_ptr() as *mut _,
570 b"notify::actions\0".as_ptr() as *const _,
571 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
572 notify_actions_trampoline::<F> as *const (),
573 )),
574 Box_::into_raw(f),
575 )
576 }
577 }
578
579 #[cfg(feature = "v4_4")]
580 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
581 #[doc(alias = "current-drop")]
582 pub fn connect_current_drop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
583 unsafe extern "C" fn notify_current_drop_trampoline<F: Fn(&DropTarget) + 'static>(
584 this: *mut ffi::GtkDropTarget,
585 _param_spec: glib::ffi::gpointer,
586 f: glib::ffi::gpointer,
587 ) {
588 let f: &F = &*(f as *const F);
589 f(&from_glib_borrow(this))
590 }
591 unsafe {
592 let f: Box_<F> = Box_::new(f);
593 connect_raw(
594 self.as_ptr() as *mut _,
595 b"notify::current-drop\0".as_ptr() as *const _,
596 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
597 notify_current_drop_trampoline::<F> as *const (),
598 )),
599 Box_::into_raw(f),
600 )
601 }
602 }
603
604 #[cfg_attr(feature = "v4_4", deprecated = "Since 4.4")]
605 #[doc(alias = "drop")]
606 pub fn connect_drop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
607 unsafe extern "C" fn notify_drop_trampoline<F: Fn(&DropTarget) + 'static>(
608 this: *mut ffi::GtkDropTarget,
609 _param_spec: glib::ffi::gpointer,
610 f: glib::ffi::gpointer,
611 ) {
612 let f: &F = &*(f as *const F);
613 f(&from_glib_borrow(this))
614 }
615 unsafe {
616 let f: Box_<F> = Box_::new(f);
617 connect_raw(
618 self.as_ptr() as *mut _,
619 b"notify::drop\0".as_ptr() as *const _,
620 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
621 notify_drop_trampoline::<F> as *const (),
622 )),
623 Box_::into_raw(f),
624 )
625 }
626 }
627
628 #[doc(alias = "preload")]
629 pub fn connect_preload_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
630 unsafe extern "C" fn notify_preload_trampoline<F: Fn(&DropTarget) + 'static>(
631 this: *mut ffi::GtkDropTarget,
632 _param_spec: glib::ffi::gpointer,
633 f: glib::ffi::gpointer,
634 ) {
635 let f: &F = &*(f as *const F);
636 f(&from_glib_borrow(this))
637 }
638 unsafe {
639 let f: Box_<F> = Box_::new(f);
640 connect_raw(
641 self.as_ptr() as *mut _,
642 b"notify::preload\0".as_ptr() as *const _,
643 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
644 notify_preload_trampoline::<F> as *const (),
645 )),
646 Box_::into_raw(f),
647 )
648 }
649 }
650
651 #[doc(alias = "value")]
652 pub fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
653 unsafe extern "C" fn notify_value_trampoline<F: Fn(&DropTarget) + 'static>(
654 this: *mut ffi::GtkDropTarget,
655 _param_spec: glib::ffi::gpointer,
656 f: glib::ffi::gpointer,
657 ) {
658 let f: &F = &*(f as *const F);
659 f(&from_glib_borrow(this))
660 }
661 unsafe {
662 let f: Box_<F> = Box_::new(f);
663 connect_raw(
664 self.as_ptr() as *mut _,
665 b"notify::value\0".as_ptr() as *const _,
666 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
667 notify_value_trampoline::<F> as *const (),
668 )),
669 Box_::into_raw(f),
670 )
671 }
672 }
673}
674
675impl Default for DropTarget {
676 fn default() -> Self {
677 glib::object::Object::new::<Self>()
678 }
679}
680
681// rustdoc-stripper-ignore-next
682/// A [builder-pattern] type to construct [`DropTarget`] objects.
683///
684/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
685#[must_use = "The builder must be built to be used"]
686pub struct DropTargetBuilder {
687 builder: glib::object::ObjectBuilder<'static, DropTarget>,
688}
689
690impl DropTargetBuilder {
691 fn new() -> Self {
692 Self {
693 builder: glib::object::Object::builder(),
694 }
695 }
696
697 /// The `GdkDragActions` that this drop target supports.
698 pub fn actions(self, actions: gdk::DragAction) -> Self {
699 Self {
700 builder: self.builder.property("actions", actions),
701 }
702 }
703
704 /// The [`gdk::ContentFormats`][crate::gdk::ContentFormats] that determine the supported data formats.
705 pub fn formats(self, formats: &gdk::ContentFormats) -> Self {
706 Self {
707 builder: self.builder.property("formats", formats.clone()),
708 }
709 }
710
711 /// Whether the drop data should be preloaded when the pointer is only
712 /// hovering over the widget but has not been released.
713 ///
714 /// Setting this property allows finer grained reaction to an ongoing
715 /// drop at the cost of loading more data.
716 ///
717 /// The default value for this property is [`false`] to avoid downloading
718 /// huge amounts of data by accident.
719 ///
720 /// For example, if somebody drags a full document of gigabytes of text
721 /// from a text editor across a widget with a preloading drop target,
722 /// this data will be downloaded, even if the data is ultimately dropped
723 /// elsewhere.
724 ///
725 /// For a lot of data formats, the amount of data is very small (like
726 /// `GDK_TYPE_RGBA`), so enabling this property does not hurt at all.
727 /// And for local-only Drag-and-Drop operations, no data transfer is done,
728 /// so enabling it there is free.
729 pub fn preload(self, preload: bool) -> Self {
730 Self {
731 builder: self.builder.property("preload", preload),
732 }
733 }
734
735 /// The name for this controller, typically used for debugging purposes.
736 pub fn name(self, name: impl Into<glib::GString>) -> Self {
737 Self {
738 builder: self.builder.property("name", name.into()),
739 }
740 }
741
742 /// The limit for which events this controller will handle.
743 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
744 Self {
745 builder: self
746 .builder
747 .property("propagation-limit", propagation_limit),
748 }
749 }
750
751 /// The propagation phase at which this controller will handle events.
752 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
753 Self {
754 builder: self
755 .builder
756 .property("propagation-phase", propagation_phase),
757 }
758 }
759
760 // rustdoc-stripper-ignore-next
761 /// Build the [`DropTarget`].
762 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
763 pub fn build(self) -> DropTarget {
764 assert_initialized_main_thread!();
765 self.builder.build()
766 }
767}