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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
// 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 crate::{EventController, Gesture, GestureSingle, PropagationLimit, PropagationPhase};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// [`DragSource`][crate::DragSource] is an event controller to initiate Drag-And-Drop operations.
    ///
    /// [`DragSource`][crate::DragSource] can be set up with the necessary
    /// ingredients for a DND operation ahead of time. This includes
    /// the source for the data that is being transferred, in the form
    /// of a [`gdk::ContentProvider`][crate::gdk::ContentProvider], the desired action, and the icon to
    /// use during the drag operation. After setting it up, the drag
    /// source must be added to a widget as an event controller, using
    /// [`WidgetExt::add_controller()`][crate::prelude::WidgetExt::add_controller()].
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static void
    /// my_widget_init (MyWidget *self)
    /// {
    ///   GtkDragSource *drag_source = gtk_drag_source_new ();
    ///
    ///   g_signal_connect (drag_source, "prepare", G_CALLBACK (on_drag_prepare), self);
    ///   g_signal_connect (drag_source, "drag-begin", G_CALLBACK (on_drag_begin), self);
    ///
    ///   gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drag_source));
    /// }
    /// ```
    ///
    /// Setting up the content provider and icon ahead of time only makes
    /// sense when the data does not change. More commonly, you will want
    /// to set them up just in time. To do so, [`DragSource`][crate::DragSource] has
    /// [`prepare`][struct@crate::DragSource#prepare] and [`drag-begin`][struct@crate::DragSource#drag-begin]
    /// signals.
    ///
    /// The ::prepare signal is emitted before a drag is started, and
    /// can be used to set the content provider and actions that the
    /// drag should be started with.
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static GdkContentProvider *
    /// on_drag_prepare (GtkDragSource *source,
    ///                  double         x,
    ///                  double         y,
    ///                  MyWidget      *self)
    /// {
    ///   // This widget supports two types of content: GFile objects
    ///   // and GdkPixbuf objects; GTK will handle the serialization
    ///   // of these types automatically
    ///   GFile *file = my_widget_get_file (self);
    ///   GdkPixbuf *pixbuf = my_widget_get_pixbuf (self);
    ///
    ///   return gdk_content_provider_new_union ((GdkContentProvider *[2]) {
    ///       gdk_content_provider_new_typed (G_TYPE_FILE, file),
    ///       gdk_content_provider_new_typed (GDK_TYPE_PIXBUF, pixbuf),
    ///     }, 2);
    /// }
    /// ```
    ///
    /// The ::drag-begin signal is emitted after the [`gdk::Drag`][crate::gdk::Drag] object has
    /// been created, and can be used to set up the drag icon.
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static void
    /// on_drag_begin (GtkDragSource *source,
    ///                GdkDrag       *drag,
    ///                MyWidget      *self)
    /// {
    ///   // Set the widget as the drag icon
    ///   GdkPaintable *paintable = gtk_widget_paintable_new (GTK_WIDGET (self));
    ///   gtk_drag_source_set_icon (source, paintable, 0, 0);
    ///   g_object_unref (paintable);
    /// }
    /// ```
    ///
    /// During the DND operation, [`DragSource`][crate::DragSource] emits signals that
    /// can be used to obtain updates about the status of the operation,
    /// but it is not normally necessary to connect to any signals,
    /// except for one case: when the supported actions include
    /// [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE], you need to listen for the
    /// [`drag-end`][struct@crate::DragSource#drag-end] signal and delete the
    /// data after it has been transferred.
    ///
    /// ## Properties
    ///
    ///
    /// #### `actions`
    ///  The actions that are supported by drag operations from the source.
    ///
    /// Note that you must handle the [`drag-end`][struct@crate::DragSource#drag-end] signal
    /// if the actions include [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE].
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `content`
    ///  The data that is offered by drag operations from this source.
    ///
    /// Readable | Writeable
    /// <details><summary><h4>GestureSingle</h4></summary>
    ///
    ///
    /// #### `button`
    ///  Mouse button number to listen to, or 0 to listen for any button.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `exclusive`
    ///  Whether the gesture is exclusive.
    ///
    /// Exclusive gestures only listen to pointer and pointer emulated events.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `touch-only`
    ///  Whether the gesture handles only touch events.
    ///
    /// Readable | Writeable
    /// </details>
    /// <details><summary><h4>Gesture</h4></summary>
    ///
    ///
    /// #### `n-points`
    ///  The number of touch points that trigger
    /// recognition on this gesture.
    ///
    /// Readable | Writeable | Construct Only
    /// </details>
    /// <details><summary><h4>EventController</h4></summary>
    ///
    ///
    /// #### `name`
    ///  The name for this controller, typically used for debugging purposes.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `propagation-limit`
    ///  The limit for which events this controller will handle.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `propagation-phase`
    ///  The propagation phase at which this controller will handle events.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `widget`
    ///  The widget receiving the `GdkEvents` that the controller will handle.
    ///
    /// Readable
    /// </details>
    ///
    /// ## Signals
    ///
    ///
    /// #### `drag-begin`
    ///  Emitted on the drag source when a drag is started.
    ///
    /// It can be used to e.g. set a custom drag icon with
    /// [`DragSource::set_icon()`][crate::DragSource::set_icon()].
    ///
    ///
    ///
    ///
    /// #### `drag-cancel`
    ///  Emitted on the drag source when a drag has failed.
    ///
    /// The signal handler may handle a failed drag operation based on
    /// the type of error. It should return [`true`] if the failure has been handled
    /// and the default "drag operation failed" animation should not be shown.
    ///
    ///
    ///
    ///
    /// #### `drag-end`
    ///  Emitted on the drag source when a drag is finished.
    ///
    /// A typical reason to connect to this signal is to undo
    /// things done in [`prepare`][struct@crate::DragSource#prepare] or
    /// [`drag-begin`][struct@crate::DragSource#drag-begin] handlers.
    ///
    ///
    ///
    ///
    /// #### `prepare`
    ///  Emitted when a drag is about to be initiated.
    ///
    /// It returns the [`gdk::ContentProvider`][crate::gdk::ContentProvider] to use for the drag that is about
    /// to start. The default handler for this signal returns the value of
    /// the [`content`][struct@crate::DragSource#content] property, so if you set up that
    /// property ahead of time, you don't need to connect to this signal.
    ///
    ///
    /// <details><summary><h4>Gesture</h4></summary>
    ///
    ///
    /// #### `begin`
    ///  Emitted when the gesture is recognized.
    ///
    /// This means the number of touch sequences matches
    /// [`n-points`][struct@crate::Gesture#n-points].
    ///
    /// Note: These conditions may also happen when an extra touch
    /// (eg. a third touch on a 2-touches gesture) is lifted, in that
    /// situation @sequence won't pertain to the current set of active
    /// touches, so don't rely on this being true.
    ///
    ///
    ///
    ///
    /// #### `cancel`
    ///  Emitted whenever a sequence is cancelled.
    ///
    /// This usually happens on active touches when
    /// [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called on @gesture
    /// (manually, due to grabs...), or the individual @sequence
    /// was claimed by parent widgets' controllers (see
    /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
    ///
    /// @gesture must forget everything about @sequence as in
    /// response to this signal.
    ///
    ///
    ///
    ///
    /// #### `end`
    ///  Emitted when @gesture either stopped recognizing the event
    /// sequences as something to be handled, or the number of touch
    /// sequences became higher or lower than [`n-points`][struct@crate::Gesture#n-points].
    ///
    /// Note: @sequence might not pertain to the group of sequences that
    /// were previously triggering recognition on @gesture (ie. a just
    /// pressed touch sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]).
    /// This situation may be detected by checking through
    /// [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
    ///
    ///
    ///
    ///
    /// #### `sequence-state-changed`
    ///  Emitted whenever a sequence state changes.
    ///
    /// See [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know
    /// more about the expectable sequence lifetimes.
    ///
    ///
    ///
    ///
    /// #### `update`
    ///  Emitted whenever an event is handled while the gesture is recognized.
    ///
    /// @sequence is guaranteed to pertain to the set of active touches.
    ///
    ///
    /// </details>
    ///
    /// # Implements
    ///
    /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "GtkDragSource")]
    pub struct DragSource(Object<ffi::GtkDragSource, ffi::GtkDragSourceClass>) @extends GestureSingle, Gesture, EventController;

    match fn {
        type_ => || ffi::gtk_drag_source_get_type(),
    }
}

impl DragSource {
    /// Creates a new [`DragSource`][crate::DragSource] object.
    ///
    /// # Returns
    ///
    /// the new [`DragSource`][crate::DragSource]
    #[doc(alias = "gtk_drag_source_new")]
    pub fn new() -> DragSource {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gtk_drag_source_new()) }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`DragSource`] objects.
    ///
    /// This method returns an instance of [`DragSourceBuilder`](crate::builders::DragSourceBuilder) which can be used to create [`DragSource`] objects.
    pub fn builder() -> DragSourceBuilder {
        DragSourceBuilder::new()
    }

    /// Cancels a currently ongoing drag operation.
    #[doc(alias = "gtk_drag_source_drag_cancel")]
    pub fn drag_cancel(&self) {
        unsafe {
            ffi::gtk_drag_source_drag_cancel(self.to_glib_none().0);
        }
    }

    /// Gets the actions that are currently set on the [`DragSource`][crate::DragSource].
    ///
    /// # Returns
    ///
    /// the actions set on @self
    #[doc(alias = "gtk_drag_source_get_actions")]
    #[doc(alias = "get_actions")]
    pub fn actions(&self) -> gdk::DragAction {
        unsafe { from_glib(ffi::gtk_drag_source_get_actions(self.to_glib_none().0)) }
    }

    /// Gets the current content provider of a [`DragSource`][crate::DragSource].
    ///
    /// # Returns
    ///
    /// the [`gdk::ContentProvider`][crate::gdk::ContentProvider] of @self
    #[doc(alias = "gtk_drag_source_get_content")]
    #[doc(alias = "get_content")]
    pub fn content(&self) -> Option<gdk::ContentProvider> {
        unsafe { from_glib_none(ffi::gtk_drag_source_get_content(self.to_glib_none().0)) }
    }

    /// Returns the underlying [`gdk::Drag`][crate::gdk::Drag] object for an ongoing drag.
    ///
    /// # Returns
    ///
    /// the [`gdk::Drag`][crate::gdk::Drag] of the current
    ///   drag operation
    #[doc(alias = "gtk_drag_source_get_drag")]
    #[doc(alias = "get_drag")]
    pub fn drag(&self) -> Option<gdk::Drag> {
        unsafe { from_glib_none(ffi::gtk_drag_source_get_drag(self.to_glib_none().0)) }
    }

    /// Sets the actions on the [`DragSource`][crate::DragSource].
    ///
    /// During a DND operation, the actions are offered to potential
    /// drop targets. If @actions include [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE], you need
    /// to listen to the [`drag-end`][struct@crate::DragSource#drag-end] signal and
    /// handle @delete_data being [`true`].
    ///
    /// This function can be called before a drag is started,
    /// or in a handler for the [`prepare`][struct@crate::DragSource#prepare] signal.
    /// ## `actions`
    /// the actions to offer
    #[doc(alias = "gtk_drag_source_set_actions")]
    pub fn set_actions(&self, actions: gdk::DragAction) {
        unsafe {
            ffi::gtk_drag_source_set_actions(self.to_glib_none().0, actions.into_glib());
        }
    }

    /// Sets a content provider on a [`DragSource`][crate::DragSource].
    ///
    /// When the data is requested in the cause of a DND operation,
    /// it will be obtained from the content provider.
    ///
    /// This function can be called before a drag is started,
    /// or in a handler for the [`prepare`][struct@crate::DragSource#prepare] signal.
    ///
    /// You may consider setting the content provider back to
    /// [`None`] in a [`drag-end`][struct@crate::DragSource#drag-end] signal handler.
    /// ## `content`
    /// a [`gdk::ContentProvider`][crate::gdk::ContentProvider]
    #[doc(alias = "gtk_drag_source_set_content")]
    pub fn set_content(&self, content: Option<&impl IsA<gdk::ContentProvider>>) {
        unsafe {
            ffi::gtk_drag_source_set_content(
                self.to_glib_none().0,
                content.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    /// Sets a paintable to use as icon during DND operations.
    ///
    /// The hotspot coordinates determine the point on the icon
    /// that gets aligned with the hotspot of the cursor.
    ///
    /// If @paintable is [`None`], a default icon is used.
    ///
    /// This function can be called before a drag is started, or in
    /// a [`prepare`][struct@crate::DragSource#prepare] or
    /// [`drag-begin`][struct@crate::DragSource#drag-begin] signal handler.
    /// ## `paintable`
    /// the [`gdk::Paintable`][crate::gdk::Paintable] to use as icon
    /// ## `hot_x`
    /// the hotspot X coordinate on the icon
    /// ## `hot_y`
    /// the hotspot Y coordinate on the icon
    #[doc(alias = "gtk_drag_source_set_icon")]
    pub fn set_icon(&self, paintable: Option<&impl IsA<gdk::Paintable>>, hot_x: i32, hot_y: i32) {
        unsafe {
            ffi::gtk_drag_source_set_icon(
                self.to_glib_none().0,
                paintable.map(|p| p.as_ref()).to_glib_none().0,
                hot_x,
                hot_y,
            );
        }
    }

    /// Emitted on the drag source when a drag is started.
    ///
    /// It can be used to e.g. set a custom drag icon with
    /// [`set_icon()`][Self::set_icon()].
    /// ## `drag`
    /// the [`gdk::Drag`][crate::gdk::Drag] object
    #[doc(alias = "drag-begin")]
    pub fn connect_drag_begin<F: Fn(&Self, &gdk::Drag) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn drag_begin_trampoline<F: Fn(&DragSource, &gdk::Drag) + 'static>(
            this: *mut ffi::GtkDragSource,
            drag: *mut gdk::ffi::GdkDrag,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(drag))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"drag-begin\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    drag_begin_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted on the drag source when a drag has failed.
    ///
    /// The signal handler may handle a failed drag operation based on
    /// the type of error. It should return [`true`] if the failure has been handled
    /// and the default "drag operation failed" animation should not be shown.
    /// ## `drag`
    /// the [`gdk::Drag`][crate::gdk::Drag] object
    /// ## `reason`
    /// information on why the drag failed
    ///
    /// # Returns
    ///
    /// [`true`] if the failed drag operation has been already handled
    #[doc(alias = "drag-cancel")]
    pub fn connect_drag_cancel<
        F: Fn(&Self, &gdk::Drag, gdk::DragCancelReason) -> bool + 'static,
    >(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn drag_cancel_trampoline<
            F: Fn(&DragSource, &gdk::Drag, gdk::DragCancelReason) -> bool + 'static,
        >(
            this: *mut ffi::GtkDragSource,
            drag: *mut gdk::ffi::GdkDrag,
            reason: gdk::ffi::GdkDragCancelReason,
            f: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let f: &F = &*(f as *const F);
            f(
                &from_glib_borrow(this),
                &from_glib_borrow(drag),
                from_glib(reason),
            )
            .into_glib()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"drag-cancel\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    drag_cancel_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted on the drag source when a drag is finished.
    ///
    /// A typical reason to connect to this signal is to undo
    /// things done in [`prepare`][struct@crate::DragSource#prepare] or
    /// [`drag-begin`][struct@crate::DragSource#drag-begin] handlers.
    /// ## `drag`
    /// the [`gdk::Drag`][crate::gdk::Drag] object
    /// ## `delete_data`
    /// [`true`] if the drag was performing [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE],
    ///    and the data should be deleted
    #[doc(alias = "drag-end")]
    pub fn connect_drag_end<F: Fn(&Self, &gdk::Drag, bool) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn drag_end_trampoline<F: Fn(&DragSource, &gdk::Drag, bool) + 'static>(
            this: *mut ffi::GtkDragSource,
            drag: *mut gdk::ffi::GdkDrag,
            delete_data: glib::ffi::gboolean,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                &from_glib_borrow(this),
                &from_glib_borrow(drag),
                from_glib(delete_data),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"drag-end\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    drag_end_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when a drag is about to be initiated.
    ///
    /// It returns the [`gdk::ContentProvider`][crate::gdk::ContentProvider] to use for the drag that is about
    /// to start. The default handler for this signal returns the value of
    /// the [`content`][struct@crate::DragSource#content] property, so if you set up that
    /// property ahead of time, you don't need to connect to this signal.
    /// ## `x`
    /// the X coordinate of the drag starting point
    /// ## `y`
    /// the Y coordinate of the drag starting point
    ///
    /// # Returns
    ///
    /// a [`gdk::ContentProvider`][crate::gdk::ContentProvider]
    #[doc(alias = "prepare")]
    pub fn connect_prepare<F: Fn(&Self, f64, f64) -> Option<gdk::ContentProvider> + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn prepare_trampoline<
            F: Fn(&DragSource, f64, f64) -> Option<gdk::ContentProvider> + 'static,
        >(
            this: *mut ffi::GtkDragSource,
            x: libc::c_double,
            y: libc::c_double,
            f: glib::ffi::gpointer,
        ) -> *mut gdk::ffi::GdkContentProvider {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), x, y).to_glib_full()
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"prepare\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    prepare_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "actions")]
    pub fn connect_actions_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_actions_trampoline<F: Fn(&DragSource) + 'static>(
            this: *mut ffi::GtkDragSource,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::actions\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_actions_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "content")]
    pub fn connect_content_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_content_trampoline<F: Fn(&DragSource) + 'static>(
            this: *mut ffi::GtkDragSource,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::content\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_content_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for DragSource {
    fn default() -> Self {
        Self::new()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`DragSource`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct DragSourceBuilder {
    builder: glib::object::ObjectBuilder<'static, DragSource>,
}

impl DragSourceBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    /// The actions that are supported by drag operations from the source.
    ///
    /// Note that you must handle the [`drag-end`][struct@crate::DragSource#drag-end] signal
    /// if the actions include [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE].
    pub fn actions(self, actions: gdk::DragAction) -> Self {
        Self {
            builder: self.builder.property("actions", actions),
        }
    }

    /// The data that is offered by drag operations from this source.
    pub fn content(self, content: &impl IsA<gdk::ContentProvider>) -> Self {
        Self {
            builder: self.builder.property("content", content.clone().upcast()),
        }
    }

    /// Mouse button number to listen to, or 0 to listen for any button.
    pub fn button(self, button: u32) -> Self {
        Self {
            builder: self.builder.property("button", button),
        }
    }

    /// Whether the gesture is exclusive.
    ///
    /// Exclusive gestures only listen to pointer and pointer emulated events.
    pub fn exclusive(self, exclusive: bool) -> Self {
        Self {
            builder: self.builder.property("exclusive", exclusive),
        }
    }

    /// Whether the gesture handles only touch events.
    pub fn touch_only(self, touch_only: bool) -> Self {
        Self {
            builder: self.builder.property("touch-only", touch_only),
        }
    }

    /// The number of touch points that trigger
    /// recognition on this gesture.
    pub fn n_points(self, n_points: u32) -> Self {
        Self {
            builder: self.builder.property("n-points", n_points),
        }
    }

    /// The name for this controller, typically used for debugging purposes.
    pub fn name(self, name: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("name", name.into()),
        }
    }

    /// The limit for which events this controller will handle.
    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
        Self {
            builder: self
                .builder
                .property("propagation-limit", propagation_limit),
        }
    }

    /// The propagation phase at which this controller will handle events.
    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
        Self {
            builder: self
                .builder
                .property("propagation-phase", propagation_phase),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`DragSource`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> DragSource {
        self.builder.build()
    }
}